// <source lang="javascript">
//Script to automate closing XfDs by adding a 'close' links to XfD debates
//written by ] inspired by ] and ]
function closeXfD_links() {
// no point in running unless in view mode
if (mw.config.get('wgAction') == 'view') {
// Articles for Deletion
if (mw.config.get('wgTitle').indexOf('Articles for deletion/Log/') == 0) {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Articles_for_deletion\/+&action=edit§ion=T-1/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re)) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
// Articles for Deletion sub-page
if (mw.config.get('wgTitle').indexOf('Articles for deletion/') == 0) {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Articles_for_deletion\/+&action=edit§ion=1/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re)) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
// Files for deletion
if (mw.config.get('wgTitle').indexOf('Files for deletion') == 0) {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Files_for_deletion\/+&action=edit§ion=(T-)?(|\d\d+)/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re)) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
// Miscellany for deletion
if (mw.config.get('wgTitle') == 'Miscellany for deletion') {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Miscellany_for_deletion\/+&action=edit&/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re) && anchorsAll.href.indexOf('/Front_matter&action=edit') == -1 ) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
// Redirects for discussion
if (mw.config.get('wgTitle').indexOf('Redirects for discussion') == 0) {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Redirects_for_discussion\/+&action=edit§ion=(T-)?(|\d\d+)/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re) && anchorsAll.href.indexOf('/Header&action=edit') == -1 ) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
// Templates for deletion
if (mw.config.get('wgTitle').indexOf('Templates for deletion') == 0) {
var anchorsAll = document.getElementById('bodyContent').getElementsByTagName('a');
var url_re = /\?title=Wikipedia:Templates_for_deletion\/+&action=edit§ion=(T-)?(|\d\d+)/;
var anchorsToAdd = new Array();
for (var i = 0; i < anchorsAll.length; i++) {
if (anchorsAll.parentNode.className == 'editsection' && anchorsAll.href.match(url_re) && anchorsAll.href.indexOf('/Header&action=edit') == -1 && anchorsAll.href.indexOf('/Holding_cell&action=edit') == -1 ) {
anchorsToAdd.push(anchorsAll);
}
}
closeXfD_addlinks(anchorsToAdd);
return;
}
}
}
function closeXfD_action() {
// no point in running unless in edit mode
if (mw.config.get('wgAction') == 'edit' && document.location.search.indexOf('&closeXfD=true') != -1) {
var result = prompt("Result of discussion?");
// check if no result entered and if not exit
if (result == null || result == "") return;
var comments = prompt("Comments?");
var nonadmin = " (])";
if (typeof mw.config.get('wgUserGroups') == "object" && mw.config.get('wgUserGroups')) {
for ( var g = 0; g < mw.config.get('wgUserGroups').length; ++g ) {
if ( mw.config.get('wgUserGroups') == "sysop" ) {
nonadmin = "";
break;
}
}
}
var f = document.editform, t = f.wpTextbox1;
if (document.title.indexOf("Editing Wikipedia:Articles for deletion/") != -1) {
var searchKey = new RegExp('{'+'{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD..}}\n', 'i');
t.value = t.value.replace(searchKey, "");
t.value = "{"+"{subst:" + "at" + "}} '''" + result + "'''." + nonadmin + " " + comments + " ~" + "~" + "~" + "~\n\n" + t.value;
t.value += "\n{"+"{subst:" + "ab" + "}}";
}
if (document.title.indexOf("Editing Wikipedia:Files for deletion/") != -1) {
t.value = t.value.substr(0, t.value.indexOf('\n')) + "\n{"+"{subst:" + "ffd top" + "}} '''" + result + "'''." + nonadmin + " " + comments + " ~" + "~" + "~" + "~\n" + t.value.substr(t.value.indexOf('\n'));
t.value += "\n{"+"{subst:" + "ffd bottom" + "}}";
}
if (document.title.indexOf("Editing Wikipedia:Miscellany for deletion/") != -1) {
t.value = "{"+"{subst:" + "mfd top" + "}} '''" + result + "'''." + nonadmin + " " + comments + " ~" + "~" + "~" + "~\n\n" + t.value;
t.value += "\n{"+"{subst:" + "mfd bottom" + "}}";
}
if (document.title.indexOf("Editing Wikipedia:Redirects for discussion/") != -1) {
t.value = t.value.substr(0, t.value.indexOf('\n')) + "\n{"+"{subst:" + "rfd top" + "}} '''" + result + "'''." + nonadmin + " " + comments + " ~" + "~" + "~" + "~\n" + t.value.substr(t.value.indexOf('\n'));
t.value += "{"+"{subst:" + "rfd bottom" + "}}";
}
if (document.title.indexOf("Editing Wikipedia:Templates for deletion/") != -1) {
t.value = t.value.substr(0, t.value.indexOf('\n')) + "\n{"+"{subst:" + "tfd top" + "}} '''" + result + "'''." + nonadmin + " " + comments + " ~" + "~" + "~" + "~\n" + t.value.substr(t.value.indexOf('\n'));
t.value += "{"+"{subst:" + "tfd bottom" + "}}";
}
f.wpSummary.value = "Closing debate; result was " + result + nonadmin;
}
}
function closeXfD_addlinks(anchorsToAdd) {
for (var i = 0; i < anchorsToAdd.length; i++) {
var closelink = document.createElement('a');
closelink.href = anchorsToAdd.href + '&closeXfD=true';
closelink.title = 'Close XfD';
closelinktext = document.createElement('sup');
closelinktext.appendChild(document.createTextNode(' Close '));
closelink.appendChild(closelinktext);
anchorsToAdd.parentNode.insertBefore(closelink, anchorsToAdd.nextSibling);
}
}
$(closeXfD_links);
$(closeXfD_action);
//end XfD closing script
// </source>