میڈیا وکی:Gadget-RenommageCategorie.js

آزاد انسائیکلوپیڈیا، وکیپیڈیا توں

نوٹ: بچان مگروں توانوں اپنے براؤزر دے کاشے توں بار جانا پوے گا تبدیلیاں ویکھن لئی۔

  • Firefox / Safari: Shift پھڑی رکھو ریلوڈ تے کلکنگ کردیاں ہویاںCtrl-F5 or Ctrl-R (Command-R میک تے)
  • گوکل کروم: دباؤ Ctrl-Shift-R (Command-Shift-R میک تے)

Internet Explorer: hold Ctrl کلک کردیاں Refresh, یا دباؤ Ctrl-F5 Konqueror:کلک ریلوڈ یا F5 دباؤ۔ Opera: کاشے نوں صاف کرو آوزار → تانگاں

/* ***************************************************************************************************************

Fonction : Renommage/vidage de catégorie

* Ajoute un onglet "renommer" en haut d'une page de catégorie.

* Détail du fonctionnement :
   1. modification/retrait¹ automatique de lien catégorie dans les pages et les sous-catégories d'une catégorie;
   2. si nécessaire² : copie du contenu de l'ancienne catégorie dans la nouvelle + crédit des auteurs en page de discussion;
   3. si nécessaire² : suppression de l'ancienne catégorie³;

 ¹ basé sur la partie "édition" du gadget [[MediaWiki:Gadget-HotCats.js]], plusieurs pop-up permettent de définir les paramètres.
 ² après une pop-up de confirmation
 ³ si utilisateur sysop uniquement

* Documentation complète : [[Projet:JavaScript/Notices/RenommageCategorie]]

* Licence : Domaine public

{{Catégorisation JS|RenommageCategorie}}
******************************************************************************************************************* */
//<source lang=javascript><pre><nowiki>

////////////////////////////////////////////// TEXTES GLOBAUX ///////////////////////////

// Libellé de l'onglet
window.RenommageCategorie_Text_Move = 'گٹھ منتقل';
var lang = document.getElementsByTagName("html")[0].getAttribute("lang=ur");
document.documentElement.setAttribute("lang", 'ur');
// Pop-up paramètres
window.RenommageCategorie_Text_PopRemoveCat = 'گٹھ برائے حذف';
window.RenommageCategorie_Text_PopAddCat = 'گٹھ برائے اضافہ';
window.RenommageCategorie_Text_PopConfirm = 'بلا توثیق محفوظ ؟';
window.RenommageCategorie_Text_PopWatch = 'ترمیماں نوں زیر نظر کرو ؟';
window.RenommageCategorie_Text_PopButtonOKText = 'ٹھیک';
window.RenommageCategorie_Text_PopButtonOKTitle = 'محفوظ';
window.RenommageCategorie_Text_PopButtonCancelText = 'منسوخ';
window.RenommageCategorie_Text_PopButtonCancelTitle = 'منسوخ';
window.RenommageCategorie_Text_PopMoveOnlyCat = 'صرف گٹھ دا ناں  تبدیل کرو';

// Pop-up de confirmation
window.RenommageCategorie_Text_Modif = "تسیں $1 صفحےآں چ ترمیم کرن والے او.\n\n"
                                  + "جاری رکھو ؟\n";                                  // Confirmation édition (<50 pages)
window.RenommageCategorie_Text_GrosseModif = "تسیں $1 صفحےآں چ ترمیم کرن والے او.\n"
                                        + "تساں دیاں درج کردہ درخواستاں زیادہ نیں، بہتر ہوۓ گا کہ بوٹ توں منتقل کرن لئی [[وپ:منتقلی گٹھ|ایتھے]] درخواست دیؤ۔\n\n"
                                        + "جاری رکھو ؟\n";                  // Confirmation grosse édition (>50 pages)
