User:Jonesey95/AutoEd/authorlink.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Jonesey95/AutoEd/authorlink. |
var AutoEd_baseurl = 'http://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Jonesey95/AutoEd/';
if (location.protocol === 'https:') {
AutoEd_baseurl = 'https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Jonesey95/AutoEd/';
}
mw.loader.load(AutoEd_baseurl + 'core7.js'); //Imports the "framework" script needed to make this function
//Sets variable configuration
autoEdTag7 = "Fixing citation [[:Category:CS1 errors: parameter link|parameter link]] parameter error using [[WP:AutoEd|AutoEd]]"; //Tweaks edit summary
autoEdLinkName7 = "AutoEd param-link"; //Changes the link name at the top of the page
autoEdLinkHover7 = "Run AutoEd to fix param-link error"; //When user hovers over link
//Set up function
function ReplaceParamlink(str) { //function to remove or fix param-link parameter
//Fix URL to a Wikipedia page
str = str.replace(/(\|\s*[abcdehilnoprstu]+\d*)(-*link\d*\s*=\s*)https*\:\/\/en\.wikipedia\.org\/wiki\/([a-z\d\.\/\_\s\(\)#:]+\s*[\}\|])/gi, '$1$2$3');
//Change param-link parameter to URL (may produce false positives - watch out) (exclude "series-link" because url goes with title)
str = str.replace(/\|\s*(?!series)[abcdehilnoprstu]+\d*-*link\d*\s*=\s*(https*\:\/\/[a-z\d\.\/\~\?\=\&\+\#\%\-\_\,\:\@\(\)\s\;]+\s*[\}\|])/gi, '\| url = $1');
//Remove URL from series-link parameter (watch for false positives that should be url= )
str = str.replace(/(\|\s*series\d*-*link\d*\s*=\s*)https*\:\/\/[a-z\d\.\/\~\?\=\&\+\#\%\-\_\,\:\@\(\)\s\;]+(\s*[\}\|])/gi, '$1$2');
//Remove brackets from param-link parameter
str = str.replace(/(\|\s*[abcdehilnoprstu]+\d*)(-*link\d*\s*=\s*)\[*([a-z\d\.\/\~\?\=\&\+\#\%\-\_\,\:\@\(\)\s\;]+)\]+(\s*[\}\|])/gi, '$1$2$3$4');
//Replace blank URL parameter (to prevent duplicate URL parameters after the above changes)
str = str.replace(/({{\s*[cC]it[ea](?:[^}{]*(?:\{\{[^}{]*}}[^}{]*)*))\|\s*url*\s*=\s*([\}\|])/gi, '$1 $2');
return str;
}
function autoEdFunctions7() { //Activates individual modules when "auto ed" tab is clicked
var txt = document.editform.wpTextbox1;
txt.value = ReplaceParamlink(txt.value);
// txt.value = autoEdWhitespace(txt.value);
}