Aller au contenu

Utilisateur:Pixeltoo/orphantabs.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
mw.loader.using('mediawiki.util', function () {

/*
===================================================================================================
Go to [[User:Manishearth/OrphanTabs]] to see how this script is used.
[[User:Manishearth]]
===================================================================================================
 
*/
 

//Support for config template
var undefined; //to check for undefined config template
var OrphanTabsConfig
if(OrphanTabsConfig === undefined){
OrphanTabsConfig = {
auto 			:	true,
autoChoice 		:	3,
showCompleteTab	:	true,
completeTabText	:	"adopter",
wikifyTabText		:	"Wikify",
showWikifyTab :  true,
showWLHTab		:	true,
wLHTabText		:	"WhatLinksHere",
showSearchItTab	:	false,
searchItTabText	:	"Search It!",
showGoogleItTab	:	true,
googleItTabText	:	"Google It!"
}
}else{
if(OrphanTabsConfig.auto === undefined){
OrphanTabsConfig.auto = new Boolean(true)
}
if(OrphanTabsConfig.autoChoice === undefined){
OrphanTabsConfig.autoChoice = new Number(2)
}
if(OrphanTabsConfig.showCompleteTab === undefined){
OrphanTabsConfig.showCompleteTab = new Boolean(true)
}
if(OrphanTabsConfig.completeTabText === undefined){
OrphanTabsConfig.completeTabText = new String("de-orphan")
}
if(OrphanTabsConfig.showWikifyTab === undefined){
OrphanTabsConfig.showCompleteTab = new Boolean(true)
}
if(OrphanTabsConfig.wikifyTabText === undefined){
OrphanTabsConfig.completeTabText = new String("de-orphan-wikify")
}
if(OrphanTabsConfig.showWLHTab === undefined){
OrphanTabsConfig.showCompleteTab = new Boolean(false)
}
if(OrphanTabsConfig.wLHTabText === undefined){
OrphanTabsConfig.completeTabText = new String("WhatLinksHere")
}
if(OrphanTabsConfig.showSearchItTab === undefined){
OrphanTabsConfig.showCompleteTab = new Boolean(false)
}
if(OrphanTabsConfig.searchItTabText === undefined){
OrphanTabsConfig.completeTabText = new String("Search It!")
}
if(OrphanTabsConfig.showGoogleItTab === undefined){
OrphanTabsConfig.showCompleteTab = new Boolean(false)
}
if(OrphanTabsConfig.googleItTabText === undefined){
OrphanTabsConfig.completeTabText = new String("Google It!")
}
}
var currentLinkWin
var otherOrphanTabs = true
var deOrphanDocumentLinkArray = new Array()
var linkACounter=0
var howManyActuallyDeOrphaned = 0
var linkAlreadyThere = 0
var deOrphaning = false
var deOrphanPgName = ""
var deOrphanProcessFirstCall=false
$(function () {
var gServerPre;
var gServerPost;
gServerPre = "http://www.google.com/search?hl=fr&rlz=1G1GGLQ_ENUS255&as_q="
gServerPost="&as_epq=&as_oq=&as_eq=&num=100&lr=&as_filetype=&ft=i&as_sitesearch=" + mw.config.get('wgServer') + "&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images"
var pgname = encodeURIComponent( mw.config.get('wgTitle') );
 
if(otherOrphanTabs){
if(OrphanTabsConfig.showWLHTab){
mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + "/wiki/Special:WhatLinksHere/" + pgname, OrphanTabsConfig.wLHTabText, "ca-whatlinks" , "What links here");
}
if(OrphanTabsConfig.showSearchItTab){
mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + "/wiki/Special:WhatLinksHere/" + pgname, OrphanTabsConfig.searchItTabText, "ca-searchit" , "What links here");
}
if(OrphanTabsConfig.showGoogleItTab){
mw.util.addPortletLink("p-cactions", gServerPre + pgname + gServerPost, OrphanTabsConfig.googleItTabText, "ca-googleit", "Find all Wikipedia pages with this page name in them"); 
}
}
if (document.editform && OrphanTabsConfig.showWikify){
mw.util.addPortletLink("p-cactions","javascript:deOrphanWikify(prompt(\"What page are you de-orphaning?\",\"\"))", OrphanTabsConfig.wikifyTabText, "ca-de-orphan-wikify", "Wikify to deorphan another page"); 
}
if(OrphanTabsConfig.showCompleteTab){
mw.util.addPortletLink("p-cactions", "javascript:initDeOrphan(prompt(\"What page\?\"\,\""+ ((mw.config.get('wgCanonicalNamespace')=="")?mw.config.get('wgPageName'):"")+"\"));", OrphanTabsConfig.completeTabText, "ca-de-orphan", "Find all Wikipedia pages with this page name in them");} 
 
});
var intID;
var sWin;
var allLinks = new Array()
function deOrphanWikify(pgName){
if (!document.editform){
alert("Only available on the edit page \(currently\)")
}else{
 
document.editform.wpTextbox1.value = orphanRawWikify(pgName,document.editform.wpTextbox1.value)
document.editform.wpSummary.value = "Ajout d'un lien à [[" + pgName+ "|article]], projet pages orphelines: [[WP:ORPH|Vous pouvez nous aidez !]]"
}  
}
function orphanRawWikify(pgName,text){
rXP = new RegExp("([ '\"()<>,.])(" + pgName + ")([ '\"()<>,.])", "gi")
var t = text.replace(rXP, "$1[[" + pgName + " |$2]]$3")
return t;
}
function initDeOrphan(pgName){
sWin = window.open(mw.config.get('wgServer') + "/w/index.php?title=Special:Search&ns0=1&redirs=1&search=%22" + pgName + "%22&limit=100&offset=0","","")
 
deOrphanPgName = pgName
deOrphanProcessFirstCall=true
intID = setInterval('checkWin()', 3000)
}
function checkWin(){
if(sWin.document.readyState == "complete"){
clearInterval(intID)
//alert("passes clear")
CreateArray()
}
}
function CreateArray(){
//alert("creating")
		var sLinkArray = new Array()
var allLinksArray = new Array()
		var allLists = sWin.document.getElementsByTagName("ul")
//alert(allLists.length)
		for (i=0;i<allLists.length;i++){
			if (allLists[i].className == "mw-search-results"){
alert(allLists[i].innerHTML)
allLinksArray = returnArray(allLists[i].innerHTML)
			}
		}
deOrphanDocumentLinkArray = allLinksArray
alert("final a:\n" + deOrphanDocumentLinkArray)
openALinkWin()
 
};
function returnArray(text){
	var orphanCompleteRegxp = new RegExp("<a[^<]*<\/a>","gi")
	//alert(orphanCompleteRegxp)
	anchTags = new Array()
	//alert(text.match(orphanCompleteRegxp).toString())
	//alert(text.match(orphanCompleteRegxp).length)
	anchTags = text.match(orphanCompleteRegxp)
	allImpLinks = new Array()
	var orphanAnchRegxp = new RegExp("href=\"([^<>=\"]*)\"","i")
		for (i=0;i<anchTags.length;i++){
		allImpLinks[i] = anchTags[i].match(orphanAnchRegxp)[0].split("=")[1].replace(/\"/g,"")
	}
var colorRectifier = "\""
//Just to return syntax highlighting to normal
	sWin.close()
	return allImpLinks;
}
 
 
function openALinkWin(){
currentLinkWin = window.open("about:blank","","")
currentLinkWin.location.replace(mw.config.get('wgServer')+"/w/index.php?title=" + deOrphanDocumentLinkArray[linkACounter].replace(/\/wiki\//,"") + "&action=edit")
if(!currentLinkWin.addOnloadHook){
currentLinkWin.onload=function(){
currentLinkWin.addOnloadHook(function () {
openALInnerFunct()
});
}
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook(function () {
openALInnerFunct()
});
}else{
openALInnerFunct()
}
 
}
}
 
function closeTheWindow(){
//alert("closing")
if(!currentLinkWin.addOnloadHook){
currentLinkWin.onload=function(){
currentLinkWin.addOnloadHook(function () {
closeTWInnerFunct()
});
}
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook(function () {
closeTWInnerFunct()
});
}else{
closeTWInnerFunct()
}
}
}
 
function endOfLinkWins(){
if(OrphanTabsConfig.auto){
var choice = ((linkAlreadyThere + howManyActuallyDeOrphaned)>OrphanTabsConfig.autoChoice)?true:false;
}else{
var choice = confirm(linkAlreadyThere + " pages linked to " + deOrphanPgName + " before de-orphaning.\n" + howManyActuallyDeOrphaned + " pages were linked to " + deOrphanPgName + "\n" + (linkAlreadyThere + howManyActuallyDeOrphaned) + " pages link to " + deOrphanPgName + " now\n De-orphan? (Press cancel to tag the page with \'do-attempt\'.")
currentLinkWin = window.open("about:blank","","")
}
currentLinkWin.location.replace(mw.config.get('wgServer')+"/w/index.php?title=" + deOrphanPgName + "&action=edit")
if(!currentLinkWin.addOnloadHook){
currentLinkWin.onload=function(){
currentLinkWin.addOnloadHook(function () {
addOrphanTag(choice)
});
};
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook(function () {
addOrphanTag(choice)
});
}else{
addOrphanTag(choice)
}
}
}
 
