MediaWiki:Gadget-HotCatsMulti.js

Une page de Wikiquote, le recueil des citations libres.

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).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
/**
 * 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
 * Adaptation édition multiple : Dr Brains
 *
 * {{Catégorisation JS|HotCatsMulti}}
 */

//<source lang=javascript><pre><nowiki>

///////////////////////// VARIABLES ////////////////////////////////////////////////////////

function hotcat_initialize_settings() {
    var defaults = {};
    var restore = {};

    //// PARAMÈTRES PERSONNALISABLES ////

    // Délai avant les suggestions, en ms
    defaults.hotcat_suggestion_delay = 200;

    // Taille de la liste déroulante (en items)
    defaults.hotcat_list_size = 10;

    // Nombre de catégories suggérées lors de la recherche (maximum autorisé : 5000 pour les sysop et les bots, 500 pour les autres utilisateurs)
    defaults.hotcat_list_items = 50;

    // Permet d'afficher la liste de suggestion vers le bas
    defaults.hotcat_list_down = false;

    // Permet d'enregistrer automatiquement la modification
    defaults.hotcat_autocommit = true;

    // Modification mineure ( -1 = défaut ; 0 = jamais ; 1 = toujours )
    defaults.hotcat_Minoredit = 1;

    // Suivre la page modifiée ( -1 = défaut ; 0 = jamais ; 1 = toujours )
    defaults.hotcat_Watchthis = -1;

    // Activation automatique du mode "multi"
    defaults.hotcat_AutoMulti = false;

    // Afficher de la légende
    defaults.hotcat_ShowLegend = true;

    // Afficher sur une seule ligne
    defaults.hotcat_ShowInline = false;

    // Ne pas confirmer la suppression
    defaults.hotcat_SkipConfirm = false;

    // Ne pas afficher le récapitulatif
    defaults.hotcat_SkipRecap = false;

    // Afficher le bouton pour suggérer les catégories-mères
    defaults.hotcat_ParentButton = true;

    // Afficher le bouton pour suggérer les catégories-filles
    defaults.hotcat_DaughterButton = true;

    // Icônes pour signifier l'existence ou non de la catégorie choisie
    defaults.hotcat_exists_size = 20;
    defaults.hotcat_exists_yes = "//upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png" ;
    defaults.hotcat_exists_no = "//upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png" ;

    // Lien vers la documentation
    defaults.hotcat_docURL = "//fr.wikipedia.org/wiki/Projet:JavaScript/Notices/HotCatsMulti#Fonctionnement";

    // ID du lien pour les catégories cachées
    defaults.hotcat_HiddenCatsLinkID = "mw-hidden-cats-link";

    // Titre de catégorie sensible à la casse de la première lettre
    defaults.hotcat_CaseSensitive = false;

    // Mode débuggage
    defaults.hotcat_DebugMode = false;

    // Groupe nécessaire pour appliquer une balise
    defaults.hotcat_TagGroup = "user";

    //// TEXTES ////

    defaults.hotcat_text_MultiLinkText = "(±)";
    defaults.hotcat_text_MultiLinkTitle = "Modifier plusieurs catégories";
    defaults.hotcat_text_MultiInputOK = "Valider";
    defaults.hotcat_text_MultiInputCancel = "Annuler";

    defaults.hotcat_text_Minoredit = "Édition mineure : $1";
    defaults.hotcat_text_Watchthis = "Suivre cette page : $1";
    defaults.hotcat_text_RadioDefault = "Défaut";
    defaults.hotcat_text_RadioYes = "Oui";
    defaults.hotcat_text_RadioNo = "Non";

    defaults.hotcat_text_LabelText = "Légende :";
    defaults.hotcat_text_LabelTitle = "Voir la page d\'aide (nouvelle fenêtre)";

    defaults.hotcat_text_DefaultSortText = "(D)";
    defaults.hotcat_text_DefaultSortTitle = "Ajouter/modifier/supprimer la clef de tri principale";

    defaults.hotcat_text_RemoveLinkText = "(–)";
    defaults.hotcat_text_RemoveLinkTitle = "Supprimer la catégorie « $1 »";
    defaults.hotcat_text_RemoveConfirm = "Voulez-vous vraiment supprimer la catégorie « $1 » ?";
    defaults.hotcat_text_ModifyLinkText = "(±)";
    defaults.hotcat_text_ModifyLinkTitle = "Modifier la catégorie « $1 »";
    defaults.hotcat_text_AddLinkText = "(+)";
    defaults.hotcat_text_AddLinkTitle = "Ajouter une catégorie";

    defaults.hotcat_text_Exists_YesTitle = "Cette catégorie existe.";
    defaults.hotcat_text_Exists_NoTitle = "Cette catégorie n'existe pas.";
    defaults.hotcat_text_ParentTitle = "Suggérer les catégories-mères";
    defaults.hotcat_text_ParentText = "↑";
    defaults.hotcat_text_DaughterTitle = "Suggérer les catégories-filles";
    defaults.hotcat_text_DaughterText = "↓";
    defaults.hotcat_text_InputOK = "OK";
    defaults.hotcat_text_InputCancel = "Annuler";

    defaults.hotcat_text_RecapTitle = 'Récapitulatif :';
    defaults.hotcat_text_RecapRemove = 'Catégories à supprimer';
    defaults.hotcat_text_RecapModify = 'Catégories à modifier';
    defaults.hotcat_text_RecapAdd = 'Catégories à ajouter';
    defaults.hotcat_text_RecapSort = 'Clef de tri globale';

    defaults.hotcat_text_AlertProblem1 = "Impossible de trouver la catégorie « $1 » - elle est peut-être incluse via un modèle.";
    defaults.hotcat_text_AlertProblem2 = "La catégorie « $1 » est déjà présente.";
    defaults.hotcat_text_AlertProblem3 = "Plusieurs occurrences de la catégorie « $1 » trouvées.";

    defaults.hotcat_text_ResumeScript = "[[w:Projet:JavaScript/Notices/HotCatsMulti|HotCatsMulti]] : ";

    defaults.hotcat_text_NoCatTemplate = "à catégoriser";

    defaults.hotcat_text_HotCatTag = "";
    if (mw.config.get( 'wgServer' ) == '//fr.wikiquote.org') defaults.hotcat_text_HotCatTag = "HotCats";


    // si une variable globale existe, on enregistre sa valeur et on la restaure après les callbacks, car elle est prioritaire
    // si elle n'existe pas, on la crée avec la valeur par défaut

    $.each(defaults, function (name, value) {
        if (window[name] !== undefined) {
            restore[name] = window[name];
        } else {
            window[name] = value;
        }
    });

    if (typeof hotcat_LangCustom == "function") hotcat_LangCustom();
    if (typeof hotcat_SiteCustom == "function") hotcat_SiteCustom();
    if (typeof hotcat_UserCustom == "function") hotcat_UserCustom();

    $.each(restore, function (name, value) {
        window[name] = value;
    });
}


//// VARIABLES NON PERSONNALISABLES ////

window.hotcat_text_SystemMessage = {
  "red-link-title" : false,
  "pagecategorieslink" : false,
  "categories" : false,
  "pagecategories" : false
};


window.hotcat_Multi_Edit = false ;
window.hotcat_suggest_running = 0 ;
window.hotcat_running = 0 ;
window.hotcat_last_v = "" ;
window.hotcat_last_key = "";
window.hotcat_OldDefaultSort = "";
window.hotcat_OldPageContent = false;
window.hotcat_Form_Index = 1000;
window.hotcat_NewCatsIndex = 2000;
window.hotcat_CatNamespace = mw.config.get('wgFormattedNamespaces')[14]+':';
window.hotcat_DefaultsortAliases = [];
window.hotcat_Multi_IsEditPage = ((mw.config.get('wgAction')=="edit")||(mw.config.get('wgAction')=="submit")) ;
window.hotcat_Multi_IsSection = false ;

window.hotcat_SpanMatrix = [];
window.hotcat_CatLinkMatrix = [];
window.hotcat_CatLinkIsRedMatrix = [];
window.hotcat_RemoveLinkMatrix = [];
window.hotcat_ModifyLinkMatrix = [];
window.hotcat_FormMatrix = [];
window.hotcat_TextMatrix = [];
window.hotcat_ListMatrix = [];
window.hotcat_ExistMatrix = [];
window.hotcat_CatNameMatrix = [];
window.hotcat_SortMatrix = [];

///////////////////////// AJAX ////////////////////////////////////////////////////////

window.hotcat_ajax = {
    http: function (bundle) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4)
                hotcat_ajax.httpComplete(xmlhttp, bundle);
        };
        xmlhttp.open(bundle.method ? bundle.method : "GET", bundle.url, bundle.async === false ? false : true);
        if (bundle.headers) {
            $.each(bundle.headers, function (field, value) {
                try {
                    xmlhttp.setRequestHeader(field, value);
                } catch (err) {  }
            });
        }
        xmlhttp.send(bundle.data ? bundle.data : null);
        return xmlhttp;
    },
    httpComplete: function (xmlhttp, bundle) {
        if (xmlhttp.status == 200 || xmlhttp.status == 302) {
            if (bundle.onSuccess) bundle.onSuccess(xmlhttp, bundle);
        } else if (bundle.onFailure) {
            bundle.onFailure(xmlhttp, bundle);
        }
    }
};


///////////////////////// REQUÊTES PRÉLIMINAIRES ////////////////////////////////////////////////////////


// RÉCUPÉRATION ALIAS DE LA CLEF DE TRI GLOBALE ET DES MESSAGES SYSTEME

// Mise à jour du cookie

window.hotcat_SetCookie = function(cookieName, cookieValue) {
    mw.cookie.set(cookieName, cookieValue, 86400 * 30);
};

// Interrogation du cookie

window.hotcat_GetCookie = function(cookieName) {
    return mw.cookie.get(cookieName);
};

window.hotcat_getDefaultsortAliasesAndMessages = function(){
    var meta = [];
    var otherparams = {};
    var missingmessages = [];
    var CookieMessages = hotcat_GetCookie("hotcatmessages");
    if(CookieMessages){
        CookieMessages = CookieMessages.split("||");
        $.each(hotcat_text_SystemMessage, function (Message, _value) {
            var found = false;
            for(var a=0,l=CookieMessages.length;a<l;a++){
                if(CookieMessages[a].indexOf(Message+"::") !== 0) continue;
                found = true;
                hotcat_text_SystemMessage[Message] = CookieMessages[a].split("::")[1];
            }
            if(!found) missingmessages.push(Message);
        });

    }else{
        $.each(hotcat_text_SystemMessage, function (Message, _value) {
            missingmessages.push(Message);
        });
    }
    if(missingmessages.length > 0){
        meta.push("allmessages");
        otherparams["ammessages"] = missingmessages.join("|");
    }
    var CookieDefaultsortAliases = hotcat_GetCookie("hotcatdefaultsortaliases");
    if(CookieDefaultsortAliases){
        hotcat_DefaultsortAliases = CookieDefaultsortAliases.split("||");
    }
    if(hotcat_DefaultsortAliases.length === 0){
        meta.push("siteinfo");
        otherparams["siprop"] = "magicwords";
    }
    if(meta.length === 0){
        hotcat_getOldPageContent();
        return;
    }
    var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&meta=' + meta.join("|");
    $.each(otherparams, function (name, value) {
        URL += "&" + name + "=" + value;
    });
    hotcat_ajax.http({url          : URL,
                      onSuccess    : hotcat_receiveDefaultsortAliasesAndMessages,
                      nextcallback : hotcat_getOldPageContent
    });
};

