MediaWiki:Gadget-ProtectionIndicators.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.
( function () {

	var restrictions = mw.config.get( 'wgRestrictionEdit' );
	var action = mw.config.get( 'wgAction' );
	var isMainPage = mw.config.get( 'wgIsMainPage' );

	if ( !restrictions || !restrictions.length || action !== 'view' || isMainPage ) {
		return;
	}

	var protectLevel;
	if ( restrictions.indexOf( 'sysop' ) !== -1 ) {
		protectLevel = 'editprotected';
	} else if ( restrictions.indexOf( 'autoconfirmed' ) !== -1 ) {
		protectLevel = 'autoconfirmed';
	} else {
		return;
	}

	var $indicators = $( '.mw-indicators' ).first();
	if ( $indicators.find( '#mw-indicator-protected' ).length ) {
		return;
	}

	var translations = require( './ProtectionIndicators-i18n.json' );
	$.i18n().load( translations );

	var protectText = $.i18n( 'gadget-protection-' + protectLevel );

	$( '<div>' )
		.prop( {
			id: 'mw-indicator-protect-' + protectLevel,
			title: protectText,
			alt: protectText,
			className: 'mw-indicator mw-indicator-protect'
		} )
		.appendTo( $indicators );

}() );