MediaWiki:Gadget-morebits.js: Difference between revisions

m
1 revision: new version of Twinkle
m (1 revision)
m (1 revision: new version of Twinkle)
 
(One intermediate revision by one other user not shown)
Line 269:
if( current.disabled ) {
subnode.setAttribute( 'disabled', 'disabled' );
}
if( data.event ) {
subnode.addEventListener( 'change', data.event, false );
} else if ( current.event ) {
subnode.addEventListener( 'change', current.event, true );
}
label = cur_div.appendChild( document.createElement( 'label' ) );
Line 281 ⟶ 276:
Morebits.quickForm.element.generateTooltip( label, current );
}
 
var event;
if( current.subgroup ) {
var tmpgroup = current.subgroup; // $.extend({}, current.subgroup); really needed?
 
if( ! $.isArray( tmpgroup ) ) {
Line 294 ⟶ 290:
});
$.each( tmpgroup, function( idx, el ) {
ifvar newEl = $.extend( !{}, el.type ) {;
el.typeif( =! datanewEl.type; ) {
newEl.type = data.type;
}
elnewEl.name = (current.name || data.name) + '.' + elnewEl.name;
subgroupRaw.append( elnewEl );
} );
 
Line 335 ⟶ 332:
};
subnode.addEventListener( 'change', event, true );
}
// add users' event last, so it can interact with the subgroup
if( data.event ) {
subnode.addEventListener( 'change', data.event, false );
} else if ( current.event ) {
subnode.addEventListener( 'change', current.event, true );
}
}
Line 792 ⟶ 795:
 
RegExp.escape = function( text, space_fix ) {
 
text = $.escapeRE(text);
 
Line 1,201 ⟶ 1,203:
'101': 'Portal talk',
'108': 'Book',
'109': 'Book talk',
'446': 'Education Program',
'447': 'Education Program talk',
'710': 'TimedText',
'711': 'TimedText talk',
'828': 'Module',
'829': 'Module talk'
};
 
Line 1,224 ⟶ 1,232:
'101': 'Portal talk',
'108': 'Book',
'109': 'Book talk',
'446': 'Education Program',
'447': 'Education Program talk',
'710': 'TimedText',
'711': 'TimedText talk',
'828': 'Module',
'829': 'Module talk'
};
 
Line 1,236 ⟶ 1,250:
Morebits.wiki = {};
 
// AnalyzesDetermines the HTML ofwhether the current page (i.e. no AJAXis requests)a toredirect determineor ifsoft itredirect
// (fails to detect soft redirects on edit, history, etc. pages)
// is a redirect or soft redirect
Morebits.wiki.isPageRedirect = function wikipediaIsPageRedirect() {
return !!($mw.config.get("span.redirectTextwgIsRedirect").length > 0 || document.getElementById("softredirect"));
};
 
Line 1,574 ⟶ 1,588:
*
* getCreator(): returns the user who created the page following lookupCreator()
*
* getCurrentID(): returns a string containing the current revision ID of the page
*
* patrol(): marks the page as patrolled, if possible
Line 1,666 ⟶ 1,682:
revertUser: null,
fullyProtected: false,
suppressProtectWarning: false,
conflictRetries: 0,
retries: 0,
Line 1,767 ⟶ 1,784:
this.setOldID = function(oldID) {
ctx.revertOldID = oldID;
};
 
this.getCurrentID = function() {
return ctx.revertCurID;
};
 
Line 1,835 ⟶ 1,856:
ctx.watchlistOption = 'nochange';
}
};
 
this.suppressProtectWarning = function() {
ctx.suppressProtectWarning = true;
};
 
Line 1,899 ⟶ 1,924:
}
 