window.hotcat_receiveDefaultsortAliasesAndMessages = function(Req, data){
    var Response = Req.responseXML;
    var MagicWords = Response.getElementsByTagName('magicword');
    if(MagicWords.length > 0){
        for(var a=0;a<MagicWords.length;a++){
            var MagicWordName = MagicWords[a].getAttribute('name');
            if(MagicWordName=="defaultsort"){
                var Aliases = MagicWords[a].getElementsByTagName('alias');
                for(var b=0;b<Aliases.length;b++){
                    var ThisAlias = Aliases[b].firstChild.nodeValue;
                    ThisAlias = ThisAlias.replace(/:/g, "");
                    if(hotcat_DefaultsortAliases.indexOf(ThisAlias)==-1) hotcat_DefaultsortAliases.push(ThisAlias);
                }
            }
        }
        hotcat_SetCookie("hotcatdefaultsortaliases", hotcat_DefaultsortAliases.join("||"));
    }
    var Messages = Response.getElementsByTagName('message');
    if(Messages.length > 0){
        var cookievalue = [];
        for(var a=0;a<Messages.length;a++){
            var MessageName = Messages[a].getAttribute('name');
            var MessageContent = (Messages[a].firstChild ? Messages[a].firstChild.nodeValue : "");
            $.each(hotcat_text_SystemMessage, function (Message, _value) {
                if(MessageName == Message){
                    hotcat_text_SystemMessage[Message] = MessageContent;
                    cookievalue.push(Message+"::"+MessageContent);
                }
            });
        }
        hotcat_SetCookie("hotcatmessages", cookievalue.join("||"));
    }
    if(typeof(data.nextcallback) === "function") data.nextcallback(data);
};

// RÉCUPÉRATION DU CONTENU ACTUEL DE LA PAGE (asynchrone ou synchrone)

window.hotcat_getOldPageContent = function(){
    var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=raw&oldid=' + mw.config.get('wgCurRevisionId');
    hotcat_ajax.http({url : URL, onSuccess : hotcat_receiveOldPageContent });
};

window.hotcat_receiveOldPageContent = function(Req, data){
    hotcat_OldPageContent = Req.responseText;
    hotcat();
};

window.hotcat_gettag = function(){
  if(!hotcat_text_HotCatTag || !hotcat_TagGroup) return false;
  var UserGroups = mw.config.get('wgUserGroups');
  if(UserGroups === null) UserGroups = ["*"];
  if(UserGroups.indexOf(hotcat_TagGroup) !== -1) return hotcat_text_HotCatTag;
  return false;
};


// FONCTION DE TRANSFORMATION INITIALE

window.hotcat = function() {
    if(hotcat_running!==0) return;
    hotcat_running = 1;
    var catlinks = document.getElementById("catlinks");
    var hotcatStop = hotcat_getSectionNumber();
    if(hotcatStop){
        if(catlinks) catlinks.parentNode.removeChild(catlinks);
        return;
    }
    if (! catlinks) {
        var bodyC = document.getElementById("bodyContent");             // Monobook, Vector
        if(!bodyC) bodyC = document.getElementById("article");          // Cologneblue
        if(!bodyC) bodyC = document.getElementById("mw_contentholder"); // Modern
        if(!bodyC) return;
        catlinks = document.createElement("div");
        catlinks.id = "catlinks";
        catlinks.className = "catlinks";
        catlinks = bodyC.appendChild(catlinks);
    }else{
        catlinks.classList.remove("catlinks-allhidden");
    }
    if(mw.config.get('wgAction')=="edit") hotcat_list_down = true;
    var catline = document.getElementById ('mw-normal-catlinks');
    if ( !catline || catline === null || typeof catline == 'undefined' ){
        catline = catlinks.insertBefore(document.createElement("div"), catlinks.firstChild);
        catline.id = "mw-normal-catlinks";
    }
    hotcat_append_firstlink(catline);
    hotcat_modify_existing(catline);
    hotcat_append_add_span(catline);
    hotcat_append_multiedit_span(catline);
    if(hotcat_Multi_IsEditPage){
        var CatLine = document.getElementById("catlinks");
        var PreviewWindow = document.getElementById("wikiPreview");
        if((CatLine)&&(PreviewWindow)){
            CatLine.parentNode.removeChild(CatLine);
            PreviewWindow.parentNode.insertBefore(CatLine, PreviewWindow.nextSibling);
            hotcat_update_existing();
        }
    }
};

// DÉTERMINATION DE LA SECTION ÉDITÉE  (si section et section != dernière ou section == new : arrêt hotCats)

window.hotcat_getSectionNumber = function(){
    if(!hotcat_Multi_IsEditPage) return false;
    var SectionNumber = document.editform.wpSection.value;
    if(SectionNumber==="") return false;
    hotcat_Multi_IsSection = SectionNumber;
    if(SectionNumber==="new") return true;
    SectionNumber = parseInt(SectionNumber);
    hotcat_Multi_IsSection = SectionNumber;
    var SectionRegExp = new RegExp("[^=\\|\\{\n]*={1,6}[^=\n]+={1,6}\n", "ig");
    var Sections = hotcat_OldPageContent.match(SectionRegExp);
    if(Sections===null) return false;
    if(Sections.length === SectionNumber) return false;
    return true;
};

// CRÉATION DU LIEN "CATÉGORIES"

window.hotcat_append_firstlink = function( catline, plural) {
    if(!hotcat_text_SystemMessage.pagecategorieslink||!hotcat_text_SystemMessage.categories||!hotcat_text_SystemMessage.pagecategories){
        hotcat_GetMessages(false);
    }
    if (!catline.firstChild ){
        var a = document.createElement('a');
        a.href = mw.config.get('wgServer')+mw.config.get('wgArticlePath').split('$1').join(hotcat_text_SystemMessage.pagecategorieslink);
        a.title = hotcat_text_SystemMessage.categories;
        a.appendChild(document.createTextNode(hotcat_PLURAL(hotcat_text_SystemMessage.pagecategories, plural)));
        catline.appendChild(a);
        catline.appendChild(document.createTextNode(' : '));
    }else{
        catline.firstChild.title = hotcat_text_SystemMessage.categories;
    }
};

// MODIFICATION DE LA BARRE DE CATÉGORIES

window.hotcat_modify_existing = function(catline) {
    var ul = catline.getElementsByTagName("ul")[0];
    if(!ul){ // ( Mediawiki < 1.18 )
        var spans = catline.getElementsByTagName("span");
        for(var i=0,l=spans.length;i<l;i++){
            hotcat_modify_span ( spans[i], i ) ;
        }
        return;
    }
    var lis = ul.getElementsByTagName("li");
    for(var i=0,l=lis.length;i<l;i++){
        var li = lis[i];
        var cat_link = li.getElementsByTagName('a')[0];
        var span = document.createElement('span');
        li.appendChild(span);
        span.appendChild(cat_link);
        hotcat_modify_span ( span, i ) ;
    }
};

// AJOUT DES LIENS (–) ET (±)

