MediaWiki:Gadget-protect.js
Wygląd
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
- Opera: Naciśnij klawisze Ctrl+F5.
// UWAGA! Z tego gadżetu korzystają także inne projekty
// Styl .userSummaryButtons → [[Mediawiki:Common.css]]
// Autor: [[:pl:User:Beau]]
window.protectGadget = {
version: 2,
levels: [ 'edit', 'move', 'create' ],
init: function() {
if ( jQuery.inArray( mw.config.get( 'wgAction' ), ['protect', 'unprotect'] ) == -1 ) {
return;
}
for ( var i in this.levels ) {
this.addExpiryButtons( this.levels[i], pt$times );
}
var select = document.getElementById('wpProtectReasonSelection');
if ( select ) {
var reason = document.getElementsByName( 'mwProtect-reason' )[0];
var td = select.parentNode;
td.className += ' userSummaryButtons';
for ( var caption in pt$reasons ) {
var newButton = document.createElement( 'a' );
newButton.title = pt$reasons[caption];
newButton.onclick = function() {
reason.value = this.title;
};
newButton.appendChild( document.createTextNode( caption ) );
td.appendChild( newButton );
}
}
},
addExpiryButtons: function( level, times ) {
var select = document.getElementsByName( 'wpProtectExpirySelection-' + level )[0];
if ( !select ) {
return;
}
var td = select.parentNode;
td.className += ' userSummaryButtons';
for ( var caption in times ) {
var newButton = document.createElement( 'a' );
newButton.onclick = this.getExpiryHandler( level, times[caption] );
newButton.appendChild( document.createTextNode(caption) );
td.appendChild( newButton );
}
},
getExpiryHandler: function( level, value ) {
var that = this;
return function() {
that.setExpiry( level, value );
};
},
setExpiry: function( level, value ) {
var select = document.getElementsByName( 'wpProtectExpirySelection-' + level )[0];
var listed = false;
for ( var i = 0; i < select.options.length; i++ ) {
if ( select.options[i].value == value ) {
listed = true;
}
}
var selectValue;
var textValue;
if ( listed ) {
selectValue = value;
textValue = '';
}
else {
selectValue = 'othertime';
textValue = value;
}
select.value = selectValue;
if ( select.onchange ) {
select.onchange( select );
}
$(select).change();
jQuery( '#mwProtect-' + level + '-expires input' ).val( textValue );
if ( level == 'edit' && !jQuery( '#mwProtectUnchained' ).attr( 'checked' ) ) {
jQuery( '#mwProtectExpirySelection-move' ).val( selectValue );
jQuery( '#mwProtect-move-expires input' ).val( textValue );
}
}
};
jQuery(document).ready(function() {
protectGadget.init();
});