MediaWiki:Gadget-HotCats.js
Apparence
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
// {{Catégorisation JS}}<pre><nowiki>
/*
HotCat V2.34
Ajax-based simple Categorie manager. Allows adding/removing/changing categories on a page view.
Supports multiple Categorie changes, as well as redirect and disambiguation resolution. Also
plugs into the upload form. Search engines to use for the suggestion list are configurable, and
can be selected interactively.
Documentation: https://commons.wikimedia.org/wiki/Help:Gadget-HotCat
List of main authors: https://commons.wikimedia.org/wiki/Help:Gadget-HotCat/Version_history
License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
Choose whichever license of these you like best :-)
*/
/*
This code is MW version safe. It should run on any MediaWiki installation >= MW 1.15. Note
that HotCat is supposed to run with or without jQuery, and also on older installations that
do not yet have window.mw. If you use any of these newer features, make sure you qualify them
by checking whether they exist at all, and by providing some meaningful fallback implementation
if not. To start itself, HotCat uses jQuery(document).ready(). If it doesn't exist, HotCat won't
start.
*/
/* jshint ignore:start */ // This old code uses too many coding conventions incompatible with jshint.
(function () {
// Support: MW 1.16
var conf = window.mw ? mw.config.get() : window;
if (
// Guard against double inclusions (in old IE/Opera element ids become window properties)
(window.HotCat && !window.HotCat.nodeName)
// Not on edit pages
|| conf.wgAction == 'edit'
) {
return;
}
// Configuration stuff.
window.HotCat = {
// Localize these messages to the main language of your wiki.
messages :
{cat_removed : '[[Categorie:$1]] enlevée'
,template_removed : '{{[[Categorie:$1]]}} elevé'
,cat_added : '[[Categorie:$1]] ajoutée'
,cat_keychange: 'nouvelle clé de tri pour [[Categorie:$1]]: "$2"' // $2 is the new key
,cat_notFound : 'La catégorie « $1 » est introuvable.'
,cat_exists : 'La catégorie « $1 » existe déjà ; elle n\'a pas été ajoutée.'
,cat_resolved : ' (redirection de [[Categorie:$1]] réparée)'
,uncat_removed: 'bandeau {{Maintenance}} retiré'
,separator : '; '
,prefix : ""
// Some text to prefix to the edit summary.
,using : ' avec [[Help:Gadget-HotCat|HotCat]]'
// Some text to append to the edit summary. Named 'using' for historical reasons. If you prefer
// to have a marker at the front, use prefix and set this to the empty string.
,multi_change : '$1 catégories'
// $1 is replaced by a number. If your language has several plural forms (c.f. [[:en:Dual (grammatical form)]]),
// you can set this to an array of strings suitable for passing to mw.language.configPlural().
// If that function doesn't exist, HotCat will simply fall back to using the last
// entry in the array.
,commit : 'Enregistrer'
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
,ok : 'OK'
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
,cancel : 'Annuler'
// Button text. Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
,multi_error : 'Impossible de récupérer la page sur le serveur. Vos changements ne peuvent donc '
+'pas être enregistré. Veuillez nous excuser pour l\'inconvénient.'
// Localize to wgContentLanguage here; localize to wgUserLanguage in a subpage,
// see localization hook below.
,short_catchange : null
// Defaults to '[[' + Categorie_canonical + ':$1]]'. Can be overridden if in the short edit summaries
// not the standard Categorie name should be used but, say, a shorter namespace alias. $1 is replaced
// by a Categorie name.
}
,Categorie_regexp : '[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]'
// Regular sub-expression matching all possible names for the Categorie namespace. Is automatically localized
// correctly if you're running MediaWiki 1.16 or later. Otherwise, set it appropriately, e.g. at the German
// Wikipedia, use '[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]|[Kk][Aa][Tt][Ee][Gg][Oo][Rr][Ii][Ee]', or at the
// Chinese Wikipedia, use '[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]|分类|分類'. Note that namespaces are case-
// insensitive!
,Categorie_canonical : 'Categorie'
// The standard Categorie name on your wiki. Is automatically localized correctly if you're running
// MediaWiki 1.16 or later; otherwise, set it to the preferred Categorie name (e.g., "Kategorie").
,categories : 'Categories'
// Plural of Categorie_canonical.
,disambig_Categorie : 'Disambiguation'
// Any Categorie in this Categorie is deemed a disambiguation Categorie; i.e., a Categorie that should not contain
// any items, but that contains links to other categories where stuff should be categorized. If you don't have
// that concept on your wiki, set it to null. Use blanks, not underscores.
,redir_Categorie : 'Categorie redirects'
// Any Categorie in this Categorie is deemed a (soft) redirect to some other Categorie defined by a link
// to another non-blacklisted Categorie. If your wiki doesn't have soft Categorie redirects, set this to null.
// If a soft-redirected Categorie contains more than one link to another non-blacklisted Categorie, it's considered
// a disambiguation Categorie instead.
,links : {change: '(±)', remove: '(\u2212)', add: '(+)', restore: '(×)', undo: '(×)', down: '(\u2193)', up: '(\u2191)'}
// The little modification links displayed after Categorie names. U+2212 is a minus sign; U+2193 and U+2191 are
// downward and upward pointing arrows. Do not use ↓ and ↑ in the code!
,tooltips : {
change: 'Modifier'
,remove: 'Retirer'
,add: 'Ajouter une catégorie'
,restore: 'Annuler les modifications'
,undo: 'Annuler les modifications'
,down: 'Voir et modifier les sous-catégories'
,up: 'Voir et modifier les catégories mères'
}
// The tooltips for the above links
,addmulti : '<span>+<sup>+</sup></span>'
// The HTML content of the "enter multi-mode" link at the front.
,multi_tooltip : 'Modify several categories'
// Tooltip for the "enter multi-mode" link
,disable :
function () { // Return true to disable HotCat.
var ns = conf.wgNamespaceNumber;
var nsIds = conf.wgNamespaceIds;
return ( ns < 0 // Special pages; Special:Upload is handled differentlye
|| ns === 828 // Module (Lua)
|| ns === 8 // MediaWiki
|| ns === 6 && conf.wgArticleId === 0 // Non-existing file pages
|| ns === 2 && /\.(js|css)$/.test(conf.wgTitle) // User scripts
|| nsIds
&& ( ns === nsIds['creator']
|| ns === nsIds['timedtext']
|| ns === nsIds['institution']
)
);
}
,uncat_regexp : /\{\{[Mm]aintenance(?:\|(?:job=)catégoriser)?(?:\|(?:date=)?[0-9a-z ]*)?\}\}/g
// A regexp matching a templates used to mark uncategorized pages, if your wiki does have that.
// If not, set it to null.
,existsYes : '//upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png'
,existsNo : '//upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png'
// The images used for the little indication icon. Should not need changing.
,template_regexp : '[Tt][Ee][Mm][Pp][Ll][Aa][Tt][Ee]'
// Regexp to recognize templates. Like "Categorie" above; autolocalized for MW 1.16+, otherwise set manually here.
// On the German Wikipedia, you might use '[Tt][Ee][Mm][Pp][Ll][Aa][Tt][Ee]|[Vv][Oo][Rr][Ll][Aa][Gg][Ee]'.
,template_categories : {}
// a list of categories which can be removed by removing a template
// key: the Categorie without namespace
// value: A regexp matching the template name, again without namespace
// If you don't have this at your wiki, or don't want this, set it to an empty object {}.
,engine_names : {
searchindex : 'Search index'
,pagelist : 'Page list'
,combined : 'Combined search'
,subcat : 'Subcategories'
,parentcat : 'Parent categories'
}
// Names for the search engines
,capitalizePageNames : true
// Set to false if your wiki has case-sensitive page names. MediaWiki has two modes: either the first letter
// of a page is automatically capitalized ("first-letter"; Categorie:aa == Categorie:Aa), or it isn't
// ("case-sensitive"; Categorie:aa != Categorie:Aa). It doesn't currently have a fully case-insensitive mode
// (which would mean Categorie:aa == Categorie:Aa == Categorie:AA == Categorie:aA)
// HotCat tries to set this correctly automatically using an API query. It's still a good idea to manually
// configure it correctly; either directly here if you copied HotCat, or in the local configuration file
// MediaWiki:Gadget-HotCat.js/local_defaults if you hotlink to the Commons-version, to ensure it is set even
// if that API query should fail for some strange reason.
,upload_disabled : false
// If upload_disabled is true, HotCat will not be used on the Upload form.
,blacklist : null
// Single regular expression matching blacklisted categories that cannot be changed or
// added using HotCat. For instance /\bstubs?$/ (any Categorie ending with the word "stub"
// or "stubs"), or /(\bstubs?$)|\bmaintenance\b/ (stub categories and any Categorie with the
// word "maintenance" in its title.
// Stuff changeable by users:
,bg_changed : '#F8CCB0'
// Background for changed categories in multi-edit mode. Default is a very light salmon pink.
,no_autocommit : false
// If true, HotCat will never automatically submit changes. HotCat will only open an edit page with
// the changes; users must always save explicitly.
,del_needs_diff : false
// If true, the "Categorie deletion" link "(-)" will never save automatically but always show an
// edit page where the user has to save the edit manually. Is false by default because that's the
// traditional behavior. This setting overrides no_autocommit for "(-)" links.
,suggest_delay : 100
// Time, in milliseconds, that HotCat waits after a keystroke before making a request to the
// server to get suggestions.
,editbox_width : 40
// Default width, in characters, of the text input field.
,suggestions : 'combined'
// One of the engine_names above, to be used as the default suggestion engine.
,fixed_search : false
// If true, always use the default engine, and never display a selector.
,use_up_down : true
// If false, do not display the "up" and "down" links
,list_size : 5
// Default list size
,single_minor : true
// If true, single Categorie changes are marked as minor edits. If false, they're not.
,dont_add_to_watchlist : false
// If true, never add a page to the user's watchlist. If false, pages get added to the watchlist if
// the user has the "Add pages I edit to my watchlist" or the "Add pages I create to my watchlist"
// options in his or her preferences set.
,shortcuts : null
,addShortcuts :
function (map) {
if (!map) return;
window.HotCat.shortcuts = window.HotCat.shortcuts || {};
for (var k in map) {
if (!map.hasOwnProperty (k) || typeof k != 'string') continue;
var v = map[k];
if (typeof v != 'string') continue;
k = k.replace (/^\s+|\s+$/g, "");
v = v.replace (/^\s+|\s+$/g, "");
if (k.length === 0 || v.length === 0) continue;
window.HotCat.shortcuts[k] = v;
}
}
};
// More backwards compatibility. We have a few places where we test for the browser: once for
// Safari < 3.0, and twice for WebKit (Chrome or Safari, any versions)
var ua = navigator.userAgent.toLowerCase();
var is_webkit = /applewebkit\/\d+/.test(ua) && ua.indexOf ('spoofer') < 0;
// And even more compatbility. HotCat was developed without jQuery, and anyway current jQuery
// (1.7.1) doesn't seem to support in jquery.getJSON() or jQuery.ajax() the automatic
// switching from GET to POST requests if the query arguments would make the uri too long.
// (IE has a hard limit of 2083 bytes, and the servers may have limits around 4 or 8kB.)
// Anyway, HotCat is supposed to run on wikis without jQuery, so we'd have to supply some
// ajax routines ourselves in any case. We can't rely on the old sajax_init_object(), newer
// MW versions (>= 1.19) might not have it.
var getJSON = (function () {
function getRequest () {
var request = null;
try {
request = new window.XMLHttpRequest();
} catch (anything) {
if (window.ActiveXObject) {
try {
request = new window.ActiveXObject('Microsoft.XMLHTTP');
} catch (any) {
}
} // end if IE
} // end try-catch
return request;
}
return function (settings) {
var req = getRequest();
if (!req && settings && settings.error) settings.error (req);
if (!req || !settings || !settings.uri) return req;
var uri = armorUri (settings.uri);
var args = settings.data || null;
var method;
if (args && uri.length + args.length + 1 > 2000) {
// We lose caching, but at least we can make the request
method = 'POST';
req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
} else {
method = 'GET';
if (args) uri += '?' + args;
args = null;
}
req.open (method, uri, true);
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 || !req.responseText || !(/^\s*[\{\[]/.test(req.responseText))) {
if (settings.error) settings.error (req);
} else {
if (settings.success) settings.success (eval ('(' + req.responseText + ')'));
}
};
req.setRequestHeader ('Pragma', 'cache=yes');
req.setRequestHeader ('Cache-Control', 'no-transform');
req.send (args);
return req;
};
})();
function armorUri (uri) {
// Avoid protocol-relative URIs, IE7 has a bug with them in Ajax calls
if (uri.length >= 2 && uri.substring(0, 2) == '//') return document.location.protocol + uri;
return uri;
}
function LoadTrigger (needed) {
this.queue = [];
this.toLoad = needed;
}
LoadTrigger.prototype = {
register : function (callback) {
if (this.toLoad <= 0) {
callback (); // Execute directly
} else {
this.queue[this.queue.length] = callback;
}
},
loaded : function () {
if (this.toLoad > 0) {
this.toLoad--;
if (this.toLoad === 0) {
// Run queued callbacks once
for (var i = 0; i < this.queue.length; i++) this.queue[i]();
this.queue = [];
}
}
}
};
var setupCompleted = new LoadTrigger(1);
// Used to run user-registered code once HotCat is fully set up and ready.
HotCat.runWhenReady = function (callback) {setupCompleted.register(callback);};
var loadTrigger = new LoadTrigger(2);
// Used to delay running the HotCat setup until /local_defaults and localizations have been loaded.
function load (uri) {
var head = document.getElementsByTagName ('head')[0];
var s = document.createElement ('script');
s.setAttribute ('src', armorUri(uri));
s.setAttribute ('type', 'text/javascript');
var done = false;
function afterLoad () {
if (done) return;
done = true;
s.onload = s.onreadystatechange = s.onerror = null; // Properly clean up to avoid memory leaks in IE
if (head && s.parentNode) head.removeChild (s);
loadTrigger.loaded();
}
s.onload = s.onreadystatechange = function () { // onreadystatechange for IE, onload for all others
if (done) return;
if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
afterLoad ();
}
};
s.onerror = afterLoad; // Clean up, but otherwise ignore errors
head.insertBefore (s, head.firstChild); // appendChild may trigger bugs in IE6 here
}
function loadJS (page) {
load (conf.wgServer + conf.wgScript + '?title=' + encodeURIComponent (page) + '&action=raw&ctype=text/javascript');
}
function loadURI (href) {
var url = href;
if (url.substring (0, 2) == '//') {
url = window.location.protocol + url;
} else if (url.substring (0, 1) == '/') {
url = conf.wgServer + url;
}
load (url);
}
// Load local configurations, overriding the pre-set default values in the HotCat object above. This is always loaded
// from the wiki where this script is executing, even if this script itself is hotlinked from the Commons. This can
// be used to change the default settings, or to provide localized interface texts for edit summaries and so on.
loadJS ('MediaWiki:Gadget-HotCat.js/local_defaults');
// Load localized UI texts. These are the texts that HotCat displays on the page itself. Texts shown in edit summaries
// should be localized in /local_defaults above.
if (conf.wgUserLanguage != 'en') {
// Lupo: somebody thought it would be a good idea to add this. So the default is true, and you have to set it to false
// explicitly if you're not on the Commons and don't want that.
if (typeof window.hotcat_translations_from_commons == 'undefined') {
window.hotcat_translations_from_commons = true;
}
// Localization hook to localize HotCat messages, tooltips, and engine names for wgUserLanguage.
if (window.hotcat_translations_from_commons && conf.wgServer.indexOf('//commons') < 0) {
loadURI ('//commons.wikimedia.org/w/index.php?title='
+ 'MediaWiki:Gadget-HotCat.js/' + conf.wgUserLanguage
+ '&action=raw&ctype=text/javascript'
);
} else {
// Load translations locally
loadJS ('MediaWiki:Gadget-HotCat.js/' + conf.wgUserLanguage);
}
} else {
loadTrigger.loaded();
}
// No further changes should be necessary here.
// The following regular expression strings are used when searching for categories in wikitext.
var wikiTextBlank = '[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+';
var wikiTextBlankRE = new RegExp (wikiTextBlank, 'g');
// Regexp for handling blanks inside a Categorie title or namespace name.
// See http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Title.php?revision=104051&view=markup#l2722
// See also http://www.fileformat.info/info/unicode/Categorie/Zs/list.htm
// MediaWiki collapses several contiguous blanks inside a page title to one single blank. It also replace a
// number of special whitespace characters by simple blanks. And finally, blanks are treated as underscores.
// Therefore, when looking for page titles in wikitext, we must handle all these cases.
// Note: we _do_ include the horizontal tab in the above list, even though the MediaWiki software for some reason
// appears to not handle it. The zero-width space \u200B is _not_ handled as a space inside titles by MW.
var wikiTextBlankOrBidi = '[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200B\\u200E\\u200F\\u2028-\\u202F\\u205F\\u3000]*';
// Whitespace regexp for handling whitespace between link components. Including the horizontal tab, but not \n\r\f\v:
// a link must be on one single line.
// MediaWiki also removes Unicode bidi override characters in page titles (and namespace names) completely.
// This is *not* handled, as it would require us to allow any of [\u200E\u200F\u202A-\u202E] between any two
// characters inside a Categorie link. It _could_ be done though... We _do_ handle strange spaces, including the
// zero-width space \u200B, and bidi overrides between the components of a Categorie link (adjacent to the colon,
// or adjacent