Science Fair Project Encyclopedia
User:Poccil/Automation.js
Note: After saving, you have to bypass your browser's cache to see the changes. Mozilla/Safari/Konqueror: hold down Shift while clicking Reload (or press Ctrl-Shift-R), IE: press Ctrl-F5, Opera: press F5.
//<nowiki>
/*--------------------------------
This script can be used for automating the listing of
pages on votes for deletion and cleanup, and for
placing boilerplate tags.
This program is meant to be run with Windows Script Host.
Functions:
vfd("ArticleName","Reason for deleting.")
cleanup("ArticleName","Reason for cleaning up.")
cleanup("ArticleName","Reason for cleaning up.","{{tag}}")
speedy("ArticleName","Reason for speedy deletion.")
speedy("ArticleName")
tag("ArticleName","{{tag}}")
tag("ArticleName","{{tag}}{{anothertag}}")
merge("ArticleName","ArticleToMergeWith")
redir("ArticleName","ArticleToRedirectTo")
Handling entries on [[Wikipedia:Votes for deletion/Old]]:
vfdkeep("ArticleName")
vfddelete("ArticleName")
vfdmerge("ArticleName")
Moving to other Wikimedia projects
wiktionarytw("ArticleName")
wikibookstw("ArticleName")
wikimemorialtw("ArticleName")
wikisourcetw("ArticleName")
Add functions on the area indicated at the bottom of this file.
Created by Wikipedia User:Poccil
--------------------------------*/
var ie=new ActiveXObject("InternetExplorer.Application")
ie.Visible=1
ie.Silent=1
ie.Width=500//260
ie.Height=500//260
//ie.Left=2000
function tryquit(ie){
try{ie.Quit()}catch(e){return e.Number}
return 0
}
function removetags(doc,tn){
var col=doc.all.tags(tn)
for(var i in col){
try{
// WScript.Echo('imgname '+i)
// WScript.Echo('imgsrc '+col[i].outerHTML)
col[i].outerHTML="( )"
// doc.images[i].src=""
}catch(e){if(e.Number==0x80010108)break;}
}
}
function noimages(doc){
try{var rs=doc.readyState}catch(e){return}
// WScript.Echo(rs)
if(rs=="interactive"
||rs=="complete"){
removetags(doc,"IMG")
removetags(doc,"img")
removetags(doc,"OBJECT")
removetags(doc,"object")
}
}
function navigate(ie,u){
ie.Navigate(u);
while(ie.readystate!=4){
try{
// noimages(ie.Document)
// WScript.Sleep(200)
}catch(e){if(e.Number==0x80010108)break;}
}
// noimages(ie.Document)
return ie.Document
}
function waitHrefChange(ie,doc,func,rs){
var href=doc.location.href
var rs=(rs)?rs:4
func()
while(1){
try{
// WScript.Echo(ie.Document.location.href)
if(ie.Document.location.href!=href)break;
}
catch(e){if(e.Number==0x80010108)break;}
}
while(ie.readystate<rs){
try{
noimages(ie.Document)
}catch(e){if(e.Number==0x80010108)break;}
}
return ie.Document
}
function vfd(pg,notes){
var t="Listing [["+pg+"]] on [[WP:VFD|votes for deletion]] - "+notes
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+pg+"&action=edit")
if(doc.editform.wpTextbox1.value.indexOf("votes for deletion")==-1){
doc.editform.wpTextbox1.value="{{subst:vfd}}\n\n"+doc.editform.wpTextbox1.value
doc.editform.wpSummary.value=t
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Votes for
deletion/"+pg+"&action=edit")
if(!doc.editform.wpTextbox1.value){
doc.editform.wpTextbox1.value="===[["+pg+"]]===\n"+notes+" ~~~~"
doc.editform.wpSummary.value=t
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Votes for
deletion&action=edit")
var io=doc.editform.wpTextbox1.value.search(/\=\=\s*VfD\s*footer\s*\=\=/i)
var val=doc.editform.wpTextbox1.value
doc.editform.wpTextbox1.value=
val.substr(0,io)+"{{Wikipedia:Votes for deletion/"+pg+"}}\n"+val.substr(io)
doc.editform.wpSummary.value=t
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function tag(pg,t,note,checkempty){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+pg+"&action=edit")
if(!note)note=""
if(note)note=" - "+note
if(checkempty){
if(!doc.editform.wpTextbox1.value)
return
}
if(doc.editform.wpTextbox1.value.indexOf(t)==-1){
doc.editform.wpTextbox1.value=t+"\n\n"+doc.editform.wpTextbox1.value
doc.editform.wpSummary.value=t+note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
}
function speedy(pg,because,note){
var t=""
if(because){
t="{{deletebecause|"+because+"}}"
} else {
t="{{delete}}"
}
tag(pg,t,note,1)
}
function def(w,pos,def){
var doc=navigate(ie,"http://en.wiktionary.org/w/wiki.phtml?title="+w+"&action=edit")
var t="==English==\n==="+pos+"===\n'''"+((pos=="Verb")?"to ":"")+w+"'''\n#"+def
doc.editform.wpTextbox1.value=t+"\n\n"+doc.editform.wpTextbox1.value
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function cleanup(pg,note,others){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+pg+"&action=edit")
if(!others)others=""
doc.editform.wpTextbox1.value="{{cleanup}}"+others+"\n\n"+doc.editform.wpTextbox1.value
doc.editform.wpSummary.value="{{cleanup}} - "+note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Cleanup&action=edit&
section=2")
note="[["+pg+"]] - "+note
var io=doc.editform.wpTextbox1.value.search(/\=\=\=(?=[\r\n])/)
var val=doc.editform.wpTextbox1.value
doc.editform.wpTextbox1.value=
val.substr(0,io+3)+"\n*"+note+" ~~~~"+val.substr(io+3)
doc.editform.wpSummary.value+=note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function merge(pg,other){
tag(pg,"{{merge}} [["+other+"]].")
tag(other,"{{mergefrom}} [["+pg+"]].")
}
function settext(pg,t,note){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+pg+"&action=edit")
if(!note)note=""
doc.editform.wpTextbox1.value=t
doc.editform.wpSummary.value=note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function settexttw(domain,pg,t,note){
var doc=navigate(ie,"http://"+domain+"/w/wiki.phtml?title="+pg+"&action=edit")
if(!note)note=""
doc.editform.wpTextbox1.value=t
doc.editform.wpSummary.value=note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function redir(pg,other,note){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+pg+"&action=edit")
if(!note)note=""
if(note)note=" - "+note
var t="#redirect [["+unescape(other)+"]]"
doc.editform.wpTextbox1.value=t
doc.editform.wpSummary.value=t+note
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
var ws="[[Wikipedia:WikiProject Wiki Syntax|Please help out by clicking here "
+"to fix someone else's Wiki syntax]]"
function wsredir(p,o){
redir(p,o,ws)
}
function badredir(p){
speedy(p,"Page being redirected to is non-existent",ws)
}
function selfredir(p){
speedy(p,"Redirects to itself",ws)
}
function loopredir(p){
speedy(p,"Redirected page redirects to this redirect",ws)
}
function redirvfd(p,o){
redir(p,o,"Per decision on [[WP:VFD|votes for deletion]]")
}
function copyviodel(p){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+p+"&action=edit")
if(doc.editform.wpTextbox1.value.indexOf("copyvio")!=-1){
t="{{deletebecause|Outstanding unhandled copyright problem. Check the page history.}}"
doc.editform.wpTextbox1.value=t+"\n\n"+doc.editform.wpTextbox1.value
doc.editform.wpSummary.value=t
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
}
function copyviomove(p){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+p+"&action=edit")
if(doc.editform.wpTextbox1.value.indexOf("copyvio")!=-1){
t="{{deletebecause|To prepare for the move of [["+p+"/Temp]]. Compare the temp page
with history.}}"
doc.editform.wpTextbox1.value=t+"\n\n"+doc.editform.wpTextbox1.value
doc.editform.wpSummary.value=t
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
tag(p+"/Temp","{{move|"+unescape(p)+"}}")
}
}
function copyviohist(p){
speedy(p,"A previous version of this article is in violation of copyright policy and must
be removed (see history and listing on [[WP:CP]])."
+" Once deleted, please recreate this article and copy the text on this version.")
}
function pgescre(re){
re=re.replace(/\(\)\[\]\/\\\:\?\.\!/g,"\\$1")
re=re.replace(/\s/g,"[ \_]")
return re
}
function vfdremoveold(parr,detail){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?"
+"title=Wikipedia:Votes for deletion/Old&action=edit")
var val=doc.editform.wpTextbox1.value
if(parr.constructor==String)
parr=[parr]
for(var i=0;i<parr.length;i++){
var re=new RegExp("\\{\\{\\s*wikipedia\\:votes for
deletion\\/"+pgescre(parr[i])+"\\s*\\}\\}","ig")
val=val.replace(re,"")
}
doc.editform.wpTextbox1.value=val
if(detail)detail="; "+detail
if(!detail)detail=""
if(parr.length==1){
doc.editform.wpSummary.value="Removing listing for [["+parr[0]+"]]"+detail
} else {
doc.editform.wpSummary.value="Removing listings for handled articles"
}
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function vfdclose(p,result,detail){
if(detail)detail="; "+detail
if(!detail)detail=""
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Votes for
deletion/"+p+"&action=edit")
if(doc.editform.wpTextbox1.value.indexOf("this page is preserved as an historic
record")==-1){
doc.editform.wpTextbox1.value="[["+p+"]] {{subst:vfd top}}
"+result+"\n"+doc.editform.wpTextbox1.value+"\n{{subst:vfd bottom}}"
doc.editform.wpSummary.value="Closing discussion for [["+p+"]] with result
\""+result+"\""+detail
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
}
String.prototype.between = function(beg,end,atpos){
if(!atpos)atpos=0
var sta=this.indexOf(beg,atpos)
if(sta==-1)return ""
var sts=this.substring(sta+beg.length,this.length)
if(sts.indexOf(end)!=-1){return sts.substring(0,sts.indexOf(end))}
return ""
}
String.prototype.including = function(beg,end,atpos){
if(!atpos)atpos=0
var sta=this.indexOf(beg,atpos)
if(sta==-1)return ""
var sts=this.substring(sta+beg.length-1,this.length)
if(sts.indexOf(end)!=-1){return sts.substring(0,sts.indexOf(end)+1)}
return ""
}
var sysop=-1
function deletepage(p,reason){
speedy(p,reason)
}
function deletevfd(p){
deletepage(p,"Consensus on [[WP:VFD|votes for deletion]] was to delete this article.")
}
function deleteassocvfd(assocp,p){
deletepage(assocp,"Consensus on [[WP:VFD|votes for deletion]] was to delete "
+"[["+p+"]]; this is an associated page.")
}
function deleteredirvfd(redirp,p){
deletepage(redirp,"Consensus on [[WP:VFD|votes for deletion]] was to delete "
+"[["+p+"]], to which this page redirects.")
}
function archivedel(parr){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Archived delete
debates&action=edit")
if(parr.constructor==String)
parr=[parr]
for(var i=0;i<parr.length;i++){
doc.editform.wpTextbox1.value+="\n*[[Wikipedia:Votes for deletion/"+parr[i]+"]]"
}
if(parr.length==1){
doc.editform.wpSummary.value="Recording the fact of the deletion of [["+parr[0]+"]]"
} else {
doc.editform.wpSummary.value="Recording deletions"
}
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function findredirs(p){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?"
+"title=Special:Whatlinkshere&target="+p)
var val=doc.body.innerHTML.between("<!-- start content -->","<!-- end content -->")
var txttofind="<LI><A "
var curpos=0
var io
var redirs=[]
while((io=val.indexOf(txttofind,curpos))!=-1){
doc.body.innerHTML;
io+=txttofind.length;
var a=val.between(">","<",io)
var iot=val.indexOf("</A>",io)
var iou=iot+22
var redirstr=val.substring(iot,iou)
// WScript.Echo([redirstr,a])
var isRedir=(redirstr.indexOf("(redirect page)")!=-1)
if(isRedir){
redirs[redirs.length]=a
// WScript.Echo(a)
}
curpos=io
}
// WScript.Echo(redirs)
return redirs
}
var vfdbegin='<div class="boilerplate metadata" id="attention" style="backgro'
+'und-color: #FFFCE6; margin: 0 2.5%; padding: 0 10px; border: 1px solid #aaa;">'
function vfdkeep(p,keepstr){
if(!keepstr)keepstr="keep"
vfdclose(p,"'''"+keepstr+"'''","consensus was to "+keepstr+" the article [["+p+"]].")
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+p+"&action=edit")
var val=doc.editform.wpTextbox1.value
val=val.replace(/\{\{vfd\}\}/g,"")
var ioBegin=val.indexOf('<div class="boilerplate metadata" id="attention"')
var ioEnd=val.indexOf('</div>',ioBegin)+6
if(ioBegin!=-1){
val=val.substr(0,ioBegin)+val.substr(ioEnd)
}
val=val.replace(/\[\[Category\:Pages on votes for deletion.*\]\]/g,"")
if(val!=doc.editform.wpTextbox1.value){
doc.editform.wpTextbox1.value=val
doc.editform.wpSummary.value="Removing VFD tag; consensus was to "+keepstr+" the
article."
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
tag("Talk:"+p,"This article was listed on [[WP:VFD|votes for deletion]]; see "
+"[[Wikipedia:Votes for deletion/"+p+"]]. ~~~~")
vfdremoveold(p,"consensus was to "+keepstr+" the article [["+p+"]].")
}
function vfddelete(p){
vfdclose(p,"'''delete'''","consensus was to delete the article [["+p+"]].")
var redirs=findredirs(p)
for(var i=0;i<redirs.length;i++){
deleteredirvfd(redirs[i],p)
}
deleteassocvfd("Talk:"+p,p)
deletevfd(p)
archivedel(p)
vfdremoveold(p,"consensus was to delete the article [["+p+"]].")
}
function vfdspeedy(p){
vfdclose(p,"'''delete'''","consensus was to delete the article [["+p+"]].")
archivedel(p)
vfdremoveold(p,"consensus was to delete the article [["+p+"]].")
}
function vfdmerge(p, whatart){
vfdkeep(p,"merge into "+whatart)
cleanup(p,"Consensus on [[WP:VFD|votes for deletion]] was to merge "
+"this article into "+whatart+".","{{merge}} "+whatart)
}
function vrok(c,conc){
vfdremoveold(c,"consensus was to keep the article [["+c+"]].")
}
function vrod(c,conc){
vfdremoveold(c,"consensus was to delete the article [["+c+"]].")
}
function vfddeletemult(parr,ii){
if(parr.length==0)return
if(!ii)ii=0
for(var i=ii;i<parr.length;i++){
var p=parr[i]
vfdclose(p,"'''delete'''","consensus was to delete the article [["+p+"]].")
var redirs=findredirs(p)
for(var j=0;j<redirs.length;j++){
deleteredirvfd(redirs[j],p)
}
deleteassocvfd("Talk:"+p,p)
deletevfd(p)
}
archivedel(parr)
vfdremoveold(parr)
}
function transwikilog(p,domain,dst){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title=Wikipedia:Transwiki
log&action=edit")
var val=doc.editform.wpTextbox1.value
var io=val.indexOf("==Articles moved to the Transwiki namespace of this project")
var move="[["+p+"]] --> [http://"+domain+"/wiki/"+dst.replace(/\s/g,"_")+" "+dst+"]."
doc.editform.wpTextbox1.value=
val.substr(0,io)+"*"+move+" ~~~~\n"+val.substr(io)
doc.editform.wpSummary.value=move
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function transwikilogdst(p,domain,log,dst){
var doc=navigate(ie,"http://"+domain+"/w/wiki.phtml?title="+log+"&action=edit")
var val=doc.editform.wpTextbox1.value
var move="[["+p+"]] --> [http://"+domain+"/wiki/"+dst.replace(/\s/g,"_")+" "+dst+"]."
doc.editform.wpTextbox1.value+=
"*"+move+" ~~~~\n"
doc.editform.wpSummary.value=move
waitHrefChange(ie,doc,function(){doc.editform.wpSave.click()},3)
}
function getsrc(p){
var doc=navigate(ie,"http://en.wikipedia.org/w/wiki.phtml?title="+p+"&action=edit")
return doc.editform.wpTextbox1.value
}
function transwiki(p,domain,dst,otherlog){
var doc=navigate(ie,
"http://en.wikipedia.org/wiki/Special:Export?action=submit&pages="+escape(p)+"%0D%0A"
//
"http://en.wikipedia.org/wiki/Special:Export?action=submit&pages=Making+Period+Mail%0D%0A"
)
var dd=doc.body.innerText
// WScript.Echo(doc.body.innerHTML)
var curpos=0
var io
var ttl=dd.between("<title>","</title>")
var lastrev=""
var contribs="This page was transwikied from en.wikipedia.org. List of contributors:\n"
while((io=dd.indexOf("</revision>",curpos))!=-1){
var dds=dd.substring(curpos,io)
var ts=dds.between("<timestamp>","</timestamp>")
var un=dds.between("<username>","</username>")
if(!un)
var un=dds.between("<ip>","</ip>")
var cmt=dds.between("<comment>","</comment>")
// lastrev=dds.between("<text>","</text>")
contribs+="*["+ts+"] [[:w:User:"+un+"|"+un+"]]
"+(cmt?"(<nowiki>"+cmt+"</nowiki>)":"")+"\n"
curpos=io+1
}
// WScript.Echo(contribs)
// WScript.Echo(lastrev)
contribs+="[[User:Poccil|[[User:Poccil|Peter O.]] ([[User Talk:Poccil|Talk]], [[User:Poccil/Automation.js|automation script]])]] 22:32, Dec 7, 2004 (UTC)"
lastrev=getsrc(p)
settexttw(domain,dst.replace(/\s/g,"_"),lastrev,"Transwiki of page [[:w:"+p+"]]")
settexttw(domain,"Talk:"+dst.replace(/\s/g,"_"),contribs,"Transwiki of page [[:w:"+p+"]]:
Listing contributors")
transwikilog(p,domain,dst)
speedy(p,"The contents of this page have been moved to
http://"+domain+"/wiki/"+dst.replace(/\s/g,"_")+" .")
if(otherlog)
transwikilogdst(p,domain,otherlog,dst)
}
function wiktionarytw(p){
transwiki(p,"en.wiktionary.org","Transwiki:"+p,"Wiktionary:Transwiki log")
}
function wikimemorialtw(p){
transwiki(p,"sep11.wikipedia.org",p,"")
}
function wikibookstw(p){
transwiki(p,"en.wikibooks.org","Transwiki:"+p,"Wikibooks:Transwiki log")
}
function wikisourcetw(p){
transwiki(p,"en.wikisource.org","Transwiki:"+p,"Wikisource:Transwiki_log")
}
function wikiquotetw(p){
transwiki(p,"en.wikiquote.org","Transwiki:"+p,"Wikiquote:Transwiki log")
}
function wikicommonstw(p){
transwiki(p,"commons.wikimedia.org","Transwiki:"+p,"")
}
//try{
//****************************************************************************
// Place functions below this line
// Place functions above this line
//****************************************************************************
// Following line is optional.
// WScript.Echo("All done")
//}catch(e){}
tryquit(ie)
//</nowiki>
Last updated: 06-02-2005 16:39:44
10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details