window.RenommageCategorie_Text_Delay = "(دو ترمیماں دی درمیانی مدت $1 سیکنڈ)";
window.RenommageCategorie_Text_ConfirmEdit = "$1 -> $2\n\nخلاصۂ ترمیم : $3";  // Confirmation édition
window.RenommageCategorie_Text_ConfirmMove = "منتقل کرو توں $1 ول $2 ؟";      // Copie
window.RenommageCategorie_Text_ConfirmMoveS = "$1 نوں $2  دے ول منتقل کرو؟ ";                     // Déplacement
window.RenommageCategorie_Text_ConfirmMoveBis = 'گٹھ حذف کرو؟'          // Confirmation Copie
window.RenommageCategorie_Text_ConfirmWikidata = 'منتقلی l\'ویکی ڈیٹا $1 توں مربوط کرن لئی $2؟' // Copie de l'entrée wikidata
window.RenommageCategorie_Text_ConfirmDelete = "$1 گٹھ نوں حذف کرو؟";            // Suppression

// Pop-up lors d'un problème
window.RenommageCategorie_Text_AlertSameCat = "گٹھاں برائے  حذف ہی دا اضافہ مقصود اے";
window.RenommageCategorie_Text_AlertEditPb1 = "گٹھ نہیں مل سکی « $1 » - ایہ اک سانچے دے ذریعے شامل کیتی جا سکدی اہے.";
window.RenommageCategorie_Text_AlertEditPb2 = "گٹھ« $1 » پہلے ہی موجود اے.";
window.RenommageCategorie_Text_AlertEditPb3 = "مکرر « $1 » گٹھ.";
window.RenommageCategorie_Text_AlertEditTryAgain = 'خطا!\n\nدوبارہ کوشش کرو ؟';
window.RenommageCategorie_Text_AlertEditNextPage = 'اگلا صفحہ ؟'

// Résumés de modification
window.RenommageCategorie_Text_ResumeEditModif = "منتقلی  [[$1]] ← [[$2]]";
window.RenommageCategorie_Text_ResumeEditDelete = "حذف گٹھ[[$1]]";
window.RenommageCategorie_Text_ResumeMove = "منتقلی مواد [[$1]]";
window.RenommageCategorie_Text_ResumeMoveHist = "منتقلی تاریخچہ [[$1]]";
window.RenommageCategorie_Text_ResumeDelete = "گٹھ منتقل شدہ بجانب [[$2]]";
window.RenommageCategorie_Text_ResumeDeleteBis = "غیر مستعمل خالی گٹھ";

////////////////////////////////////////////// TEXTES ET PARAMETRES LOCAUX ///////////////////////////

// Résumés de modification : lien vers la documentation
window.RenommageCategorie_Text_Script = '[[میڈیا وکی:Gadget-RenommageCategorie|منتقلی گٹھاں]] : ';

// Modèle pour crédit des auteurs en page de discussion
window.RenommageCategorie_Text_HistTemplate = "{{منتقل شدہ گٹھ|$1|م=$2}}\n";

// Modèle User
window.RenommageCategorie_Text_UserTemplate = "{{م|$1}}";

// Modèle Suppression Immédiate
window.RenommageCategorie_Text_DeleteTemplate = "{{حذف|$1|م=$2}}";

// Modèle Wikidata à mettre à jour
window.RenommageCategorie_Text_WikidataTemplate = "{{Données wikidata obsolètes|id=$1}}";

// Titre de page sensibles à la casse ?
window.RenommageCategorie_CaseSensitive = false;

// Groupe nécessaire pour appliquer une balise
window.RenommageCategorie_TagGroup = "user";

// Balise
window.RenommageCategorie_Tag = "";
if(mw.config.get('wgServer') == '//pnb.wikipedia.org') window.RenommageCategorie_Tag = "RenommageCategorie";


//////////////////////////////////////////////////////////////////////////////

// --------------------------------------------------------------------------------------------
// Variables par défaut

window.RenommageCategorie_RemoveCat = mw.config.get('wgTitle');    // گٹھ ہٹاؤ
window.RenommageCategorie_AddCat = mw.config.get('wgTitle');       // گٹھ شامل کرو
window.RenommageCategorie_Autoconfirm = false;    // Publication automatique
window.RenommageCategorie_AutoWatch = false;      // Suivi automatique
window.RenommageCategorie_TimeOut = 10;           // Délai par défaut après publication