if (ctx.fullyProtected && !confirm('You are about to make an edit to the fully protected page "' + ctx.pageNamesuppressProtectWarning && +
!confirm('You are about to make an edit to the fully protected page "' + ctx.pageName +
(ctx.fullyProtected === 'infinity' ? '" (protected indefinitely)' : ('" (protection expiring ' + ctx.fullyProtected + ')')) +
'. \n\nClick OK to proceed with the edit, or Cancel to skip this edit.')) {
Line 2,223 ⟶ 2,249:
 
ctx.editToken = $(xml).find('page').attr('edittoken');
if (!ctx.editToken) {
{
ctx.statusElement.error("Failed to retrieve edit token.");
ctx.onLoadFailure(this);
Line 2,230 ⟶ 2,255:
}
ctx.loadTime = $(xml).find('page').attr('starttimestamp');
if (!ctx.loadTime) {
{
ctx.statusElement.error("Failed to retrieve start timestamp.");
ctx.onLoadFailure(this);
Line 2,237 ⟶ 2,261:
}
ctx.lastEditTime = $(xml).find('page').attr('touched');
ctx.revertCurID = $(xml).find('page').attr('lastrevid');
 
if (ctx.editMode === 'revert') {
Line 2,321 ⟶ 2,346:
 
// errors here are only generated by extensions which hook APIEditBeforeSave within MediaWiki
// Wikimedia wikis should only return spam blacklist errors, captchas, and captchasAbuseFilter messages
var blacklist$editNode = $(xml).find('edit').attr('spamblacklist');
var blacklist = $editNode.attr('spamblacklist');
 
if (blacklist) {
Line 2,329 ⟶ 2,355:
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 ) {
}
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 {
} 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");
}
Line 2,424 ⟶ 2,459:
if (Morebits.userIsInGroup('sysop')) {
var editprot = $(xml).find('pr[type="edit"]');
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !confirm('You are about to move the fully protected page "' + ctx.pageNamesuppressProtectWarning && +
!confirm('You are about to move the fully protected page "' + ctx.pageName +
(editprot.attr('expiry') === 'infinity' ? '" (protected indefinitely)' : ('" (protection expiring ' + editprot.attr('expiry') + ')')) +
'. \n\nClick OK to proceed with the move, or Cancel to skip this move.')) {
Line 2,476 ⟶ 2,512:
// extract protection info
var editprot = $(xml).find('pr[type="edit"]');
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !confirm('You are about to delete the fully protected page "' + ctx.pageNamesuppressProtectWarning +&&
!confirm('You are about to delete the fully protected page "' + ctx.pageName +
(editprot.attr('expiry') === 'infinity' ? '" (protected indefinitely)' : ('" (protection expiring ' + editprot.attr('expiry') + ')')) +
'. \n\nClick OK to proceed with the deletion, or Cancel to skip this deletion.')) {
Line 2,792 ⟶ 2,829:
removeLink: function( link_target ) {
var first_char = link_target.substr( 0, 1 );
var link_re_string = "[" + first_char.toUpperCase() + first_char.toLowerCase() + ']' + RegExp.escape( link_target.substr( 1 ), true );
var link_simple_re = new RegExp( "\\[\\[:?(" + link_re_string + ")\\]\\]", 'g' );
var link_named_re = new RegExp( "\\[\\[:?" + link_re_string + "\\|(.+?)\\]\\]", 'g' );
Line 2,803 ⟶ 2,840:
reason = reason ? (reason + ': ') : '';
var first_char = image.substr( 0, 1 );
var image_re_string = "[" + first_char.toUpperCase() + first_char.toLowerCase() + ']' + RegExp.escape( image.substr( 1 ), true );
 
/*
Line 2,862 ⟶ 2,899:
removeTemplate: function( template ) {
var first_char = template.substr( 0, 1 );
var template_re_string = "(?:[Tt]emplate:)?\\s*[" + first_char.toUpperCase() + first_char.toLowerCase() + ']' + RegExp.escape( template.substr( 1 ), true );
var links_re = new RegExp( "\\{\\{" + template_re_string );
var allTemplates = Morebits.array.uniq(Morebits.string.splitWeightedByKeys( this.text, '{{', '}}', [ '{{{', '}}}' ] ));
0

edits