বিষয়বস্তুতে চলুন
🎉 বইপিডিয়ার ১ বছর পূর্তি! · আমাদের ফেসবুক পেজ অনুসরণ করুন.

ব্যবহারকারী:ARI/common.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বইপিডিয়া থেকে
সম্পাদনা সারাংশ নেই
সম্পাদনা সারাংশ নেই
১ নং লাইন: ১ নং লাইন:
/**
mw.loader.using(['mediawiki.api'], function () {
* 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
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Contributions') return;
        var userGroups = mw.config.get( 'wgUserGroups' );
        if ( !userGroups.includes('sysop') && !userGroups.includes('rollbacker') ) {
            return;
        }


        // 3. Add the link to the interface
const api = new mw.Api();
        var $rollbackLink = $( '<a>' )
const username = mw.util.getParamValue('user');
            .text( 'Mass Rollback' )
if (!username) return;
            .attr( 'href', '#' )
            .css( { 'font-weight': 'bold', 'color': '#d33' } )
            .click( function ( e ) {
                e.preventDefault();
                confirmRollback();
            } );


        $( '#contentSub' ).append( ' [', $rollbackLink, ']' );
const btn = $('<button>')
.text('Rollback all visible edits')
.css({
marginLeft: '10px',
padding: '4px 8px',
fontSize: '90%'
})
.on('click', async function () {


        // 4. Function to confirm and execute
if (!confirm('Rollback all visible top edits by "' + username + '" ?')) return;
        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 );
let rolled = 0;
            if ( reason === null ) return; // User cancelled


            var limit = prompt( "How many edits to check? (Max 100)", "20" );
try {
            if ( !limit ) return;
const data = await api.get({
action: 'query',
list: 'usercontribs',
ucuser: username,
uclimit: 100,
ucprop: 'title|flags'
});


            executeRollback( targetUser, reason, limit );
for (const edit of data.query.usercontribs) {
        }
if (!edit.top) continue;


        // 5. The API Execution
await api.postWithToken('csrf', {
        function executeRollback( user, summary, limit ) {
action: 'rollback',
            var api = new mw.Api();
title: edit.title,
           
user: username,
            // Notification start
summary: 'Rollback spam edits'
            mw.notify( 'Fetching contributions...', { tag: 'mass-rollback' } );
});


            // Get user contributions
rolled++;
            api.get( {
await new Promise(r => setTimeout(r, 1200)); // VERY important
                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
alert('Rollback finished. Reverted: ' + rolled + ' edits.');
                contribs.forEach( function ( contrib ) {
} catch (e) {
                    // Only rollback if the edit is the current "top" revision
console.error(e);
                    if ( contrib.top !== undefined ) {
alert('Stopped due to an error. Check console.');
                        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' } );
$('#firstHeading').append(btn);
            } ).fail( function () {
});
                mw.notify( 'API Error: Could not fetch contributions.', { type: 'error' } );
            } );
        }
    } );
} );

২৩:৪৩, ৬ জানুয়ারি ২০২৬ তারিখে সংশোধিত সংস্করণ

mw.loader.using(['mediawiki.api'], function () {

	if (mw.config.get('wgCanonicalSpecialPageName') !== 'Contributions') return;

	const api = new mw.Api();
	const username = mw.util.getParamValue('user');
	if (!username) return;

	const btn = $('<button>')
		.text('Rollback all visible edits')
		.css({
			marginLeft: '10px',
			padding: '4px 8px',
			fontSize: '90%'
		})
		.on('click', async function () {

			if (!confirm('Rollback all visible top edits by "' + username + '" ?')) return;

			let rolled = 0;

			try {
				const data = await api.get({
					action: 'query',
					list: 'usercontribs',
					ucuser: username,
					uclimit: 100,
					ucprop: 'title|flags'
				});

				for (const edit of data.query.usercontribs) {
					if (!edit.top) continue;

					await api.postWithToken('csrf', {
						action: 'rollback',
						title: edit.title,
						user: username,
						summary: 'Rollback spam edits'
					});

					rolled++;
					await new Promise(r => setTimeout(r, 1200)); // VERY important
				}

				alert('Rollback finished. Reverted: ' + rolled + ' edits.');
			} catch (e) {
				console.error(e);
				alert('Stopped due to an error. Check console.');
			}
		});

	$('#firstHeading').append(btn);
});