window.hotcat_modify_span  = function( span, i ) {
    if(!hotcat_text_SystemMessage["red-link-title"]) hotcat_GetMessages(false);
    var cat_link = span.getElementsByTagName('a')[0];
    if(!cat_link) return;
    cat_link.id = "CatLink_"+i;
    var cat_title = cat_link.title;
    if(!cat_title) return;
    cat_title = cat_title.split(hotcat_CatNamespace).join('');
    cat_title = cat_title.replace(hotcat_text_SystemMessage["red-link-title"].split('$1').join(''), "");
    var sep1 = document.createTextNode ( " " ) ;
    span.id = "hotcat_Span_" + i ;
    var a1 = document.createTextNode ( "(–)" ) ;
    var remove_link = document.createElement ( "a" ) ;
    var remove_id = "hotcat_remove_" + i ;
    remove_link.id = remove_id;
    remove_link.href = "javascript:hotcat_remove(\"" + cat_title + "\","+i+");" ;
    remove_link.title = hotcat_text_RemoveLinkTitle.split("$1").join(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(\""+cat_title+"\"," + i + ");" ;
    modify_link.title = hotcat_text_ModifyLinkTitle.split("$1").join(cat_title);
    modify_link.appendChild ( a2 ) ;
    span.appendChild ( sep2 ) ;
    span.appendChild ( modify_link ) ;
    hotcat_SpanMatrix[i] = span;
    hotcat_CatLinkMatrix[i] = cat_link;
    hotcat_CatLinkIsRedMatrix[i] = cat_link.classList.contains("new");
    hotcat_CatNameMatrix[i] = cat_title;
    hotcat_RemoveLinkMatrix[i] = remove_link;
    hotcat_ModifyLinkMatrix[i] = modify_link;
};

// AJOUT DU LIEN (+)

window.hotcat_append_add_span = function(catline) {
    var Spans = catline.getElementsByTagName('span');
    var span_add = document.createElement('span');
    var a_add = document.createElement ( "a" ) ;
    var a_text = document.createTextNode ( hotcat_text_AddLinkText ) ;
    span_add.id = "hotcat_add" ;
    a_add.id = "hotcat_addlink" ;
    a_add.href = "javascript:hotcat_add_new("+hotcat_Form_Index+")" ;
    a_add.title = hotcat_text_AddLinkTitle ;
    a_add.appendChild( a_text ) ;
    span_add.appendChild( a_add ) ;
    if(Spans[0]) catline.appendChild(document.createTextNode(' | '));
    catline.appendChild(span_add);
    hotcat_SpanMatrix[hotcat_Form_Index] = span_add;
    hotcat_Form_Index++;
};

///////////////////////// ÉDITION SIMPLE ////////////////////////////////////////////////////////

// FONCTION DE RETRAIT D'UNE CATÉGORIE

window.hotcat_remove  = function( cat_title, Index ) {
    if(!hotcat_Multi_Edit){
        var RemovedCategories = [];
        var ModifiedCategories_from = [];
        var ModifiedCategories_to = [];
        var AddedCategories = [];
        RemovedCategories.push(cat_title);
        if (hotcat_SkipConfirm || confirm(hotcat_text_RemoveConfirm.split("$1").join(cat_title))){
            hotcat_Edit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, hotcat_OldDefaultSort);
        }
    }else{
        var Span = hotcat_SpanMatrix[Index];
        if(Span.classList.contains("AddedCatSpan")){
            Span.parentNode.removeChild(Span);
        }else{
            var FirstLink = hotcat_CatLinkMatrix[Index];
            var OldCat = hotcat_CatNameMatrix[Index];
            FirstLink.innerHTML = OldCat;
            FirstLink.title = hotcat_CatNamespace+OldCat;
            FirstLink.href = mw.config.get('wgServer')+mw.config.get('wgArticlePath').split('$1').join(hotcat_CatNamespace+OldCat);
            FirstLink.classList.add("RemovedCategory");
            FirstLink.classList.remove("ModifiedCategory");
            if(hotcat_CatLinkIsRedMatrix[Index]){
                if(!FirstLink.classList.contains("new")) FirstLink.classList.add("new");
            }else{
                FirstLink.classList.remove("new");
            }
        }
        hotcat_Multi_CheckForChanges();
    }
};

// MODIFICATION D'UNE CATÉGORIE

window.hotcat_modify  = function( catname, Index  ) {
    var span = hotcat_SpanMatrix[Index] ;
    var Links = span.getElementsByTagName('a');
    for(var a=0;a<Links.length;a++){
         Links[a].style.display = "none";
    }
    span.firstChild.style.display = "none" ;
    hotcat_create_new_span ( span , catname, Index ) ;
    hotcat_text_changed(Index);
};

// AJOUT D'UNE CATÉGORIE

window.hotcat_add_new  = function(Index) {
    var span_add = document.getElementById( "hotcat_add" ) ;
    span_add.getElementsByTagName('a')[0].style.display = "none";
    hotcat_create_new_span ( span_add , "", Index ) ;
};

// CRÉATION DU FORMULAIRE DE MODIFICATION OU D'AJOUT D'UNE CATÉGORIE

window.hotcat_create_new_span  = function( thespan , init_text, Index ) {
    var DefaultSort = hotcat_defaultSort_getOneOld(init_text);
    if(thespan.classList.contains("AddedCatSpan" )) DefaultSort = hotcat_SortMatrix[Index];
    hotcat_CatNameMatrix[Index] = init_text;
    var form = document.createElement ( "form" ) ;
    form.id = "hotcat_form" + Index;
    form.method = "post" ;
    form.onsubmit = function () {
        var FormIndex = hotcat_getIndex(this);
        hotcat_ok(FormIndex);
        return false;
    } ;
    form.style.display = "inline" ;
    var text = document.createElement ( "input" ) ;
    text.size = 40 ;
    text.id = "hotcat_text" + Index ;
    text.type = "text" ;
    text.value = init_text + DefaultSort ;
    text.onkeyup = function () {
        var FormIndex = hotcat_getIndex(this);
        window.setTimeout("hotcat_text_changed("+FormIndex+");", hotcat_suggestion_delay );
    } ;
    var list = document.createElement ( "select" ) ;
    list.id = "hotcat_list" + Index ;
    list.style.display = "none" ;
    list.onclick = function () {
        var FormIndex = hotcat_getIndex(this);
        hotcat_text_replace(FormIndex);
    } ;
    var exists = document.createElement ( "img" ) ;
    exists.id = "hotcat_exists" + Index ;
    exists.height = hotcat_exists_size ;
    exists.width = hotcat_exists_size ;
    exists.title = hotcat_text_Exists_NoTitle;
    exists.src = hotcat_exists_no ;
    var ParentCats = document.createElement ( "input" ) ;
    ParentCats.id = "hotcat_parents" + Index ;
    ParentCats.type = "button" ;
    ParentCats.value = hotcat_text_ParentText ;
    ParentCats.title = hotcat_text_ParentTitle ;
    ParentCats.onclick = function(){
        var FormIndex = hotcat_getIndex(this);
        hotcat_text_changed(FormIndex, "UP");
    };
    var DaughterCats = document.createElement ( "input" ) ;
    DaughterCats.id = "hotcat_daughters" + Index ;
    DaughterCats.type = "button" ;
    DaughterCats.value = hotcat_text_DaughterText ;
    DaughterCats.title = hotcat_text_DaughterTitle ;
    DaughterCats.onclick = function(){
        var FormIndex = hotcat_getIndex(this);
        hotcat_text_changed(FormIndex, "DOWN");
    };
    var OK = document.createElement ( "input" ) ;
    OK.id = "hotcat_OK" + Index ;
    OK.type = "button" ;
    OK.value = hotcat_text_InputOK ;
    OK.onclick = function(){
        var FormIndex = hotcat_getIndex(this);
        hotcat_ok(FormIndex) ;
    };
    var cancel = document.createElement ( "input" ) ;
    cancel.id = "hotcat_cancel" + Index ;
    cancel.type = "button" ;
    cancel.value = hotcat_text_InputCancel ;
    cancel.onclick = function(){
        var FormIndex = hotcat_getIndex(this);
        hotcat_cancel(FormIndex) ;
    };
    form.appendChild ( text ) ;
    form.appendChild ( list ) ;
    form.appendChild ( exists ) ;
    if ( hotcat_ParentButton ) {
        form.appendChild ( ParentCats ) ;
    }
    if ( hotcat_DaughterButton ) {
        form.appendChild ( DaughterCats ) ;
    }
    form.appendChild ( OK ) ;
    form.appendChild ( cancel ) ;
    thespan.appendChild ( form ) ;
    text.focus () ;
    hotcat_upDate_FormPositions();
    hotcat_FormMatrix[Index] = form;
    hotcat_TextMatrix[Index] = text;
    hotcat_ListMatrix[Index] = list;
    hotcat_ExistMatrix[Index] = exists;
};

// VALIDATION DU FORMULAIRE

window.hotcat_ok = function(Index) {
    var Form = hotcat_FormMatrix[Index];
    var Input = hotcat_TextMatrix[Index];
    var TheSpan = hotcat_SpanMatrix[Index] ;
    var CatLink = hotcat_CatLinkMatrix[Index];
    var IfExist = hotcat_ExistMatrix[Index];
    var OldCatName = hotcat_CatNameMatrix[Index];
    var OldDefaultSort = hotcat_defaultSort_getOneOld(OldCatName);
    var NewCatName = Input.value.ucFirst().replace(/\|.*/, "") ;
    var NewDefaultSort = Input.value.ucFirst().split(NewCatName).join("");
    hotcat_SortMatrix[Index] = NewDefaultSort;
    if ( NewCatName == "" ) {
        hotcat_cancel(Index) ;
        return ;
    }
    if(hotcat_Multi_Edit==false){
        if((OldCatName+OldDefaultSort)==(NewCatName+NewDefaultSort)) return;
        var RemovedCategories = [];
        var ModifiedCategories_from = [];
        var ModifiedCategories_to = [];
        var AddedCategories = [];
        if ( TheSpan.id != "hotcat_add" ) {
            ModifiedCategories_from.push(OldCatName+OldDefaultSort);
            ModifiedCategories_to.push(NewCatName+NewDefaultSort);
        }else{
            AddedCategories.push(NewCatName+NewDefaultSort);
        }
        hotcat_Edit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, hotcat_OldDefaultSort);
    }else{
        var Exist = (IfExist.title == hotcat_text_Exists_YesTitle);
        if(TheSpan.id!="hotcat_add"){
            CatLink.innerHTML = NewCatName;
            CatLink.title = hotcat_CatNamespace+NewCatName;
            CatLink.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(hotcat_CatNamespace+NewCatName);
            if((!CatLink.classList.contains("AddedCategory"))&&(!CatLink.classList.contains("ModifiedCategory"))) CatLink.classList.add("ModifiedCategory");
            if((OldCatName+OldDefaultSort)==(NewCatName+NewDefaultSort)){
                CatLink.classList.remove("ModifiedCategory");
            }
            CatLink.classList.remove("RemovedCategory");
        }else{
            hotcat_NewCatsIndex++;
            hotcat_CatNameMatrix[hotcat_NewCatsIndex] = NewCatName;
            hotcat_SortMatrix[hotcat_NewCatsIndex] = NewDefaultSort;
            var NewSpan = document.createElement('span');
            NewSpan.id = "hotcat_Span_"+hotcat_NewCatsIndex;
            NewSpan.className = "AddedCatSpan";
            CatLink = document.createElement('a');
            CatLink.id = "CatLink_"+hotcat_NewCatsIndex;
            CatLink.innerHTML = NewCatName;
            CatLink.title = hotcat_CatNamespace+NewCatName;
            CatLink.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(hotcat_CatNamespace+NewCatName);
            CatLink.classList.add("AddedCategory");
            var RemoveLink = document.createElement('a');
            RemoveLink.innerHTML = hotcat_text_RemoveLinkText;
            RemoveLink.id = "hotcat_remove_"+hotcat_NewCatsIndex;
            RemoveLink.title = hotcat_text_RemoveLinkTitle.split("$1").join(NewCatName);
            RemoveLink.href = "javascript:hotcat_remove(\"" + NewCatName+ "\","+hotcat_NewCatsIndex+");";
            var ModifyLink = document.createElement('a');
            ModifyLink.innerHTML = hotcat_text_ModifyLinkText;
            ModifyLink.id = "hotcat_modify_"+hotcat_NewCatsIndex;
            ModifyLink.title = hotcat_text_ModifyLinkTitle.split("$1").join(NewCatName);
            ModifyLink.href = "javascript:hotcat_modify(\""+NewCatName+"\","+hotcat_NewCatsIndex+ ")";
            NewSpan.appendChild(CatLink);
            NewSpan.appendChild(document.createTextNode(" "));
            NewSpan.appendChild(RemoveLink);
            NewSpan.appendChild(document.createTextNode(" "));
            NewSpan.appendChild(ModifyLink);
            NewSpan.appendChild(document.createTextNode(" | "));
            TheSpan.parentNode.insertBefore(NewSpan, TheSpan);
            hotcat_SpanMatrix[hotcat_NewCatsIndex] = NewSpan;
            hotcat_CatLinkMatrix[hotcat_NewCatsIndex] = CatLink;
            hotcat_RemoveLinkMatrix[hotcat_NewCatsIndex] = RemoveLink;
            hotcat_ModifyLinkMatrix.push[hotcat_NewCatsIndex] = ModifyLink;
        }
        if(!Exist){
            CatLink.classList.add("new");
        }else{
            CatLink.classList.remove("new");
        }
        var Links = TheSpan.getElementsByTagName('a');
        for(var a=0;a<Links.length;a++){
            Links[a].style.display = "";
        }
        TheSpan.removeChild(Form);
        hotcat_Multi_CheckForChanges();
        hotcat_upDate_FormPositions();
        if(TheSpan.id!="hotcat_add"){
            document.getElementById("hotcat_modify_"+Index).focus();
        }else{
            document.getElementById("hotcat_addlink").focus();
        }
    }
};

