Utilisateur:PoM/monobook.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.importScript('User:EDUCA33E/LiveRC.js');
<!--
/*********************************************************
* OUTILS GÉNÉRAUX
*********************************************************/
/*
* addLoadEvent : appeler une fonction lorsque la page est chargée
*/
//''Testé avec MediaWiki 1.6a'' - ajoute un onglet "Google" qui permet de lancer une recherche locale ou globale sur Google avec le nom de l'article //comme mot-clé. Hégésippe a ajouté quelques liens en plus à la version originale.
function googleOnglet() {
var a = document.getElementById("p-cactions");
if (a)
{
var pageName = document.title.replace(" - Wikipédia", "");
b = a.getElementsByTagName("ul");
if(b.length > 0)
{
b[0].innerHTML = b[0].innerHTML
+ '<li id="ca-nstab-user"><img src="http://www.google.com/intl/en/logos/Logo_60wht.gif" height="20px">'
+ '<a href="http://www.google.fr/search?num=20&hl=en&safe=off&q=site%3Afr.wikipedia.org+' + pageName + '&btnG=Search">'
+ 'wp-fr</a>'
+ '<a href="http://www.google.fr/search?num=20&hl=en&safe=off&q=site%3Awikipedia.org+' + pageName + '&btnG=Search">'
+ 'wp</a>'
+ '<a href="http://www.google.fr/search?num=20&hl=fr&safe=off&q=' + pageName + '&btnG=Search&meta=lr%3Dlang_fr">'
+ 'web-fr</a>'
+ '<a href="http://www.google.fr/search?num=20&hl=en&safe=off&q=' + pageName + '&btnG=Search">'
+ 'web</a>'
+ '</li>';
}
}
}
addLoadEvent(googleOnglet);
// -----------------------------------------------------------------
function addLoadEvent(func) {
if (window.addEventListener) {
window.addEventListener("load", func, false);
} else
if (window.attachEvent) {
window.attachEvent("onload", func);
}
}
/*
* insertAfter : insérer un élément dans une page
*/
function insertAfter(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
/*********************************************************
* OUTILS À DESTINATION DE TOUS UTILISATEURS
*********************************************************/
/*
* NUPatrol : Patrouille nouveaux arrivants
*/
function TodayDate() {
m = new Array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
today = new Date();
day = today.getDate();
year = today.getYear();
if (year < 2000)
year = year + 1900;
return (day + " " + m[today.getMonth()] + " " + year);
}
function NUPatrol(){
if ( window.location.href.indexOf( 'Special:Log/newusers') < 0 &&
window.location.href.indexOf( '&type=newusers' ) < 0 ) return;
var items, item, i, links, user, name, talk, contribs, insertLoc, link;
items = document.getElementById( 'bodyContent' ).getElementsByTagName( 'ul' )[ 0 ].getElementsByTagName( 'li' );
function NewLink( txt, url, plainlinks, linkColor )
{ var a = document.createElement( 'a' );
a.appendChild( document.createTextNode( txt ) );
a.href = url;
if ( plainlinks ) a.className = 'plainlinks';
if ( linkColor )
{ if ( typeof linkColor == "string" )
a.style.color = linkColor;
else a.style.color = '#FF0000'; // old default behavior
}
return a;
}
for ( i = 0; i < items.length; i++ )
{
item = items[ i ];
links = item.getElementsByTagName( 'a' );
user = links[ 0 ]; name = user.firstChild.nodeValue;
talk = links[ 2 ]; talk.firstChild.nodeValue = 'discussion'; // lowercase 'Talk' for consistency
contribs = links[ 3 ];
insertLoc = user.nextSibling; // ' newusers '
item.insertBefore( document.createTextNode( ' ( ' ), insertLoc );
item.insertBefore( talk, insertLoc );
item.insertBefore( document.createTextNode( ', ' ), insertLoc );
item.insertBefore( contribs, insertLoc );
item.insertBefore( document.createTextNode( ', ' ), insertLoc );
item.insertBefore( NewLink( 'actions', '/w/index.php?title=Special%3ALog&user=' + name, true, '#000088' ), insertLoc );
item.insertBefore( document.createTextNode( ', ' ), insertLoc );
item.insertBefore( NewLink( 'blocages', '/w/index.php?title=Special%3ALog&type=block&page=User%3A' + name, true, '#008800' ), insertLoc );
item.insertBefore( document.createTextNode( ', ' ), insertLoc );
item.insertBefore( NewLink( 'est bloqué ?', '/wiki/Special:Ipblocklist?action=search&ip=' + name, true, '#888800' ), insertLoc );
item.insertBefore( document.createTextNode( ', ' ), insertLoc );
item.insertBefore( NewLink( 'bloquer', '/w/index.php?title=Special:Blockip&ip=' + name, true, '#880000' ), insertLoc );
item.insertBefore( document.createTextNode( ' )' ), insertLoc );
item.removeChild( insertLoc.nextSibling ); // should remove the span
item.removeChild( insertLoc ); // should remove ' newusers ' text
}
}
addLoadEvent (NUPatrol);
/*
* DeluxeBar : meilleur champ d'édition
*/
function DeluxeBar() {
if (document.createTextNode) {
var toolbar = document.getElementById("toolbar");
if (!toolbar) return;
var messages = new Array()
messages[0] = "{{subst:" + "Bienvenue sur ta page" + "}}" + "~~" + "~~";
messages[1] = "{{subst:" + "Bienvenue" + "}}" + "~~" + "~~";
messages[2] = "{{subst:" + "Test 1" + "}}" + "~~" + "~~";
messages[3] = "{{subst:" + "Test 2" + "}}" + "~~" + "~~";
messages[4] = "{{subst:" + "Test 3" + "}}" + "~~" + "~~";
messages[5] = "{{subst:" + "Bienvenue spammeur" + "}}" + "~~" + "~~";
messages[6] = "{{subst:" + "VandaleBloqué|n" + "}}" + "~~" + "~~";
messages[7] = "{{" + "suppression" + "}}";
messages[8] = "#" + "{{"+ "Supprimer" + "}}" + " Pour des raisons que moi seul connait mais qui respecte ainsi la PdD qui oblige à argumenter.";
messages[9] = "#" + "{{"+ "Conserver" + "}}" + " Pour des raisons que moi seul connait mais qui respecte ainsi la PdD qui oblige à argumenter.";
messages[10] = "--{{"+ "Utilisateur:PoM/Signature" + "}}";
var images = new Array()
images[0] = "http://commons.wikimedia.org/wiki/Image:Button_accueilA.png";
images[1] = "http://commons.wikimedia.org/wiki/Image:Button_accueilB.png";
images[2] = "http://commons.wikimedia.org/wiki/Image:Bouton_Vandale1.png";
images[3] = "http://commons.wikimedia.org/wiki/Image:Bouton_Vandale2.png";
images[4] = "http://commons.wikimedia.org/wiki/Image:Bouton_Vandale3.png";
images[5] = "http://commons.wikimedia.org/wiki/Image:Button_base.png";
images[6] = "http://commons.wikimedia.org/wiki/Image:Button_base.png";
images[7] = "http://commons.wikimedia.org/wiki/Image:Button_base.png";
images[8] = "http://commons.wikimedia.org/wiki/Image:Button_base.png";
images[9] = "http://commons.wikimedia.org/wiki/Image:Button_base.png";
images[10] = "http://upload.wikimedia.org/wikipedia/commons/f/ff/Qsicon_Achtung.png";
var commentaires = new Array()
commentaires[0] = "Bienvenue sur ta page !";
commentaires[1] = "Bienvenue !";
commentaires[2] = "avertissement 1er niveau";
commentaires[3] = "avertissement 2e niveau";
commentaires[4] = "avertissement 3e niveau" ;
commentaires[5] = "avertissement spammeur";
commentaires[6] = "avis de blocage" ;
commentaires[7] = "Proposé à la suppression";
commentaires[8] = "Supprimer et motif";
commentaires[9] = "Conserver et motif";
commentaires[10] = "Signature pas content";
////////////////////////////////
for (var i=0;i<messages.length;i++) {
var img = document.createElement("img");
img.setAttribute("src", images[i]);
img.setAttribute("alt", commentaires[i]);
var ref = document.createElement("a");
ref.setAttribute("href", "javascript:insertTags('', \"" + messages[i] + "\", '');" +
"javascript:changeSummary(\"" + commentaires[i] + "\");" );
ref.appendChild(img);
toolbar.appendChild(ref);
}
}
}
function changeSummary(sampleText) {
document.editform.wpSummary.value = sampleText;
}
addLoadEvent(DeluxeBar);
/*
* OptimizedShortPages : rajout de fonctionnalités dans [[Special:Shortpages]]
*/
function OptimizedShortPages() {
if (document.URL.indexOf("http://fr.wikipedia.org/wiki/Special:Shortpages")!=0) return;
var mainNode = document.getElementsByTagName("ol");
var allArticles = mainNode[0].getElementsByTagName("li");
for (i=0; i<allArticles.length; i++) {
var articleName = allArticles[i].childNodes[0].getAttribute("title");
var historyElement = document.createElement("a");
var histUrl = "/w/index.php?title=" + articleName + "&action=history"
historyElement.setAttribute("href", histUrl);
var historyText = document.createTextNode("… (hist) ");
historyElement.appendChild(historyText);
insertAfter(allArticles[i], historyElement, allArticles[i].childNodes[1]);
var relatedElement = document.createElement("a");
var relatedUrl = "/wiki/Special:Whatlinkshere/" + articleName
relatedElement.setAttribute("href", relatedUrl);
var relatedText = document.createTextNode(" (liens) ");
relatedElement.appendChild(relatedText);
var diffElement = document.createElement("a");
var diffUrl = "/w/index.php?title=" + articleName + "&diff=0"
diffElement.setAttribute("href", diffUrl);
var diffText = document.createTextNode(" (diff) ");
diffElement.appendChild(diffText);
insertAfter(allArticles[i], relatedElement, historyElement);
insertAfter(allArticles[i], diffElement, relatedElement);
insertAfter(allArticles[i], document.createTextNode(allArticles[i].childNodes[1].data), diffElement);
allArticles[i].removeChild(allArticles[i].childNodes[1]);
}
}
addLoadEvent(OptimizedShortPages);
/*
* Bistro_Oracle, PaS_PaF_CSS_JS, Vandalisme : Ajout de liens dans la barre de navigation vers des pages souvent consultées
*/
function Bistro_Oracle() {
var a = document.getElementById("p-navigation");
if (a) {
b = a.getElementsByTagName("ul");
if(b.length > 0) {
b[0].innerHTML = b[0].innerHTML + '<li><a style="display: inline" id="n-bistro" title="Wikipédia:Le Bistro/'+ TodayDate() +'" href="/wiki/Wikip%C3%A9dia:Le_Bistro/'+ TodayDate() +'">Bistro</a>, <a style="display: inline" id="n-bistro" title="Oracle" href="/wiki/Wikipédia:Oracle">Oracle</a>, <a style="display: inline" id="n-bistro" title="BA" href="/wiki/WP:BA">BA</a></li>'
}
}
}
addLoadEvent(Bistro_Oracle);
function PaS_PaF_CSS_JS() {
var a = document.getElementById("p-navigation");
if (a) {
b = a.getElementsByTagName("ul");
if(b.length > 0) {
b[0].innerHTML = b[0].innerHTML + '<li><a style="display: inline" id="n-pas" title="Wikipédia:Pages à supprimer" href="/w/index.php?title=Wikip%E9dia:Pages%20%E0%20supprimer&action=purge">PàS</a>, <a style="display: inline" id="n-paf" title="Wikipédia:Pages à fusionner" href="/w/index.php?title=Wikip%E9dia:Pages%20%E0%20fusionner&action=purge">PàF</a>, <a style="display: inline" id="n-CSS" title="Utilisateur:PoM/monobook.css" href="/w/index.php?title=Utilisateur:PoM/monobook.css">CSS</a>, <a style="display: inline" id="n-JS" title="Utilisateur:PoM/monobook.js"href="/w/index.php?title=Utilisateur:PoM/monobook.js">JS</a></li>'
}
}
}
addLoadEvent(PaS_PaF_CSS_JS);
function Vandalisme() {
var a = document.getElementById("p-navigation");
if (a) {
b = a.getElementsByTagName("ul");
if(b.length > 0) {
b[0].innerHTML = b[0].innerHTML + '<li><a style="display: inline" id="n-vand" title="Wikipédia:Vandalisme en cours"href="/wiki/Wikipédia:Vandalisme_en_cours/Alertes_en_cours">Vandalisme</a>, <a style="display: inline" id="n-vand" title="Liste de blocage"href="/wiki/Special:ipblocklist">ListeB</a></li>' ;
}
}
}
addLoadEvent(Vandalisme);
function LienArbitrage() {
var a = document.getElementById("p-navigation");
if (a) {
b = a.getElementsByTagName("ul");
if(b.length > 0) {
b[0].innerHTML = b[0].innerHTML + '<li><a style="display: inline" id="n-arbcom" title="Comité d\'arbitrage" href="/wiki/Wikipédia:Comité d\'arbitrage/Arbitrage">Arbitrage</a>, <a style="display: inline" id="n-arbcom" title="Requêtes" href="/wiki/Wikipédia:Requête aux administrateurs">Requêtes</a></li>' ;
}
}
}
addLoadEvent(LienArbitrage);
/*
* CategoryTree : Arborescence de catégories
*/
function CategoryTree() {
// Auteur : Anakin, version du 11 décembre 2005
var element = document.getElementById('ca-nstab-category');
if (element) {
var categoryname = element.firstChild.href;
categoryname = categoryname.substring(7);
var wikiname = categoryname.substring(0, categoryname.indexOf('.'));
var indexofname = categoryname.indexOf(":") + 1;
categoryname = categoryname.substring(indexofname);
var indexofampercent = categoryname.indexOf("&");
if (indexofampercent != -1)
categoryname = categoryname.substring(0, indexofampercent);
var li = document.createElement('li');
li.id = 'ca-categorytree';
var a = document.createElement('a');
a.appendChild(document.createTextNode("Arborescence"));
a.href = 'http://tools.wikimedia.de/~daniel/WikiSense/CategoryTree.php?wiki=' + wikiname + '&art=on&cat=' + categoryname;
li.appendChild(a);
document.getElementById('ca-nstab-category').parentNode.appendChild(li);
}
}
addLoadEvent(CategoryTree);
/*
* OngletPurge : Onglet pour purger le cache
*/
function OngletPurge() {
var a = document.getElementById("p-cactions");
if (a) {
var pageName = document.title.replace(" - Wikipédia", "");
b = a.getElementsByTagName("ul");
if(b.length > 0) {
b[0].innerHTML = b[0].innerHTML + '<li id="ca-nstab-user">' + '<a href="/w/index.php?action=purge&title=' + pageName + '">purger</a>' + '</li>';
}
}
}
addLoadEvent(OngletPurge);
/* == Popup de Lupin == */
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
simplePopups=true;
popupDelay=0.7;
popupStructure='original';
popupOnEditSelection=false;
popupAdminLinks=true;
var oldEditsectionLinks = true;
/*************************
* Importer commons *
*************************/
function PaletteOutils()
{
var a = document.getElementById("p-tb");
if (a)
{
b = a.getElementsByTagName("ul");
if(b.length > 0)
{
b[0].innerHTML = b[0].innerHTML
+ '<li><span id="n-bistro" title="http://commons.wikimedia.org/wiki/Special:Upload">'
+ '<a href="http://commons.wikimedia.org/wiki/Special:Upload">'
+ 'Importer une image ou un son sur Commons</a></span> </li>'
}
}
}
addLoadEvent(PaletteOutils);
/*************************
* Gestion améliorée *
*************************/
var suiviManagerAllPages = new Array();
function SuiviManagerRegexp(regexp)
{
var match = new RegExp(regexp);
for (var i=0;i<suiviManagerAllPages.length;i++) {
var pageName = suiviManagerAllPages[i].childNodes[0].getAttribute("value");
if (match.test(pageName)) {
suiviManagerAllPages[i].childNodes[0].checked=true;
}
}
}
function SuiviManagerLiensRouges()
{
for (var i=0;i<suiviManagerAllPages.length;i++) {
var pageClass = suiviManagerAllPages[i].childNodes[2].getAttribute("class");
if (pageClass && pageClass=="new") {
suiviManagerAllPages[i].childNodes[0].checked=true;
}
}
}
function SuiviManagerDeselect()
{
for (var i=0;i<suiviManagerAllPages.length;i++) {
suiviManagerAllPages[i].childNodes[0].checked=false;
}
}
function SuiviManager() {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EditWatchlist') return;
var a=-1;
var interfaceMsg = new Array();
var regexpList = new Array();
//////////////////////////////////////////////////
// Expressions régulières et liens de l'interface
//
// besoin d'aide pour les regexp ?
// http://www.commentcamarche.net/javascript/jsregexp.php3
//////////////////////////////////////////////////
interfaceMsg[++a] = "<b>Tout cocher</b>";
regexpList[a] = "^.*";
interfaceMsg[++a] = "Utilisateurs";
regexpList[a] = "^Utilisateur:";
interfaceMsg[++a] = "Wikipédia:*";
regexpList[a] = "^Wikipédia:";
interfaceMsg[++a] = "Sous-pages de PàS";
regexpList[a] = "^Wikipédia:Pages à supprimer\/";
interfaceMsg[++a] = "Sous-pages de PàV";
regexpList[a] = "^Wikipédia:Pages à vérifier\/";
interfaceMsg[++a] = "Pages du bistro";
regexpList[a] = "^Wikipédia:Le Bistro\/";
interfaceMsg[++a] = "Images";
regexpList[a] = "^Image:";
interfaceMsg[++a] = "Modèles";
regexpList[a] = "^Modèle:";
interfaceMsg[++a] = "Aide";
regexpList[a] = "^Aide:";
interfaceMsg[++a] = "Catégories";
regexpList[a] = "^Catégorie:";
interfaceMsg[++a] = "Portails";
regexpList[a] = "^Portail:";
//////////////////////////////////////////////////
var topTag = document.getElementById("contentSub")
// récupère toutes les pages
var watchlist = document.getElementsByTagName("ul");
for (u=0;u<watchlist.length;u++) {
var entries = watchlist[u].getElementsByTagName("li");
for (i=0;i<entries.length;i++) {
suiviManagerAllPages.push(entries[i]);
}
}
// prépare la mini-interface
var str = "<div style=\"background-color:#8ecfe4;font-size:1px;height:8px;border:1px solid #AAAAAA;-moz-border-radius-topright:0.5em;-moz-border-radius-topleft:0.5em;\"></div>"
+ "<div style=\"border:1px solid #6ac1de;border-top:0px solid white;padding:5px 5px 0 5px;margin-bottom:3ex;\"><p>"
+ "<div style=\"float: left; text-align: left; white-space: nowrap;\"></div>"
for (var cpt = 0; cpt < interfaceMsg.length; cpt ++) {
str += "<a href=\"javascript:SuiviManagerRegexp('" + regexpList[cpt] + "')\">"
+ interfaceMsg[cpt]
+ " •</a> "
}
str += "<a href=\"javascript:SuiviManagerLiensRouges()\">"
+ "Retirer les liens rouges"
+ " •</a> "
str += "<a href=\"javascript:SuiviManagerDeselect()\">"
+ "<b>Enlever toutes les coches</b>"
+ " •</a> "
topTag.innerHTML = topTag.innerHTML + "<br clear=all />" + str + "<p></div>"
}
addLoadEvent(SuiviManager);
//<nowiki>
/**
* Ajoute des liens après les catégories pour rapidement
* supprimer / modifier / ajouter une catégorie sur un article.
* Utilise Ajax et l'api MediaWiki pour rechercher une catégorie.
* Version adaptée pour WP:fr de [[:commons:MediaWiki:HotCat.js]]
*
* Auteur original : Magnus Manske
* Adaptation pour WP:fr : Zelda
* [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]
*/
// VARIABLES PERSONNALISABLES
// Suggestion delay in ms
var hotcat_suggestion_delay = 200;
// Taille de la liste déroulante (en items)
var hotcat_list_size = 10;
// Nombre de categories suggérées lors de la recherche
var hotcat_list_items = 50;
// Permet d'enregistrer automatiquement la modif sans repasser par la fenêtre d'édition
// var hotcat_autocommit = false;
// Permet d'afficher la liste de suggestion vers le bas
// var hotcat_list_down = false;
// FIN DE LA PERSONNALISATION DES VARIABLES
var hotcat_running = 0 ;
var hotcat_last_v = "" ;
var hotcat_exists_yes = "http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png" ;
var hotcat_exists_no = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png" ;
addOnloadHook ( hotcat ) ;
function hotcat () {
if ( hotcat_check_action() ) return ; // Edited page, reloading anyway
var catlinks = document.getElementById("catlinks");
if (! catlinks && mw.config.get('wgNamespaceNumber') %2 == 0) { // all except discussion
// let's create a fake one
var bodyC = document.getElementById("bodyContent");
catlinks = document.createElement("div");
catlinks.id = "catlinks";
catlinks.appendChild(document.createElement("div"));
catlinks.firstChild.className = "catlinks";
catlinks.firstChild.appendChild(document.createElement("div"));
catlinks.firstChild.firstChild.id = "mw-normal-catlinks";
bodyC.appendChild(catlinks);
}
var catline = document.getElementById ('mw-normal-catlinks'); // Since MW 1.13alpha
if (catline == null)
catline = getElementsByClassName ( document , "p" , "catlinks" ) [0] ; // Earlier versions
if ( catline == null || typeof catline == 'undefined' ) return ;
hotcat_modify_existing ( catline ) ;
hotcat_append_add_span ( catline ) ;
}
function hotcat_append_add_span ( catline ) {
var span_add = document.createElement ( "span" ) ;
var span_sep = document.createTextNode ( " | " ) ;
if ( catline.firstChild ) catline.appendChild ( span_sep ) ;
catline.appendChild ( span_add ) ;
hotcat_create_span ( span_add ) ;
}
String.prototype.ucFirst = function () {
return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}
function hotcat_modify_span ( span , i ) {
var cat_title = span.firstChild.getAttribute ( "title" ) ;
// Removing leading Category:
cat_title = cat_title.substr(cat_title.indexOf(":") + 1);
var sep1 = document.createTextNode ( " " ) ;
var a1 = document.createTextNode ( "(–)" ) ;
var remove_link = document.createElement ( "a" ) ;
remove_link.href = "javascript:hotcat_remove(\"" + cat_title + "\");" ;
remove_link.appendChild ( a1 ) ;
span.appendChild ( sep1 ) ;
span.appendChild ( remove_link ) ;
var mod_id = "hotcat_modify_" + i ;
var sep2 = document.createTextNode ( " " ) ;
var a2 = document.createTextNode ( "(±)" ) ;
var modify_link = document.createElement ( "a" ) ;
modify_link.id = mod_id ;
modify_link.href = "javascript:hotcat_modify(\"" + mod_id + "\");" ;
modify_link.appendChild ( a2 ) ;
span.appendChild ( sep2 ) ;
span.appendChild ( modify_link ) ;
}
function hotcat_modify_existing ( catline ) {
var spans = catline.getElementsByTagName ( "span" ) ;
for ( var i = 0 ; i < spans.length ; i++ ) {
hotcat_modify_span ( spans[i] , i ) ;
}
}
function hotcat_remove ( cat_title ) {
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
if (window.confirm("Voulez-vous vraiment supprimer la catégorie '" + cat_title + "' ?")) {
document.location = editlk + '&hotcat_removecat=' + encodeURIComponent(cat_title) ;
}
}
function hotcatGetParamValue(paramName, h) {
if (typeof h == 'undefined' ) { h = document.location.href; }
var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
var m=cmdRe.exec(h);
if (m) {
try {
return decodeURIComponent(m[1]);
} catch (someError) {}
}
return null;
}
function hotcat_check_action () {
var ret = 0 ;
if ( mw.config.get('wgAction') != "edit" ) return ret ; // Not an edit page, so no business...
var summary = new Array () ;
var t = document.editform.wpTextbox1.value ;
var prevent_autocommit = 1 ;
if ( typeof hotcat_autocommit != 'undefined' && hotcat_autocommit ) prevent_autocommit = 0 ;
// Remove existing category?
var hrc = hotcatGetParamValue('hotcat_removecat') ;
// Add new category?
var hnc = hotcatGetParamValue('hotcat_newcat') ;
if ( typeof hrc != "undefined" && hrc != null && hrc != "" ) {
var hcre = new RegExp("(\\s*)\\[\\[ *(?:Catégorie|Category) *: *" + hrc.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
var matches = t.match(hcre);
if (matches != null && matches.length == 1) { // Found one occurrence of the category - good!
if ( typeof hnc != "undefined" && hnc != null && hnc != "" ) {
t = t.replace(hcre, "$1[[Catégorie:" + hnc + "$2]]");
summary.push ( "Modification de la catégorie [[Catégorie:" + hrc + "]] → [[Catégorie:" + hnc + "]]" ) ;
} else {
t = t.replace(hcre, "");
summary.push ( "Retrait de la catégorie [[Catégorie:" + hrc + "]]" ) ;
}
ret = 1 ;
} else {
alert ( "Impossible de trouver une occurrence unique de \"" + hrc + "\" - elle est peut-être incluse via un modèle" ) ;
prevent_autocommit = 1 ;
}
} else {
// Only adding?
if ( typeof hnc != "undefined" && hnc != null && hnc != "" ) {
// Looking for last cat
var re = /\[\[(?:Catégorie|Category):[^\]]+\]\]/ig
var index = -1;
while (re.exec(t) != null) index = re.lastIndex;
var txt = "[[Catégorie:" + hnc + "]]" ;
if (index < 0) {
t = t + '\n' + txt ;
} else {
t = t.substring(0, index) + '\n' + txt + t.substring(index);
}
summary.push ( "Ajout rapide de la catégorie [[Catégorie:" + hnc + "]]" ) ;
ret = 1 ;
}
}
if ( ret ) {
document.editform.wpTextbox1.value = t ;
document.editform.wpSummary.value = summary.join( " ; " ) + " (avec [[MediaWiki:Gadget-HotCats.js|HotCats]])" ;
document.editform.wpMinoredit.checked = true ;
if ( !prevent_autocommit ) {
document.getElementById("bodyContent").style.display = "none" ; // Hiding the entire edit section so as not to tempt the user into editing...
document.editform.wpSave.click();
}
}
// This is the end, my friend, the end...
return ret ;
}
function hotcat_clear_span ( span_add ) {
while ( span_add.firstChild ) span_add.removeChild ( span_add.firstChild ) ;
}
function hotcat_create_span ( span_add ) {
hotcat_clear_span ( span_add ) ;
var a_add = document.createElement ( "a" ) ;
var a_text = document.createTextNode ( "(+)" ) ;
span_add.id = "hotcat_add" ;
a_add.href = "javascript:hotcat_add_new()" ;
a_add.appendChild ( a_text ) ;
span_add.appendChild ( a_add ) ;
}
function hotcat_modify ( link_id ) {
var link = document.getElementById ( link_id ) ;
var span = link.parentNode ;
var catname = span.firstChild.firstChild.data ;
while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ;
span.firstChild.style.display = "none" ;
hotcat_create_new_span ( span , catname ) ;
hotcat_last_v = "" ;
hotcat_text_changed () ; // Update icon
}
function hotcat_add_new () {
var span_add = document.getElementById ( "hotcat_add" ) ;
hotcat_clear_span ( span_add ) ;
hotcat_last_v = "" ;
hotcat_create_new_span ( span_add , "" ) ;
}
function hotcat_create_new_span ( thespan , init_text ) {
var form = document.createElement ( "form" ) ;
form.method = "post" ;
form.onsubmit = function () { hotcat_ok(); return false; } ;
form.id = "hotcat_form" ;
form.style.display = "inline" ;
var list = document.createElement ( "select" ) ;
list.id = "hotcat_list" ;
list.onclick = function () { document.getElementById("hotcat_text").value = document.getElementById("hotcat_list").value ; hotcat_text_changed() ; } ;
list.ondblclick = function () { document.getElementById("hotcat_text").value = document.getElementById("hotcat_list").value ; hotcat_text_changed() ; hotcat_ok(); } ;
list.style.display = "none" ;
var text = document.createElement ( "input" ) ;
text.size = 40 ;
text.id = "hotcat_text" ;
text.type = "text" ;
text.value = init_text ;
text.onkeyup = function () { window.setTimeout("hotcat_text_changed();", hotcat_suggestion_delay ); } ;
var exists = document.createElement ( "img" ) ;
exists.id = "hotcat_exists" ;
exists.src = hotcat_exists_no ;
var OK = document.createElement ( "input" ) ;
OK.type = "button" ;
OK.value = "OK" ;
OK.onclick = hotcat_ok ;
var cancel = document.createElement ( "input" ) ;
cancel.type = "button" ;
cancel.value = "Annuler" ;
cancel.onclick = hotcat_cancel ;
form.appendChild ( list ) ;
form.appendChild ( text ) ;
form.appendChild ( exists ) ;
form.appendChild ( OK ) ;
form.appendChild ( cancel ) ;
thespan.appendChild ( form ) ;
text.focus () ;
}
function hotcat_ok () {
var text = document.getElementById ( "hotcat_text" ) ;
var v = text.value ;
// Empty category ?
if ( v == "" ) {
hotcat_cancel() ;
return ;
}
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
var url = editlk + '&hotcat_newcat=' + encodeURIComponent( v ) ;
// Editing existing?
var span = text.parentNode.parentNode ; // span.form.text
if ( span.id != "hotcat_add" ) { // Not plain "addition"
var cat_title = span.firstChild.innerHTML ;
// Removing leading Category:
cat_title = cat_title.substr(cat_title.indexOf(":") + 1);
url += '&hotcat_removecat=' + encodeURIComponent( cat_title ) ;
}
document.location = url ;
}
function hotcat_cancel () {
var span = document.getElementById("hotcat_form").parentNode ;
if ( span.id == "hotcat_add" ) {
hotcat_create_span ( span ) ;
} else {
while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ;
span.firstChild.style.display = "" ;
for ( var i = 0 ; i < span.parentNode.childNodes.length ; i++ ) {
if ( span.parentNode.childNodes[i] != span ) continue ;
hotcat_modify_span ( span , i ) ;
break ;
}
}
}
function hotcat_text_changed () {
if ( hotcat_running ) return ;
var text = document.getElementById ( "hotcat_text" ) ;
var v = text.value.ucFirst() ;
if ( hotcat_last_v == v ) return ; // Nothing's changed...
hotcat_running = 1 ;
hotcat_last_v = v ;
if ( v != "" ) {
var url = mw.config.get('wgServer') + "/" + mw.config.get('wgScriptPath') + "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent( v ) + "&aplimit=" + encodeURIComponent( hotcat_list_items );
if ( typeof ( hotcat_xmlhttp ) != "undefined" ) hotcat_xmlhttp.abort() ; // Just to make sure...
hotcat_xmlhttp = new sajax_init_object() ;
hotcat_xmlhttp.open('GET', url, true);
hotcat_xmlhttp.onreadystatechange = function () {
if ( typeof hotcat_xmlhttp == "undefined" ) return ;
if (hotcat_xmlhttp.readyState == 4) {
var xml = hotcat_xmlhttp.responseXML ;
if ( xml == null ) return ;
var pages = xml.getElementsByTagName( "p" ) ;
var titles = new Array () ;
for ( var i = 0 ; i < pages.length ; i++ ) {
var s = pages[i].getAttribute("title");
// Removing leading "Category:"
s = s.substr(s.indexOf(":") + 1);
if ( s.substr ( 0 , hotcat_last_v.length ) != hotcat_last_v ) break ;
titles.push ( s ) ;
}
hotcat_show_suggestions ( titles ) ;
}
};
hotcat_xmlhttp.send(null);
} else {
var titles = new Array () ;
hotcat_show_suggestions ( titles ) ;
}
hotcat_running = 0 ;
}
function hotcat_show_suggestions ( titles ) {
var text = document.getElementById ( "hotcat_text" ) ;
var list = document.getElementById ( "hotcat_list" ) ;
var icon = document.getElementById ( "hotcat_exists" ) ;
if ( titles.length == 0 ) {
list.style.display = "none" ;
icon.src = hotcat_exists_no ;
return ;
}
var listh = hotcat_list_size * 20 ;
if (titles.length < hotcat_list_size) {
listh = titles.length * 20 ;
}
var nl = parseInt ( text.parentNode.offsetLeft ) - 1 ;
var nt = parseInt(text.offsetTop) - listh ;
// Parameter to show suggestion list beneath categories instead of above
if (typeof hotcat_list_down != "undefined" && hotcat_list_down) {
nt = text.offsetTop + text.offsetHeight;
}
list.size = 5 ;
list.style.align = "left" ;
list.style.zIndex = 5 ;
list.style.position = "absolute" ;
list.style.top = nt + "px" ;
list.style.width = text.offsetWidth + "px" ;
list.style.height = listh + "px" ;
list.style.left = nl + "px" ;
while ( list.firstChild ) list.removeChild ( list.firstChild ) ;
for ( var i = 0 ; i < titles.length ; i++ ) {
var opt = document.createElement ( "option" ) ;
var ot = document.createTextNode ( titles[i] ) ;
opt.appendChild ( ot ) ;
opt.setAttribute( "value", titles[i] );
list.appendChild ( opt ) ;
}
list.style.display = "block" ;
icon.src = hotcat_exists_yes ;
var first_title = titles.shift () ;
if ( first_title == hotcat_last_v ) return ;
var suggestion = first_title;
text.value = suggestion ;
if (text.createTextRange) {
// IE
var ra = text.createTextRange();
ra.moveStart("character", hotcat_last_v.length);
ra.moveEnd("character", suggestion.length);
ra.select();
} else if( is_khtml ) {
text.setSelectionRange( hotcat_last_v.length, suggestion.length );
} else {
text.selectionStart = hotcat_last_v.length ;
text.selectionEnd = suggestion.length ;
}
}
//</nowiki>