//<source lang=javascript>//<pre><nowiki>
var dfnBot_ResultsPage = "Utilisateur:Dr Brains/dfnBot.js/Test";
var dfnBot_Template = "Terme défini";
var dfnBot_Resume = "Ajout modèle ]";
var dfnBot_ajax = {
http: function(bundle) {
// mandatory: bundle.url
// optional: bundle.async
// optional: bundle.method
// optional: bundle.headers
// optional: bundle.data
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
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)
dfnBot_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);
} 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 {
// A activer en debug mode ?
// alert(xmlhttp.status+xmlhttp.responseText);
}
}
};
function dfnBot_GetPage(Params){
dfnBot_ajax.http({ url : Params.url,
onSuccess : Params.NextFunc,
allParams : Params
});
}
function dfnBot_SavePage(Params){
if(!confirm("OK ?")) return;
var Form = document.getElementById('editform');
var action = Form.action;
var headers = new Array();
headers = 'application/x-www-form-urlencoded';
dfnBot_ajax.http({ url: action,
method : "POST",
headers : headers,
data : dfnBot_createURLFromParams(dfnBot_getFormParams(Form)),
onSuccess : (Params && Params.NextFunc ? Params.NextFunc : function(){ window.location.reload(); } ),
allParams : (Params ? Params : null)
});
}
function dfnBot_getFormParams(Form){
var Params = new Array();
var Tags = new Array("textarea", "select", "input");
for(var a=0,l=Tags.length;a<l;a++){
var Elements = Form.getElementsByTagName(Tags);
for(var b=0,m=Elements.length;b<m;b++){
var Element = Elements;
var ElName = Element.name;
var ElValue = Element.value;
var ElType = Element.type;
if(Tags.toLowerCase()=='input' && (ElType == "checkbox" || ElType == "radio") && Element.checked){
Params = ElValue;
}else if(Tags.toLowerCase()=='input' && (ElType == "text" || ElType == "hidden") ){
Params = ElValue;
}else if(Tags.toLowerCase()!='input'){
Params = ElValue;
}
}
}
return Params;
}
function dfnBot_createURLFromParams(Params){
var ParamsInURL = new Array();
for(var P in Params){
if(typeof(Params)=="string") ParamsInURL.push(P+"="+encodeURIComponent(Params));
}
return ParamsInURL.join('&');
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ===============================================================================================================
if(mw.config.get('wgNamespaceNumber')==0 || mw.config.get('wgNamespaceNumber')==2){
addOnloadHook(dfnBot_GetHomon);
addOnloadHook(dfnBot_AddLink);
}
// ===============================================================================================================
var dfnBot_HomonArray = new Array();
function dfnBot_GetHomon(more){
var APILimit = ( (mw.config.get('wgUserGroups').indexOf("sysop")!=-1 || mw.config.get('wgUserGroups').indexOf("bot")!=-1) ? 4999 : 499 );
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&prop=links'
+ '&pllimit=' + APILimit
+ '&plnamespace=10'
+ '&titles=' + encodeURIComponent("MediaWiki:Disambiguationspage")
+ ( more ? '&plcontinue=' + encodeURIComponent(more) : '' );
dfnBot_GetPage({ url : URL,
NextFunc : dfnBot_GetHomonDone,
});
}
function dfnBot_GetHomonDone(Req, data){
var ObjectXML = Req.responseXML;
var PL = ObjectXML.getElementsByTagName('pl');
for(var a=0,l=PL.length;a<l;a++){
var Title = PL.getAttribute('title');
if(dfnBot_HomonArray.indexOf(Title)==-1) dfnBot_HomonArray.push(Title);
}
var QContinue = ObjectXML.getElementsByTagName('query-continue');
if(QContinue){
var ContinueData = QContinue.firstChild.getAttribute('plcontinue');
dfnBot_GetHomon(ContinueData);
}
}
// ===============================================================================================================
function dfnBot_AddLink(){
var OngletsCactions = document.getElementById('p-cactions');
if(OngletsCactions){
var CactionsUl = OngletsCactions.getElementsByTagName('ul');
CactionsUl.innerHTML += '<li><a href="javascript:dfnBot_CreateMenu();">dfn (bot)</a></li>';
$(OngletsCactions).removeClass("emptyPortlet");
}
}
// ===============================================================================================================
function dfnBot_CreateMenu(){
if(document.getElementById('dfnBot_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='dfnBot_Menu';
Menu.className ='dfnBot_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= '550px';
// Menu.style.height= '250px';
document.body.appendChild(Menu);
PositionGauche = parseInt((LargeurEcran-Menu.clientWidth)/2) ;
PositionHaut = parseInt((HauteurEcran-Menu.clientHeight)/3) ;
Menu.style.left=PositionGauche + 'px';
Menu.style.top=PositionHaut + 'px';
var MenuContent = ''
+ '<form>'
+ '<table width="100%" style="background:none;"><tr><td width="50%" valign="top">'
+ '<input type="text" id="StartListing" value="'+mw.config.get('wgTitle')+'" size="30"/>'
+ '<br />'
+ '<center><label for="StartListing">'+dfnBot_Text_PopStartListing+'</label></center>'
+ '</td><td>'
+ '<input type="radio" name="Mode" id="EndListingEnable" value="1" checked="checked" style="cursor:pointer;" onclick="dfnBot_Click(this)" />'
+ '<input type="text" id="EndListing" value="'+mw.config.get('wgTitle')+'" size="30" />'
+ '<br />'
+ '<center><label for="EndListing">'+dfnBot_Text_PopEndListing+'</label></center>'
+ '<br />'
+ '<input type="radio" name="Mode" id="MaxListingEnable" value="1" style="cursor:pointer;" onclick="dfnBot_Click(this)" />'
+ '<input type="text" id="MaxListing" value="100" size="30" />'
+ '<br />'
+ '<center><label for="MaxListing">'+dfnBot_Text_PopMaxListing+'</label></center>'
+ '<br />'
+ '<input type="radio" name="Mode" id="OnePageEnable" value="1" style="cursor:pointer;" onclick="dfnBot_Click(this)" />'
+ '<input type="text" id="OnePageListing" value="'+mw.config.get('wgTitle')+'" size="30" />'
+ '<br />'
+ '<center><label for="OnePageListing">'+dfnBot_Text_OnePageListing+'</label></center>'
+ '</td></tr></table>'
+ '<br />'
+ '<hr />'
+ '<br />'
+ '<center>'
+ '<input type="checkbox" id="Autoconfirm" style="cursor:pointer;" />'
+ '<label for="Autoconfirm">'+dfnBot_Text_PopConfirm+'</label>'
+ ' '
+ '<input type="checkbox" id="AutoWatch" style="cursor:pointer;" />'
+ '<label for="AutoWatch">'+dfnBot_Text_PopWatch+'</label>'
+ '</center>'
+ '<br />'
+ '<hr />'
+ '<br />'
+ '<center>'
+ '<input type="button" style="cursor:pointer;" '
+ ' value="'+dfnBot_Text_PopButtonOKText+'" title="'+dfnBot_Text_PopButtonOKTitle+'" '
+ ' onclick="dfnBot_Run();" onselect="dfnBot_Run();"/>'
+ ' '
+ '<input type="button" style="cursor:pointer;" '
+ ' value="'+dfnBot_Text_PopButtonCancelText+'" title="'+dfnBot_Text_PopButtonCancelTitle+'" '
+ ' onclick="dfnBot_CloseMenu();" onselect="dfnBot_CloseMenu();"/>'
+ '</center>'
+ '</form>'
Menu.innerHTML = MenuContent;
dfnBot_Click();
document.getElementById("StartListing").focus();
}
var dfnBot_Text_PopStartListing = "Début de listing";
var dfnBot_Text_PopEndListing = "Fin de listing";
var dfnBot_Text_PopMaxListing = "Max listing";
var dfnBot_Text_OnePageListing = "Une seule page";
var dfnBot_Text_PopConfirm = "Confirmer automatiquement";
var dfnBot_Text_PopWatch = "Suivre les pages modifiées";
var dfnBot_Text_PopButtonOKText = "OK";
var dfnBot_Text_PopButtonOKTitle = "Lancer le bot";
var dfnBot_Text_PopButtonCancelText = "Annuler";
var dfnBot_Text_PopButtonCancelTitle = "Fermer le menu";
function dfnBot_Click(Radio){
var Menu = document.getElementById('dfnBot_Menu');
if(!Menu) return;
var Radios = new Array();
var Inputs = Menu.getElementsByTagName('input');
for(var a=0,l=Inputs.length;a<l;a++){
if(Inputs.type && Inputs.type == "radio"){
Radios.push(Inputs);
}
}
if(!Radio) Radio = Radios;
for(var a=0,l=Radios.length;a<l;a++){
if(Radios != Radio){
Radios.nextSibling.disabled = "disabled";
}else{
Radios.nextSibling.disabled = false;
}
}
Radio.nextSibling.focus();
}
function dfnBot_CloseMenu(){
var Menu = document.getElementById('dfnBot_Menu');
if(Menu) Menu.parentNode.removeChild(Menu);
}
function dfnBot_Run(){
var Menu = document.getElementById('dfnBot_Menu');
if(!Menu) return;
var StartListingInput = document.getElementById('StartListing');
var EndListingInput = document.getElementById('EndListing');
var MaxListingInput = document.getElementById('MaxListing');
var OnePageListingInput = document.getElementById('OnePageListing');
if(!StartListingInput || !EndListingInput || !MaxListingInput || !OnePageListingInput) return;
var StartListing = StartListingInput.value;
var EndListing = EndListingInput.value;
var MaxListing = MaxListingInput.value;
var OnePage = OnePageListingInput.value;
if(!EndListingInput.disabled == "disabled") EndListing = false;
if(!MaxListingInput.disabled == "disabled") MaxListing = false;
if(!OnePageListingInput.disabled == "disabled") OnePage = false;
if((!EndListing && !MaxListing) || (StartListing == EndListing)){
var Page = OnePage;
if(!Page) Page = StartListing;
if(!Page) Page = mw.config.get('wgTitle');
dfnBot_AllPagesList.Title.push(Page);
dfnBot_AskThisPage(0);
}else{
dfnBot_ListPages(StartListing, EndListing, MaxListing);
}
dfnBot_CloseMenu();
}
// ===============================================================================================================
var dfnBot_AllPagesList = new Array();
dfnBot_AllPagesList.Title = new Array();
dfnBot_AllPagesList.Statut = new Array();
dfnBot_AllPagesList.TextBefore = new Array();
dfnBot_AllPagesList.TextAfter = new Array();
function dfnBot_ListPages(StartListing, EndListing, MaxListing){
var APILimit = ( (mw.config.get('wgUserGroups').indexOf("sysop")!=-1 || mw.config.get('wgUserGroups').indexOf("bot")!=-1) ? 4999 : 499 );
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath')
+ '/api.php?format=xml&action=query&list=allpages'
+ '&apfilterredir=nonredirects&aplimit=' + APILimit
+ '&apfrom=' + encodeURIComponent(StartListing)
+ (MaxListing ? '' : '&apto=' + encodeURIComponent(EndListing));
dfnBot_GetPage({ url : URL,
NextFunc : dfnBot_ListPagesDone,
Start : StartListing,
End : EndListing,
Max : MaxListing
});
}
function dfnBot_ListPagesDone(Req, data){
var EndListing = data.allParams.End;
var MaxListing = data.allParams.Max;
var ObjectXML = Req.responseXML;
var AP = ObjectXML.getElementsByTagName('p');
for(var a=0,l=AP.length;a<l;a++){
var Title = AP.getAttribute('title');
if(
(EndListing && Title.match(new RegExp("^"+EndListing))!=null)
||
(MaxListing && dfnBot_AllPagesList.Title.length==parseInt(MaxListing))
){
if(!confirm(dfnBot_AllPagesList.Title.length+" pages à modifier\n\nContinuer?")) return dfnBot_Abort();
dfnBot_AskThisPage(0);
return;
}
if(dfnBot_AllPagesList.Title.indexOf(Title)==-1) dfnBot_AllPagesList.Title.push(Title);
}
var QContinue = ObjectXML.getElementsByTagName('query-continue');
if(QContinue){
var ContinueData = QContinue.firstChild.getAttribute('apfrom');
dfnBot_ListPages(ContinueData, EndListing);
}else{
if(!confirm(dfnBot_AllPagesList.Title.length+" pages à modifier\n\nContinuer?")) return dfnBot_Abort();
dfnBot_AskThisPage(0);
}
}
function dfnBot_Abort(){
for(var Arr in dfnBot_AllPagesList){
while(dfnBot_AllPagesList.length>0) dfnBot_AllPagesList.pop();
}
return false;
}
// ===============================================================================================================
function dfnBot_AskThisPage(position){
var Page = dfnBot_AllPagesList.Title;
if(!Page){
dfnBot_GetAllResults();
return;
}
if(Page.match(new RegExp("^(Liste |Glossaire )"))!=null){
dfnBot_AllPagesList.Statut = "Liste";
dfnBot_AskThisPage((position+1));
return;
}
dfnBot_IsHomon(position);
}
function dfnBot_IsHomon(position, more){
var APILimit = ( (mw.config.get('wgUserGroups').indexOf("sysop")!=-1 || mw.config.get('wgUserGroups').indexOf("bot")!=-1) ? 4999 : 499 );
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&prop=templates&tllimit='+APILimit
+ '&titles=' + encodeURIComponent(dfnBot_AllPagesList.Title)
+ (more ? '&tlcontinue=' + encodeURIComponent(more) : '');
dfnBot_GetPage({ url : URL,
NextFunc : dfnBot_IsHomonDone,
Pos : position
});
}
function dfnBot_IsHomonDone(Req, data){
var position = data.allParams.Pos;
var ObjectXML = Req.responseXML;
var TL = ObjectXML.getElementsByTagName('tl');
for(var a=0,l=TL.length;a<l;a++){
var Title = TL.getAttribute('title');
if(dfnBot_HomonArray.indexOf(Title)!=-1){
dfnBot_AllPagesList.Statut = "Homonymie";
dfnBot_AskThisPage((position+1));
return;
}
}
var QContinue = ObjectXML.getElementsByTagName('query-continue');
if(QContinue){
var ContinueData = QContinue.firstChild.getAttribute('tlcontinue');
dfnBot_IsHomon(position, ContinueData);
}else{
dfnBot_doReplace(position);
}
}
// ===============================================================================================================
function dfnBot_doReplace(position){
dfnBot_GetPage({ url : mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(dfnBot_AllPagesList.Title) + "&action=edit§ion=0",
NextFunc : dfnBot_Putdfn,
Pos : position
});
}
function dfnBot_Putdfn(Req, data){
var position = data.allParams.Pos;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = Req.responseText;
var ContenuPage = document.getElementById("wpTextbox1").value;
var AncienResumeModif = document.editform.wpSummary.value;
// -------------------------------------------------------- Extraction des modèles et des tableaux
var AncienTexte = dfnBot_HideWhiteTemplates(ContenuPage, false);
var TexteDecoupe = dfnBot_Split(AncienTexte, new Array("{{", "}}", "{|", "|}"));
var NiveauImbricationModele = new Array();
var Niveau = 0;
for(var a=0,l=TexteDecoupe.length;a<l;a++){
var CeBout = dfnBot_HideWhiteTemplates(TexteDecoupe, true);
TexteDecoupe = CeBout;
if(CeBout === "{{" || CeBout === "{|"){
Niveau++
NiveauImbricationModele = Niveau;
}else if(CeBout === "}}" || CeBout === "|}"){
NiveauImbricationModele = Niveau;
Niveau--
}else{
NiveauImbricationModele = Niveau;
}
}
// -------------------------------------------------------------------- Ajout dfn
var Replaced = false;
dfnBot_AllPagesList.Statut = "'''{{Rouge|Remplacement non effectué}}'''";
var CauseNonRemplacement = {
"NoFoundText" : { texte : " pas trouvé de texte" , statut : true },
"NoFoundBold" : { texte : " pas trouvé de gras" , statut : true },
"NotSimilar" : { texte : " similitude trop faible (0%)" , statut : true }
};
for(var a=0,l=TexteDecoupe.length;a<l;a++){
var ThisTexte = TexteDecoupe;
// -------------------------------------------------------- Recherche d'un dfn déjà présent via le modèle
if(NiveauImbricationModele>0){
if(ThisTexte.match(new RegExp("^" + dfnBot_Template+"\\|", "ig"))!=null){
dfnBot_AllPagesList.Statut = "{{Green|'''dfn déjà présent'''}}";
dfnBot_AskThisPage((position+1));
return;
}
}
if(NiveauImbricationModele>0 || Replaced===true) continue;
if(ThisTexte!="" && ThisTexte!="\n") FoundText = true;
// -------------------------------------------------------- Recherche d'un dfn déjà présent en dur
if(ThisTexte.indexOf("<dfn>")!=-1){
TexteDecoupe = ThisTexte.replace(/<dfn*>/g, "{{"+dfnBot_Template+"|").split("</dfn>").join('}}');
dfnBot_AllPagesList.Statut = "{{Green|'''Trouvé dfn en dur'''}}";
Replaced = true;
continue;
}
// -------------------------------------------------------- Recherche du titre exact en gras
var Title = dfnBot_AllPagesList.Title.replace(/ \(.*\)/, "");
var TitleReg = new RegExp("'''*"+Title+"*'''", "ig");
var MatchTitleBold = ThisTexte.match(TitleReg);
if(MatchTitleBold!=null){
TexteDecoupe = ThisTexte.replace(MatchTitleBold, "{{"+dfnBot_Template+"|" + MatchTitleBold.replace(/'''/g, "") + "}}");
dfnBot_AllPagesList.Statut = "{{Green|'''Trouvé titre exact en gras'''}}";
Replaced = true;
continue;
}
// -------------------------------------------------------- Recherche du premier texte en gras et remplacement
var BeforeText = "";
var InsideText = "";
var AfterText = "";
while(ThisTexte!=""){
if(ThisTexte.match(/+/)!=null) CauseNonRemplacement.NoFoundText.statut = false;
var BoldStartIndex = ThisTexte.indexOf("'''");
var BoldStartDoubleIndex = ThisTexte.indexOf("''''''");
if(BoldStartIndex != -1){
var Length = 0;
if(BoldStartDoubleIndex!=-1 && BoldStartDoubleIndex==BoldStartIndex) Length = 3;
BeforeText = ThisTexte.substring(0, (BoldStartIndex+Length));
ThisTexte = ThisTexte.substring( (BoldStartIndex+(3+Length)), ThisTexte.length);
var BoldEndIndex = ThisTexte.indexOf("'''");
if(BoldEndIndex != -1){
InsideText = ThisTexte.substring(0, BoldEndIndex);
AfterText = ThisTexte.substring( (BoldEndIndex+3), ThisTexte.length);
ThisTexte = "";
if(InsideText!=""){
CauseNonRemplacement.NoFoundBold.statut = false;
var InsideWords = InsideText
while(InsideWords.match(/^'/)!=null) InsideWords = InsideWords.replace(/^'/g, "");
var Compare = dfnBot_CompareTexts(InsideWords, Title);
if(Compare>74){
CauseNonRemplacement.NotSimilar.statut = false;
InsideText = "{{"+dfnBot_Template+"|" + InsideText + "}}";
var Reg = new RegExp("\\{\\{"+dfnBot_Template+"\\|'");
while(InsideText.match(Reg)!=null){
InsideText = InsideText.replace(Reg, "'{{"+dfnBot_Template+"|");
}
TexteDecoupe = BeforeText + InsideText + AfterText;
dfnBot_AllPagesList.Statut = "{{Orange|'''Trouvé terme en gras'''}} : Similitude = "+Compare+"%";
Replaced = true;
}else{
CauseNonRemplacement.NotSimilar.texte = CauseNonRemplacement.NotSimilar.texte.replace(//g, Compare);
}
}
}else{
break;
}
}else{
break
}
}
}
if(Replaced==false){
var GetCause = false;
for(var Cause in CauseNonRemplacement){
if(GetCause) continue;
if(CauseNonRemplacement.statut == true){
dfnBot_AllPagesList.Statut += CauseNonRemplacement.texte;
GetCause = true;
}
}
}
// -------------------------------------------------------- Création résultat
var TexteFinal = TexteDecoupe.join("");
document.getElementById ("wpTextbox1").value = TexteFinal ;
document.editform.wpSummary.value = AncienResumeModif + dfnBot_Resume ;
// -------------------------------------------------------- Sauvegarde
dfnBot_AllPagesList.TextBefore = ContenuPage;
dfnBot_AllPagesList.TextAfter = TexteFinal;
document.editform.wpMinoredit.checked = "checked";
document.editform.wpWatchthis.checked = "checked";
dfnBot_AskThisPage((position+1));
}
var dfnBot_TemplateWhiteList = new Array();
dfnBot_TemplateWhiteList.push("e");
dfnBot_TemplateWhiteList.push("er");
dfnBot_TemplateWhiteList.push("s");
function dfnBot_HideWhiteTemplates(Texte, reverse){
return Texte; // à commenter lorsque plus abouti
for(var a=0,l=dfnBot_TemplateWhiteList.length;a<l;a++){
var Reg = new RegExp((reverse ? "DEBUTMODELE"+dfnBot_TemplateWhiteList+"*FINMODELE" : "\\{\\{"+dfnBot_TemplateWhiteList+"*\\}\\}"), "ig");
var Matches = Texte.match(Reg);
if(Matches!=null){
for(var m=0,match=Matches.length;a<l;a++){
var SafeTemplate = (reverse ? Matches.replace(/DEBUTMODELE/g, "{{").replace(/FINMODELE/g, "}}") : Matches.replace(/\{\{/g, "DEBUTMODELE").replace(/\}\}/g, "FINMODELE"));
Texte = Texte.replace(Matches, SafeTemplate);
}
}
}
return Texte;
}
function dfnBot_Split(AncienTexte, Items){
var TexteDecoupe = new Array();
for( var a=0,l=Items.length;a<l;a++){
Items = Items.replace(/\|/g, "\\|").replace(/\{/g, "\\{").replace(/\}/g, "\\}");
}
var ItemRegExp = new RegExp("("+Items.join("|")+")", "g");
var Matches = AncienTexte.match(ItemRegExp);
if(Matches != null){
for(var a=0,l=Matches.length;a<l;a++){
var Index = AncienTexte.indexOf(Matches);
var Size = Matches.length;
TexteDecoupe.push(AncienTexte.substring(0, Index));
TexteDecoupe.push(AncienTexte.substring(Index, (Index+Size)));
AncienTexte = AncienTexte.substring((Index+Size), AncienTexte.length);
}
}
if(AncienTexte!=""){
TexteDecoupe.push(AncienTexte);
AncienTexte = "";
}
return TexteDecoupe;
}
function dfnBot_CompareTexts(TextWords, TitleWords){
var Array1 = dfnBot_CleanTexts(TextWords).Texte;
var Array2 = dfnBot_CleanTexts(TitleWords).Texte;
var TextLength = dfnBot_CleanTexts(TextWords).Length;
var TitleLength = dfnBot_CleanTexts(TitleWords).Length;
var SameWords = 0;
for(var a in Array1){
TitleLength = 0;
for(var b in Array2){
TitleLength++
if(a == b) SameWords++
}
}
var Result = parseInt((SameWords/((TextLength + TitleLength)/2))*100);
return Result;
}
function dfnBot_CleanTexts(Texte){
Texte = Texte.toLowerCase();
Texte = Texte.replace(/\]*\|/g, "");
Texte = Texte.replace(/\]/g, "");
Texte = Texte.replace(/,/g, "");
Texte = Texte.replace(/''/g, "");
Texte = Texte.replace(/(-|_)/g, " ");
Texte = Texte.replace(/’/g, "'");
Texte = Texte.replace(/(à|á|â|ä|ã|ā)/g, "a");
Texte = Texte.replace(/(ć|ĉ|ç|č)/g, "c");
Texte = Texte.replace(/(é|è|ê|ë|ē|ĕ)/g, "e");
Texte = Texte.replace(/(ĝ|ğ)/g, "g");
Texte = Texte.replace(/(ĥ)/g, "h");
Texte = Texte.replace(/(í|ì|î|ï|ī)/g, "i");
Texte = Texte.replace(/(ĵ)/g, "j");
Texte = Texte.replace(/(ñ)/g, "n");
Texte = Texte.replace(/(ó|ò|ô|ö|õ|ő|ō|ŏ)/g, "o");
Texte = Texte.replace(/(ŝ|š)/g, "s");
Texte = Texte.replace(/(ú|ù|û|ü|ŭ|ű|ū|ŭ)/g, "u");
Texte = Texte.replace(/(ý|ÿ|ȳ|y̆)/g, "y");
Texte = Texte.replace(/æ/g, "ae");
Texte = Texte.replace(/œ/g, "oe");
Texte = Texte.split(" ");
var ArrayTexte = new Array();
ArrayTexte.Length = Texte.length;
ArrayTexte.Texte = new Array();
for(var a=0,l=Texte.length;a<l;a++){
ArrayTexte.Texte] = true;
}
return ArrayTexte;
}
// ===============================================================================================================
function dfnBot_GetAllResults(){
var Template = "=== ] ===\n"
+ "* Statut : $2\n"
+ "; Texte avant\n"
+ "$3"
+ "$4"
+ "\n";
var Results = "";
var Resume = "";
for(var a=0,l=dfnBot_AllPagesList.Title.length;a<l;a++){
var Title = dfnBot_AllPagesList.Title;
var Statut = (dfnBot_AllPagesList.Statut ? dfnBot_AllPagesList.Statut : "OK");
var TexteAvant = dfnBot_AllPagesList.TextBefore;
var TexteApres = dfnBot_AllPagesList.TextAfter;
Resume += "<li> ] : "+Statut+"</li>\n"
if(a<100){
var ThisSection = Template;
ThisSection = ThisSection.split('$1').join(Title);
ThisSection = ThisSection.split('$2').join(Statut);
ThisSection = ThisSection.split('$3').join((TexteAvant ? "; Texte avant\n<pre>" + TexteAvant + "</pre>\n" : ""));
ThisSection = ThisSection.split('$4').join((TexteApres ? "; Texte après\n<pre>" + TexteApres + "</pre>\n" : ""));
Results += ThisSection;
}else{
Results = "";
}
}
Results = "== Bilan ==\n\n{{colonnes2|nombre=2|1=\n" + Resume + "}}\n\n== Détails ==\n\n" + Results;
dfnBot_GetPage({ url : mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(dfnBot_ResultsPage) + "&action=edit",
NextFunc : dfnBot_SaveAllResults,
Res : Results
});
}
function dfnBot_SaveAllResults(Req, data){
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = Req.responseText;
document.getElementById("wpTextbox1").value = data.allParams.Res;
document.editform.wpSummary.value = "Test";
document.editform.wpMinoredit.checked = "checked";
document.editform.wpWatchthis.checked = "checked";
dfnBot_SavePage();
}
//</nowiki></pre></source>