// ANNULATION DU FORMULAIRE

window.hotcat_cancel  = function(Index) {
    var Form = hotcat_FormMatrix[Index];
    var TheSpan = hotcat_SpanMatrix[Index] ;
    TheSpan.removeChild ( Form ) ;
    var Links = TheSpan.getElementsByTagName('a');
    for(var a=0;a<Links.length;a++){
        Links[a].style.display = "";
    }
    TheSpan.firstChild.style.display = "" ;
    hotcat_Multi_CheckForChanges();
    hotcat_upDate_FormPositions();
    if(TheSpan.id!="hotcat_add"){
        document.getElementById("hotcat_modify_"+Index).focus();
    }else{
        document.getElementById("hotcat_addlink").focus();
    }
};

///////////////////////// ÉDITION MULTIPLE ////////////////////////////////////////////////////////

// AJOUT DU LIEN (±)

window.hotcat_append_multiedit_span = function( CatLine ){
    var FirstLink = CatLine.getElementsByTagName('a')[0];
    var Span = document.createElement('span');
    Span.id ='hotcat_modify_multi_span';
    var Link = document.createElement('a');
    Link.id = "hotcat_modify_multi_Link";
    Link.innerHTML = hotcat_text_MultiLinkText;
    Link.title = hotcat_text_MultiLinkTitle;
    Link.href = "javascript:hotcat_multiedit_createForm();";
    Span.appendChild(Link);
    FirstLink.parentNode.insertBefore(Span, FirstLink.nextSibling);
    FirstLink.parentNode.insertBefore(document.createTextNode(" "), FirstLink.nextSibling);
    var DefaultSortSpan = document.createElement('span');
    DefaultSortSpan.id ='hotcat_DefaultSort_span';
    var DefaultSortLink = document.createElement('a');
    DefaultSortLink.id = "hotcat_DefaultSort_Link";
    DefaultSortLink.innerHTML = hotcat_text_DefaultSortText;
    DefaultSortLink.title = hotcat_text_DefaultSortTitle;
    DefaultSortLink.href = "javascript:hotcat_defaultSort_createForm();";
    DefaultSortSpan.appendChild(DefaultSortLink);
    var OldDefaultSortSpan = document.createElement('span');
    OldDefaultSortSpan.style.display = "none";
    OldDefaultSortSpan.id = "OldDefaultSortSpan";
    DefaultSortSpan.appendChild(OldDefaultSortSpan);
    Span.parentNode.insertBefore(DefaultSortSpan, Span.nextSibling);
    Span.parentNode.insertBefore(document.createTextNode(" "), Span.nextSibling);
    if(hotcat_AutoMulti) hotcat_multiedit_createForm();
};

// CREATION DU FORMULAIRE "MULTI"

window.hotcat_multiedit_createForm = function(){
    var OldForms = document.getElementById('mw-normal-catlinks').getElementsByTagName('form');
    while(OldForms[0]) OldForms[0].parentNode.removeChild(OldForms[0]);
    var OldLinks = document.getElementById('mw-normal-catlinks').getElementsByTagName('a');
    for(var a=0;a<OldLinks.length;a++){
        OldLinks[a].style.display="";
    }
    for(var a=0;a<hotcat_CatLinkMatrix.length;a++){
        if(!hotcat_CatLinkMatrix[a]) continue;
        if(hotcat_CatLinkIsRedMatrix[a]){
            if(!hotcat_CatLinkMatrix[a].classList.contains("new")) hotcat_CatLinkMatrix[a].classList.add("new");
        }else{
            hotcat_CatLinkMatrix[a].classList.remove("new");
        }
    }
    var OldSpans = document.getElementById('mw-normal-catlinks').getElementsByTagName('span');
    for(var a=0;a<OldSpans.length;a++){
        if(OldSpans[a].id != 'OldDefaultSortSpan') OldSpans[a].style.display="";
    }
    if(!document.getElementById("hotcat_addlink")) hotcat_add_new ( document.getElementById("hotcat_add") );
    var Legend = "";
    if(hotcat_ShowLegend){
        Legend = '<small>'
               + '<a href="'+hotcat_docURL+'" title="'+hotcat_text_LabelTitle+'" target="_blank" '
               + 'style="color:#002BB8;padding:0.2em;margin-left:'+(hotcat_ShowInline ? 5 :100 )+'px;">'
               + '&nbsp;<b>'+hotcat_text_LabelText+'</b>'
               + '&nbsp;<span class="RemovedCategory">'+hotcat_text_RecapRemove+'</span>'
               + '&nbsp;<span class="ModifiedCategory">'+hotcat_text_RecapModify+'</span>'
               + '&nbsp;<span class="AddedCategory">'+hotcat_text_RecapAdd+'</span>'
               + '</a>'
               + '</small>';
    }
    var BR = "";
    if(!hotcat_ShowInline) BR = "<br />";

    var RadioBoxes = "";
    if(!hotcat_Multi_IsEditPage){
        var MinorOneChecked = ( (hotcat_Minoredit==-1) ? 'checked="checked" ' : '' );
        var MinorTwoChecked = ( (hotcat_Minoredit==0) ? 'checked="checked" ' : '' );
        var MinorThreeChecked = ( (hotcat_Minoredit==1) ? 'checked="checked" ' : '' );
        var WatchOneChecked = ( (hotcat_Watchthis==-1) ? 'checked="checked" ' : '' );
        var WatchTwoChecked = ( (hotcat_Watchthis==0) ? 'checked="checked" ' : '' );
        var WatchThreeChecked = ( (hotcat_Watchthis==1) ? 'checked="checked" ' : '' );
        RadioBoxes = '<span id="hotcat_RadioBoxes">'
                   + '&nbsp;&nbsp;<span style="border:1px dotted silver;padding:0.1em;">'
                   + '<input id="Minor" type="radio" name="Minor" '+MinorOneChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Minoredit.split("$1").join(hotcat_text_RadioDefault)+'" />'
                   + '<input id="Minor_0" type="radio" name="Minor" '+MinorTwoChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Minoredit.split("$1").join(hotcat_text_RadioNo)+'" />'
                   + '<input id="Minor-1" type="radio" name="Minor" '+MinorThreeChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Minoredit.split("$1").join(hotcat_text_RadioYes)+'" />'
                   + '</span>&nbsp;&nbsp;<span style="border:1px dotted silver;padding:0.1em;">'
                   + '<input id="Watch" type="radio" name="Watch" '+WatchOneChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Watchthis.split("$1").join(hotcat_text_RadioDefault)+'" />'
                   + '<input id="Watch0" type="radio" name="Watch" '+WatchTwoChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Watchthis.split("$1").join(hotcat_text_RadioNo)+'" />'
                   + '<input id="Watch1" type="radio" name="Watch" '+WatchThreeChecked+' style="cursor:pointer;" '
                   + 'title="'+hotcat_text_Watchthis.split("$1").join(hotcat_text_RadioYes)+'" />'
                   + '</span>'
                   + '</span>';
    }

    var Link = document.getElementById('hotcat_modify_multi_Link');
    var Span = Link.parentNode;
    var Form = document.createElement('form');
    Form.id = "hotcat_modify_multi_form";
    Form.style.display = "inline";
    Form.innerHTML = ''
                   + Legend
                   + BR
                   + '<input id="hotcat_modify_multi_InputOK" type="button" disabled="disabled" '
                   + 'value="'+hotcat_text_MultiInputOK+'" '
                   + 'onclick="hotcat_multiedit_FormOK()" onselect="hotcat_multiedit_FormOK()" />'
                   + '<input id="hotcat_modify_multi_InputCancel" type="button" '
                   + 'value="'+hotcat_text_MultiInputCancel+'" '
                   + 'onclick="hotcat_multiedit_CancelForm()" onselect="hotcat_multiedit_CancelForm()" />'
                   + RadioBoxes
                   + BR;
    Span.appendChild(Form);
    Link.style.display = "none";
    hotcat_Multi_Edit = true;
    if(!hotcat_AutoMulti) document.getElementById("hotcat_modify_multi_InputCancel").focus();
};

// ANNULATION DU FORMULAIRE "MULTI" + MODIFICATION DES LIENS, FONCTIONS ET IDS DE LA BARRE DE CATÉGORIES

window.hotcat_multiedit_CancelForm = function(){
    var Link = document.getElementById('hotcat_modify_multi_Link');
    if(Link) Link.style.display = "inline";
    var CatForms = document.getElementById('mw-normal-catlinks').getElementsByTagName('form');
    while(CatForms[0]){
        CatForms[0].parentNode.removeChild(CatForms[0]);
    }
    var CatSpans = document.getElementById('mw-normal-catlinks').getElementsByTagName('span');
    var SpanToRemove = [];
    for(var a=1;a<CatSpans.length;a++){
        if(CatSpans[a].classList.contains("AddedCatSpan")) SpanToRemove.push(CatSpans[a]);
    }
    for(var a=0;a<SpanToRemove.length;a++){
        SpanToRemove[a].parentNode.removeChild(SpanToRemove[a]);
    }
    var CatLinks = document.getElementById('mw-normal-catlinks').getElementsByTagName('a');
    for(var a=0;a<CatLinks.length;a++){
        CatLinks[a].style.display = "inline";
        CatLinks[a].classList.remove("RemovedCategory");
        if(CatLinks[a].classList.contains("ModifiedCategory")){
            var Index = hotcat_getIndex( CatLinks[a] );
            var OldCatName = hotcat_CatNameMatrix[Index];
            var OldDefaultSort = hotcat_defaultSort_getOneOld(OldCatName);
            hotcat_SortMatrix[Index] = OldDefaultSort;
            CatLinks[a].innerHTML = OldCatName;
            CatLinks[a].title = hotcat_CatNamespace+OldCatName;
            CatLinks[a].href = mw.config.get('wgServer')+mw.config.get('wgArticlePath').split('$1').join(hotcat_CatNamespace+OldCatName);
            CatLinks[a].classList.remove("ModifiedCategory");
        }
        if(CatLinks[a].classList.contains("ModifiedDefaultSort")){
            var DefaultSortSpan = document.getElementById("OldDefaultSortSpan");
            DefaultSortSpan.innerHTML = hotcat_OldDefaultSort;
            CatLinks[a].classList.remove("ModifiedDefaultSort");
        }
    }
    for(var a=0;a<hotcat_CatLinkMatrix.length;a++){
        if(!hotcat_CatLinkMatrix[a]) continue;
        if(hotcat_CatLinkIsRedMatrix[a]){
            if(!hotcat_CatLinkMatrix[a].classList.contains("new")) hotcat_CatLinkMatrix[a].classList.add("new");
        }else{
            hotcat_CatLinkMatrix[a].classList.remove("new");
        }
    }
    hotcat_Multi_Edit = false;
    Link.focus();
};

