MediaWiki:Gadget-twinkleblock.js: Difference between revisions

Content deleted Content added
Repo at 712686d: Add Special:Unblock link in footer; upeblock to block options (#851); Use word boundary regex to match bot usernames; Disable CU/OS options unless user has the relevant perms
Repo at ffe5bbed: use Morebits.date instead of native Date; Show expiry in currently blocked message; Use mw.user.tokens for the blocking token
Line 4:
(function($) {
 
var api = new mw.Api(), relevantUserName;
var menuFormattedNamespaces = $.extend({}, mw.config.get('wgFormattedNamespaces'));
menuFormattedNamespaces[0] = '(Article)';
Line 98:
 
Twinkle.block.fetchUserInfo = function twinkleblockFetchUserInfo(fn) {
var api = new mw.Api();
 
api.get({
format: 'json',
Line 531:
// returns partial: '' if the user is partially blocked
var statusStr = relevantUserName + ' is ' + (Twinkle.block.currentBlockInfo.partial === '' ? 'partially blocked' : 'blocked sitewide');
if (Twinkle.block.currentBlockInfo.expiry === 'infinity') {
var infoStr = 'Submit query to reblock with supplied options';
statusStr += ' (indef)';
} else if (new Morebits.date(Twinkle.block.currentBlockInfo.expiry).isValid()) {
statusStr += ' (expires ' + new Morebits.date(Twinkle.block.currentBlockInfo.expiry).calendar('utc') + ')';
}
var infoStr = 'Submit query to reblockchange withthe supplied optionsblock';
if (Twinkle.block.currentBlockInfo.partial === undefined && partialBox) {
infoStr += ', and convertconverting to a partial block';
} else if (Twinkle.block.currentBlockInfo.partial === '' && !partialBox) {
infoStr += ', and convertconverting to a sitewide block';
}
Morebits.status.warn(statusStr, infoStr);
Line 1,435 ⟶ 1,440:
 
// execute block
blockoptions.token = tokenmw.user.tokens.get('csrfToken');
api.getToken('block').then(function(token) {
var mbApi = new Morebits.wiki.api('Executing block', blockoptions, function() {
statusElement.statusinfo('Processing...Completed');
blockoptions.token = token;
if (toWarn) {
var mbApi = new Morebits.wiki.api('Executing block', blockoptions, function() {
Twinkle.block.callback.issue_template(templateoptions);
statusElement.info('Completed');
});
if (toWarn) {
Twinkle.block.callback.issue_template(templateoptions);
}
});
mbApi.post();
}, function() {
statusElement.error('Unable to fetch block token');
});
mbApi.post();
} else if (toWarn) {
Morebits.simpleWindow.setButtonsEnabled(false);
Line 1,556:
params = pageobj.getCallbackParameters(),
messageData = params.messageData,
date = new DateMorebits.date(pageobj.getLoadTime());
 
var dateHeaderRegex = new RegExp('^==+\\s*(?:' + date.getUTCMonthNamemonthHeaderRegex(), + '|' + date.getUTCMonthNameAbbrev()dateHeaderRegexLast, +dateHeaderRegexResult;
')\\s+' + date.getUTCFullYear() + '\\s*==+', 'mg');
var dateHeaderRegexLast, dateHeaderRegexResult;
while ((dateHeaderRegexLast = dateHeaderRegex.exec(text)) !== null) {
dateHeaderRegexResult = dateHeaderRegexLast;
Line 1,577 ⟶ 1,575:
if (Twinkle.getPref('blankTalkpageOnIndefBlock') && params.template !== 'uw-lblock' && params.indefinite) {
Morebits.status.info('Info', 'Blanking talk page per preferences and creating a new level 2 heading for the date');
text = '== ' + date.getUTCMonthNamemonthHeader() + ' ' + date.getUTCFullYear() + ' ==\n';
} else if (!dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex) {
Morebits.status.info('Info', 'Will create a new level 2 heading for the date, as none was found for this month');
text += '== ' + date.getUTCMonthNamemonthHeader() + ' ' + date.getUTCFullYear() + ' ==\n';
}