MediaWiki:Gadget-morebits.js: Difference between revisions

Repo at bab8522: Use csrfToken in mw.user.tokens (#712); Convert mw.RegExp.escape to mw.util.escapeRegExp as the former is being deprecated (#711); Update handling of blacklist and abusefilter errors from API (breaking change for 1.34.0-wmf.23) (#707); internationalize Date, and remove unused functions (#635); enable multiline unbinder (#510); replace + in Morebits.queryString (fix longstanding bug) (#678)
imported>Krinkle
(Maintenance: mw:RL/MGU - Updated deprecated module name, Updated deprecated user.tokens key)
(Repo at bab8522: Use csrfToken in mw.user.tokens (#712); Convert mw.RegExp.escape to mw.util.escapeRegExp as the former is being deprecated (#711); Update handling of blacklist and abusefilter errors from API (breaking change for 1.34.0-wmf.23) (#707); internationalize Date, and remove unused functions (#635); enable multiline unbinder (#510); replace + in Morebits.queryString (fix longstanding bug) (#678))
Line 962:
 
RegExp.escape = function(text, space_fix) {
text = mw.RegExputil.escapeescapeRegExp(text);
 
// Special MediaWiki escape - underscore/space are often equivalent
Line 1,190:
*/
unbind: function UnbinderUnbind(prefix, postfix) {
var re = new RegExp(prefix + '(.[\\s\\S]*?)' + postfix, 'g');
this.content = this.content.replace(re, Morebits.unbinder.getCallback(this));
},
Line 1,232:
* is fairly unlikely that anyone will iterate over a Date object.
*/
 
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December' ];
 
Date.monthNamesAbbrev = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
 
Date.prototype.getMonthName = function() {
return Date.monthNames[this.getMonth()];
};
 
Date.prototype.getMonthNameAbbrev = function() {
return Date.monthNamesAbbrev[this.getMonth()];
};
 
Date.prototype.getUTCMonthName = function() {
return Datemw.monthNamesconfig.get('wgMonthNames')[this.getUTCMonth() + 1];
};
 
Date.prototype.getUTCMonthNameAbbrev = function() {
return Datemw.monthNamesAbbrevconfig.get('wgMonthNamesShort')[this.getUTCMonth() + 1];
};
 
 
// Morebits.wikipedia.namespaces is deprecated - use mw.config.get('wgFormattedNamespaces') or mw.config.get('wgNamespaceIds') instead
Line 2,623 ⟶ 2,609:
// errors here are only generated by extensions which hook APIEditBeforeSave within MediaWiki,
// which as of 1.34.0-wmf.23 (Sept 2019) should only encompass captcha messages
var $editNode =if ($(xml).find('editcaptcha');.length > 0) {
var blacklist = $editNode.attr('spamblacklist');
 
if (blacklist) {
var code = document.createElement('code');
code.style.fontFamily = 'monospace';
code.appendChild(document.createTextNode(blacklist));
ctx.statusElement.error(['Could not save the page because the URL ', code, ' is on the spam blacklist.']);
} else if ($(xml).find('captcha').length > 0) {
ctx.statusElement.error('Could not save the page because the wiki server wanted you to fill out a CAPTCHA.');
} else if ($editNode.attr('code') === 'abusefilter-disallowed') {
ctx.statusElement.error('The edit was disallowed by the edit filter rule "' + $editNode.attr('info').substring(17) + '".');
} else if ($editNode.attr('info').indexOf('Hit AbuseFilter:') === 0) {
var div = document.createElement('div');
div.className = 'toccolours';
div.style.fontWeight = 'normal';
div.style.color = 'black';
div.innerHTML = $editNode.attr('warning');
ctx.statusElement.error([ 'The following warning was returned by the edit filter: ', div, 'If you wish to proceed with the edit, please carry it out again. This warning wil not appear a second time.' ]);
// XXX provide the user with a way to automatically retry the action if they so choose -
// I can't see how to do this without creating a UI dependency on Morebits.wiki.page though -- TTO
} else {
ctx.statusElement.error('Unknown error received from API while saving page');
Anonymous user