// VALIDATION DU FORMULAIRE "MULTI" + LISTING DES CATÉGORIES À ENLEVER/MODIFIER/AJOUTER

window.hotcat_multiedit_FormOK = function(){
    var RemovedCategories = [];
    var ModifiedCategories_from = [];
    var ModifiedCategories_to = [];
    var AddedCategories = [];
    var DefaultSort = hotcat_OldDefaultSort;
    var CatLinks = document.getElementById('mw-normal-catlinks').getElementsByTagName('a');
    for(var a=0;a<CatLinks.length;a++){
        var Link = CatLinks[a];
        var Index = hotcat_getIndex( Link );
        if(Link.classList.contains("RemovedCategory")){
            RemovedCategories.push(Link.innerHTML.ucFirst());
        }
        if(Link.classList.contains("ModifiedCategory")){
            var NewCatName = Link.innerHTML.ucFirst();
            var OldCatName = hotcat_CatNameMatrix[Index];
            var OldDefaultSort = hotcat_defaultSort_getOneOld(OldCatName);
            var NewDefaultSort = hotcat_SortMatrix[Index];
            if((OldCatName+OldDefaultSort)!=(NewCatName+NewDefaultSort)){
                ModifiedCategories_from.push((OldCatName+OldDefaultSort));
                ModifiedCategories_to.push((NewCatName+NewDefaultSort));
            }
        }
        if(Link.classList.contains("AddedCategory")){
            var NewDefaultSort = hotcat_SortMatrix[Index];
            AddedCategories.push(Link.innerHTML.ucFirst()+NewDefaultSort);
        }
        if(Link.classList.contains("ModifiedDefaultSort")){
            var DefaultSortSpan = document.getElementById("OldDefaultSortSpan");
            DefaultSort = DefaultSortSpan.innerHTML;
        }
    }
    var RadioBoxesSpan = document.getElementById("hotcat_RadioBoxes");
    var RecapMinor = '';
    var RecapWatch = '';
    var Newhotcat_Minoredit = false;
    var Newhotcat_Watchthis = false;
    if(RadioBoxesSpan){
        var RadioBoxes = RadioBoxesSpan.getElementsByTagName('input');
        for(var a=0;a<RadioBoxes.length;a++){
            if(RadioBoxes[a].type!="radio") continue;
            if(!RadioBoxes[a].checked) continue;
            var BoxName = RadioBoxes[a].name;
            var Number = hotcat_getIndex(RadioBoxes[a]);
            if(BoxName=="Minor"){
                var Minor = -1;
                var TextMinor = hotcat_text_RadioDefault;
                if(Number==0){
                    Minor = Number;
                    TextMinor = hotcat_text_RadioNo;
                }else if(Number==1){
                    Minor = Number;
                    TextMinor = hotcat_text_RadioYes;
                }
                Newhotcat_Minoredit = Minor;
                RecapMinor += hotcat_text_Minoredit.split("$1").join(TextMinor)+ '\n';
            }else if(BoxName=="Watch"){
                var Watch = -1;
                var TextWatch = hotcat_text_RadioDefault;
                if(Number==0){
                    Watch = Number;
                    TextWatch = hotcat_text_RadioNo;
                }else if(Number==1){
                    Watch = Number;
                    TextWatch = hotcat_text_RadioYes;
                }
                Newhotcat_Watchthis = Watch;
                RecapWatch += hotcat_text_Watchthis.split("$1").join(TextWatch)+ '\n';
            }
        }
    }
    var TextrecapTitle = hotcat_text_RecapTitle+'\n\n';
    var TextRecap = TextrecapTitle;
    if(RemovedCategories[0]){
        TextRecap += hotcat_text_RecapRemove+' :\n';
        for(var a=0;a<RemovedCategories.length;a++){
            TextRecap += '* « '+RemovedCategories[a]+' »\n';
        }
    }
    if(ModifiedCategories_to[0]){
        TextRecap += hotcat_text_RecapModify+' :\n';
        for(var a=0;a<ModifiedCategories_to.length;a++){
            TextRecap += '* « '+ModifiedCategories_from[a]+' » -> « '+ModifiedCategories_to[a]+' »\n';
        }
    }
    if(AddedCategories[0]){
        TextRecap += hotcat_text_RecapAdd+' :\n';
        for(var a=0;a<AddedCategories.length;a++){
            TextRecap += '* « '+AddedCategories[a]+' »\n';
        }
    }
    if(DefaultSort!=hotcat_OldDefaultSort){
        TextRecap += hotcat_text_RecapSort+' :\n';
        TextRecap += '* « '+hotcat_OldDefaultSort+' » -> « '+DefaultSort+' »\n';
    }
    if(TextRecap == TextrecapTitle) return;
    TextRecap += RecapMinor;
    TextRecap += RecapWatch;
    if(hotcat_SkipRecap || confirm(TextRecap)){
        hotcat_Minoredit = Newhotcat_Minoredit;
        hotcat_Watchthis = Newhotcat_Watchthis;
        hotcat_Edit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort);
    }
};

// VÉRIFICATION DES CHANGEMENTS EFFECTUÉS

window.hotcat_Multi_CheckForChanges = function(){
    if(!hotcat_Multi_Edit) return;
    var CatLinks = document.getElementById('mw-normal-catlinks').getElementsByTagName('a');
    var AnythingChanged = false;
    for(var a=0;a<CatLinks.length;a++){
        var Link = CatLinks[a];
        if((Link.classList.contains("RemovedCategory"))||(Link.classList.contains("ModifiedCategory"))||(Link.classList.contains("AddedCategory"))||(Link.classList.contains("ModifiedDefaultSort"))){
            AnythingChanged = true;
        }
    }
    if(AnythingChanged){
        document.getElementById('hotcat_modify_multi_InputOK').disabled = "";
    }else{
        document.getElementById('hotcat_modify_multi_InputOK').disabled = "disabled";
    }
};

///////////////////////// CLEFS DE TRI ////////////////////////////////////////////////////////

// RÉCUPÉRATION CLEF DE TRI GLOBALE

window.hotcat_defaultSort_getOld = function(ID){
    var OldDefaultSpan = document.getElementById(ID);
    if(!OldDefaultSpan) return;
    var Page = hotcat_OldPageContent;
    for(var a=0;a<hotcat_DefaultsortAliases.length;a++){
        if(Page.indexOf('{{'+hotcat_DefaultsortAliases[a]+':')!=-1){
            var AvantCle = Page.substring(0,Page.indexOf('{{'+hotcat_DefaultsortAliases[a]+':'));
            var Cle = Page.split(AvantCle).join('');
            Cle = Cle.substring(0,Cle.indexOf("}"));
            Cle = Cle.substring((Cle.indexOf(":")+1),Cle.length);
            hotcat_OldDefaultSort = Cle;
            OldDefaultSpan.innerHTML = hotcat_OldDefaultSort;
            return;
        }
    }
};

// RÉCUPÉRATION CLEF DE TRI PARTICULIÈRE

window.hotcat_defaultSort_getOneOld = function(TargetCategory){
    var Page = hotcat_OldPageContent;
    var Key = "";
    var CurrentKey = "";
    var REGEXP = new RegExp("(\\s*)\\[\\[ *(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category) *: *" + TargetCategory.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
    var matches = Page.match(REGEXP);
    if (matches != null && matches.length == 1){
        CurrentKey = Page.replace(REGEXP, "DEFAULTKEYstart$2DEFAULTKEYend");
        if((CurrentKey.indexOf("DEFAULTKEYstart")!=-1)&&(CurrentKey.indexOf("DEFAULTKEYend")!=-1)){
            var Before = CurrentKey.split("DEFAULTKEYstart")[0]+"DEFAULTKEYstart";
            var After = "DEFAULTKEYend"+CurrentKey.split("DEFAULTKEYend")[1];
            CurrentKey = CurrentKey.split(Before).join("");
            CurrentKey = CurrentKey.split(After).join("");
            if(CurrentKey.indexOf('|')!=-1) Key = CurrentKey;
        }
    }
    return Key;
};

// CRÉATION FORMULAIRE CLEF DE TRI GLOBALE

window.hotcat_defaultSort_createForm = function(){
    hotcat_defaultSort_getOld("OldDefaultSortSpan");
    var thespan = document.getElementById('hotcat_DefaultSort_span');
    var OldDefaultSort = thespan.getElementsByTagName('span')[0].innerHTML;
    thespan.getElementsByTagName('a')[0].style.display = "none";
    var form = document.createElement ( "form" ) ;
    form.id = "hotcat_form_Default";
    form.method = "post" ;
    form.onsubmit = function () {
        hotcat_Default_ok(this) ;
        return false;
    } ;
    form.style.display = "inline" ;
    var text = document.createElement ( "input" ) ;
    text.size = 40 ;
    text.id = "hotcat_text_Default" ;
    text.type = "text" ;
    text.value = OldDefaultSort ;
    var OK = document.createElement ( "input" ) ;
    OK.type = "button" ;
    OK.value = hotcat_text_InputOK ;
    OK.onclick = function(){
        hotcat_Default_ok(this.parentNode) ;
    };
    var cancel = document.createElement ( "input" ) ;
    cancel.type = "button" ;
    cancel.value = hotcat_text_InputCancel ;
    cancel.onclick = function(){
        var Form = this.parentNode;
        hotcat_Default_Cancel(Form) ;
    };
    form.appendChild ( text ) ;
    form.appendChild ( OK ) ;
    form.appendChild ( cancel ) ;
    thespan.appendChild ( form ) ;
    hotcat_upDate_FormPositions();
    text.focus () ;
};

// ANNULATION FORMULAIRE CLEF DE TRI GLOBALE

window.hotcat_Default_Cancel = function(Form){
    var Span = Form.parentNode;
    Form.parentNode.getElementsByTagName('a')[0].style.display = "";
    Form.parentNode.removeChild(Form) ;
    if(hotcat_Multi_Edit){
        Span.getElementsByTagName('span')[0].innerHTML = hotcat_OldDefaultSort;
        Span.getElementsByTagName('a')[0].classList.remove("ModifiedDefaultSort");
        Span.getElementsByTagName('a')[0].style.display = "";
        hotcat_Multi_CheckForChanges();
    }
    document.getElementById("hotcat_DefaultSort_Link").focus();
};

// VALIDATION FORMULAIRE CLEF DE TRI GLOBALE

window.hotcat_Default_ok = function(Form){
    var Text = document.getElementById("hotcat_text_Default");
    var OldDefaultSort = hotcat_OldDefaultSort;
    var NewDefaultSort = Text.value;
    if(!hotcat_Multi_Edit){
        if(OldDefaultSort==NewDefaultSort){
            hotcat_Default_Cancel(Form);
            return;
        }else{
            var RemovedCategories = [];
            var ModifiedCategories_from = [];
            var ModifiedCategories_to = [];
            var AddedCategories = [];
            var DefaultSort = NewDefaultSort ;
            hotcat_Edit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort);
        }
    }else{
        if(OldDefaultSort==NewDefaultSort){
            hotcat_Default_Cancel(Form);
            return;
        }else{
            var Span = Form.parentNode;
            Span.getElementsByTagName('span')[0].innerHTML = Text.value;
            var Link = Span.getElementsByTagName('a')[0];
            Link.style.display = "";
            Link.classList.add("ModifiedDefaultSort");
            Form.parentNode.removeChild(Form) ;
            hotcat_Multi_CheckForChanges();
            hotcat_upDate_FormPositions();
            document.getElementById("hotcat_DefaultSort_Link").focus();
        }
    }
};

