Jump to content
Wikipedia The Free Encyclopedia

User:Zackmann08/AddCheckForClobberedParameters.js

From Wikipedia, the free encyclopedia
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.
This user script seems to have a documentation page at User:Zackmann08/AddCheckForClobberedParameters.
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.
 //<nowiki>
 jQuery(document).ready(function($){

 // Disable in article namespace as it shouldn't ever be used there
 if(mw.config.get('wgNamespaceNumber')!=0&&document.getElementsByName('wpTextbox1')[0]){
 mw.loader.using(['mediawiki.util']).done(function(){
 varportletlink=mw.util.addPortletLink('p-tb','#','Chk4Clob','t-cfu');
 $(portletlink).click(function(e){
 e.preventDefault();
 wpBuildCheckForClobberedParameters();
 });
 });
 }
 // -------------------------------------------------------------------------------- //
 functionwpBuildCheckForClobberedParameters()
 {
 varalready_added=false;

 // Send {{clobbered parameters category|template_title}} to the clipboard to make the next step easier
 vartemplate_title=mw.config.get('wgTitle');
 template_title=template_title.replace(/(.*)\/sandbox/,"1ドル");
 varpaste_text="{{clobbered parameters category|"+template_title+"}}";

 vardummy=$('<input>').val(paste_text).appendTo('body').select();
 document.execCommand('copy');

 varmycontent=document.getElementById('wpTextbox1');
 // Copy the contents of the text window so we can modify it without problems
 varmytxt=mycontent.value;
 varoriginal_text=mycontent.value;
 // Make sure we haven't already done this before
 if(mytxt.search(/\{\{#invoke:[Cc]heck[_ ]+for[_ ]+clobbered[_ ]+parameters/g)>=0){
 already_added=true;
 alert('Already added, attempting to replace. CHECK DIFF CAREFULLY');
 }

 myfullpagename=mw.config.get('wgPageName');
 myfullpagename=myfullpagename.replace(/_/g,' ');
 myfullpagename=myfullpagename.replace(/\/sandbox$/,'');
 mypagename=myfullpagename.replace(/^Template:/,'');
 mypagename=mypagename.charAt(0).toLowerCase()+mypagename.slice(1);
 mypagename=mypagename.replace(/^wikiProject/,'WikiProject');

 // // Attempt to remove the previous incarnation of {{#invoke:Check for unknown parameters
 // if (already_added) {
 // 		mycontent.value = mycontent.value.replace(/{{#invoke:[Cc]heck[_ ]+for[_ ]+unknown[_ ]+parameters[\W\w]*}}\s*<noinclude>/, '<noinclude>');
 // }

 // Finally, build the blank template

 mytxt='{'+'{#invoke:'
 +'Check for clobbered parameters|check\n'
 +'| template = [['+myfullpagename+']]\n'
 +'| cat = {'+'{main other|Category:Pages using '+mypagename+' with conflicting parameters}}\n';

 constalias_regex=/\|\s*\_alias\-map\s*=\s*([^\|]+)/;
 varalias_map=original_text.match(alias_regex);
 varaliases=[];
 if(alias_map&&alias_map[1]){
 aliases=alias_map[1].split(',');
 for(leti=0;i<aliases.length;i++){
 mytxt=mytxt+'| '+aliases[i].trim().split(':')[0]+'; '+aliases[i].trim().split(':')[1]+'\n';
 }
 }

 constif_empty_regex=/(\{\{if empty\s*\|(?:\{\{\{[^\{\}]*\}\}\}|[^\{\}])*\}\})/gmi;
 // var allMatches = original_text.matchAll(if_empty_regex);
 constallMatches=[...original_text.matchAll(if_empty_regex)];


 //TODO: Check for no matches...
 if(allMatches&&allMatches[0]&&allMatches[0][0]){
 for(leti=0;i<allMatches.length;i++){
 varmatch=allMatches[i][0];
 match=match.replace(/\|\}\}\}/g,'}}}');

 constparams=[...match.matchAll(/\{\{\{([\w\s\-\(\)]+)\}\}\}/gm)];
 varnew_param='| ';
 if(params.length>1){
 for(letj=0;j<params.length;j++){
 new_param=new_param+params[j][1]+'; ';
 }
 new_param=new_param.replace(/;([^;]*)$/gm,'1ドル');
 mytxt=mytxt+new_param+'\n';
 }
 }
 }
 mytxt=mytxt+"}}";

 alert('Clobbered param check added with '+
 aliases.length+
 ' alias parameters & '+
 allMatches.length+
 ' ifEmpty parameters.');

 mycontent.value=mycontent.value+mytxt;
 // Move up
 mycontent.value=mycontent.value.replace(/([\r\n \t][\r\n \t]*)(\{\{#invoke:Check for clobbered parameters(?:\{\{(?:\{\{[^{}]*\}\}|[^{}])*\}\}|[^{}])*\}\})/gi,'2ドル1ドル');
 mycontent.value=mycontent.value.replace(/(<noinclude>(?:<!--[^<>]*-->|[^<>])*<\/noinclude>)(\{\{#invoke:Check for clobbered parameters(?:\{\{(?:\{\{[^{}]*\}\}|[^{}])*\}\}|[^{}])*\}\})/gi,'2ドル1ドル');
 mycontent.value=mycontent.value.replace(/([\r\n \t][\r\n \t]*)(\{\{#invoke:Check for clobbered parameters(?:\{\{(?:\{\{[^{}]*\}\}|[^{}])*\}\}|[^{}])*\}\})/gi,'2ドル1ドル');

 if(already_added){
 mysummary='Updating clobbered parameter tracking through ['
 +'[:Category:Pages using '+mypagename+' with conflicting parameters]] using ['
 +'[User:Zackmann08/AddCheckForClobberedParameters.js|AddCheckForClobberedParameters]]'
 +' using [[Module:check for clobbered parameters]]';
 }else{
 mysummary='Adding clobbered parameter tracking through ['
 +'[:Category:Pages using '+mypagename+' with conflicting parameters]] using ['
 +'[User:Zackmann08/AddCheckForClobberedParameters.js|AddCheckForClobberedParameters]]'
 +' and [[Module:check for clobbered parameters]]';
 }

 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;
 }
 }
 }

 }
 // -------------------------------------------------------------------------------- //
 });
 //</nowiki>

AltStyle によって変換されたページ (->オリジナル) /