MediaWiki:HideButtonsFromNonGsProjects.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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* HideButtonsFromNonGsProjects.js
 * by Quentinv57 on 2010-12-30 (to make stewards life easier :D)
 * feel free to use, copy or modify my script
 * (function UserIsInGroup by Mike.lifeguard)
 * Forked from [[User:Quentinv57/HideButtonsFromNonGsProjects.js]]; revid. #20525604
 * @license CC-BY-SA-3.0 and GFDL
 */
 
var dbName = mw.config.get('wgDBname');
var canonicalNamespace = mw.config.get('wgCanonicalNamespace');
var canonicalSpecialPageName = mw.config.get('wgCanonicalSpecialPageName');

function in_array (string, array) {
    var i = '';
        for (i in array) {
            if (array[i] == string) {
                return true;
            }
        }
    return false;
}

function userIsInGroup (group) {
	var wgUserGroups = mw.config.get( 'wgUserGroups' );
    //are they in a given local group?
	if (wgUserGroups) {
		if (!group || group.length === 0) group = '*';
		if (wgUserGroups.join (' ').indexOf (group) != -1){
			return true;
		}
		else{
			return false;
		}
	}
	return false;
}

function IsGlobalSysopWiki () {
    var nonGSwikis = ["alswiki","anwiki","arwiki","betawikiversity","bgwiki","bnwiki","bswiki","cawiki","commonswiki","cswiki","cswikisource","cswiktionary","cywiki","dawiki","dewiki","dewikibooks","dewikisource","dewikivoyage","dewiktionary","elwiki","enwiki","enwikinews","enwikiquote","enwikisource","enwiktionary","eowiki","eswiki","eswikinews","etwiki","euwiki","fawiki","fiwiki","frwiki","frwikibooks","frwikisource","frwikiversity","frwiktionary","glwiki","hewiki","hewikisource","hrwiki","huwiki","idwiki","iswiki","itwiki","jawiki","kawiki","kowiki","lawiki","loginwiki","ltwiki","lvwiki","metawiki","mkwiki","mlwiki","mrwiki","mswiki","nlwiki","nlwikibooks","nlwiktionary","nnwiki","nowiki","plwiki","plwikimedia","plwikiquote","plwikisource","plwiktionary","ptwiki","rowiki","ruwiki","sewikimedia","simplewiki","skwiki","slwiki","sourceswiki","specieswiki","srwiki","svwiki","svwiktionary","tawiki","testwiki","tewiki","thwiki","tlwiki","trwiki","urwiki","viwiki","wikidatawiki","zh_yuewiki","zhwiki"];
    
    if( in_array(dbName, nonGSwikis) ) {
        return false;
    } else {
        return true;
    }
}


// Beginning -------------------------------------------------------------------------- 
if (userIsInGroup('sysop')) {
        $('#p-personal ul').prepend( $.parseHTML( '<li id="pt-gsinfo" style="color:green">[local sysop]</li>' ) );
 
} else if (IsGlobalSysopWiki()) {
        $('#p-personal ul').prepend( $.parseHTML( '<li id="pt-gsinfo" style="color:blue">[GS wiki]</li>' ) );
 
} else {
        $('#p-personal ul').prepend( $.parseHTML( '<li id="pt-gsinfo" style="color:red">[non-GS wiki]</li>' ) );
 
        // buttons become red
        $('#ca-delete, #ca-protect, #ca-unprotect').css('background-color', 'red');
 
        // warning if the deletion/protection/block page is opened
        if (location.href.match(/&action=delete/))
                $('#deleteconfirm').prepend( $.parseHTML( '<p id="wpDeleteWarning" style="color:red; font-size:200%; text-align: center">Warning: you\'re about to delete a page on a non-GS wiki!</p>' ) );
 
        if (location.href.match(/&action=(un)?protect/))
                $('#mw-Protect-Form').prepend( $.parseHTML( '<p id="wpProtectWarning" style="color:red; font-size:200%; text-align: center">Warning: you\'re about to protect a page on a non-GS wiki!</p>' ) );
 
        if (canonicalNamespace=='Special' && canonicalSpecialPageName == 'Block')
                $('form:first').prepend( $.parseHTML( '<p id="wpBlockWarning" style="color:red; text-align: center"><span style="font-size:200%">Warning: you\'re about to block a user on a non-GS wiki!</span><br />This should be done for emergencies only.</p>' ) );
 
        if (canonicalNamespace=='Special' && canonicalSpecialPageName == 'Revisiondelete')
                $('form:first').prepend( $.parseHTML( '<p id="wpDeleterevisionWarning" style="color:red; text-align: center; font-size:200%">Warning: you\'re about to delete a revision on a non-GS wiki!</p>' ) );
}