///////////////////////// ÉDITION ////////////////////////////////////////////////////////

window.hotcat_Edit = function(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort){
    if(hotcat_Multi_IsEditPage){
        hotcat_autocommit = false;
        hotcat_DoEdit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort);
        hotcat_multiedit_CancelForm();
        return;
    }
    var URL = mw.config.get('wgServer')+mw.config.get('wgScript')+'?title='+encodeURIComponent(mw.config.get('wgPageName'))+'&action=submit';
    hotcat_ajax.http({url              : URL,
                      onSuccess        : hotcat_TrueEdit,
                      removedcats      : RemovedCategories,
                      modifiedcatsfrom : ModifiedCategories_from,
                      modifiedcatsto   : ModifiedCategories_to,
                      addedcats        : AddedCategories,
                      defaultsort      : DefaultSort
    });
};

window.hotcat_TrueEdit = function(Req, data){
    var RemovedCategories = data.removedcats;
    var ModifiedCategories_from = data.modifiedcatsfrom;
    var ModifiedCategories_to = data.modifiedcatsto;
    var AddedCategories = data.addedcats;
    var DefaultSort = data.defaultsort;
    while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
    document.body.innerHTML = Req.responseText;
    hotcat_DoEdit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort);
};

window.hotcat_DoEdit = function(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort){
    var prevent_autocommit = 0;
    if(typeof(hotcat_EditCustom)=="function") hotcat_EditCustom();
    if(hotcat_autocommit)document.editform.style.display = "none";
    for(var a=0,l=ModifiedCategories_to.length;a<l;a++){
        ModifiedCategories_to[a] = ModifiedCategories_to[a].replace(new RegExp("^"+hotcat_CatNamespace, "ig"), "");
    }
    for(var a=0,l=AddedCategories.length;a<l;a++){
        AddedCategories[a] = AddedCategories[a].replace(new RegExp("^"+hotcat_CatNamespace, "ig"), "");
    }
    var OldText = document.getElementById('wpTextbox1').value;
    var summary = [];
    for(var a=0;a<RemovedCategories.length;a++){
        var OldCatName = RemovedCategories[a];
        var OldCatNameUnsorted = OldCatName.replace(/\|.*/, "");
        var REGEXP = new RegExp("(\\s*)\\[\\[ *(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category) *: *" + OldCatName.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
        var matchesCatName = OldText.match(REGEXP);
        if (matchesCatName != null && matchesCatName.length == 1) {
            OldText = OldText.replace(REGEXP, "");
            summary.push( " – [[" + hotcat_CatNamespace+OldCatNameUnsorted + "]]" ) ;
        }else{
            prevent_autocommit = 1;
            if(matchesCatName == null){
                alert(hotcat_text_AlertProblem1.split('$1').join(OldCatNameUnsorted));
            }else if(matchesCatName.length > 1){
                alert(hotcat_text_AlertProblem3.split('$1').join(OldCatNameUnsorted));
            }
        }
    }
    if((RemovedCategories[0])&&((ModifiedCategories_from[0])||(AddedCategories[0]))) summary.push(" |");
    for(var a=0;a<ModifiedCategories_from.length;a++){
        var OldCatName = ModifiedCategories_from[a];
        var OldCatNameUnsorted = OldCatName.replace(/\|.*/, "");
        var NewCatName = ModifiedCategories_to[a];
        var NewCatNameUnsorted = NewCatName.replace(/\|.*/, "");
        var REGEXP_OLD = hotcat_CreateRegExp(OldCatName);
        var REGEXP_NEW = hotcat_CreateRegExp(NewCatNameUnsorted);
        var matchesOldCatName = OldText.match(REGEXP_OLD);
        var matchesNewCatName = OldText.match(REGEXP_NEW);
        if( ((matchesNewCatName == null)||(OldCatNameUnsorted==NewCatNameUnsorted)) && matchesOldCatName != null &&  matchesOldCatName.length == 1) {
            OldText = OldText.replace(REGEXP_OLD, "$1[[" + hotcat_CatNamespace+NewCatName + "$6]]");
            summary.push ( " ± [["+hotcat_CatNamespace+OldCatNameUnsorted+"]]->[["+hotcat_CatNamespace+ NewCatNameUnsorted+"]]");
        }else{
            prevent_autocommit = 1;
            if(matchesOldCatName == null){
                alert(hotcat_text_AlertProblem1.split('$1').join(OldCatNameUnsorted));
            }else if(matchesOldCatName.length > 1){
                alert(hotcat_text_AlertProblem3.split('$1').join(OldCatNameUnsorted));
            }else if((matchesNewCatName != null)&&(OldCatNameUnsorted!=NewCatNameUnsorted)){
                alert(hotcat_text_AlertProblem2.split('$1').join(NewCatNameUnsorted));
            }
        }
    }
    if((AddedCategories[0])&&(ModifiedCategories_from[0])) summary.push(" |");
    for(var a=0;a<AddedCategories.length;a++){
        var NewCatName = AddedCategories[a];
        var NewCatNameUnsorted = NewCatName.replace(/\|.*/, "");
        var REGEXP = hotcat_CreateRegExp(NewCatNameUnsorted);
        var matchesCatNameUnsorted = OldText.match(REGEXP);
        if (matchesCatNameUnsorted != null){
            alert(hotcat_text_AlertProblem2.split('$1').join(NewCatNameUnsorted));
            prevent_autocommit = 1;
            continue;
        }
        var re = new RegExp("\\[\\[(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category):[^\\]]+\\]\\]", "ig");
        var index = -1;
        while (re.exec(OldText) != null) index = re.lastIndex;
        var txt = "[[" + hotcat_CatNamespace+NewCatName + "]]" ;
        if (index < 0) {  // no category
            var interWiki = new RegExp('^\\s*\\[\\[([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)\\]\\]\\s*$');
            var blank = new RegExp('^\\s*$');
            var lines = OldText.split('\n');
            var DebutModele = '';
            var SuiteModele = '';
            for (var lineId = lines.length - 1; lineId >= 0; --lineId){
                if (!interWiki.test(lines[lineId]) && !blank.test(lines[lineId])) {
                    DebutModele = lines.slice(0, lineId + 1).join('\n') + '\n\n';
                    SuiteModele = lines.slice(lineId + 1).join('\n');
                    break;
                }
            }
            if (DebutModele === '') {
                // edge case: source has nothing else than interwikis
                SuiteModele = OldText;
            }
            while(SuiteModele.indexOf('\n\n')!=-1){
                SuiteModele = SuiteModele.split("\n\n").join("\n");
            }
            SuiteModele = SuiteModele.replace(/^\n/, "");
            OldText = DebutModele + txt + '\n\n' + SuiteModele;
        }else{
            OldText = OldText.substring(0, index) + '\n' + txt + OldText.substring(index);
        }
        summary.push ( " + [[" + hotcat_CatNamespace+NewCatNameUnsorted + "]]" ) ;
    }
    if((DefaultSort!=hotcat_OldDefaultSort)&&(DefaultSort!="undefined")){
        var NewDefaultSort = "{{DEFAULTSORT:"+DefaultSort+"}}\n";
        var HasDefaultSort = null;
        for(var d=0;d<hotcat_DefaultsortAliases.length;d++){
            if(OldText.indexOf(hotcat_DefaultsortAliases[d])!=-1) HasDefaultSort = hotcat_DefaultsortAliases[d]+":";
        }
        if(HasDefaultSort!=null){
            if(DefaultSort==""){
                NewDefaultSort = "";
                summary.push (";  – {{DEFAULTSORT:" + hotcat_OldDefaultSort +"}}") ;
            }else{
                summary.push (";  ± {{DEFAULTSORT:}} : " + hotcat_OldDefaultSort + " -> " + DefaultSort ) ;
            }
            OldText = OldText.split("{{"+HasDefaultSort+hotcat_OldDefaultSort+"}}\n").join(NewDefaultSort);
            OldText = OldText.split("{{"+HasDefaultSort+hotcat_OldDefaultSort+"}}").join(NewDefaultSort);
        }else if(DefaultSort!=""){
            var re = new RegExp("\\[\\[(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category):[^\\]]+\\]\\]", "ig");
            var index = re.exec(OldText);
            if(index ==null ) {
                var interWiki = new RegExp('^\\s*\\[\\[([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)\\]\\]\\s*$');
                var blank = new RegExp('^\\s*$');
                var lines = OldText.split('\n');
                var DebutModele = '';
                var SuiteModele = '';
                for (var lineId = lines.length - 1; lineId >= 0; --lineId){
                    if (!interWiki.test(lines[lineId]) && !blank.test(lines[lineId])) {
                        DebutModele = lines.slice(0, lineId + 1).join('\n') + '\n\n';
                        SuiteModele = lines.slice(lineId + 1).join('\n');
                        break;
                    }
                }
                if (DebutModele === '') {
                    // edge case: source has nothing else than interwikis
                    SuiteModele = OldText;
                }
                SuiteModele = SuiteModele.replace(/^\n/, "");
                OldText = DebutModele + NewDefaultSort + '\n' + SuiteModele;
            }else{
                var lastindex = re.lastIndex;
                re.lastIndex = 0;
                var FirstCat = re.exec(OldText).toString();
                FirstCat = FirstCat.replace(/\n/g, "");
                var Before = OldText.substring(0, lastindex).replace(FirstCat, "");
                var After = FirstCat+OldText.substring(lastindex);
                OldText = Before + NewDefaultSort + After;
            }
            summary.push (";  + " + NewDefaultSort ) ;
        }
    }
    var cat = new RegExp("\\[\\[(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category):[^\\]]+\\]\\]", "ig");
    var nocat1 = "{{"+hotcat_text_NoCatTemplate.ucFirst()+"}}\n";
    var nocat1Bis = "{{"+hotcat_text_NoCatTemplate.lcFirst()+"}}\n";
    var nocat2 = "{{"+hotcat_text_NoCatTemplate.ucFirst()+"}}";
    var nocat2Bis = "{{"+hotcat_text_NoCatTemplate.lcFirst()+"}}";
    if(cat.exec(OldText) != null){
        OldText = OldText.split(nocat1).join("");
        OldText = OldText.split(nocat1Bis).join("");
        OldText = OldText.split(nocat2).join("");
        OldText = OldText.split(nocat2Bis).join("");
    }
    document.getElementById('wpTextbox1').value = OldText;
    document.getElementById('wpSummary').value = hotcat_text_ResumeScript + summary.join("");
    if(!hotcat_Multi_IsEditPage){
        if(hotcat_Minoredit==1) document.editform.wpMinoredit.checked = true;
        if(hotcat_Minoredit==0) document.editform.wpMinoredit.checked = false;
        if(hotcat_Watchthis==1) document.editform.wpWatchthis.checked = true;
        if(hotcat_Watchthis==0) document.editform.wpWatchthis.checked = false;
    }
    if((hotcat_autocommit)&&(prevent_autocommit != 1)){
        var watchthisparam = {};
        watchthisparam[-1] = "nochange";
        watchthisparam[ 0] = "unwatch";
        watchthisparam[ 1] = "watch";
        var datas = {
              action    : 'edit',
              title     : mw.config.get('wgPageName'),
              text      : OldText,
              summary   : hotcat_text_ResumeScript + summary.join(""),
              watchlist : watchthisparam[hotcat_Watchthis],
              token     : document.editform.wpEditToken.value
        };
        if(document.editform.wpMinoredit.checked){
            datas['minor'] = 1;
        }
        var hotcattag = hotcat_gettag();
        if(hotcattag){
            datas.summary = summary.join("");
            datas.tags = hotcattag;
        }
        new mw.Api()
            .post(datas, {'contentType': 'application/x-www-form-urlencoded'})
            .then(function (data) {
                window.location.reload();
            });
        return;
    }
    if(prevent_autocommit == 1) document.editform.style.display = "";
    if(hotcat_Multi_IsEditPage) hotcat_update_existing();
};

///////////////////////// SUGGESTIONS ////////////////////////////////////////////////////////

// REQUÊTE DE SUGGESTIONS

window.hotcat_text_changed  = function(FormIndex, Mode, titles, catContinue) {
    if ( hotcat_suggest_running ) return ;
    if(!Mode) Mode = false;
    if((!FormIndex)||(FormIndex=="")) FormIndex = "0";
    if(!titles) titles = [];
    if(!catContinue) catContinue = "";
    var text = hotcat_TextMatrix[FormIndex];
    if(!text){alert('PB hotcat_text_changed () : ' + FormIndex); return; }
    var v = text.value;
    v = hotcat_deleteUnwantedUnicodeChars(v);
    v = v.replace(new RegExp("^"+hotcat_CatNamespace, "ig"), "");
    v = v.ucFirst() ;
    text.value = v;
    if(v.indexOf("|")!=-1) v = v.split("|")[0];
    var APILimit = ( ((mw.config.get('wgUserGroups').indexOf("sysop")!=-1)||(mw.config.get('wgUserGroups').indexOf("bot")!=-1)) ? 5000 : 500 );
    if(hotcat_list_items>APILimit) hotcat_list_items = APILimit; // API max
    var URL, TagName, Replace;
    if(Mode=="UP"){ // Suggestions catégories-mères
        URL = "/api.php?format=xml&action=query&prop=categories&titles=" + hotcat_CatNamespace+encodeURIComponent(v) + "&cllimit=" + hotcat_list_items;
        TagName = "cl";
        Replace = false;
    }else if(Mode=="DOWN"){ // Suggestions catégories-filles
        URL = "/api.php?format=xml&action=query&list=categorymembers&cmnamespace=14&cmtitle=" + hotcat_CatNamespace+encodeURIComponent(v) + "&cmlimit=" + APILimit + catContinue;
        TagName = "cm";
        Replace = false;
    }else{ // Suggestions normales
        URL =  "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent(v) + "&aplimit=" + hotcat_list_items;
        TagName = "p";
        Replace = true;
    }
    hotcat_suggest_running = 1 ;
    if ( v != "" ) {
        hotcat_ajax.http({url         : mw.config.get('wgServer') + mw.config.get('wgScriptPath') + URL,
                          onSuccess   : hotcat_text_changedBis,
                          tagname     : TagName,
                          replacetext : Replace,
                          titles      : titles,
                          formindex   : FormIndex,
                          mode        : Mode
        });
    }else{
        hotcat_show_suggestions ( titles , FormIndex, Replace ) ;
    }
};

window.hotcat_text_changedBis = function(Req, data){
    var titles = data.titles;
    var FormIndex = data.formindex;
    var Mode = data.mode;
    var TagName = data.tagname;
    var Replace = data.replacetext;
    var xml = Req.responseXML ;
    if ( xml == null ) return ;
    var pages = xml.getElementsByTagName( TagName ) ;
    for ( var i = 0 ; i < pages.length ; i++ ) {
        var s = pages[i].getAttribute("title");
        if(s.indexOf(hotcat_CatNamespace)!=-1){
            s = s.split(hotcat_CatNamespace).join('');
            titles.push ( s ) ;
        }
    }
    var CanContinue = xml.getElementsByTagName("query-continue")[0];
    if(Mode=="DOWN"&&CanContinue){
        var CanContinueId = "&cmcontinue="+encodeURIComponent(CanContinue.firstChild.getAttribute("cmcontinue"));
        hotcat_suggest_running = 0 ;
        hotcat_text_changed(FormIndex, Mode, titles, CanContinueId) ;
    }else{
        hotcat_show_suggestions(titles, FormIndex, Replace);
    }
};

// AFFICHAGE DES SUGGESTIONS

window.hotcat_show_suggestions  = function( titles, FormIndex, Replace, Mode ) {
    hotcat_suggest_running = 0 ;
    var text = hotcat_TextMatrix[FormIndex] ;
    var list = hotcat_ListMatrix[FormIndex] ;
    var icon = hotcat_ExistMatrix[FormIndex] ;
    if((!text)||(!list)||(!icon)) { alert('PB hotcat_show_suggestions() : ' + FormIndex); return; }
    if(titles.length==0){
        list.style.display = "none" ;
        if(Replace){
            icon.src = hotcat_exists_no ;
            icon.title = hotcat_text_Exists_NoTitle ;
        }
        return ;
    }
    var TailleListe = hotcat_list_size;
    if (titles.length < TailleListe ) TailleListe = titles.length;
    var listh = TailleListe * 20 ;
    list.size = 5 ;
    list.style.align = "left" ;
    list.style.zIndex = 5;
    list.style.position = "relative" ;
    list.style.width = text.offsetWidth + "px" ;
    list.style.height = listh + "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.value = titles[i];
        list.appendChild ( opt ) ;
    }
    if(hotcat_list_down){
        list.style.top = parseInt(text.offsetHeight) + "px";
        list.style.marginBottom = "-" + (listh + parseInt(text.offsetHeight)) + "px" ;
    }else{
        list.style.marginTop = "-" + listh + "px" ;
        list.style.display = "inline" ;
        list.style.bottom = parseInt(text.offsetHeight -2) + "px";
    }
    list.style.marginLeft = "-" + text.offsetWidth + "px" ;
    list.onkeyup = hotcat_KeypressedOnList;
    list.style.display = "inline" ;
    icon.title = hotcat_text_Exists_YesTitle ;
    icon.src = hotcat_exists_yes ;
    var first_title = titles.shift () ;
    hotcat_last_v = text.value.ucFirst();
    var hotcat_last_v_Split = hotcat_last_v;
    if(hotcat_last_v.indexOf('|')!=-1){
       hotcat_last_key = hotcat_last_v.substring(hotcat_last_v.indexOf("|"), hotcat_last_v.length);
       hotcat_last_v_Split = hotcat_last_v.split(hotcat_last_key).join('');
    }else{
       hotcat_last_key = "";
    }
    if ( first_title == hotcat_last_v_Split ) return ;
    if(Replace){
        var suggestion = first_title;
        if(suggestion.indexOf(hotcat_last_v_Split)==-1){
            icon.src = hotcat_exists_no ;
            icon.title = hotcat_text_Exists_NoTitle ;
            return;
        }
        text.value = suggestion + hotcat_last_key ;
        if (text.createTextRange) {
            var ra = text.createTextRange();
            ra.moveStart("character", hotcat_last_v.length);
            ra.moveEnd("character", suggestion.length);
            ra.select();
        } else if( text.setSelectionRange ) {
            text.setSelectionRange( hotcat_last_v.length, suggestion.length );
        } else {
            text.selectionStart = hotcat_last_v.length ;
            text.selectionEnd = suggestion.length ;
        }
    }else{
        list.focus();
    }
};

