MediaWiki:Gadget-twinkleblock.js: Difference between revisions

Content deleted Content added
Repo at e7d4c6c: fix some no-jquery/no-extend autofixes (#2088); capitalize Morebit class names (#2087); fix linter error no-sequences (#2083)
deploy #2180: soft redirect to Special:Block for multi-blocked targets
 
(3 intermediate revisions by one other user not shown)
Line 3:
(function() {
 
letconst api = new mw.Api(),;
let relevantUserName, blockedUserName, blockWindow;
const menuFormattedNamespaces = Object$.assignextend({}, mw.config.get('wgFormattedNamespaces'));
menuFormattedNamespaces[0] = '(Article)';
 
Line 34 ⟶ 35:
Twinkle.block.field_template_options = {};
 
const WindowblockWindow = new Morebits.SimpleWindow(650, 530);
// need to be verbose about who we're blocking
WindowblockWindow.setTitle('Block or issue block template to ' + relevantUserName);
WindowblockWindow.setScriptName('Twinkle');
WindowblockWindow.addFooterLink('Block templates', 'Template:Uw-block/doc/Block_templates');
WindowblockWindow.addFooterLink('Block policy', 'WP:BLOCK');
WindowblockWindow.addFooterLink('Block prefs', 'WP:TW/PREF#block');
WindowblockWindow.addFooterLink('Twinkle help', 'WP:TW/DOC#block');
WindowblockWindow.addFooterLink('Give feedback', 'WT:TW');
 
// Always added, hidden later if actual user not blocked
WindowblockWindow.addFooterLink('Unblock this user', 'Special:Unblock/' + relevantUserName, true);
 
const form = new Morebits.QuickForm(Twinkle.block.callback.evaluate);
Line 125 ⟶ 126:
 
const result = form.render();
WindowblockWindow.setContent(result);
WindowblockWindow.display();
result.root = result;
 
Line 154 ⟶ 155:
// Store fetched user data, only relevant if switching IPv6 to a /64
Twinkle.block.fetchedData = {};
// Processes the data from a a query response, separated from
// Twinkle.block.fetchUserInfo to allow reprocessing of already-fetched data
Twinkle.block.processUserInfo = function twinkleblockProcessUserInfo(data, fn) {
let blockinfo = data.query.blocks[0],;
// Soft redirect to Special:Block if the user is multi-blocked (#2178)
userinfo = data.query.users[0];
if (blockinfo && data.query.blocks.length > 1) {
// Remove submission buttons.
$(blockWindow.content).dialog('widget').find('.morebits-dialog-buttons').empty();
Morebits.Status.init(blockWindow.content.querySelector('form'));
Morebits.Status.warn(
`This target has ${data.query.blocks.length} active blocks`,
`Multiblocks is not supported by Twinkle. Use [[Special:Block/${relevantUserName}]] instead.`
);
return;
}
const userinfo = data.query.users[0];
// If an IP is blocked *and* rangeblocked, the above finds
// whichever block is more recent, not necessarily correct.
Line 170 ⟶ 182:
Twinkle.block.isRegistered = !!userinfo.userid;
if (Twinkle.block.isRegistered) {
Twinkle.block.userIsBot = !!userinfo.groupmemberships && userinfo.groupmemberships.map((e) => e.group).indexOfincludes('bot') !== -1;
} else {
Twinkle.block.userIsBot = false;
Line 297 ⟶ 309:
 
Twinkle.block.callback.change_action = function twinkleblockCallbackChangeAction(e) {
let field_preset, field_template_options, field_block_options,;
const $form = $(e.target.form);
// Make ifs shorter
const blockBox = $form.find('[name=actiontype][value=block]').is(':checked');
Line 1,535 ⟶ 1,548:
Twinkle.block.callback.toggle_see_alsos = function twinkleblockCallbackToggleSeeAlso() {
const reason = this.form.reason.value.replace(
new RegExp('( <!--|;) ' + 'see also ' + Twinkle.block.seeAlsos.join(' and ') + '( -->)?'), ''
);
 
Line 1,547 ⟶ 1,560:
if (!Twinkle.block.seeAlsos.length) {
this.form.reason.value = reason;
} else if (reason.indexOfincludes('{{') !== -1) {
this.form.reason.value = reason + ' <!-- see also ' + seeAlsoMessage + ' -->';
} else {
Line 1,573 ⟶ 1,586:
 
Twinkle.block.callback.update_form = function twinkleblockCallbackUpdateForm(e, data) {
letconst form = e.target.form,;
let expiry = data.expiry;
 
// don't override original expiry if useInitialOptions is set
Line 1,724 ⟶ 1,738:
 
Twinkle.block.callback.evaluate = function twinkleblockCallbackEvaluate(e) {
letconst $form = $(e.target),
toBlock = $form.find('[name=actiontype][value=block]').is(':checked'),
toWarn = $form.find('[name=actiontype][value=template]').is(':checked'),
toPartial = $form.find('[name=actiontype][value=partial]').is(':checked'),;
let blockoptions = {}, templateoptions = {};
 
Twinkle.block.callback.saveFieldset($form.find('[name=field_block_options]'));
Line 1,758 ⟶ 1,772:
if (toBlock) {
if (blockoptions.partial) {
if (blockoptions.disabletalk && !blockoptions.namespacerestrictions.indexOfincludes('3') === -1) {
return alert('Partial blocks cannot prevent talk page access unless also restricting them from editing User talk space!');
}
Line 1,900 ⟶ 1,914:
const userTalkPage = 'User_talk:' + mw.config.get('wgRelevantUserName');
 
const params = ObjectTwinkle.assignblock.combineFormDataAndFieldTemplateOptions(formData || {}, {
messageData: formData,
Twinkle.block.blockPresetsInfo[formData.template],
reason: Twinkle.block.field_template_options.block_reason,
disabletalk: Twinkle.block.field_template_options.notalk,
noemail: Twinkle.block.field_template_options.noemail_template,
nocreate: Twinkle.block.field_template_options.nocreate_template
});
 
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Line 1,914 ⟶ 1,929:
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.block.callback.main);
};
 
Twinkle.block.combineFormDataAndFieldTemplateOptions = function(formData, messageData, reason, disabletalk, noemail, nocreate) {
return $.extend(formData, {
messageData: messageData,
reason: reason,
disabletalk: disabletalk,
noemail: noemail,
nocreate: nocreate
});
};
 
Twinkle.block.callback.getBlockNoticeWikitext = function(params) {
let text = '{{',;
const settings = Twinkle.block.blockPresetsInfo[params.template];
if (!settings.nonstandard) {
text += 'subst:' + params.template;
Line 1,991 ⟶ 2,017:
 
Twinkle.block.callback.main = function twinkleblockcallbackMain(pageobj) {
letconst params = pageobj.getCallbackParameters(),
date = new Morebits.Date(pageobj.getLoadTime()),
messageData = params.messageData,;
let text;
 
params.indefinite = Morebits.string.isInfinity(params.expiry);
Line 2,004 ⟶ 2,030:
text = pageobj.getPageText();
 
letconst dateHeaderRegex = date.monthHeaderRegex(),;
let dateHeaderRegexLast, dateHeaderRegexResult;
while ((dateHeaderRegexLast = dateHeaderRegex.exec(text)) !== null) {
dateHeaderRegexResult = dateHeaderRegexLast;