MediaWiki:Gadget-patrolRevisions.js
Poznámka: Po uložení musíte vyprázdnit mezipaměť vašeho prohlížeče, jinak změny neuvidíte.
( function ( mw, $ ) {
var api = new mw.Api();
function markAsPatrolled( rcid ) {
return api.postWithToken( 'patrol', {
'action': 'patrol',
'rcid': rcid,
} );
}
function processNext( queue ) {
if ( queue.length === 0 ) {
return $.Deferred().resolve();
}
var rcid = queue.pop();
return markAsPatrolled( rcid )
.then( function () {
return processNext( queue );
} );
}
function getRevToRcIdMapping( response ) {
var revToRcIdMapping = {};
response.query.recentchanges.forEach( function ( info ) {
revToRcIdMapping[ info.revid ] = info.rcid;
} );
return revToRcIdMapping;
}
function queryRevToRcIdMapping( query ) {
return api.get( query ).then( getRevToRcIdMapping );
}
function notifyOfMissingButton( text ) {
mw.loader.using( [ 'mediawiki.jqueryMsg' ] ).then( function () {
mw.messages.set( {
'gadget-patrolRevisions-notice': 'Nepodařilo se umístit tlačítko <nowiki>[' + text + ']</nowiki>. '
+ 'Zřejmě došlo ke změně v rozhraní. '
+ 'Upozorněte na to prosím v [[Diskuse k MediaWiki:Gadget-patrolRevisions.js|diskusi]].'
} );
mw.notify(
$( '<div>' + mw.message( 'gadget-patrolRevisions-notice' ).parse() + '</div>' ),
{ autoHide: false, type: 'warn' }
);
} );
}
function onHistory() {
if ( mw.config.get( 'wgAction' ) !== 'history' ) {
return;
}
queryRevToRcIdMapping( {
'action': 'query',
'list': 'recentchanges',
'rcprop': 'ids',
'rcshow': 'unpatrolled',
'rclimit': 'max',
'rctype': [ 'edit', 'new' ],
'rctitle': mw.config.get( 'wgPageName' ),
} ).then( function ( revToRcIdMapping ) {
var length = Object.values( revToRcIdMapping ).length,
queue = [];
$( function () {
$( 'ul.mw-contributions-list > li' ).each( function () {
var $this = $( this ),
revid = +$this.data( 'mw-revid' );
if ( revToRcIdMapping[ revid ] ) {
$this.addClass( 'row-unpatrolled' );
queue.push( revToRcIdMapping[ revid ] );
return --length !== 0;
}
} );
if ( queue.length === 0 ) {
return;
}
var $anchor = $( '.mw-history-revisionactions' ), // admins only
after = true;
if ( $anchor.length === 0 ) {
$anchor = $( '.mw-history-compareselectedversions' );
after = false;
}
if ( $anchor.length === 0 ) {
notifyOfMissingButton( 'Označit neprověřené revize jako prověřené' );
return;
}
mw.util.addCSS( '.row-unpatrolled { background-color: #fff0c2 !important; }' );
var $el = $( '<div>' )
.addClass( 'mark-all-as-patrolled' )
.css( {
'float': 'right',
'clear': 'both',
} )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Označit neprověřené revize jako prověřené' )
.on( 'click', function ( event ) {
event.preventDefault();
$( '.mark-all-as-patrolled a' ).replaceWith( $.createSpinner( {
size: 'small',
type: 'inline',
} ) );
processNext( queue )
.then( function () {
$( '.mark-all-as-patrolled' ).remove();
$( '.row-unpatrolled' ).removeClass( 'row-unpatrolled' );
mw.notify( 'Všechny zobrazené revize byly označeny jako prověřené' );
} );
} ),
']'
);
if ( after ) {
$anchor.after( $el );
} else {
$anchor.append( $el );
}
} );
} );
}
function onUserContribs() {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Contributions' ) {
return;
}
if ( !mw.config.get( 'wgRelevantUserName' ) ) {
return;
}
queryRevToRcIdMapping( {
'action': 'query',
'list': 'recentchanges',
'rcprop': 'ids',
'rcshow': 'unpatrolled',
'rclimit': 'max',
'rctype': [ 'edit', 'new' ],
'rcuser': mw.config.get( 'wgRelevantUserName' ),
} ).then( function ( revToRcIdMapping ) {
var queue = [],
length = Object.values( revToRcIdMapping ).length,
marker = $( '<abbr>' )
.attr( 'title', 'Tato změna dosud nebyla prověřena' )
.addClass( 'unpatrolled' )
.html( '!' );
$( function () {
$( '.mw-contributions-list > li' ).each( function () {
var $this = $( this ),
revid = +$this.data( 'mw-revid' );
if ( revToRcIdMapping[ revid ] ) {
$this.find( '.mw-changeslist-separator' ).eq( 1 ).after( [ ' ', marker.clone() ] );
queue.push( revToRcIdMapping[ revid ] );
return --length !== 0;
}
} );
if ( queue.length === 0 ) {
return;
}
var $anchor = $( 'section.mw-pager-body, div.mw-pager-navigation-bar' ).first();
if ( $anchor.length === 0 ) {
notifyOfMissingButton( 'Označit všechny editace jako prověřené' );
return;
}
$anchor.before(
$( '<div>' )
.addClass( 'mark-all-as-patrolled' )
.css( {
'float': 'right',
} )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Označit všechny editace jako prověřené' )
.on( 'click', function ( event ) {
event.preventDefault();
$( '.mark-all-as-patrolled a' ).replaceWith( $.createSpinner( {
size: 'small',
type: 'inline',
} ) );
processNext( queue )
.then( function () {
$( '.mark-all-as-patrolled, .unpatrolled' ).remove();
mw.notify( 'Všechny zobrazené editace uživatele byly označeny jako prověřené' );
} );
} ),
']'
)
);
} );
} );
}
function onDiff( $diff ) {
if ( !mw.config.get( 'wgDiffNewId' ) || !mw.config.get( 'wgDiffOldId' ) ) {
return;
}
var $el = $diff.find( '.diff-multi' );
if ( $el.length !== 1 ) {
return;
}
var newId = mw.config.get( 'wgDiffNewId' ),
oldId = mw.config.get( 'wgDiffOldId' );
api.get( {
'formatversion': 2,
'action': 'query',
'prop': 'revisions',
'titles': mw.config.get( 'wgPageName' ),
'rvprop': [ 'ids', 'timestamp' ],
'rvlimit': 'max',
'rvdir': 'older',
'rvstartid': newId,
'rvendid': oldId,
} ).then( function ( resp ) {
var revisions = resp.query.pages[0].revisions,
len = revisions.length;
if ( len < 3 ) {
return {};
}
return queryRevToRcIdMapping( {
'action': 'query',
'list': 'recentchanges',
'rcprop': 'ids',
'rcshow': 'unpatrolled',
'rclimit': 'max',
'rctype': [ 'edit', 'new' ],
'rctitle': mw.config.get( 'wgPageName' ),
'rcdir': 'older',
'rcstart': revisions[0].timestamp,
'rcend': revisions[len-1].timestamp,
} );
} ).then( function ( revToRcIdMapping ) {
var queue = [];
for ( var revid in revToRcIdMapping ) {
if ( oldId < revid && revid <= newId ) {
queue.push( revToRcIdMapping[ revid ] );
}
}
if ( queue.length === 0 ) {
return;
}
$( function () {
$el
.append(
$( '<div>' )
.addClass( 'mark-revisions-as-patrolled' )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Označit všechny mezilehlé revize jako prověřené' )
.on( 'click', function ( event ) {
event.preventDefault();
$( this ).replaceWith( $.createSpinner( {
size: 'small',
type: 'inline',
} ) );
processNext( queue )
.then( function () {
$el.find( '.mark-revisions-as-patrolled' ).remove();
$( '.patrollink' ).remove();
mw.notify( 'Všechny mezilehlé revize byly označeny jako prověřené' );
} );
} ),
']'
)
);
} );
} );
}
onHistory();
onUserContribs();
mw.hook( 'wikipage.diff' ).add( onDiff );
} )( mediaWiki, jQuery );