MediaWiki:Gadget-ProtectionIndicator.js
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
- Opera: натисніть Ctrl-F5
( function ( mw, $ ) {
function setMessages() {
mw.messages.set( {
'gadget-protection-autoconfirmed': 'Ця сторінка частково захищена.',
'gadget-protection-editprotected': 'Ця сторінка повністю захищена.',
'gadget-protection-move': 'Ця сторінка захищена від перейменувань'
} );
}
function init() {
var params = {
action: 'query',
prop: 'info',
titles: mw.config.get('wgPageName'),
format: 'json',
inprop: 'protection'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var cascade = 0;
for (var i in data.query.pages) {
var pages = data.query.pages[i].protection;
for (var j in pages)
if (pages[j].source != undefined) {
cascade = 1;
if ($.inArray('sysop', mw.config.get("wgUserGroups")) == -1) {
var editbutton = $('li#ca-edit').html();
if (editbutton != undefined)
$('li#ca-edit').html(editbutton.replace('Редагувати код', 'Перегляд'));
}
if (mw.config.get("wgAction") == "view")
$('div.mw-indicators').append('<div class="mw-indicator mw-indicator-protect" title="Ця сторінка захищена каскадним захистом." id="mw-indicator-protect-cascade"></div>');
break;
}
}
if (cascade == 0)
noCascade();
} );
}
function noCascade () {
// є думка, що на Головній воно неестетично...
if (mw.config.get( 'wgIsMainPage' ))
return;
var restrictions = mw.config.get( 'wgRestrictionEdit', [] ),
restrictions_move = mw.config.get('wgRestrictionMove', []),
action = mw.config.get( 'wgAction' );
if ( action === 'view' && (restrictions_move.length > 0 || restrictions.length > 0)) {
var $indicators = $( '.mw-indicators' ).first();
protectLevel = null;
if ( $indicators.find( '#mw-indicator-protected' ).length > 0 ) {
return;
}
setMessages();
if ( restrictions.indexOf( 'sysop' ) !== -1 ) {
protectLevel = 'editprotected';
} else if ( restrictions.indexOf( 'autoconfirmed' ) !== -1 ) {
protectLevel = 'autoconfirmed';
}
var protectText = mw.msg( 'gadget-protection-' + protectLevel );
$( '<div>' )
.addClass( 'mw-indicator mw-indicator-protect' )
.attr( {
id: 'mw-indicator-protect-' + protectLevel,
title: protectText,
alt: protectText
} )
.appendTo( $indicators );
if (protectLevel !== 'editprotected' && restrictions_move.indexOf('sysop') !== -1)
$( '<div>' )
.addClass( 'mw-indicator mw-indicator-protect' )
.attr( {
id: 'mw-indicator-protect-move',
title: mw.msg('gadget-protection-move'),
alt: mw.msg('gadget-protection-move')
} )
.appendTo( $indicators );
}
}
mw.loader.using('mediawiki.api').then( init );
}( mediaWiki, jQuery ) );