window.RenommageCategorie_CanMoveCat = false;
window.RenommageCategorie_WikidataId = false;

if( (mw.config.get('wgUserGroups').indexOf("sysop")!=-1)||(mw.config.get('wgUserGroups').indexOf("bot")!=-1)){
   var RenommageCategorie_APILimit = 4999;
}else{
   var RenommageCategorie_APILimit = 499;
}
if(mw.config.get('wgUserGroups').indexOf("bot")!=-1){
   var RenommageCategorie_IsBot = true;
}else{
   var RenommageCategorie_IsBot = false;
}

// --------------------------------------------------------------------------------------------
// Fonction de requête

window.RenommageCategorie_ajax = {
  http:function(bundle){ var xmlhttp; try{ xmlhttp = new XMLHttpRequest(); }catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xmlhttp = false; }}}; if(xmlhttp){ xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ RenommageCategorie_ajax.httpComplete(xmlhttp,bundle);}}; xmlhttp.open(bundle.method ? bundle.method : "GET",bundle.url,bundle.async == false ? false : true); if (bundle.headers) { for (var field in bundle.headers){ try{ xmlhttp.setRequestHeader(field,bundle.headers[field]); }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); }else{ }}
};

// --------------------------------------------------------------------------------------------
// Ajout du lien "Renommer"

window.RenommageCategorie_AddLink = function(){
     if(typeof(RenommageCategorie_LangCustom)=="function") RenommageCategorie_LangCustom();
     if(typeof(RenommageCategorie_SiteCustom)=="function") RenommageCategorie_SiteCustom();
     if(typeof(RenommageCategorie_UserCustom)=="function") RenommageCategorie_UserCustom();
     var OngletMove = document.getElementById('ca-move');
     if(OngletMove){
          var movelink = OngletMove.getElementsByTagName('a')[0];
          if(movelink){
               movelink.href = "javascript:RenommageCategorie_OpenMenu();";
          }
     }
}

// --------------------------------------------------------------------------------------------
// Création du menu

window.RenommageCategorie_OpenMenu = function(){
    if(document.getElementById('RenommageCategorie_Menu')) return;

    var agt=navigator.userAgent.toLowerCase();
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    if(is_ie){
        var LargeurEcran = parseInt(screen.width);
        var HauteurEcran = parseInt(screen.height);
    }else{
        var LargeurEcran = parseInt(window.innerWidth);
        var HauteurEcran = parseInt(window.innerHeight);
    }

    var Menu = document.createElement('div');
    Menu.id='RenommageCategorie_Menu';
    Menu.className ='RenommageCategorie_Menu';
    Menu.style.position='fixed';
    Menu.style.zIndex= 500;
    Menu.style.padding='5px';
    Menu.style.backgroundColor='white';
    Menu.style.border='3px double black';
    Menu.style.width= '450px';
    document.body.appendChild(Menu);
    PositionGauche = parseInt((LargeurEcran-Menu.clientWidth)/2) ;
    PositionHaut = parseInt((HauteurEcran-Menu.clientHeight)/3) ;
    Menu.style.right=PositionGauche + 'px';
    Menu.style.top=PositionHaut + 'px';
    var StandardMoveLink = '<a href="' + mw.util.getUrl('Special:Movepage/' + mw.config.get('wgPageName')) + '">' + RenommageCategorie_Text_PopMoveOnlyCat + '</a> ';
    var MenuContent = ''
    + '<input type="text" id="RemoveCat" value="'+mw.config.get('wgTitle')+'" disabled="disabled" size="50"/>'
    + '<label for="RemoveCat">'+RenommageCategorie_Text_PopRemoveCat+'</label>'
    + '<br />'
    + '<input type="text" id="AddCat" value="'+mw.config.get('wgTitle')+'" size="50" />'
    + '<label for="AddCat">'+RenommageCategorie_Text_PopAddCat+'</label>'
    + '<br />'
    + '<input type="checkbox" id="Autoconfirm" style="cursor:pointer;" '+(RenommageCategorie_Autoconfirm ? 'checked="checked"' : '') +'/>'
    + '<label for="Autoconfirm">'+RenommageCategorie_Text_PopConfirm+'</label>'
    + '&nbsp;&nbsp;'
    + '<br />'
    + '<br />'
    + '<div style="text-align:left;">'
    + StandardMoveLink + '&nbsp;&nbsp;&nbsp;&nbsp;'
    + '<input type="button" style="cursor:pointer;" '
    + ' value="'+RenommageCategorie_Text_PopButtonOKText+'" title="'+RenommageCategorie_Text_PopButtonOKTitle+'" '
    + ' onclick="RenommageCategorie_CheckMenu();" onselect="RenommageCategorie_CheckMenu();"/>'
    + '&nbsp;&nbsp;'
    + '<input type="button" style="cursor:pointer;" '
    + ' value="'+RenommageCategorie_Text_PopButtonCancelText+'" title="'+RenommageCategorie_Text_PopButtonCancelTitle+'" '
    + ' onclick="RenommageCategorie_CloseMenu();" onselect="RenommageCategorie_CloseMenu();"/>'
    + '</div>';
    Menu.innerHTML = MenuContent;
    document.getElementById("AddCat").focus();
}

