User:Chaotic Enby/Unblock wizard redirect.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* MediaWiki:Unblock-wizard-redirect.js
*
* JavaScript used for submitting unblock requests.
* Additional script for MediaWiki:Unblock-wizard.js parsing blocks and redirecting users to the correct page.
* Used on [[Wikipedia:Unblock wizard]].
* Loaded via [[mw:Snippets/Load JS and CSS by URL]].
*
* Edits can be proposed via [[Wikipedia talk:Unblock wizard]].
*
* Author: [[User:Chaotic Enby]] (derived from a script by [[User:SD0001]])
* Licence: MIT
*/
/* jshint maxerr: 999 */
/* globals mw, $, OO */
/* <nowiki> */
(function () {
$.when(
$.ready,
mw.loader.using([
'mediawiki.util', 'mediawiki.api', 'mediawiki.Title',
'mediawiki.widgets', 'oojs-ui-core', 'oojs-ui-widgets'
])
).then(function () {
if (!(mw.config.get('wgPageName') == 'Wikipedia:Unblock_wizard' || mw.config.get('wgPageName') == 'User:Chaotic_Enby/Unblock_wizard') ||
mw.config.get('wgAction') !== 'view') {
return;
}
init();
});
var wizard = {}, ui = {}, block = {};
window.wizard = wizard;
wizard.ui = ui;
// For each block template, links the relevant subpage
var blockTemplates = {
"uw-adblock": ["Promo", "Promotional editing"],
"uw-asblock": ["Promo", "Promotional editing"],
"uw-spamublock": ["Promo", "Promotional editing"],
"uw-soablock": ["Promo", "Promotional editing"],
"uw-sockblock": ["Sockpuppet", "Sockpuppetry"],
"uw-upeblock": ["Promo", "Promotional editing"],
};
function init() {
var apiOptions = {
parameters: {
format: 'json',
formatversion: '2'
},
ajax: {
headers: {
'Api-User-Agent': 'w:en:MediaWiki:Unblock-wizard-redirect.js'
}
}
};
wizard.api = new mw.Api(apiOptions);
wizard.lookupApi = new mw.Api(apiOptions);
wizard.lookupApi.get({
"action": "query",
"meta": "userinfo",
"uiprop": "blockinfo"
}).then( setBlockData ).then( function ( reason ) {
ui.itemsLayout = [];
if(reason && reason in blockTemplates) {
targetPage = mw.config.get('wgPageName') + '/' + blockTemplates[reason][0];
targetUrl = mw.Title.newFromText( targetPage ).getUrl();
ui.itemsLayout.push(new OO.ui.FieldLayout(new OO.ui.LabelWidget({
label: $('<div>').style("font-size", "200%").append(linkify("Your current block status:<br>Blocked for " + blockTemplates[reason][1].toLowerCase()))}), { align: 'top' }));
ui.itemsLayout.push(ui.submitLayout = new OO.ui.FieldLayout(ui.submitButton = new OO.ui.ButtonWidget({
label: "Appeal my " + blockTemplates[reason][1].toLowerCase() + " block", flags: [ 'progressive', 'primary' ]})));
ui.itemsLayout.push(ui.submitLayout = new OO.ui.FieldLayout(ui.submitButton = new OO.ui.ButtonWidget({
label: "Learn more about " + blockTemplates[reason][1].toLowerCase() + " blocks", flags: [ 'progressive', 'primary' ]})));
ui.itemsLayout.push(ui.submitLayout = new OO.ui.FieldLayout(ui.submitButton = new OO.ui.ButtonWidget({
label: "Appeal a different kind of block", flags: [ 'primary' ]})));
}
else if(reason === null) { // Not blocked, this check is needed to avoid cases where the block reason is empty
// Check for global blocks
// Perform a check on the underlying IP
// Add a "You are not currently blocked" message
// Link to demo mode
}
else {
// Link to the current buttons
}
ui.fieldset = new OO.ui.FieldsetLayout({
classes: [ 'container' ],
items: ui.itemsLayout
});
$('#unblock-wizard-container').empty().append(ui.fieldset.$element);
});
function setBlockData(json) {
var userinfo = json.query.userinfo;
if(userinfo && "blockid" in userinfo){
block.id = userinfo.blockid;
block.by = userinfo.blockedby;
block.reason = userinfo.blockreason;
block.template = block.reason.match(/\{\{(.*)\}\}/)[1].toLowerCase();
return block.template;
}
return null;
}
}
function linkify(input) {
return input
.replace(/\{\{pb\}\}/g, '<br>')
.replace(
/\[\[:?(?:([^|\]]+?)\|)?([^\]|]+?)\]\]/g,
function(_, target, text) {
if (!target) {
target = text;
}
return '<a target="_blank" href="' + mw.util.getUrl(target) +
'" title="' + target.replace(/"/g, '"') + '">' + text + '</a>';
}
)
// for ext links, display text should be given
.replace(
/\[(\S*?) (.*?)\]/g,
function (_, target, text) {
return '<a target="_blank" href="' + target + '">' + text + '</a>';
}
);
}
})(); // File-level closure to protect functions from being exposed to the global scope or overwritten
/* </nowiki> */