User:WhitePhosphorus/js/GS Rationale.js
Appearance
From Meta, a Wikimedia project coordination wiki
< User:WhitePhosphorus | js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* * Script that adds several global sysop delete, block and protect reasons to * action=delete, action=(un)protect and Special:Block forms * and append a "(global sysop action)" suffix to Special:Nuke rationale. * If you are a steward, the suffix will change correspondingly * * Reasons provided by Mathonius and Trijnstel, modified by WhitePhosphorus * Rewritten by [[User:Hoo man]] * Rewritten again by [[User:WhitePhosphorus]] for OOUI support and more * * For more info: https://meta.wikimedia.org/wiki/User:WhitePhosphorus/GS_Rationale * * <nowiki> */ /*global mw*/ $(asyncfunction(){ "use strict"; mw.loader.using(['oojs-ui-core','oojs-ui-widgets'],asyncfunction(){ if(mw.config.get('wgAction')!=='delete'&& !mw.config.get('wgAction').includes('protect')/* protect, unprotect */&& mw.config.get('wgCanonicalSpecialPageName')!=='Block'&& mw.config.get('wgCanonicalSpecialPageName')!=='Nuke'&& mw.config.get('wgCanonicalSpecialPageName')!=='Undelete'){ return; } // not loading if user is local admin // but will still load on wikis having, say, "deleters" groups. if(mw.config.get('wgUserGroups',[]).includes('sysop')){ return; } if(typeof(window.p4js_gs_rationale)!=='object')window.p4js_gs_rationale={}; letsuffix=""; constgroups=mw.config.get('wgGlobalGroups',[]); if(groups.includes('global-sysop')){ suffix=" ([[m:GS|global sysop]] action)"; }elseif(groups.includes('steward')){ suffix=" ([[m:steward|steward]] action)"; } constcommonReasons=window.p4js_gs_rationale.common||[]; // Reasons for both delete and block constadditionalReasons= commonReasons.concat(window.p4js_gs_rationale.del_block||[ "Spam", "Vandalism", ]); // Reasons for delete only letadditionalDelete= additionalReasons.concat(window.p4js_gs_rationale.del||[ "No useful content", "Nonsense", "Test page", "Not written in this project's language", "Requested by the author", "Outside the project's scope", "Empty", "Broken redirect", ]); additionalDelete=additionalDelete.map(function(r){returnr+suffix;}); // Reasons for blocks only letadditionalBlock= additionalReasons.concat(window.p4js_gs_rationale.block||[ "Intimidating behaviour/harassment", "Cross-wiki vandalism", "Spambot", "Spam-only account", "Open proxy ([[m:No open proxies|more info]])", ]); additionalBlock=additionalBlock.map(function(r){returnr+suffix;}); // Reasons for protection only letadditionalProtect= commonReasons.concat(window.p4js_gs_rationale.protect||[ "Persistent vandalism", "Persistent spamming", "Page-move vandalism", "Protection against re-creation", "Protection no longer required", ]); additionalProtect=additionalProtect.map(function(r){returnr+suffix;}); if(mw.config.get('wgAction')==='delete'){ // Append reasons to action=delete letOOUIoptions=$.map(additionalDelete,function(option){ return{label:option,data:option}; }); OOUIoptions.unshift({optgroup:"Global sysop/Steward reasons",data:undefined}); letOOUIselect=OO.ui.DropdownWidget.static.infuse($('#wpDeleteReasonList')); // I doubt this is kind of a hack and am not familiar with OOUI :/ // directly pass items to setOptions will remain `disabled` being true if(window.p4js_gs_rationale.position==='top'){ // Prevent local reasons without an optgroup from showing below global reasons OOUIoptions.push({optgroup:"Local Reasons",data:undefined}); OOUIselect.setOptions(OOUIoptions.concat( $.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }))); }else{ // bottom OOUIselect.setOptions($.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }).concat(OOUIoptions)); } }elseif(mw.config.get('wgAction').includes('protect')){ letOOUIoptions=$.map(additionalProtect,function(option){ return{label:option,data:option}; }); OOUIoptions.unshift({optgroup:"Global sysop/Steward reasons",data:undefined}); letOOUIselect=OO.ui.DropdownInputWidget.static.infuse($('#wpProtectReasonSelection')); if(window.p4js_gs_rationale.position==='top'){ // Prevent local reasons without an optgroup from showing below global reasons OOUIoptions.push({optgroup:"Local Reasons",data:undefined}); OOUIselect.setOptions(OOUIoptions.concat( $.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }))); }else{ // bottom OOUIselect.setOptions($.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }).concat(OOUIoptions)); } }elseif(mw.config.get('wgCanonicalSpecialPageName')==='Nuke'){ // Special:Nuke $('input[name=wpReason]').val($('input[name=wpReason]').val()+suffix); }elseif(mw.config.get('wgCanonicalSpecialPageName')==='Undelete'){ // Special:Undelete $('#wpComment').val($('#wpComment').val()+suffix); }else{ // Special:Block letOOUIoptions=$.map(additionalBlock,function(option){ return{label:option,data:option}; }); OOUIoptions.unshift({optgroup:"Global sysop/Steward reasons",data:undefined}); letOOUIselect=OO.ui.DropdownInputWidget.static.infuse($('#mw-input-wpReason')).dropdowninput; if(window.p4js_gs_rationale.position==='top'){ // Prevent local reasons without an optgroup from showing below global reasons OOUIoptions.push({optgroup:"Local Reasons",data:undefined}); OOUIselect.setOptions(OOUIoptions.concat( $.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }))); }else{ // bottom OOUIselect.setOptions($.map(OOUIselect.dropdownWidget.menu.items,function(option){ returnoption.data?{label:option.label,data:option.data}:{optgroup:option.label,data:undefined}; }).concat(OOUIoptions)); } // If GS reasons are selected, // we need to unselect it and put it into the "Other:" field // or there will be a "htmlform-select-badoption" error $('button[type=submit]').click( function(){ letblockReason=OOUIselect.value; if(additionalBlock.includes(blockReason)){ if($('input[name=wpReason-other]').val()){ blockReason+=(': '+$('input[name=wpReason-other]').val()); } $('input[name=wpReason-other]').val(blockReason); OOUIselect.setValue(OOUIselect.defaultValue); } } ); } }); }); /* </nowiki> */