// --------------------------------------------------------------------------------------------
// Annulation du menu

window.RenommageCategorie_CloseMenu = function(){
    var Menu = document.getElementById('RenommageCategorie_Menu');
    if(Menu) RenommageCategorie_DeleteElement(Menu);
}

// --------------------------------------------------------------------------------------------
// Validation du menu

window.RenommageCategorie_CheckMenu = function(){
     var AddCat = document.getElementById('AddCat');
     var Autoconfirm = document.getElementById('Autoconfirm');
     if( !AddCat || !Autoconfirm ) return;

     RenommageCategorie_AddCat = RenommageCategorie_deleteUnwantedUnicodeChars(AddCat.value);
     if(RenommageCategorie_AddCat == RenommageCategorie_RemoveCat){
          alert(RenommageCategorie_Text_AlertSameCat);
          return;
     }
     if(Autoconfirm.checked) RenommageCategorie_Autoconfirm = true;
     else RenommageCategorie_Autoconfirm = false;
     RenommageCategorie_CloseMenu();
     RenommageCategorie_ListPages();
}

// --------------------------------------------------------------------------------------------
// Listage des pages de la catégorie cible

window.RenommageCategorie_ListPages = function(CatArray, category, categorycontinue){
     if(!CatArray) CatArray = new Array();
     if(!category) category = mw.config.get('wgPageName');
     if(!categorycontinue) categorycontinue = '';
     var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&list=categorymembers'
             + '&cmlimit=' + RenommageCategorie_APILimit
             + '&cmtitle=' + encodeURIComponent(category)
             + categorycontinue;

     RenommageCategorie_ajax.http({
          url: URL,
          cat: category,
          catlist: CatArray,
          onSuccess:RenommageCategorie_ListPagesDone
     });
}

window.RenommageCategorie_ListPagesDone = function(Req, data){
     var CatArray = data.catlist;
     var category = data.cat;
     var ElementTraitement = Req.responseXML;
     var Pages = ElementTraitement.getElementsByTagName('cm');
     for(a=0;a<Pages.length;a++){
          var TitrePage = Pages[a].getAttribute('title');
          if(CatArray.indexOf(TitrePage)==-1) CatArray.push(TitrePage);
     }
     var CatContinue = ElementTraitement.getElementsByTagName('query-continue')[0];
     if(CatContinue){
          var AutreRequeteContinue = '&cmcontinue=' + encodeURIComponent(CatContinue.firstChild.getAttribute("cmcontinue"));
          RenommageCategorie_ListPages(CatArray, category, AutreRequeteContinue);
     }else{
          RenommageCategorie_SortList(CatArray);
      }
}

// --------------------------------------------------------------------------------------------
// Triage des pages de la catégorie cible

window.RenommageCategorie_CatList = new Array();

