MediaWiki:Gadget-ppIndicators.js

// Testcases can be found on User:Technical 13/Protection tests //  var protectionLevel; var isMW = ( mw.config.get( 'wgCanonicalNamespace' ) === 'MediaWiki' ? true : false ); var isSpecial = ( mw.config.get( 'wgCanonicalNamespace' ) === 'Special' ? true : false ); var isUserCssJs = false; var editUserCssJs = false; if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User' &&// IF it is User: space   ( mw.config.get( 'wgPageContentModel' ) === 'javascript' ||// AND is .js    mw.config.get( 'wgPageContentModel' ) === 'css' ) ) {// OR .css isUserCssJs = true; } if ( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) ||// IF it is current user's space    $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) !== -1 ) {// OR is an administrator editUserCssJs = true; } function createDie( edit, move, title ) { var piClass = edit.toLowerCase + '-' + move.toLowerCase; if ( edit.toLowerCase === move.toLowerCase ) { ppSection = ( edit.toUpperCase === 'PURPLE' ? 'PP' : edit.toUpperCase + 'DIE' ); ppIcon = edit; } else { ppSection = edit.toUpperCase + move.toUpperCase + 'DIE'; ppIcon = edit + move; }   var imgSource = 'https://ddowiki.com/images/' + ppIcon + '_d20.png'; var imgStyle = 'style="width: 16px; height: 16px;"'; var imgIcon = ''; var anchorLink = '' + imgIcon + ''; return lineItem = '' + anchorLink + ''; } if ( !isMW && !isSpecial && ( !isUserCssJs || editUserCssJs ) ) {// No need to do all this processing if it's not editable var editLevel = mw.config.get( 'wgRestrictionEdit' );// Get the edit protection flag for page if ( editLevel == '' || editLevel == 'undefined' || editLevel == null ) { editLevel = 'none';// page isn't protected at all } else { if ( $.inArray( 'sysop', editLevel ) >= 0 ) { editLevel = 'full';// sysop is full }     else if ( $.inArray( 'autoconfirmed', editLevel ) >= 0 ) { editLevel = 'semi';// autoconfirmed is semi } else { editLevel = 'none';// otherwise there's none }   }    var moveLevel = mw.config.get( 'wgRestrictionMove' );// Get the move protection flag for page if ( moveLevel == '' || moveLevel == 'undefined' || moveLevel == null ) { moveLevel = 'none';// page isn't protected at all } else { if ( $.inArray( 'sysop', moveLevel ) >= 0 ) { moveLevel = 'full';// sysop is full }     else if ( $.inArray( 'autoconfirmed', moveLevel ) >= 0 ) { moveLevel = 'semi';// autoconfirmed is semi } else { moveLevel = 'none';// otherwise there's none }   }    protectionLevel = editLevel + '/' + moveLevel; } if ( isSpecial ) { $( 'li#pt-userpage' ).before( createDie( 'Black', 'Black', 'Special page' ) ); } else if ( isMW ) { $( 'li#pt-userpage' ).before( createDie( 'Black', 'Black', 'User Interface page' ) ); } else if ( isUserCssJs && !editUserCssJs ) { $( 'li#pt-userpage' ).before( createDie( 'Black', 'Black', 'User CSS or JavaScript page' ) ); } else if ( protectionLevel === 'full/full' ) { $( 'li#pt-userpage' ).before( createDie( 'Red', 'Red', 'Full protection enabled' ) ); } else if ( protectionLevel === 'full/semi' ){ $( 'li#pt-userpage' ).before( createDie( 'Red', 'Blue', 'Full/Semi protection enabled' ) ); } else if ( protectionLevel === 'full/none' ){ $( 'li#pt-userpage' ).before( createDie( 'Red', 'Purple', 'Full edit protection enabled' ) ); } else if ( protectionLevel === 'semi/full' ){ $( 'li#pt-userpage' ).before( createDie( 'Blue', 'Red', 'Semi/Full protection enabled' ) ); } else if ( protectionLevel === 'semi/semi' ){ $( 'li#pt-userpage' ).before( createDie( 'Blue', 'Blue', 'Semi protection enabled' ) ); } else if ( protectionLevel === 'semi/none' ){ $( 'li#pt-userpage' ).before( createDie( 'Blue', 'Purple', 'Semi edit protection enabled' ) ); } else if ( protectionLevel === 'none/full' ){ $( 'li#pt-userpage' ).before( createDie( 'Purple', 'Red', 'Full move protection enabled' ) ); } else if ( protectionLevel === 'none/semi' ){ $( 'li#pt-userpage' ).before( createDie( 'Purple', 'Blue', 'Semi move protection enabled' ) ); } else { $( 'li#pt-userpage' ).before( createDie( 'Purple', 'Purple', 'Not protected' ) ); } //