User:Estopedist1/common.js: Difference between revisions
Content deleted Content added
Estopedist1 (talk | contribs) Blanked the page Tags: Blanking Manual revert |
Estopedist1 (talk | contribs) No edit summary |
||
Line 1:
( function ( mw, $ ) {
var 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 onHistory() {
if ( mw.config.get( 'wgAction' ) !== 'history' ) {
return;
}
api.get( {
'action': 'query',
'list': 'recentchanges',
'rcprop': 'ids',
'rcshow': 'unpatrolled',
'rclimit': 'max',
'rctype': [ 'edit', 'new' ],
'rctitle': mw.config.get( 'wgPageName' ),
} ).then( function ( resp ) {
var data = {};
$.each( resp.query.recentchanges, function ( i, info ) {
data[ info.revid ] = info.rcid;
} );
if ( $.isEmptyObject( data ) ) {
return;
}
$( function() {
$( '.mw-checkbox-toggle-controls' )
.append(
$( '<div>' )
.addClass( 'mark-all-as-patrolled' )
.css( {
'float': 'right',
} )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Mark all revisions as patrolled' )
.on( 'click', function ( event ) {
event.preventDefault();
$( this ).replaceWith( '...' );
processNext( Object.values( data ) )
.then( function () {
$( '.mark-all-as-patrolled' ).remove();
$( '.row-unpatrolled' ).removeClass( 'row-unpatrolled' );
mw.notify( 'All revisions have been marked as patrolled' );
} );
} ),
']'
)
);
var rows = Object.values( data ).length;
$( '#pagehistory > li' ).each( function () {
var $this = $( this );
if ( data[ $this.data( 'mw-revid' ) ] ) {
$this.addClass( 'row-unpatrolled' );
return --rows !== 0;
}
} );
mw.util.addCSS( '.row-unpatrolled { background-color: #fff0c2 !important; }' );
} );
} );
}
function onUserContribs() {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Contributions' ) {
return;
}
if ( !mw.config.get( 'wgRelevantUserName' ) ) {
return;
}
api.get( {
'action': 'query',
'list': 'recentchanges',
'rcprop': 'ids',
'rcshow': 'unpatrolled',
'rclimit': 'max',
'rctype': [ 'edit', 'new' ],
'rcuser': mw.config.get( 'wgRelevantUserName' ),
} ).then( function ( resp ) {
var data = {};
$.each( resp.query.recentchanges, function ( i, info ) {
data[ info.revid ] = info.rcid;
} );
if ( $.isEmptyObject( data ) ) {
return;
}
$( function() {
$( '.mw-pager-navigation-bar' )
.after(
$( '<div>' )
.addClass( 'mark-all-as-patrolled' )
.css( {
'float': 'right',
} )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Mark all revisions as patrolled' )
.on( 'click', function( event ) {
event.preventDefault();
$( this ).replaceWith( '...' );
processNext( Object.values( data ) )
.then( function() {
$( '.mark-all-as-patrolled' ).remove();
$( '.unpatrolled' ).remove();
mw.notify( 'All user\'s revisions have been marked as patrolled' );
} );
} ),
']'
)
);
var marker = $( '<abbr>' )
.attr( 'title', 'This change has not been patrolled yet' )
.addClass( 'unpatrolled' )
.html( '!' );
var rows = Object.values( data ).length;
$( '.mw-contributions-list > li' ).each( function () {
var $this = $( this );
if ( data[ $this.data( 'mw-revid' ) ] ) {
$this.find( '.mw-changeslist-separator' ).eq( 1 ).after( [ ' ', marker.clone() ] );
return --rows !== 0;
}
} );
} );
} );
}
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 $.Deferred().reject();
}
return api.get( {
'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 ( resp ) {
var data = {};
$.each( resp.query.recentchanges, function ( i, info ) {
if ( oldId < info.revid && info.revid <= newId ) {
data[ info.revid ] = info.rcid;
}
} );
if ( $.isEmptyObject( data ) ) {
return;
}
$( function() {
$el
.append(
$( '<div>' )
.addClass( 'mark-revisions-as-patrolled' )
.append(
'[',
$( '<a>' )
.attr( 'href', '#' )
.text( 'Mark all revisions as patrolled' )
.on( 'click', function ( event ) {
event.preventDefault();
$( this ).replaceWith( '...' );
processNext( Object.values( data ) )
.then( function () {
$el.find( '.mark-revisions-as-patrolled' ).remove();
$diff.find( '#mw-diff-ntitle4 .patrollink' ).remove();
mw.notify( 'All revisions have been marked as patrolled' );
} );
} ),
']'
)
);
} );
} );
}
mw.loader.using( [ 'mediawiki.api' ] ).then( function () {
api = new mw.Api();
onHistory();
onUserContribs();
mw.hook( 'wikipage.diff' ).add( onDiff );
} );
} )( mediaWiki, jQuery );
|