window.RenommageCategorie_SortList = function(CatArray){
      while(RenommageCategorie_CatList[0]) RenommageCategorie_CatList.pop();
      var PagesTemp = CatArray.sort();
      for(var a=0;a<PagesTemp.length;a++){
           if(PagesTemp[a]!=PagesTemp[(a+1)]){
                 RenommageCategorie_CatList.push(PagesTemp[a]);
           }
      }
      var Length = RenommageCategorie_CatList.length;
      if(!RenommageCategorie_IsBot){
            if(Length<10) RenommageCategorie_TimeOut = (RenommageCategorie_TimeOut/2);
            if(Length>50){
                  RenommageCategorie_TimeOut = (RenommageCategorie_TimeOut*2);
                  var Text = ''
                           + RenommageCategorie_Text_GrosseModif.split('$1').join(Length)
                           + RenommageCategorie_Text_Delay.split('$1').join(RenommageCategorie_TimeOut)
                  var GrosseModif = confirm(Text);
                  if(!GrosseModif) window.location.reload();
            }else if(Length>0){
                  var Text = ''
                           + RenommageCategorie_Text_Modif.split('$1').join(Length)
                           + RenommageCategorie_Text_Delay.split('$1').join(RenommageCategorie_TimeOut)
                  var Modif = confirm(Text);
                  if(!Modif) window.location.reload();
            }
      }
      RenommageCategorie_ModifCat(0);
}

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

// --------------------------------------------------------------------------------------------
// Changement de catégorie dans une page

window.RenommageCategorie_ModifCat = function(position){
     var Page = RenommageCategorie_CatList[position];
     if(!Page){
          var CreateNewCat_SurEtCertain = false;
          if(RenommageCategorie_AddCat!='') CreateNewCat_SurEtCertain = confirm(RenommageCategorie_Text_ConfirmMoveS.split('$1').join(RenommageCategorie_RemoveCat).split('$2').join(RenommageCategorie_AddCat));
          if(!CreateNewCat_SurEtCertain){
               var urlOldCat = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title='
                             + mw.config.get('wgFormattedNamespaces')[14]+':'+encodeURIComponent(RenommageCategorie_RemoveCat);
               var DeleteOldCat_SurEtCertain = confirm(RenommageCategorie_Text_ConfirmDelete.split('$1').join(RenommageCategorie_RemoveCat));
               if(DeleteOldCat_SurEtCertain){
                    if(mw.config.get('wgUserGroups').indexOf('sysop')!=-1){
                         RenommageCategorie_ajax.http({
                              url: urlOldCat + '&action=delete',
                              onSuccess:RenommageCategorie_DeleteOldCat
                         });
                    }else{
                         RenommageCategorie_ajax.http({
                              url: urlOldCat + '&action=edit',
                              onSuccess:RenommageCategorie_DoDeletionRequest
                         });
                    }
               }else{
                    window.location.reload();
               }
          }else{
               RenommageCategorie_MoveCat();
          }
          return;
     }
     watchStatusQuery = {'format': 'json', 'action': 'query', 'prop': 'info', 'inprop': 'watched', 'titles': Page};
     $.getJSON(mw.util.wikiScript('api'), watchStatusQuery, function(obj) {
          var watchStatus = false;
          for (var pageid in obj.query.pages) {
               watchStatus = typeof obj.query.pages[pageid].watched != 'undefined';
               break;
          }
          var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(Page) + '&action=edit';
          RenommageCategorie_ajax.http({
               url: URL,
               watchStatus: watchStatus,
               pos: position,
               onSuccess:RenommageCategorie_ModifCatRunning
          });
     });
}

