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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
jQuery(document).ready(function($){varmyContent=document.getElementsByName('wpTextbox1')[0];// -------------------------------------------------------------------------------- //varmysummary="Clean up [[:Category:Pages using duplicate arguments in template calls|duplicate template arguments]] using [[:en:User:Frietjes/findargdups|findargdups]]";if(typeoffindargdupseditsummary=='string'){mysummary=findargdupseditsummary;}varmorefound="More duplicates found, fix some and run again!";if(typeoffindargdupsmorefound=='string'){morefound=findargdupsmorefound;}varlinktext="Find dups";if(typeoffindargdupslinktext=='string'){linktext=findargdupslinktext;}varshowresultsbox=0;if(typeoffindargdupsresultsbox=='string'){showresultsbox=1;}varshowalertbox=1;if(typeoffindargdupsnoalertbox=='string'){showalertbox=0;showresultsbox=1;}varnonefound='No duplicates were found!';if(typeoffindargdupsnonefound=='string'){nonefound=findargdupsnonefound;}// -------------------------------------------------------------------------------- //if(mw.config.get('wgNamespaceNumber')!=-1&&myContent){mw.loader.using(['mediawiki.util']).done(function(){varportletlink=mw.util.addPortletLink('p-tb','#',linktext,'t-fdup');$(portletlink).click(function(e){e.preventDefault();wpFindDuplicateArgs(0);});});}// -------------------------------------------------------------------------------- //functionwpAddResultsBox(text,num){vardiv=document.getElementById('wpSummaryLabel').parentNode;if(div){if(num<2){if(document.getElementById('FindArgDupsResultsBox')){document.getElementById('FindArgDupsResultsBox').innerHTML='';}else{div.innerHTML='<div id="FindArgDupsResultsBox"></div>'+div.innerHTML;}}div1=document.getElementById('FindArgDupsResultsBox');if(div1){text=text.replace(/</g,'<');text=text.replace(/>/g,'>');div1.innerHTML=div1.innerHTML+'<div class="FindArgDupsResultsBox" '+'id="FindArgDupsResultsBox-'+num+'" '+'style="max-height:5em; overflow:auto; padding:5px; border:#aaa 1px solid; '+'background-color:cornsilk;">'+text+'</div>'+"\n";}}}functionwpClearResultsBox(){vardiv=document.getElementById('wpSummaryLabel').parentNode;if(div){if(document.getElementById('FindArgDupsResultsBox')){document.getElementById('FindArgDupsResultsBox').innerHTML='';}}}// -------------------------------------------------------------------------------- //functionwpFindDuplicateArgs(debugflag){// Flag used to determine if we have issued an alert popupvaralertissued=0;// Flag used to determine if we've selected one of the problem templates yetvarselectedone=false;// Internal for and while loop variablesvari=0;varj=0;varloopcount=0;// Array used to hold the list of unnested templatesvartlist=[];// Regular expression which matchs a template argvarargexp=newRegExp("\\|[\\s]*([^\\s=\\|\\[\\]\\{\\}][^=\\|\\[\\]\\{\\}]*[^\\s=\\|\\[\\]\\{\\}]|[^\\s=\\|\\[\\]\\{\\}]|)[\\s]*=","gm");// Copy the contents of the text window so we can modify it without problemsvarmytxt=myContent.value;// Remove some includeonly, noinclude, and onlyinclude tagsmytxt=mytxt.replace(/<\/?[ ]*(?:includeonly|noinclude|onlyinclude)[ ]*>/gi,'');// Remove PAGENAME, BASEPAGENAME, ... nested inside of triple bracesmytxt=mytxt.replace(/\{\{\{[^\{\}]*\|[ ]*\{\{[A-Z]+\}\}\}\}\}/g,'');// Mangle some ref tagsmytxt=mytxt.replace(/(<ref[^<>=]*name[ ]*)=/gi,'$1=');mytxt=mytxt.replace(/(<ref[^<>=]*group[ ]*)=/gi,'$1=');// Mangle some math tagsloopcount=0;while((mytxt.search(/<[\s]*math[^<>]*>[^<>=]*=/gi)>=0)&&(loopcount<10)){mytxt=mytxt.replace(/(<[\s]*math[^<>]*>[^<>=]*)=/gi,'$1=');loopcount++;}// Remove some triple braces and parserfunctions inside of triple bracesloopcount=0;while((mytxt.search(/\{\{\{[^\{\}]*\}\}\}/g)>=0)&&(loopcount<5)){mytxt=mytxt.replace(/\{\{\{[^\{\}]*\}\}\}/g,'');mytxt=mytxt.replace(/\{\{#[a-z]+:[^{}=]*\}\}/gi,'');loopcount++;}// Replace some bare braces with HTML equivalentmytxt=mytxt.replace(/([^\{])\{([^\{])/g,'$1{$2');mytxt=mytxt.replace(/([^\}])\}([^\}])/g,'$1}$2');// Remove newlines and tabs which confuse the regexp searchmytxt=mytxt.replace(/[\s]/gm,' ');// Compress whitespacemytxt=mytxt.replace(/[\s][\s]+/gm,' ');// Remove some nowiki and pre textmytxt=mytxt.replace(/<nowiki[^<>]*>(?:<[^\/]|[^<])*<\/nowiki[^<>]*>/gi,'');mytxt=mytxt.replace(/<pre[^<>]*>(?:<[^\/]|[^<])*<\/pre[^<>]*>/gi,'');// Remove some HTML commentsmytxt=mytxt.replace(/<!--(?:[^>]|[^\-]>|[^\-]->)*-->/gm,'');// Modify some = inside of file/image/wikilinks which cause false positivesloopcount=0;while((mytxt.search(/\[\[[^\[\]\{\}]*=/gi)>=0)&&(loopcount<5)){mytxt=mytxt.replace(/(\[\[[^\[\]\{\}]*)=/gi,'$1=');loopcount++;}// Now start unnesting the templatesloopcount=0;while((mytxt.search(/(?:\{\{|\}\})/g)>=0)&&(loopcount<20)){// Replace some bare braces with HTML equivalentmytxt=mytxt.replace(/([^\{])\{([^\{])/g,'$1{$2');mytxt=mytxt.replace(/([^\}])\}([^\}])/g,'$1}$2');// Split into chunks, isolating the unnested templatesvarstrlist=mytxt.split(/(\{\{[^\{\}]*\}\})/);// Loop through the chunks, removing the unnested templatesfor(i=0;i<strlist.length;i++){if(strlist[i].search(/^\{\{[^\{\}]*\}\}$/)>=0){tlist.push(strlist[i]);strlist[i]='';}}// Join the chunks back together for the next iterationmytxt=strlist.join('');loopcount++;}// Preprocess some = signs inside of non-citation-templated citationsfor(i=0;i<tlist.length;++i){j=0;while((tlist[i].search(/<ref[^<>\/]*>(?:<[^\/]|[^<])*=/gi)>=0)&&(j<50)){tlist[i]=tlist[i].replace(/(<ref[^<>\/]*>(?:<[^\/]|[^<])*)=/gi,'$1=');}}// Now find duplicates in the list of unnested templatesfor(i=0;i<tlist.length;++i){// Add numbers for unnamed parametersvarunp=0;tlist[i]=tlist[i].replace(/(\{\{[\s_]*#invoke[\s ]*:[^{}\|]*)\|([^{}\|=]*\|)/gi,'$1|0=$2');while((tlist[i].search(/(\{\{(?:[^{}\[\]]|\[\[[^\[\]]*\]\])*?\|)((?:[^{}\[\]=\|]|\[[^\[\]=]*\]|\[\[[^\[\]]*\]\])*(?:\||\}\}))/)>=0)&&(unp<25)){unp++;tlist[i]=tlist[i].replace(/(\{\{(?:[^{}\[\]]|\[\[[^\[\]]*\]\])*?\|)((?:[^{}\[\]=\|]|\[[^\[\]=]*\]|\[\[[^\[\]]*\]\])*(?:\||\}\}))/,'$1'+unp+'=$2');}// Array to hold any found duplicate args (reduce number of alerts)varf=[];// Split the template into an array of | arg = ... stringsvarp=tlist[i].match(argexp);if(p){for(j=0;j<p.length;++j){p[j]=p[j].replace(argexp,'$1');}p=p.sort();for(j=0;j<p.length-1;++j){if(p[j]==p[j+1]){f.push(p[j]);}}}if(f.length>0){alertissued=alertissued+1;if(alertissued<5){if(!selectedone){varselectmatch=myContent.value.match(tlist[i].replace(/[.*+?^${}()|[\]\\]/g,'\\$&').replace(/\s+/g,'\\s*'));if(selectmatch!==null){myContent.setSelectionRange(selectmatch.index,selectmatch.index+selectmatch[0].length);selectedone=true;}}if(showresultsbox>0){wpAddResultsBox('Duplicate \"'+f.join('\", \"')+'\" in\n'+tlist[i],alertissued);}if(showalertbox>0){alert('\"'+f.join('\", \"')+'\" in\n'+tlist[i]);}}elseif(alertissued==6){alert(morefound);}}}if(alertissued){vareditsummary=document.getElementsByName('wpSummary')[0];if(typeofeditsummary=='object'){if(editsummary.value.indexOf(mysummary)==-1){if(editsummary.value.match(/[^\*\/\s][^\/\s]?\s*$/)){editsummary.value+='; '+mysummary;}else{editsummary.value+=mysummary;}}}if(selectedone){setTimeout(function(){myContent.focus();},0);}}elseif(nonefound.trim().length>0){mw.notify(nonefound);}else{if(showresultsbox>0){wpClearResultsBox();}}}// -------------------------------------------------------------------------------- //});