MediaWiki:Gadget-olafbot-sk-exclusions.js
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.
var config = mw.config.get( [
'wgAction',
'wgCurRevisionId',
'wgDiffNewId',
'wgDiffOldId',
'wgPageName',
'wgRevisionId',
'wgUserLanguage'
] ),
messages = {
'ob-ski-summary-base': 'przeniesiono $1 {{PLURAL:$1|pozycję|pozycje|pozycji}} do [[$2|listy wykluczeń]' + ']',
'ob-ski-summary-subpage': 'przeniesiono nowe pozycje z [[$1|listy błędów]' + ']'
};
function doWork() {
var pre, post, basetimestamp, curtimestamp, $review, $edit,
$ol = $( '#mw-content-text' ).find( 'ol:not(.references)' ).first(),
retained = [],
removed = [],
api = new mw.Api( { parameters: {
formatversion: 2,
errorformat: 'html',
errorlang: config.wgUserLanguage,
errorsuselocal: true
} } );
$ol.before( [
$review = $( '<input>' )
.attr( {
type: 'button',
value: 'Wybierz do wykluczeń'
} )
.on( 'click', function ( evt ) {
evt.preventDefault();
$review
.prop( 'disabled', true )
.attr( 'value', 'Czekaj...' );
$.when(
api.get( {
prop: 'revisions',
rvprop: [ 'content', 'ids', 'timestamp' ],
rvslots: 'main',
titles: config.wgPageName,
curtimestamp: true
} ),
mw.loader.using( 'mediawiki.jqueryMsg' )
)
.done( function ( data ) {
var m, lastEl,
revision = data[ 0 ].query.pages[ 0 ].revisions[ 0 ],
content = revision.slots.main.content,
re = /^#[^\n]+$/gm;
if ( revision.revid !== config.wgRevisionId ) {
mw.notify( 'Strona została zmodyfikowana w międzyczasie. Przeładuj ją i spróbuj ponownie.', {
'type': 'error'
} );
return;
}
basetimestamp = revision.timestamp;
curtimestamp = data[ 0 ].curtimestamp;
while ( m = re.exec( content ) ) {
retained.push( m[ 0 ] );
}
pre = content.slice( 0, content.indexOf( retained[ 0 ] ) );
lastEl = retained[ retained.length - 1 ];
post = content.slice( content.lastIndexOf( lastEl ) + lastEl.length );
$( '<input>' )
.attr( 'type', 'checkbox' )
.prependTo( $ol.children() );
$review.attr( 'value', 'Zaznacz wybrane pozycje' );
$edit.prop( 'disabled', false );
mw.messages.set( messages );
} );
} ),
$edit = $( '<input>' )
.attr( {
type: 'button',
value: 'Zapisz zmiany'
} )
.prop( 'disabled', true )
.on( 'click', function ( evt ) {
evt.preventDefault();
$ol.find( ':has(:checked)' ).each( function () {
Array.prototype.push.apply( removed, retained.splice( $( this ).index() - removed.length, 1 ) );
} );
if ( removed.length ) {
$edit
.prop( 'disabled', true )
.attr( 'value', 'Wysyłanie danych...' );
api.edit( config.wgPageName + '/usuwane', function ( revision ) {
return {
text: revision.content + '\n' + removed.join( '\n' ),
summary: mw.msg( 'ob-ski-summary-subpage', config.wgPageName ),
tags: 'script'
};
} ).then( function () {
return api.postWithEditToken( api.assertCurrentUser( {
action: 'edit',
title: config.wgPageName,
text: pre + retained.join( '\n' ) + post,
summary: mw.msg( 'ob-ski-summary-base', removed.length, config.wgPageName + '/usuwane' ),
tags: 'script',
nocreate: true,
basetimestamp: basetimestamp,
starttimestamp: curtimestamp
} ), {
timeout: 70 * 1000
} );
} ).done( function () {
$edit.attr( 'value', 'Przeładowywanie strony...' );
location.reload();
} ).fail( function ( code, data ) {
mw.notify( api.getErrorMessage( data ), { type: 'error' } );
} );
} else {
mw.notify( 'Nie wykonano żadnych zmian! (albo skrypt nie działa)', { type: 'warn' } );
}
} )
] );
}
if (
!mw.user.isAnon() && // temporary hack until the 'applychangetags' right is assigned to anons
config.wgAction === 'view' &&
config.wgRevisionId === config.wgCurRevisionId &&
config.wgDiffNewId === null &&
config.wgDiffOldId === null
) {
$( doWork );
}