ব্যবহারকারী:ARI/common.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য
অবয়ব
পাতাকে 'mw.notify('User JS loaded: rollback scripts will work');' দিয়ে প্রতিস্থাপিত করা হল ট্যাগ: প্রতিস্থাপিত |
সম্পাদনা সারাংশ নেই |
||
| ১ নং লাইন: | ১ নং লাইন: | ||
mw.notify(' | /** | ||
* Mass Rollback Script (Standalone) | |||
* Adds a "Mass Rollback" button to Special:Contributions | |||
*/ | |||
mw.loader.using( ['mediawiki.util', 'mediawiki.api'], function () { | |||
$(document).ready( function () { | |||
// 1. Only run on Special:Contributions | |||
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Contributions' ) { | |||
return; | |||
} | |||
// 2. Only run if user is Sysop or Rollbacker | |||
var userGroups = mw.config.get( 'wgUserGroups' ); | |||
if ( !userGroups.includes('sysop') && !userGroups.includes('rollbacker') ) { | |||
return; | |||
} | |||
// 3. Add the link to the interface | |||
var $rollbackLink = $( '<a>' ) | |||
.text( 'Mass Rollback' ) | |||
.attr( 'href', '#' ) | |||
.css( { 'font-weight': 'bold', 'color': '#d33' } ) | |||
.click( function ( e ) { | |||
e.preventDefault(); | |||
confirmRollback(); | |||
} ); | |||
$( '#contentSub' ).append( ' [', $rollbackLink, ']' ); | |||
// 4. Function to confirm and execute | |||
function confirmRollback() { | |||
var targetUser = mw.config.get( 'wgRelevantUserName' ); | |||
if ( !targetUser ) { | |||
alert( 'Could not determine the username.' ); | |||
return; | |||
} | |||
var reason = prompt( "Enter a reason for mass rollback (optional):", "Mass rollback of edits by " + targetUser ); | |||
if ( reason === null ) return; // User cancelled | |||
var limit = prompt( "How many edits to check? (Max 100)", "20" ); | |||
if ( !limit ) return; | |||
executeRollback( targetUser, reason, limit ); | |||
} | |||
// 5. The API Execution | |||
function executeRollback( user, summary, limit ) { | |||
var api = new mw.Api(); | |||
// Notification start | |||
mw.notify( 'Fetching contributions...', { tag: 'mass-rollback' } ); | |||
// Get user contributions | |||
api.get( { | |||
action: 'query', | |||
list: 'usercontribs', | |||
ucuser: user, | |||
uclimit: limit, | |||
ucprop: 'title|ids|top' // We need 'top' to know if it's the latest edit | |||
} ).done( function ( data ) { | |||
var contribs = data.query.usercontribs; | |||
var count = 0; | |||
// Loop through contributions | |||
contribs.forEach( function ( contrib ) { | |||
// Only rollback if the edit is the current "top" revision | |||
if ( contrib.top !== undefined ) { | |||
count++; | |||
// Perform the rollback | |||
api.postWithToken( 'rollback', { | |||
action: 'rollback', | |||
title: contrib.title, | |||
user: user, | |||
summary: summary, | |||
markbot: true // Mark as bot edit to hide from Recent Changes | |||
} ).done( function () { | |||
console.log( 'Rolled back: ' + contrib.title ); | |||
} ).fail( function ( code, result ) { | |||
console.log( 'Failed to rollback ' + contrib.title + ': ' + code ); | |||
} ); | |||
} | |||
} ); | |||
mw.notify( 'Initiated rollback on ' + count + ' pages. Check your browser console (F12) for progress.', { type: 'success' } ); | |||
} ).fail( function () { | |||
mw.notify( 'API Error: Could not fetch contributions.', { type: 'error' } ); | |||
} ); | |||
} | |||
} ); | |||
} ); | |||
২৩:২৪, ৬ জানুয়ারি ২০২৬ তারিখে সংশোধিত সংস্করণ
/**
* Mass Rollback Script (Standalone)
* Adds a "Mass Rollback" button to Special:Contributions
*/
mw.loader.using( ['mediawiki.util', 'mediawiki.api'], function () {
$(document).ready( function () {
// 1. Only run on Special:Contributions
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Contributions' ) {
return;
}
// 2. Only run if user is Sysop or Rollbacker
var userGroups = mw.config.get( 'wgUserGroups' );
if ( !userGroups.includes('sysop') && !userGroups.includes('rollbacker') ) {
return;
}
// 3. Add the link to the interface
var $rollbackLink = $( '<a>' )
.text( 'Mass Rollback' )
.attr( 'href', '#' )
.css( { 'font-weight': 'bold', 'color': '#d33' } )
.click( function ( e ) {
e.preventDefault();
confirmRollback();
} );
$( '#contentSub' ).append( ' [', $rollbackLink, ']' );
// 4. Function to confirm and execute
function confirmRollback() {
var targetUser = mw.config.get( 'wgRelevantUserName' );
if ( !targetUser ) {
alert( 'Could not determine the username.' );
return;
}
var reason = prompt( "Enter a reason for mass rollback (optional):", "Mass rollback of edits by " + targetUser );
if ( reason === null ) return; // User cancelled
var limit = prompt( "How many edits to check? (Max 100)", "20" );
if ( !limit ) return;
executeRollback( targetUser, reason, limit );
}
// 5. The API Execution
function executeRollback( user, summary, limit ) {
var api = new mw.Api();
// Notification start
mw.notify( 'Fetching contributions...', { tag: 'mass-rollback' } );
// Get user contributions
api.get( {
action: 'query',
list: 'usercontribs',
ucuser: user,
uclimit: limit,
ucprop: 'title|ids|top' // We need 'top' to know if it's the latest edit
} ).done( function ( data ) {
var contribs = data.query.usercontribs;
var count = 0;
// Loop through contributions
contribs.forEach( function ( contrib ) {
// Only rollback if the edit is the current "top" revision
if ( contrib.top !== undefined ) {
count++;
// Perform the rollback
api.postWithToken( 'rollback', {
action: 'rollback',
title: contrib.title,
user: user,
summary: summary,
markbot: true // Mark as bot edit to hide from Recent Changes
} ).done( function () {
console.log( 'Rolled back: ' + contrib.title );
} ).fail( function ( code, result ) {
console.log( 'Failed to rollback ' + contrib.title + ': ' + code );
} );
}
} );
mw.notify( 'Initiated rollback on ' + count + ' pages. Check your browser console (F12) for progress.', { type: 'success' } );
} ).fail( function () {
mw.notify( 'API Error: Could not fetch contributions.', { type: 'error' } );
} );
}
} );
} );