window.RenommageCategorie_ModifCatRunning = function(Req, data){
     var position = data.pos;
     while(document.body.firstChild){ RenommageCategorie_DeleteElement(document.body.firstChild);}
     document.body.innerHTML = Req.responseText;
     var TextArea = document.getElementById('wpTextbox1');
     if(!TextArea){
          var Problem = confirm( url + '\n\n' + RenommageCategorie_Text_AlertEditTryAgain );
          if(Problem){
               RenommageCategorie_ModifCat(position);
          }else{
               var NextPage = confirm(RenommageCategorie_Text_AlertEditNextPage);
               if(NextPage) RenommageCategorie_ModifCat((position+1));
          }
          return;
     }
     var OldText = TextArea.value;
     var Sommaire = '';
     if ( RenommageCategorie_RemoveCat != "" ) {
          OldText = RenommageCategorie_CleanCats(OldText);
          var OldCatRegExp = RenommageCategorie_CreateRegExp(RenommageCategorie_RemoveCat);
          var OldCatmatches = OldText.match(OldCatRegExp);
          var AddCatRegExp = RenommageCategorie_CreateRegExp(RenommageCategorie_AddCat);
          var NewCatmatches = OldText.match(AddCatRegExp);
          if (NewCatmatches == null && OldCatmatches != null && OldCatmatches.length == 1) { // Found one occurrence of the category - good!
               if(RenommageCategorie_AddCat != ""){
                    OldText = OldText.replace(OldCatRegExp, "$1[["+mw.config.get('wgFormattedNamespaces')[14]+":" + RenommageCategorie_AddCat + "$6]]");
                    Sommaire = RenommageCategorie_Text_ResumeEditModif.split('$1').join(mw.config.get('wgFormattedNamespaces')[14]+":"+RenommageCategorie_RemoveCat).split('$2').join(mw.config.get('wgFormattedNamespaces')[14]+":"+RenommageCategorie_AddCat);
               } else {
                    OldText = OldText.replace(OldCatRegExp, "");
                    Sommaire = RenommageCategorie_Text_ResumeEditDelete.split('$1').join(mw.config.get('wgFormattedNamespaces')[14]+":"+RenommageCategorie_RemoveCat);
               }
          } else {
               var Error;
               if(NewCatmatches!=null){
                    Error = RenommageCategorie_Text_AlertEditPb2.split('$1').join(RenommageCategorie_AddCat);
               }else if(OldCatmatches==null){
                    Error = RenommageCategorie_Text_AlertEditPb1.split('$1').join(RenommageCategorie_RemoveCat);
               }else if(OldCatmatches.length>1){
                    Error = RenommageCategorie_Text_AlertEditPb3.split('$1').join(RenommageCategorie_RemoveCat);
               }
               var Suivante = confirm(Error + "\n\n" + RenommageCategorie_Text_AlertEditNextPage);
               if(!Suivante){
                    window.location.reload();
               }else{
                    RenommageCategorie_ModifCat(position + 1);
               }
               return;
          }
     }
     var TexteFinal = OldText;
     var SommaireFinal = Sommaire ;
     document.getElementById('wpTextbox1').value = TexteFinal;
     document.getElementById('wpSummary').value = RenommageCategorie_Text_Script+SommaireFinal;
     var Minor = document.getElementById('wpMinoredit');
     if(Minor) Minor.checked = "checked";
     if(data.watchStatus) document.getElementById('wpWatchthis').checked = "checked";
     else document.getElementById('wpWatchthis').checked = "";
     if(!RenommageCategorie_Autoconfirm){
          var SurEtCertain = confirm(RenommageCategorie_Text_ConfirmEdit.split('$1').join(RenommageCategorie_RemoveCat).split('$2').join(RenommageCategorie_AddCat).split('$3').join(Sommaire));
          if(!SurEtCertain){
               var SurEtCertainBis = confirm(RenommageCategorie_Text_AlertEditNextPage);
               if(!SurEtCertainBis){
                    window.location.reload();
               }else{
                    RenommageCategorie_ModifCat((position+1));
               }
               return;
          }
     }
     var datas = {
          action    : 'edit',
          title     : RenommageCategorie_CatList[position],
          text      : TexteFinal,
          summary   : RenommageCategorie_Text_Script + SommaireFinal,
          minor     : 1,
          watchlist : "nochange",
          token     : document.editform.wpEditToken.value
     };
     var EditTag = RenommageCategorie_gettag();
     if(EditTag){
          datas.summary = SommaireFinal;
          datas.tags = EditTag;
     }
     var api = new mw.Api();
     api.post( datas, {'contentType':'application/x-www-form-urlencoded'} ).then( function ( data ) {
          if(RenommageCategorie_IsBot){
               RenommageCategorie_ModifCat((position+1));
          }else{
               while(document.body.firstChild){ RenommageCategorie_DeleteElement(document.body.firstChild);}
               var P = document.createElement('p');
               P.style.textAlign = "center";
               P.innerHTML = RenommageCategorie_Text_Delay.split("$1").join(RenommageCategorie_TimeOut);
               document.body.appendChild(P);
               setTimeout("RenommageCategorie_ModifCat("+(position+1)+")",RenommageCategorie_TimeOut*1000);
          }
     });
}

