Inscris-toi pour écrire dans l'encyclopédie Wikimini!

Utilisateur:Jereemy/Categories.js

Aller à : navigation, rechercher

Note : après avoir enregistré tes préférences, tu devras forcer son rechargement complet en ignorant le contenu actuel du cache de ton explorateur pour voir les changements : Mozilla / Firefox / Konqueror / Safari : maintiens la touche Majuscule (Shift) en cliquant le bouton Actualiser (Reload,) ou presse Maj-Ctrl-R (Maj-Cmd-R sur Apple Mac) ; Internet Explorer / Opera : maintiens la touche Ctrl en cliquant le bouton Actualiser ou presse Ctrl-F5.

 __NORICHEDITOR__ function hotcat_Edit(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 = wgServer+wgScript+'?title='+encodeURIComponent(wgPageName)+'&action=edit';
    var NouvelleRequete = sajax_init_object();
    NouvelleRequete.open("GET", URL, true);
    NouvelleRequete.onreadystatechange = function() {
        if(NouvelleRequete.readyState != 4) return;
        while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
        document.body.innerHTML = NouvelleRequete.responseText;
        hotcat_DoEdit(RemovedCategories, ModifiedCategories_from, ModifiedCategories_to, AddedCategories, DefaultSort);
    };
    NouvelleRequete.send(null);
}

function hotcat_DoEdit(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 = new Array();
    for(var a=0;a<RemovedCategories.length;a++){
        var OldCatName = RemovedCategories[a];
        var OldCatNameUnsorted = OldCatName.replace(/\|.*/, "");
        var REGEXP = new RegExp("(\\s*)\\[\\[ *(?:"+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(matchesCatNameUnsorted == null){
                alert(hotcat_text_AlertProblem1.split('$1').join(OldCatNameUnsorted));
            }else if(matchesCatNameUnsorted.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 = new RegExp("(\\s*)\\[\\[ *(?:"+wgFormattedNamespaces[14]+"|Category) *: *" + OldCatName.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
        var REGEXP_NEW = new RegExp("(\\s*)\\[\\[ *(?:"+wgFormattedNamespaces[14]+"|Category) *: *" + NewCatNameUnsorted.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
        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 + "]]");
            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 = new RegExp("(\\s*)\\[\\[ *(?:"+wgFormattedNamespaces[14]+"|Category) *: *" + NewCatNameUnsorted.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi");
        var matchesCatNameUnsorted = OldText.match(REGEXP);
        if (matchesCatNameUnsorted != null){
            alert(hotcat_text_AlertProblem2.split('$1').join(NewCatNameUnsorted));
            prevent_autocommit = 1
            continue;
        }
        var re = new RegExp("\\[\\[(?:"+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 (";  – " + 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("\\[\\[(?:"+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);
                var compile = re.compile(re);
                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("\\[\\[(?:"+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)) document.editform.submit();
    if(prevent_autocommit == 1) document.editform.style.display = "";
    if(hotcat_Multi_IsEditPage) hotcat_update_existing();
}
///////////////////////// SUGGESTIONS ////////////////////////////////////////////////////////

// REQUÊTE DE SUGGESTIONS

function hotcat_text_changed (FormIndex, Mode, titles, catContinue) {
    if ( hotcat_suggest_running ) return ;
    if(!Mode) Mode = false;
    if((!FormIndex)||(FormIndex=="")) FormIndex = "0";
    if(!titles) titles = new Array () ;
    if(!catContinue) catContinue = "";
    var text = hotcat_TextMatrix[FormIndex];
    if(!text){alert('PB hotcat_text_changed () : ' + FormIndex); return; }
    var v = text.value;
    v = v.replace(new RegExp("^"+hotcat_CatNamespace, "ig"), "");
    v = v.ucFirst() ;
    text.value = v;
    if(v.indexOf("|")!=-1) v = v.split("|")[0];
    var APILimit = ( ((wgUserGroups.indexOf("sysop")!=-1)||(wgUserGroups.indexOf("bot")!=-1)) ? 4999 : 499 );
    if(hotcat_list_items>APILimit) hotcat_list_items = APILimit; // API max
    if(Mode=="UP"){ // Suggestions catégories-mères
        var URL = "/api.php?format=xml&action=query&prop=categories&titles=" + hotcat_CatNamespace+encodeURIComponent(v) + "&cllimit=" + hotcat_list_items;
        var TagName = "cl";
        var Replace = false;
    }else if(Mode=="DOWN"){ // Suggestions catégories-filles
        var URL = "/api.php?format=xml&action=query&list=categorymembers&cmnamespace=14&cmtitle=" + hotcat_CatNamespace+encodeURIComponent(v) + "&cmlimit=" + APILimit + catContinue;
        var TagName = "cm";
        var Replace = false;
    }else{ // Suggestions normales
        var URL =  "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent(v) + "&aplimit=" + hotcat_list_items;
        var TagName = "p";
        var Replace = true;
    }
    hotcat_suggest_running = 1 ;
    if ( v != "" ) {
        if ( typeof ( hotcat_xmlhttp ) != "undefined" ) hotcat_xmlhttp.abort() ;
        hotcat_xmlhttp = new sajax_init_object() ;
        hotcat_xmlhttp.open('GET', wgServer + wgScriptPath + 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( 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){
                    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);
                }
            }
        };
        hotcat_xmlhttp.send(null);
    } else {
        hotcat_show_suggestions ( titles , FormIndex, Replace ) ;
    }
}

<div style="clear:both;" class="NavFrame">
<div class="NavHead" align="center">Choisis une ou plusieurs catégorie(s)</div>
<div class="NavContent" align="left">
<div style="display:none">$1</div>
$2
<div id="CategorySelect_CheckedCats"></div>
<div class="NavEnd">&nbsp;</div>
</div>
</div>
Wikiboo Outils personnels