User:A930913/vada/plugin/ufd.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:A930913/vada/plugin/ufd. |
//<nowiki>
if(typeof window!="undefined"){
//inside Vada DOM
(function(){
var a930913_ufd={
about:{
name:"A930913's Unused File Director",
description:"Given a file redirect, searches for all uses, replaces them, then tags the redirect for deletion.",
namespace:"a930913_ufd",
userscript:"User:A930913/vada/plugin/ufd.js",
}
}
window.vada.loadPlugin(a930913_ufd);
})();
} else {
//inside Vada process
vada.plugins.a930913_ufd={};
vada.plugins.a930913_ufd.page=function(params){
var query={};
query.action="query";
query.list="imageusage";
query.iufilterredir="nonredirects";
query.iutitle=params.page;
var data=vada.api(query);
if(data.query.imageusage.length===0){
var bl=vada.api({"action":"query","list":"backlinks","bltitle":params.page}).query.backlinks,tag=true;
for(var i in bl){if(bl[i].title.search("sandbox")==-1){tag=false;break;}}
if(tag){
var agepi=vada.api({"action":"query","prop":"revisions","titles":params.page,"rvprop":"timestamp","rvdir":"newer","rvlimit":"1"});
for(var pageid in agepi.query.pages)break;
if(Date.now()-Date.parse(agepi.query.pages[pageid].revisions[0].timestamp)<2629744000){
//tag for deletion
var p=new vada.Page(params.page);
vada.dom.summarybox.setText("Tagging retitled media for deletion (G6)");
vada.dom.minorbox.uncheck();
} else {
//Older than a month, there may be external links pointing to the redirect
vada.plugins.a930913_ufd.removenext(params.page);
}
try{
if(p.text.substr(0,8)=="{{"+"db-g6|")throw("PageAlreadyTagged");
vada.dom.load(p,"{{"+"db-g6|reason=G6 - Retitled media with no significant incoming links. (Please check for Commons referals)}}\n"+p.text);
}catch(e){
if(e=="PageDoesNotExist"||e=="PageAlreadyTagged"){
//page already deleted
vada.plugins.a930913_ufd.removenext(params.page);
} else {
throw(e);
}
}
} else {
vada.plugins.a930913_ufd.removenext(params.page);
}
} else {
var nextms=null;
for(var i in data.query.imageusage){
if(data.query.imageusage[i].ns===0){
nextms=data.query.imageusage[i].title;
break;
}
}
if(nextms){
//replace redirects on this page
var p=new vada.Page(nextms);
var realpage=new vada.Page(params.page).text.match(/#REDIRECT \[\[(.+?)\]\]/)[1];
vada.dom.summarybox.setText("Fixing redirect ("+params.page+" → [["+realpage+"]])");
vada.dom.minorbox.check();
//vada.dom.load(p,p.text.replace(new RegExp(params.page.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"),"g"),realpage));
vada.dom.load(p,p.text.replace(new RegExp(params.page.split(":")[1].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1").replace(/ /g,"[\ _]"),"g"),realpage.split(":")[1]));
} else {
vada.plugins.a930913_ufd.removenext(params.page);
}
}
}
vada.plugins.a930913_ufd.queueclick=function(params){
vada.plugins.a930913_ufd.page({page:params.title});
vada.dom.queue.splice(vada.dom.queue.indexOf(new vada.Page(params.title)),1);
vada.dom.queue.redraw();
}
vada.plugins.a930913_ufd.saveclick=function(params){
vada.dom.queue.next();
}
vada.plugins.a930913_ufd.removenext=function(page){
vada.dom.queue.splice(vada.dom.queue.indexOf(new vada.Page(page)),1);
vada.dom.queue.redraw();
vada.dom.queue.next();
}
vada.plugins.a930913_ufd.start=function(){
vada.events.trigger("plugins.stop",{});
vada.events.addListener("plugins.stop",vada.plugins.a930913_ufd.stop);
vada.dom.menu.new([vada.dom.menu.buttons.nextq,vada.dom.menu.buttons.save]);
vada.dom.queue.builders.show();
vada.events.addListener("pagename",vada.plugins.a930913_ufd.page);
vada.events.addListener("queue.page.selected",vada.plugins.a930913_ufd.queueclick);
vada.events.addListener("save.click",vada.plugins.a930913_ufd.saveclick);
vada.plugins.a930913_ufd.running=true;
}
vada.plugins.a930913_ufd.stop=function(){
vada.plugins.a930913_ufd.running=false;
vada.dom.queue.builders.hide();
vada.events.removeListener("pagename",vada.plugins.a930913_ufd.page);
vada.events.removeListener("queue.page.selected",vada.plugins.a930913_ufd.queueclick);
vada.events.removeListener("save.click",vada.plugins.a930913_ufd.saveclick);
}
vada.plugins.a930913_ufd.running=false;
vada.plugins.a930913_ufd.button=(function(pl){
var button=new vada.dom.menu.Button("a930913_ufd_start");
button.text="A930913's Unused File Director";
button.click=pl.start;
vada.dom.menu.buttons.vada.children.push(button);
vada.dom.menu.redraw();
return button;
})(vada.plugins.a930913_ufd);
}
//</nowiki>