function addOrphanTag(choice){
//alert("adding")
currentLinkWin.document.editform.wpTextbox1.value = addOrphanTagRaw(choice, currentLinkWin.document.editform.wpTextbox1.value)
var editSum = ""
if(choice){
editSum = "Successfully de-orphaned! Wikiproject Orphanage: [[WP:ORPH|Vous pouvez nous aider !]]"
}else{
editSum = "Unsuccesful de-orphan attempt, Wikiproject Orphanage: [[WP:ORPH|Vous pouvez nous aider !]]"
}
currentLinkWin.document.editform.wpSummary.value=editSum
currentLinkWin.document.editform.submit()
alert("De-orphaning over!!!")
}
 
function openALInnerFunct(){
if(currentLinkWin.wgCanonicalNamespace == ""){
if(orphanRawWikify(deOrphanPgName, currentLinkWin.document.editform.wpTextbox1.value) == currentLinkWin.document.editform.wpTextbox1.value){
linkAlreadyThere++
}else{
howManyActuallyDeOrphaned++
currentLinkWin.deOrphanWikify(deOrphanPgName)
 
currentLinkWin.document.editform.submit()
//alert("submitting")
}
}
setTimeout("closeTheWindow()",500)
}
function closeTWInnerFunct(){
currentLinkWin.close()
linkACounter++
if(linkACounter!=deOrphanDocumentLinkArray.length){
openALinkWin()
}else{
endOfLinkWins()
}
 
}
function addOrphanTagRaw(choice, val){
var rVal
if(choice){
	if(val.replace(new RegExp("{{orphelin}}", "i"), "") != val){
		rVal = val.replace(new RegExp("{{orphelin}}", "i"), "")
//		alert(11)
	}else if(/{{orphan\|\wdate=[^\}]*}}/i.test(val)){
		rVal = val.replace(/{{orphelin\|\wdate=[^\}]*}}/i, "")
//		alert(12)
	}else if(val.indexOf("{{articleissues") !=-1){
		rVal=val.replace(/\|\w?orphelin=[^\|\}]*/i,"")
		rVal=rVal.replace(/\|\w?tent=[^\|\}]*/i,"")
//		alert(14)
	}else{
		rVal=val
//		alert(15)
	}
}else{
	if(val.replace(new RegExp("{{orphelin}}", "i"), "") != val){
		rVal = val.replace("{{orphelin}}", "{{orphelin|tent=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}}}")
//		alert(21)
	}else if(new RegExp("{{orphelin|date=[^\}]}}","i").test(val)){
		rVal = val.replace(/{{orphelin\|date=([^\}]*)}}/i, "{{do-attempt|date=$1|att=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}}}")
//		alert(22)
	}else if(new RegExp("{{do-attempt|date=[^\|\}]*\|att=[^\|\}]*}}","i").test(val)){
		rVal = val.replace(/({{do-attempt|date=[^\|\}]*\|tent=)[^\|\}]*}}/i, "$1\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}}}")
 
	}else if(val.indexOf("{{articleissues") !=-1){
		rVal=rVal.replace(/\|\w?tent=[^\|\}]*/i,"\|do-attempt=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}")
//		alert(23)
	}else{
		rVal= "{{orphelin|att=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}}}" + val
	}
}
return rVal
}

});