User:Manishearth/orphantabs.js: Difference between revisions

Content deleted Content added
No edit summary
m Maintenance: Replacing addPortletLink() with mw.util.addPortletLink() (mw:ResourceLoader/Migration_guide_(users)#addPortletLink)
 
(16 intermediate revisions by 6 users not shown)
Line 1:
// <nowiki>
/*
===================================================================================================
Go to [[User:Manishearth/OrphanTabs]] to see how this script is used.
This script works, but is'nt user-friendly.
Ask me how to use it.
[[User:Manishearth]]
===================================================================================================
Line 8:
*/
 
//Support for config template (not yet implemented in script)
var undefined; //to check for undefined laterconfig template
var OrphanTabsConfig = true
var OrphanTabsConfig
if(OrphanTabsConfig === undefined){
OrphanTabsConfig = {
auto : false,
autoChoice : 3,
showCompleteTab : true,
completeTabText : "de-orphan-complete",
showWikifyTab : true,
wikifyTabText : "de-orphan-wikifyWikify",
showWLHTab : false,
wLHTabText : "WhatLinksHere",
showSearchItTab : false,
searchItTabText : "Search It!",
showGoogleItTab : false,
googleItTabText : "Google It!"
}
}else{
Line 38 ⟶ 37:
}
if(OrphanTabsConfig.completeTabText === undefined){
OrphanTabsConfig.completeTabText = new String("de-orphan-complete")
}
if(OrphanTabsConfig.showWikifyTab === undefined){
Line 64 ⟶ 63:
OrphanTabsConfig.completeTabText = new String("Google It!")
}
 
}
var currentLinkWin
var otherOrphanTabs = falsetrue
var deOrphanDocumentLinkArray = new Array()
var linkACounter=0
Line 75 ⟶ 73:
var deOrphanPgName = ""
var deOrphanProcessFirstCall=false
addOnloadHook$(function () {
var gServerPre;
var gServerPost;
gServerPre = "http://www.google.com/search?hl=en&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){
addPortletLink("p-cactions", wgServer + "/wiki/Special:WhatLinksHere/" + pgname, "WhatLinksHere", "ca-whatlinks" , "What links here");
mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + "/wiki/Special:WhatLinksHere/" + pgname, "Search it!"OrphanTabsConfig.wLHTabText, "ca-searchitwhatlinks" , "What links here");
 
 
addPortletLink("p-cactions", gServerPre + pgname + gServerPost, "Google it!", "ca-googleit", "Find all Wikipedia pages with this page name in them");
}
if(OrphanTabsConfig.showSearchItTab){
addPortletLink("p-cactions","javascript:deOrphanWikify(prompt(\"What page are you de-orphaning?\",\"\"))", "De-orphan-wikify", "ca-de-orphan-wikify", "Wikify to deorphan another page");
mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + "/wiki/Special:WhatLinksHere/" + pgname, "WhatLinksHere"OrphanTabsConfig.searchItTabText, "ca-whatlinkssearchit" , "What links here");
 
}
addPortletLink("p-cactions", "javascript:initDeOrphan(prompt(\"What page\?\"\,\""+ ((wgCanonicalNamespace=="")?wgPageName:"")+"\"));", "De-orphan-complete", "ca-de-orphan", "Find all Wikipedia pages with this page name in them");
if(OrphanTabsConfig.showGoogleItTab){
mw.util.addPortletLink("p-cactions", gServerPre + pgname + gServerPost, "Google it!"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?\",\"\"))", "De-orphan-wikify"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'):"")+"\"));", "De-orphan-complete"OrphanTabsConfig.completeTabText, "ca-de-orphan", "Find all Wikipedia pages with this page name in them");}
 
});
Line 112 ⟶ 116:
}
function initDeOrphan(pgName){
sWin = window.open(mw.config.get('wgServer') + "/w/index.php?title=Special:Search&ns0=1&ns1=1&ns2=1&ns3=1&ns4=1&ns5=1&ns6=1&ns7=1&ns8=1&ns9=1&ns10=1&ns11=1&ns12=1&ns13=1&ns14=1&ns15=1&ns100=1&ns101=1&redirs=1&search=%22" + pgName + "%22&limit=100&offset=0","","")
 
deOrphanPgName = pgName
deOrphanProcessFirstCall=true
Line 132 ⟶ 137:
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()
 
Line 162 ⟶ 167:
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()
});
Line 171 ⟶ 176:
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook$(function () {
openALInnerFunct()
});
Line 183 ⟶ 188:
function closeTheWindow(){
//alert("closing")
if(!currentLinkWin.addOnloadHook$){
currentLinkWin.onload=function(){
currentLinkWin.addOnloadHook$(function () {
closeTWInnerFunct()
});
Line 191 ⟶ 196:
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook$(function () {
closeTWInnerFunct()
});
Line 201 ⟶ 206:
 
function endOfLinkWins(){
var if(OrphanTabsConfig = true.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)
});
Line 212 ⟶ 221:
}else{
if(!currentLinkWin.document.loaded){
currentLinkWin.addOnloadHook$(function () {
addOrphanTag(choice)
});
Line 268 ⟶ 277:
rVal = val.replace(/{{orphan\|\wdate=[^\}]*}}/i, "")
// alert(12)
}else if(val.indexOf("{{articleissuesmultiple issues") !=-1){
rVal=val.replace(/\|\w?orphan=[^\|\}]*/i,"")
rVal=rVal.replace(/\|\w?do-attempt=[^\|\}]*/i,"")
Line 286 ⟶ 295:
rVal = val.replace(/({{do-attempt|date=[^\|\}]*\|att=)[^\|\}]*}}/i, "$1\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}}}")
 
}else if(val.indexOf("{{articleissuesmultiple issues") !=-1){
rVal=rVal.replace(/\|\w?do-attempt=[^\|\}]*/i,"\|do-attempt=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}")
// alert(23)
Line 295 ⟶ 304:
return rVal
}
// </nowiki>