// --------------------------------------------------------------------------------------------
// Création d'une nouvelle catégorie par déplacement

window.RenommageCategorie_GoToNewCat = function() {
     window.location = mw.config.get('wgServer') + mw.util.getUrl(mw.config.get('wgFormattedNamespaces')[14] + ':' + RenommageCategorie_AddCat);
}


window.RenommageCategorie_MoveCat = function() {
     var api = new mw.Api();
     api.get({'action': 'query', 'meta': 'userinfo', 'uiprop': 'rights'}).done(function(data) {
          var userRights = data['query']['userinfo']['rights'];
          var canSuppressRedirect = $.inArray('suppressredirect', userRights) !== -1;
          moveParams = {
               'action': 'move',
               'from': mw.config.get('wgFormattedNamespaces')[14] + ':' + RenommageCategorie_RemoveCat,
               'to': mw.config.get('wgFormattedNamespaces')[14] + ':' + RenommageCategorie_AddCat,
               'reason': RenommageCategorie_Text_MoveReason,
               'watchlist': 'nochange',
               'movetalk': ''
          };
          if (canSuppressRedirect) {
               moveParams['noredirect'] = '';
          }
          api.postWithToken('edit', moveParams).done(function(data) {
               if (canSuppressRedirect) {
                    RenommageCategorie_GoToNewCat();
               } else {
                    RenommageCategorie_ajax.http({
                          url:mw.config.get('wgServer')+mw.config.get('wgScript')+'?title='
                              + mw.config.get('wgFormattedNamespaces')[14]+':'+encodeURIComponent(RenommageCategorie_RemoveCat)+'&action=edit',
                          onSuccess:RenommageCategorie_DoDeletionRequest
                    });
               }
          }).fail(function(data) {
               if (data === 'articleexists') {
                    alert(RenommageCategorie_Text_NewPageExists.replace('$1', moveParams['to']));
               } else {
                    alert(RenommageCategorie_Text_APIError.replace('$1', 'move').replace('$2', JSON.stringify(data)));
               }
          });
     }).fail(function(data) {
          alert(RenommageCategorie_Text_APIError.replace('$1', 'query/userinfo').replace('$2', JSON.stringify(data)));
     });
}

// --------------------------------------------------------------------------------------------
// Suppression de l'ancienne catégorie

window.RenommageCategorie_DeleteOldCat = function(Req, data){
      while(document.body.firstChild){ RenommageCategorie_DeleteElement(document.body.firstChild);}
      var ElementTraitement = document.createElement('div');
      document.body.appendChild(ElementTraitement);
      ElementTraitement.innerHTML = Req.responseText;
      var InputReason = document.getElementById('wpReason');
      if(RenommageCategorie_AddCat==''){
            InputReason.value = RenommageCategorie_Text_Script+RenommageCategorie_Text_ResumeDeleteBis;
      }else{
            InputReason.value = RenommageCategorie_Text_Script+RenommageCategorie_Text_ResumeDelete.split('$2').join(mw.config.get('wgFormattedNamespaces')[14]+":"+RenommageCategorie_AddCat);
      }
      var CheckWatch = document.getElementById('wpWatch');
      CheckWatch.checked = '';
      var DeleteForm = document.getElementById('deleteconfirm');
      if(RenommageCategorie_Autoconfirm){
            DeleteForm.submit();
      }else{
            var SurEtCertain = confirm(RenommageCategorie_Text_ConfirmDelete.split('$1').join(RenommageCategorie_RemoveCat));
            if(SurEtCertain) DeleteForm.submit();
      }
}

// --------------------------------------------------------------------------------------------
// Demande de suppression de l'ancienne catégorie

