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.
/* * filterDiff: Adds a "show changes" button to the filter editor. * Also warns about edit conflicts. */// <nowiki>// jshint esnext: false, esversion: 8(function(){/* globals $, mw, OO */'use strict';letfilterId=null;functionmakeWindow(title,$content){$content.dialog({width:mw.util.$content.width()*0.75,height:window.innerHeight*0.65,title:title});}functionnormEnds(str){returnstr.replace(/\r\n/g,'\n').replace(/\n*$/,'');}asyncfunctionshowChanges(){let$div=$('<div></div>');letresponse=await(newmw.Api()).get({action:"query",list:"abusefilters",abfstartid:filterId,abflimit:1,abfprop:"pattern"}).catch(()=>null);letoldPattern,curPattern,newPattern;try{letdump=JSON.parse($('#mw-abusefilter-export textarea').val());oldPattern=normEnds(dump.data.rules);curPattern=normEnds(response.query.abusefilters[0].pattern);newPattern=normEnds($('#wpFilterRules').val());}catch(e){mw.notify("filterDiff: Incomplete response from API or missing DOM element.");return;}if(curPattern!==oldPattern){$div.append($('<div></div>',{style:"font-size: 125%; font-color: black; background: #FB6;",text:"Someone else has modified the pattern! Your changes will overwrite theirs."}));}if(newPattern===curPattern){$div.append($('<div></div>',{style:"font-size: 125%; font-color: black; text-align: center;",text:"(pattern unchanged)"}));}else{letr=await(newmw.Api()).post({action:"compare",fromslots:"main",toslots:"main","fromtext-main":curPattern,"totext-main":newPattern}).catch(()=>null);try{$div.append('<table class="diff diff-contentalign-left diff-editfont-monospace"><colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup><tbody>'+r.compare["*"]+'</tbody></table></div>');}catch(e){mw.notify("filterDiff: Incomplete response from API");return;}}makeWindow("Difference between patterns",$div);}functionaddButtons(){filterId=mw.config.get('wgPageName').match(/(?:history)?\/([0-9]+)/);if(!filterId||!$("#mw-abusefilter-editing-form").length)return;filterId=filterId[1];letdiffButton=newOO.ui.ButtonWidget({id:"efb-show-changes",label:"Show changes",title:"Compare your version of the pattern with the version currently in the database"});diffButton.on('click',showChanges);$('#mw-abusefilter-syntaxcheck').after(diffButton.$element);/* Prevent buttons from shifting when "Check syntax" is clicked */mw.util.addCSS(".mw-spinner { display: none; } ");}if(mw.config.get('wgCanonicalSpecialPageName')=="AbuseFilter")$.when($.ready,mw.loader.using(['mediawiki.util','mediawiki.api','mediawiki.diff.styles','oojs-ui','jquery.ui',])).then(addButtons);})();//</nowiki>