MediaWiki:Gadget-twinkleblock.js: Difference between revisions
Content deleted Content added
Repo at 001f236: simplify IIFEs (#2074); apply autofixes 3 (#2079); apply autofixes 2 (#2069) |
MusikAnimal (talk | contribs) deploy #2180: soft redirect to Special:Block for multi-blocked targets |
||
(4 intermediate revisions by one other user not shown) | |||
Line 3:
(function() {
let relevantUserName, blockedUserName, blockWindow; const menuFormattedNamespaces =
menuFormattedNamespaces[0] = '(Article)';
Line 34 ⟶ 35:
Twinkle.block.field_template_options = {};
// need to be verbose about who we're blocking
// Always added, hidden later if actual user not blocked
const form = new Morebits.
const actionfield = form.append({
type: 'field',
Line 125 ⟶ 126:
const result = form.render();
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
// 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;
}
// 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).
} else {
Twinkle.block.userIsBot = false;
Line 187 ⟶ 199:
const unblockLink = document.querySelector('.morebits-dialog-footerlinks a');
if (blockedUserName !== relevantUserName) {
unblockLink.hidden = true
unblockLink.nextSibling.hidden = true; // link+trailing bullet } else {
unblockLink.hidden = false
unblockLink.nextSibling.hidden = false; // link+trailing bullet }
Line 233 ⟶ 247:
Twinkle.block.processUserInfo(data, fn);
}, (msg) => {
Morebits.
Morebits.
});
};
Line 295 ⟶ 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 341 ⟶ 356:
if (blockBox) {
field_preset = new Morebits.
field_preset.append({
type: 'select',
Line 350 ⟶ 365:
});
field_block_options = new Morebits.
field_block_options.append({ type: 'div', name: 'currentblock', label: ' ' });
field_block_options.append({ type: 'div', name: 'hasblocklog', label: ' ' });
Line 530 ⟶ 545:
};
if (templateBox) {
field_template_options = new Morebits.
field_template_options.append({
type: 'select',
Line 721 ⟶ 736:
oldfield = $form.find('fieldset[name="field_template_options"]')[0];
oldfield.parentNode.replaceChild(field_template_options.render(), oldfield);
e.target.form.root.previewer = new Morebits.wiki.
} else {
$form.find('fieldset[name="field_template_options"]').hide();
Line 732 ⟶ 747:
const sameUser = blockedUserName === relevantUserName;
Morebits.
let statusStr = relevantUserName + ' is ' + (Twinkle.block.currentBlockInfo.partial === '' ? 'partially blocked' : 'blocked sitewide');
Line 749 ⟶ 764:
if (Twinkle.block.currentBlockInfo.expiry === 'infinity') {
statusStr += ' (indefinite)';
} else if (new Morebits.
statusStr += ' (expires ' + new Morebits.
}
Line 766 ⟶ 781:
}
Morebits.
// Default to the current block conditions on intial form generation
Line 780 ⟶ 795:
const lastBlockAction = Twinkle.block.blockLog[0];
if (lastBlockAction.action === 'unblock') {
$blockloglink.append(' (unblocked ' + new Morebits.
} else { // block or reblock
$blockloglink.append(' (' + lastBlockAction.params.duration + ', expired ' + new Morebits.
}
}
Morebits.
Morebits.
}
Line 1,516 ⟶ 1,531:
Twinkle.block.callback.change_template(e);
} else {
Morebits.
}
};
Line 1,523 ⟶ 1,538:
const expiry = e.target.form.expiry;
if (e.target.value === 'custom') {
Morebits.
} else {
Morebits.
expiry.value = e.target.value;
}
Line 1,533 ⟶ 1,548:
Twinkle.block.callback.toggle_see_alsos = function twinkleblockCallbackToggleSeeAlso() {
const reason = this.form.reason.value.replace(
new RegExp('( <!--|;)
);
Line 1,545 ⟶ 1,560:
if (!Twinkle.block.seeAlsos.length) {
this.form.reason.value = reason;
} else if (reason.
this.form.reason.value = reason + ' <!-- see also ' + seeAlsoMessage + ' -->';
} else {
Line 1,571 ⟶ 1,586:
Twinkle.block.callback.update_form = function twinkleblockCallbackUpdateForm(e, data) {
let expiry = data.expiry; // don't override original expiry if useInitialOptions is set
Line 1,584 ⟶ 1,600:
form.expiry.value = expiry;
if (form.expiry_preset.value === 'custom') {
Morebits.
} else {
Morebits.
}
}
Line 1,673 ⟶ 1,689:
form.expiry.value = Twinkle.block.prev_template_expiry;
}
Morebits.
// Partial
Morebits.
Morebits.
} else if (templateBox) { // Only present if block && template forms both visible
Morebits.
form.blank_duration.parentNode,
!settings.indefinite && !settings.nonstandard
Line 1,684 ⟶ 1,700:
}
Morebits.
// Only particularly relevant if template form is present
Morebits.
Morebits.
// Partial block
Morebits.
form.root.previewer.closePreview();
Line 1,722 ⟶ 1,738:
Twinkle.block.callback.evaluate = function twinkleblockCallbackEvaluate(e) {
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')
Twinkle.block.callback.saveFieldset($form.find('[name=field_block_options]'));
Line 1,756 ⟶ 1,772:
if (toBlock) {
if (blockoptions.partial) {
if (blockoptions.disabletalk && !blockoptions.namespacerestrictions.
return alert('Partial blocks cannot prevent talk page access unless also restricting them from editing User talk space!');
}
Line 1,778 ⟶ 1,794:
}
Morebits.
Morebits.
const statusElement = new Morebits.
blockoptions.action = 'block';
Line 1,856 ⟶ 1,872:
logExpiry = 'indefinitely';
} else {
const expiryDate = new Morebits.
logExpiry += (expiryDate.isBefore(new Date()) ? ', expired ' : ' until ') + expiryDate.calendar();
}
} else { // no duration, action=unblock, just show timestamp
logExpiry = ' ' + new Morebits.
}
message += Morebits.string.toUpperCaseFirstChar(logevents.action) + 'ed by ' + logevents.user + logExpiry +
Line 1,866 ⟶ 1,882:
if (!confirm(message)) {
Morebits.
return;
}
Line 1,875 ⟶ 1,891:
blockoptions.tags = Twinkle.changeTags;
blockoptions.token = mw.user.tokens.get('csrfToken');
const mbApi = new Morebits.wiki.
statusElement.info('Completed');
if (toWarn) {
Line 1,884 ⟶ 1,900:
});
} else if (toWarn) {
Morebits.
Morebits.
Twinkle.block.callback.issue_template(templateoptions);
} else {
Line 1,898 ⟶ 1,914:
const userTalkPage = 'User_talk:' + mw.config.get('wgRelevantUserName');
const params =
Twinkle.block.blockPresetsInfo[formData.template], Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.notice = 'Actions complete, loading user talk page in a few seconds';
const wikipedia_page = new Morebits.wiki.
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,928 ⟶ 1,956:
if (params.indefinite) {
text += '|indef=yes';
} else if (!params.blank_duration && !new Morebits.
// Block template wants a duration, not date
text += '|time=' + params.expiry;
Line 1,989 ⟶ 2,017:
Twinkle.block.callback.main = function twinkleblockcallbackMain(pageobj) {
date = new Morebits.
messageData = params.messageData
params.indefinite = Morebits.string.isInfinity(params.expiry);
if (Twinkle.getPref('blankTalkpageOnIndefBlock') && params.template !== 'uw-lblock' && params.indefinite) {
Morebits.
text = date.monthHeader() + '\n';
} else {
text = pageobj.getPageText();
let dateHeaderRegexLast, dateHeaderRegexResult; while ((dateHeaderRegexLast = dateHeaderRegex.exec(text)) !== null) {
dateHeaderRegexResult = dateHeaderRegexLast;
Line 2,016 ⟶ 2,045:
if (!dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex) {
Morebits.
text += date.monthHeader() + '\n';
}
|