window.RenommageCategorie_DoDeletionRequest = function(Req, data){
      while(document.body.firstChild){ RenommageCategorie_DeleteElement(document.body.firstChild);}
      var ElementTraitement = document.createElement('div');
      document.body.appendChild(ElementTraitement);
      ElementTraitement.innerHTML = Req.responseText;
      var EditForm = document.getElementById('editform');
      EditForm.style.display = "none";
      var Reason = "";
      if(RenommageCategorie_AddCat==''){
            Reason = RenommageCategorie_Text_Script+RenommageCategorie_Text_ResumeDeleteBis;
      }else{
            Reason = RenommageCategorie_Text_Script+RenommageCategorie_Text_ResumeDelete.split('$2').join(":"+mw.config.get('wgFormattedNamespaces')[14]+":"+RenommageCategorie_AddCat);
      }
      var DeleteTemplate = RenommageCategorie_Text_DeleteTemplate;
      DeleteTemplate = DeleteTemplate.split("$1").join(Reason).split("$2").join("~"+"~~");
      document.getElementById('wpTextbox1').value = DeleteTemplate;
      document.getElementById('wpSummary').value = Reason;
      var Minor = document.getElementById('wpMinoredit');
      if(Minor) Minor.checked = "checked";
      EditForm.submit();
}

// --------------------------------------------------------------------------------------------
// FONCTION : Suppression d'un élément

window.RenommageCategorie_DeleteElement = function(OldElement){
    var agt=navigator.userAgent.toLowerCase();
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    if(is_ie){
        OldElement.removeNode(true);
    }else{
        if(OldElement.parentNode){document=OldElement.parentNode.removeChild(OldElement);}
    }
}

window.RenommageCategorie_CleanCats = function(OldText){
    var CatRegExp = new RegExp("\\[\\[(?:"+mw.config.get('wgFormattedNamespaces')[14]+"|Category):[^\\]]+\\]\\]", "ig");
    var CatNSRegExp = new RegExp("("+mw.config.get('wgFormattedNamespaces')[14]+"|Category) *: *", "ig");
    var Matches = OldText.match(CatRegExp);
    if(Matches==null) return OldText;
    for(var a=0,l=Matches.length;a<l;a++){
        var Newcat = Matches[a].replace(/_/g, " ");
        var catNSmatch = Newcat.match(CatNSRegExp);
        if(catNSmatch!=null){
            for(var b=0,m=catNSmatch.length;b<m;b++){
                Newcat = Newcat.replace(catNSmatch[b], mw.config.get('wgFormattedNamespaces')[14]+":");
            }
        }
        var Index = Newcat.indexOf(mw.config.get('wgFormattedNamespaces')[14]);
        if(Index!=-1){
            Index = (Index + mw.config.get('wgFormattedNamespaces')[14].length + 1);
            var StartCat = Newcat.substring(0, Index);
            var EndCat = Newcat.substring(Index, Newcat.length);
            EndCat = ( RenommageCategorie_CaseSensitive ? EndCat : EndCat.ucFirst() );
            Newcat = StartCat + EndCat;
        }
        OldText = OldText.replace(Matches[a], Newcat);
    }
    return OldText;
}

// FONCTION : création RegExp

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

// FONCTION : première lettre en majuscule

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

// FONCTION : première lettre en minuscule

String.prototype.lcFirst = function () {
    return this.substr(0,1).toLowerCase() + this.substr(1,this.length);
}
 
// Retrait de caractères unicode indésirables
 
window.RenommageCategorie_deleteUnwantedUnicodeChars = function(Text){
  return Text.replace(/\u200E|\u200F|\u202A|\u202B|\u202C|\u202D|\u202E/g, '');
}


// --------------------------------------------------------------------------------------------
// Lancement

if(mw.config.get('wgNamespaceNumber')==14 && mw.config.get('wgUserGroups') && mw.config.get('wgUserGroups').indexOf("autoconfirmed")!=-1){
    mw.loader.implement( "RenommageCategorieLangs", ['//pnb.wikipedia.org/w/index.php?title=Mediawiki:Gadget-RenommageCategorieLang.js&action=raw&ctype=text/javascript'], {}, {}, {} );
    mw.loader.using("RenommageCategorieLangs", function(){ $(RenommageCategorie_AddLink); });
}

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