User:SD0001/quickViewDeleted.js
Appearance
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:SD0001/quickViewDeleted. |
/*
Quickly view a preview of the last deleted revision of a deleted page.
The preview is shown at the bottom of the page.
To enable, add the line below to your common.js page:
importScript('User:SD0001/quickViewDeleted.js'); // [[User:SD0001/quickViewDeleted.js]]
*/
$.when(
$.ready,
mw.loader.using('mediawiki.api')
).then(function() {
if (!$('.mw-undelete-subtitle').length || mw.config.get('wgCurRevisionId') || mw.config.get('wgUserGroups').indexOf('sysop') === -1) {
return;
}
var api = new mw.Api();
api.get({
"action": "query",
"format": "json",
"prop": "deletedrevisions",
"titles": mw.config.get('wgPageName'),
"formatversion": "2",
"drvprop": "content",
"drvlimit": "1"
}).then(function(json) {
var wikitext = json.query.pages[0].deletedrevisions[0].content;
wikitext = '=Last deleted version=\n' + wikitext;
return api.post({
"action": "parse",
"format": "json",
"title": mw.config.get('wgPageName'),
"text": wikitext,
"prop": "text",
"disableeditsection": 1,
"formatversion": "2"
});
}).then(function(json) {
var html = json.parse.text;
$('#mw-content-text').append(
$('<div>').attr('id', 'quickViewDeleted-text').html(html)
);
$('.mw-undelete-subtitle').append(
$('<span>').css({
'float': 'right'
}).append(
$('<a>').text('Jump to preview >').attr('href', '#quickViewDeleted-text')
)
);
}).catch(console.error);
});