// MISE A JOUR DE LA POSITION DES LISTES DE SUGGESTIONS

window.hotcat_upDate_FormPositions = function(){
    var AllForms = document.getElementById('mw-normal-catlinks').getElementsByTagName('form');
    for(var a=0;a<AllForms.length;a++){
        if(AllForms[a].id == "hotcat_modify_multi_form") continue;
        if(AllForms[a].id == "hotcat_form_Default") continue;
        var ThisForm = AllForms[a];
        var ThisSelect = ThisForm.getElementsByTagName('select')[0];
        var Options = ThisSelect.getElementsByTagName('option');
        var ThisInput = ThisForm.getElementsByTagName('input')[0];
        var ListHeight = hotcat_list_size * 20 ;
        if (Options.length < hotcat_list_size) {
            ListHeight = Options.length * 20 ;
        }
        if(hotcat_list_down){
            ThisSelect.style.top = parseInt(ThisInput.offsetHeight) + "px";
            ThisSelect.style.marginBottom = "-" + (ListHeight + parseInt(ThisInput.offsetHeight)) + "px" ;
        }else{
            ThisSelect.style.marginTop = "-" + ListHeight + "px" ;
        }
        ThisSelect.style.marginLeft = "-" + ThisInput.offsetWidth + "px" ;
    }
};

// SÉLECTION D'UNE SUGGESTION AU CLAVIER

window.hotcat_KeypressedOnList = function(e){
    if (!e) var e = window.event;
    if (e.keyCode != 13) return;
    hotcat_text_replace(hotcat_getIndex(this));
};

// REMPLACEMENT DU CHAMP DE TEXTE PAR UNE SUGGESTION

window.hotcat_text_replace = function(Index){
    var Text = hotcat_TextMatrix[Index];
    var TextValue = Text.value;
    var List = hotcat_ListMatrix[Index];
    var Options = List.getElementsByTagName('option');
    for(var a=0;a<Options.length;a++){
        if(Options[a].selected){
            var ListValue = Options[a].value;
            if(TextValue.indexOf('|')!=-1){
                hotcat_last_key = TextValue.substring(TextValue.indexOf("|"), TextValue.length);
            }
            Text.value = ListValue + hotcat_last_key;
            hotcat_text_changed(Index) ;
            Text.focus();
            return;
        }
    }
};

///////////////////////// MISE A JOUR BARRE DE CATÉGORIES ////////////////////////////////////////////////////////

