User:Ainz Ooal Gown/mobilediffrollback.js
Appearance
(Redirected from User:Masumrezarock100/mobilediffrollback.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Ainz Ooal Gown/mobilediffrollback. |
//A script to add a rollback button to a diff page in mobile
if ( mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff' && mw.config.get('wgRelevantPageIsProbablyEditable') ) {
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'oojs-ui-windows', 'oojs-ui-core', 'oojs-ui.styles.icons-editing-core']).then( function () {
// Api variables and request call
var api = new mw.Api(),
callPromise = api.get({
"action": "query",
"format": "json",
"prop": "revisions",
"list": "users",
"meta": "tokens",
"titles": mw.config.get('wgRelevantPageName'),
"formatversion": "2",
"rvprop": "ids|user",
"usprop": "rights",
"ususers": mw.config.get( 'wgUserName' ),
"type": "rollback"
});
// When the response is ready, then function
$.when( callPromise, $.ready ).then( function ( results ) {
var rightsData, lastestRevisionUser, latestRevId, rollbackToken,
response = results[ 0 ];
// Avoid loading the script if one of the details is not available
if (
response.query &&
response.query.users &&
response.query.users[0].rights &&
response.query.tokens &&
response.query.tokens.rollbacktoken &&
response.query.pages[0] &&
response.query.pages[0].revisions[0] &&
response.query.pages[0].revisions[0].user &&
response.query.pages[0].revisions[0].revid
) {
//Get the revid from oldid link
window.wgRevId = ($('#mw-mf-diffarea > div.mw-mf-diff-info > h3 > a').attr('href')).split('&oldid=')[1];
// Define data variables from API
rightsData = response.query.users[0].rights;
latestRevId = response.query.pages[0].revisions[0].revid;
lastestRevisionUser = response.query.pages[0].revisions[0].user;
rollbackToken = response.query.tokens.rollbacktoken;
var mobilerollback = new OO.ui.ButtonWidget({
label: 'Rollback',
href: mw.util.getUrl( mw.config.get('wgRelevantPageName'), { action: 'rollback', token: rollbackToken, from: lastestRevisionUser }),
icon: 'editUndo',
id: 'mobileRollback',
title: '"Rollback" reverts the last contributor’s edit(s) to this page',
classes: 'mw-rollback-link',
flags: ['destructive', 'primary']
});
// Only show the rollback button if the user has rollback right and if the specified revision is latest
if ( wgRevId == latestRevId && response.query.users[0].rights.indexOf('rollback') !== -1 ) {
$('.minerva__subtitle').append( mobilerollback.$element );
}
//Construct the confirmation prompt to ask for a summary
var rollbackSummaryPrompt = function(e) {
e.preventDefault();
OO.ui.prompt( 'Are you sure you want to rollback edits made to this page by this user?', { textInput: { placeholder: 'Edit summary (optional)' } } ).done( function ( result ) {
if ( result !== null ) {
location.href = mw.util.getUrl( mw.config.get('wgRelevantPageName'), { action: 'rollback', token: rollbackToken, from: lastestRevisionUser, summary: result });
}
});
};
$('#mobileRollback').click(rollbackSummaryPrompt);
//Prompt end
}
});
});
}