window.hotcat_update_existing = function(){
    var OldText = document.getElementById("wpTextbox1").value;
    OldText = hotcat_update_existing_Strip(OldText);
    var catRegExp = new RegExp("\\[\\[(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category):[^\\]]+\\]\\]", "ig");
    var Matches = OldText.match(catRegExp);
    var Cats = [];
    if(Matches != null){
        for(var a=0,l=Matches.length;a<l;a++){
            var ThisMatch = Matches[a];
            ThisMatch = ThisMatch.replace(new RegExp("\\[\\[(" + mw.config.get('wgFormattedNamespaces')[14]+"|Category):", "ig"), "");
            ThisMatch = ThisMatch.replace(new RegExp("\\]\\]", "ig"), "");
            var ThisCat = ThisMatch.replace(/\|.*/g, "");
            Cats.push(ThisCat);
        }
    }
    hotcat_update_existing_Exists(Cats);
};

window.hotcat_update_existing_Strip = function(Text){
   Text = hotcat_update_existing_StripTag(Text, "<nowiki[^>]*>", "</"+"nowiki>");
   Text = hotcat_update_existing_StripTag(Text, "<includeonly[^>]*>", "</"+"includeonly>");
   Text = hotcat_update_existing_StripTag(Text, "<pre[ ]+[^>]*>", "</"+"pre>");
   Text = hotcat_update_existing_StripTag(Text, "<source[ ]+[^>]*>", "</"+"source>");
   Text = hotcat_update_existing_StripTag(Text, "<syntaxhighlight[ ]*[^>]*>", "</"+"syntaxhighlight>");
   Text = hotcat_update_existing_StripTag(Text, "<!--[\\-]*", "-->");
   return Text;
};

window.hotcat_update_existing_StripTag = function(Text, StartTag, EndTag){
   var TagRegExp = new RegExp(StartTag, "ig");
   var Matches = Text.match(TagRegExp);
   if(Matches!=null){
      for(var a=0,l=Matches.length;a<l;a++){
         var BeforeTag = Text.substring(0, Text.indexOf(Matches[a]));
         var AfterTag = Text.substring(BeforeTag.length, Text.length);
         if(AfterTag.indexOf(EndTag)==-1){
            AfterTag = "";
         }else{
            AfterTag = AfterTag.substring( (AfterTag.indexOf(EndTag) + (EndTag.length)) , AfterTag.length);
         }
         Text = BeforeTag + AfterTag;
         if(Text.match(TagRegExp)==null) break;
      }
   }
   return Text;
};

window.hotcat_update_existing_Exists = function(Cats, NewCats){
    if(!Cats[0]){
        hotcat_update_existing_Update(Cats, NewCats);
        return;
    }
    if(!NewCats) NewCats = [];
    var CatTitles = [];
    for(var a=0,l=Cats.length;a<l;a++){ CatTitles.push( mw.config.get('wgFormattedNamespaces')[14]+":"+encodeURIComponent(Cats[a]) ); }
    var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&prop=info&titles=' + CatTitles ;
    hotcat_ajax.http({url         : URL,
                      onSuccess   : hotcat_update_existing_ExistsBis,
                      cats        : Cats,
                      newcats     : NewCats
    });
};

window.hotcat_update_existing_ExistsBis = function(Req, data){
    var Cats = data.cats;
    var NewCats = data.newcats;

    var ObjetXML = Req.responseXML;
    if(!ObjetXML){
        hotcat_update_existing_Update(Cats, NewCats);
        return;
    }
    var Pages = ObjetXML.getElementsByTagName('page');
    for(var a=0,l=Pages.length;a<l;a++){
        var Page = Pages[a];
        var Title = Page.getAttribute("title").split(mw.config.get('wgFormattedNamespaces')[14] + ":").join("");
        var Index= Cats.indexOf(Title);
        if(Index==-1) continue;
        var Missing = Page.getAttribute("missing");
        if(Missing==""){
            NewCats[Index] = true;
        }else{
            NewCats[Index] = false;
        }
    }
    hotcat_update_existing_Update(Cats, NewCats);
};

window.hotcat_update_existing_Update = function(Cats, NewCats){
    var CatLine = document.getElementById("mw-normal-catlinks");
    var catline = document.createElement("div");
    catline.id = "mw-normal-catlinks";
    CatLine.parentNode.insertBefore(catline, CatLine);
    var plural = (Cats.length != 1);
    hotcat_append_firstlink( catline, plural);
    for(var a=0,l=Cats.length;a<l;a++){
        var Cat = Cats[a];
        var  Link = document.createElement('a');
        Link.title = mw.config.get('wgFormattedNamespaces')[14] + ":" + Cat;
        Link.appendChild(document.createTextNode(Cat));
        Link.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(mw.config.get('wgFormattedNamespaces')[14] + ":" + encodeURI(Cat));
        if(NewCats[a]) Link.className = "new";
        var Span = document.createElement('span');
        Span.appendChild(Link);
        if(a!=0) catline.appendChild(document.createTextNode(' | '));
        catline.appendChild(Span);
    }
    var  HiddenCatsLink = document.getElementById(hotcat_HiddenCatsLinkID);
    if(HiddenCatsLink){
      HiddenCatsLink.parentNode.removeChild(HiddenCatsLink);
      catline.appendChild(document.createTextNode(' | '));
      catline.appendChild(HiddenCatsLink);
    }
    CatLine.parentNode.removeChild(CatLine);
    hotcat_modify_existing(catline);
    hotcat_append_add_span(catline);
    hotcat_append_multiedit_span(catline);
};


///////////////////////// DIVERS ////////////////////////////////////////////////////////

// RÉCUPÉRATION DU N° D'INDEX

window.hotcat_getIndex = function( Element ){
    return parseInt(Element.id.replace(/[^0-9]/g, ""));
};

// GESTION {{PLURAL:}} (MESSAGES SYSTÈME)

window.hotcat_PLURAL = function(Text, Plural){
    var PluralRegExp = new RegExp("\\{\\{PLURAL[^\\}]+\\}\\}", "ig");
    var Matches = Text.match(PluralRegExp);
    if(Matches!=null){
        for(var b=0,m=Matches.length;b<m;b++){
            var Match = Matches[b];
            var Params = Match.split('}}').join('').split('|');
            var Result = "";
            if(Plural){
                Result = Params[2];
            }else{
                Result = Params[1];
            }
            if(!Result) Result = "";
            Text = Text.replace(Match, Result);
        }
    }
    return Text;
};

// GESTION {{GENDER:}} (MESSAGES SYSTÈME)

window.hotcat_GENDER = function(Text, Gender){
    var PluralRegExp = new RegExp("\\{\\{GENDER[^\\}]+\\}\\}", "ig");
    var Matches = Text.match(PluralRegExp);
    if(Matches!=null){
        for(var b=0,m=Matches.length;b<m;b++){
            var Match = Matches[b];
            var Params = Match.split('}}').join('').split('|');
            var Result = "";
            if(Gender=="male"){
                Result = Params[1];
            }else if(Gender=="female"){
                Result = Params[2];
            }else{
                Result = Params[3];
            }
            if(!Result) Result = "";
            Text = Text.replace(Match, Result);
        }
    }
    return Text;
};

// PREMIÈRE LETTRE EN MAJUSCULE

String.prototype.ucFirst = function () {
    return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
};

// PREMIÈRE LETTRE EN MINUSCULE

String.prototype.lcFirst = function () {
    return this.substr(0,1).toLowerCase() + this.substr(1,this.length);
};

window.hotcat_CreateRegExp = function(Cat){
    if(hotcat_CaseSensitive){
        Cat = Cat.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1");
    }else{
        Cat = "("+ Cat.ucFirst().replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + "|" + Cat.lcFirst().replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + ")";
    }
    var CatRegExp = new RegExp("(\\s*)\\[\\[( |_)*(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category)( |_)*:( |_)*" + Cat +"( |_)*(\\|[^\\]]*)?\\]\\]", "g");
    return CatRegExp;
};

// Retrait de caractères unicode indésirables

window.hotcat_deleteUnwantedUnicodeChars = function(Text){
  return Text.replace(/\u200E|\u200F|\u202A|\u202B|\u202C|\u202D|\u202E/g, '');
};

///////////////////////// LANCEMENT ////////////////////////////////////////////////////////


window.hotcat_Launch = function(){
    var hotcat_CanEdit = true;
    var RestrictionEdit = mw.config.get('wgRestrictionEdit');
    var Groups = mw.config.get('wgUserGroups');
    if(RestrictionEdit !== null && typeof(RestrictionEdit)==='object' && RestrictionEdit.length > 0){
        hotcat_CanEdit = false;
        if( Groups !== null  && typeof(Groups)==='object'){
            for(var a=0,l=RestrictionEdit.length;a<l;a++){
                if(Groups.indexOf(RestrictionEdit[a])!=-1) hotcat_CanEdit = true;
            }
        }
    }
    if(!hotcat_CanEdit) return;
    // Affichage pour une langue se lisant de droite à gauche.
    var isRtl = document.body.classList.contains('rtl');
    // Définition styles CSS
    mw.loader.addStyleTag(
        ".RemovedCategory { text-decoration:line-through;background-color:#FF9999; } " +
        ".ModifiedCategory { background-color:#CCCC77; } " +
        ".AddedCategory { background-color:#99FF99; } " +
        ".ModifiedDefaultSort { background-color:#CCCC77; } " +
        "#catlinks, #catlinks div { text-align:" + (isRtl ? 'right' : 'left') + " !important; } " +
        "#mw-normal-catlinks * { display:inline; } " +
        "#catlinks option { display:block !important; } "
    );
    var HCMmodules = [
      mw.config.get('wgServer')+mw.config.get('wgScript')+'?title=MediaWiki:Gadget-HotCatsMultiCustomEdit.js&action=raw&ctype=text/javascript'
    ];
    var Lang = mw.config.get('wgUserLanguage');
    if(Lang !== "fr"){
        HCMmodules.push('//fr.wikipedia.org/w/index.php?title=Mediawiki:Gadget-HotCatsMulti.js/i18n/'+Lang+'.js&action=raw&ctype=text/javascript');
    }
    // Lancement
    mw.loader.implement( "HotCatsModules", HCMmodules, {}, {}, {} );
    mw.loader.using(['HotCatsModules', 'site', 'user', 'mediawiki.cookie', 'mediawiki.api'], function () {
        hotcat_initialize_settings();
        $(function ($) {
            hotcat_getDefaultsortAliasesAndMessages();
        });
    });
};


if( mw.config.get('wgNamespaceNumber') > -1 && mw.config.get('wgNamespaceNumber')%2 === 0 && document.URL.indexOf("printable=yes") == -1 && ["history","delete"].indexOf(mw.config.get('wgAction')) === -1){
    hotcat_Launch();
}

//</nowiki></pre></source>