User:Dusti/vector.css
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. |
![]() | The accompanying .js page for this skin is at User:Dusti/vector.js. |
// See [[User:Mr.Z-man/closeAFD]] for documentation
if (wgPageName.indexOf('Wikipedia:Articles_for_deletion/') != -1 && wgPageName.indexOf('Wikipedia:Articles_for_deletion/Log/200') == -1) {
var closeAFD_PageName = wgPageName.replace(/_/g, ' ');
var closeAFD_isAdmin = (wgUserGroups.toString().indexOf('sysop') != -1);
var closeAFD_AJAXnumber = 0;
var closeAFD_deletenredirect = false;
var closeAFD_nomdate = null;
var closeAFD_deletecount = 0;
var closeAFD_redirectlimit;
var closeAFD_redirtotal;
var closeAFD_redircount = 0;
function closeAFD_relist() {
if (!wfSupportsAjax()) {
jsMsg('<div style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the closeAFD script.</div>');
return;
}
var today = new Date();
var monthnames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
month = monthnames[today.getUTCMonth()];
day = today.getUTCDate();
year = today.getUTCFullYear();
datestring = year + " " + month + " " + day;
var newlog = "Wikipedia:Articles for deletion/Log/"+datestring;
oldlog = closeAFD_getOldLog();
jsMsg('<h3>Relisting '+closeAFD_PageName+'</h3><ul><li><b>Old log:</b> <a href="/wiki/'+encodeURI(oldlog)+'" title="'+oldlog+'">'+oldlog+'</a></li><li><b>New log:</b> <a href="/wiki/'+encodeURI(newlog)+'" title="'+newlog+'">'+newlog+'</a></li></ul><br /><input type="button" id="closeAFD_relist_button" name="closeAFD_relist_button" value="Submit" onclick="closeAFD_continue_relist(\''+newlog+'\', \''+oldlog+'\')" /><input type="button" id="closeAFD_cancel_relist_button" name="closeAFD_cancel_relist_button" value="Cancel" onclick="jsMsg(\'\')" />');
}
function closeAFD_continue_relist(newlog, oldlog) {
jsMsg('<ul id="closeAFD_status"></ul><ul id="closeAFD_finish"></ul>');
document.getElementById('closeAFD_finish').innerHTML += '<span id="closeAFD_finished_wrapper"><span id="closeAFD_finished_main" style="display:none"><li id="closeAFD_done"><b>Done (<a href="/wiki/'+encodeURI(closeAFD_PageName)+'?action=purge" title="'+closeAFD_PageName+'">Reload page</a>)</b></li></span></span>';
AFDpage = closeAFD_getPageText(closeAFD_PageName);
oldlogpage = closeAFD_getPageText(oldlog);
newlogpage = closeAFD_getPageText(newlog);
if (newlogpage == '' || oldlogpage == '') {
jsMsg('<span style="color:red; font-size:120%">Log page doesn\'t seem to exist!</span>');
return;
}
var regexpagename = closeAFD_PageName.replace(/([\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E])/g, "\\$1");
regexpagename = regexpagename.replace(/ /g, "[\\s_]");
var rplstr = new RegExp("(\\{\\{" + regexpagename + "\\}\\})", "gi");
oldlogpage = oldlogpage.replace(rplstr, "<!-- $1 -->");
newlogreg = new RegExp("<!-- Add new entries to the TOP of the following list -->", "i");
if (!newlogreg.test(newlogpage)) {
jsMsg('<div style="color:red"><b><a href="/wiki/'+encodeURI(newlog)+'" title="'+newlog+'">'+newlog+'</a> is missing the <tt><!-- Add new entries to the TOP of the following list --></tt> above the AFD tranclusions! Please add it.<br/>Unable to relist. Aborting.</b></div>');
return;
}
newlogpage = newlogpage.replace(newlogreg, "<!-- Add new entries to the TOP of the following list -->\n{"+"{"+closeAFD_PageName+"}}<!--Relisted-->");
AFDpage += '\n{'+'{subst:relist}}';
AFDpage = AFDpage.replace(/Wikipedia:Articles for deletion\/Log\/\d{4} \D{4,9} \d{1,2}#/i, newlog+"#");
token = closeAFD_getToken(true);
closeAFD_editPage(newlog, newlogpage, token, "Relisting [[" + closeAFD_PageName + "]]");
closeAFD_editPage(oldlog, oldlogpage, token, "Relisting [[" + closeAFD_PageName + "]]");
closeAFD_editPage(closeAFD_PageName, AFDpage, token, "Relisting debate");
document.getElementById('closeAFD_finished_main').style.display = '';
}
function closeAFD_init() {
if (!wfSupportsAjax()) {
jsMsg('<span style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the closeAFD script.</span>');
return;
}
form = '<div id="closeAFD_initialform">'+
'<h3>Closing '+closeAFD_PageName+'</h3>'+
'<label for="closeAFD_reason">Additional closing rationale (optional):</label><input type="text" id="closeAFD_reason" name="closeAFD_reason" />'+
'<label for="closeAFD_speedy">Speedy:</label><input type="checkbox" id="closeAFD_speedy" name="closeAFD_speedy" /><br /><br />'+
'<input type="button" id="closeAFD_delete_button" name="closeAFD_delete_button" value="Delete" onclick="closeAFD_close(\'delete\')" />'+
'<input type="button" id="closeAFD_keep_button" name="closeAFD_keep_button" value="Keep" onclick="closeAFD_close(\'keep\')" />'+
'<input type="button" id="closeAFD_noconsensus_button" name="closeAFD_noconsensus_button" value="No consensus" onclick="closeAFD_close(\'no consensus\')" />'+
'<input type="button" id="closeAFD_redirect_button" name="closeAFD_redirect_button" value="Redirect" onclick="closeAFD_prompt(\'redirect\')" />'+
'<input type="button" id="closeAFD_merge_button" name="closeAFD_merge_button" value="Merge" onclick="closeAFD_prompt(\'merge\')" />'+
'<input type="button" id="closeAFD_other_button" name="closeAFD_other_button" value="Other" onclick="closeAFD_other()" /><br />'+
'<label for="closeAFD_deleteredir">Delete redirects:</label><input type="checkbox" id="closeAFD_deleteredir" name="closeAFD_deleteredir" />'+
'<input type="hidden" value="0" id="closeAFD_dodelete" name="closeAFD_dodelete" /></div><div id="closeAFD_extra"></div>';
jsMsg(form);
if (!closeAFD_isAdmin) {
document.getElementById('closeAFD_delete_button').disabled = true;
document.getElementById('closeAFD_deleteredir').disabled = true;
}
}
function closeAFD_prompt(type) {
document.getElementById('closeAFD_extra').innerHTML += '<br /><label for="closeAFD_prompt">Target for '+type+': </label><input type="text" id="closeAFD_prompt" name="closeAFD_prompt" /><br />';
if (type == 'redirect') {
document.getElementById('closeAFD_extra').innerHTML += '<label for="closeAFD_delete_first">Delete before redirecting: </label><input type="checkbox" id="closeAFD_delete_first" name="closeAFD_delete_first" />';
}
document.getElementById('closeAFD_extra').innerHTML += '<input type="button" id="closeAFD_prompt_button" name="closeAFD_prompt_button" value="Submit" onclick="closeAFD_close(\''+type+'\')" />';
if (!closeAFD_isAdmin && type == 'redirect') {
document.getElementById('closeAFD_delete_first').disabled = true;
}
}
function closeAFD_other() {
document.getElementById('closeAFD_extra').innerHTML += '<br /><br /><label for="closeAFD_otherclose">Other: </label><input type="text" id="closeAFD_otherclose" name="closeAFD_otherclose" />'+
'<input type="button" id="closeAFD_other_delete_button" name="closeAFD_other_delete_button" value="Delete article" onclick="closeAFD_otherdelete()" />'+
'<input type="button" id="closeAFD_other_nodelete_button" name="closeAFD_other_nodelete_button" value="Don\'t delete" onclick="closeAFD_otherkeep()" />';
if (!closeAFD_isAdmin) {
document.getElementById('closeAFD_other_delete_button').disabled = true;
}
}
function closeAFD_otherdelete() {
document.getElementById('closeAFD_dodelete').value = 1;
close = document.getElementById('closeAFD_otherclose').value;
closeAFD_close(close);
}
function closeAFD_otherkeep() {
close = document.getElementById('closeAFD_otherclose').value;
closeAFD_close(close);
}
function closeAFD_close(close) {
if (typeof(closeAFD_redirectlimit) == "undefined") {
closeAFD_redirectlimit = 50;
}
deleteredirects = false;
if (document.getElementById('closeAFD_deleteredir').checked) {
deleteredirects = true;
}
closetype = close;
var dodelete = false;
if (closetype == "delete" || document.getElementById('closeAFD_dodelete').value == 1) {
dodelete = true;
}
var reason = document.getElementById('closeAFD_reason').value;
if (reason != '') {
reason = ' '+reason;
}
if (closetype == "redirect" || closetype == "merge") {
var target = document.getElementById('closeAFD_prompt').value;
if (target == null || target == '') {
jsMsg('<div style="color:red; font-size:120%">No target entered.</div>')
return;
}
close+= " to [["+target+"]]";
}
if (closetype == "redirect" && document.getElementById('closeAFD_delete_first').checked == true) {
dodelete = true;
closeAFD_deletenredirect = target;
}
if (document.getElementById('closeAFD_speedy').checked == true) {
close = "speedy "+close;
}
jsMsg('<ul id="closeAFD_status"></ul><ul id="closeAFD_finish"></ul>');
document.getElementById('closeAFD_finish').innerHTML += '<span id="closeAFD_finished_wrapper"><span id="closeAFD_finished_main" style="display:none"><li id="closeAFD_done"><b>Done (<a href="/wiki/'+encodeURI(closeAFD_PageName)+'?action=purge" title="'+closeAFD_PageName+'">Reload page</a>)</b></li></span></span>';
var AFDpage = closeAFD_getPageText(closeAFD_PageName);
closeAFD_nomdate = /\d{1,2} \D{4,9} \d{4} \(UTC\)/.exec(AFDpage);
AFDpage = AFDpage.replace(/{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD\|(\w|\?)}}\n/i,"");
if (closeAFD_isAdmin) {
AFDpage = "{"+"{subst:at}} '''"+close+"'''."+reason+' ~~'+'~~\n' + AFDpage + '\n{'+'{subst:ab}}';
} else {
AFDpage = "{"+"{subst:at}} '''"+close+"'''."+reason+' ([[Wikipedia:non-admin closure|non-admin closure]]) ~~'+'~~\n' + AFDpage + '\n{'+'{subst:ab}}';
}
token = closeAFD_getToken(true);
pagetitle = wgTitle.substring(wgTitle.indexOf('/')+1);
debatename = pagetitle;
if (pagetitle.indexOf("nomination)") != -1) {
pagetitle = pagetitle.replace(/ \([^\)\(]*? nomination\)\s*$/, '');
}
closeAFD_editPage(closeAFD_PageName, AFDpage, token, "Closing debate, result was " + close);
var AFDlink = '[['+closeAFD_PageName+']]';
if (dodelete) {
if (deleteredirects) {
redirects = closeAFD_getRedirects(pagetitle);
if (redirects == "toomanyredir") {
document.getElementById('closeAFD_status').innerHTML += '<li>Number of redirects exceeds limit of '+closeAFD_redirectlimit+'</li>';
} else if (redirects == "noredir") {
document.getElementById('closeAFD_status').innerHTML += '<li>No redirects</li>';
} else {
closeAFD_deleteRedirects(pagetitle, redirects, token);
}
}
closeAFD_deletePage(pagetitle, encodeURIComponent(token), AFDlink, false, false);
closeAFD_deletePage("Talk:"+pagetitle, encodeURIComponent(token), AFDlink, false, false);
}
var articlepage = ''
if (closetype != "redirect" && closetype != "delete" && !dodelete ) {
articlepage = closeAFD_getPageText(pagetitle);
articlepage = articlepage.replace(/<!-- Please do not remove or change this AfD message until the issue is settled -->[\S\s]*?<!-- End of AfD message, feel free to edit beyond this point -->\n/, '');
}
if (closetype == "redirect") {
articlepage = "#REDIRECT [["+target+"]]";
}
if (!dodelete) {
if (closeAFD_nomdate == null) {
closeAFD_nomdate = prompt("Nomination date?", '');
}
var talkpage = '';
if (closetype != "redirect") {
talkpage = closeAFD_getPageText("Talk:"+pagetitle);
talkpage = "{"+"{oldafdfull| date = "+closeAFD_nomdate+" | result = '''"+close+"''' | page = "+pagetitle+" }}\n\n" + talkpage;
} else {
talkpage = "{"+"{oldafdfull| date = "+closeAFD_nomdate+" | result = '''"+close+"''' | page = "+pagetitle+" }}";
}
if (closetype == "merge") {
var today = new Date();
var monthnames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
month = monthnames[today.getUTCMonth()]
day = today.getUTCDate()
if (day < 10) {
day = "0"+day;
}
year = today.getUTCFullYear();
datestring = day + " " + month + " " + year;
articlepage = "{"+"{afd-mergeto|"+target+"|"+debatename+"|"+datestring+"}}\n\n" + articlepage;
var targettalkpage = closeAFD_getPageText("Talk:"+target);
targettalkpage = "{"+"{afd-mergefrom|"+pagetitle+"|"+debatename+"|"+datestring+"}}\n\n" + targettalkpage;
closeAFD_editPage("Talk:"+target, targettalkpage, token, AFDlink + " closed as " + close);
}
closeAFD_editPage(pagetitle, articlepage, token, AFDlink + " closed as " + close);
closeAFD_editPage("Talk:"+pagetitle, talkpage, token, AFDlink + " closed as " + close);
}
document.getElementById('closeAFD_finished_main').style.display = '';
}
function closeAFD_getPageText(title) {
document.getElementById('closeAFD_status').innerHTML += '<li id="closeAFD_get'+escape(title)+'">Getting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
if (pageid == "-1") {
document.getElementById('closeAFD_get'+escape(title)).innerHTML = '<a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> does not exist';
delete req;
return '';
}
pagetext = response['query']['pages'][pageid]['revisions'][0]['*'];
delete req;
document.getElementById('closeAFD_get'+escape(title)).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
return pagetext;
}
function closeAFD_getToken(show) {
if (show) {
document.getElementById('closeAFD_status').innerHTML += '<li id="closeAFD_gettoken">Getting token</li>';
}
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles="+encodeURIComponent(closeAFD_PageName), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
token = response['query']['pages'][pageid]['edittoken'];
delete req;
if (show) {
document.getElementById('closeAFD_gettoken').innerHTML = 'Got token';
}
return token;
}
function closeAFD_getOldLog() {
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&format=json&list=embeddedin&eifilterredir=nonredirects&einamespace=4&bllimit=500&eititle="+encodeURIComponent(closeAFD_PageName), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
var logpage = ''
for (var i=0; i<response['query']['embeddedin'].length; i++) {
if (response['query']['embeddedin'][i]['title'].indexOf('Wikipedia:Articles for deletion/Log/') != -1) {
logpage = response['query']['embeddedin'][i]['title'];
}
}
delete req;
return logpage;
}
function closeAFD_editPage(title, newtext, token, summary) {
document.getElementById('closeAFD_finished_wrapper').innerHTML = '<span id="closeAFD_AJAX_finished_'+closeAFD_AJAXnumber+'" style="display:none">' + document.getElementById('closeAFD_finished_wrapper').innerHTML + '</span>';
var func_id = closeAFD_AJAXnumber;
closeAFD_AJAXnumber++;
document.getElementById('closeAFD_status').innerHTML += '<li id="closeAFD_edit'+escape(title)+'">Editing <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
var req = sajax_init_object();
var params = "action=edit&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&text="+encodeURIComponent(newtext)+"¬minor=1&unwatch=1&summary="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['edit']['result'] == "Success") {
document.getElementById('closeAFD_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
} else {
document.getElementById('closeAFD_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'];
}
}
catch(err) {
document.getElementById('closeAFD_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>';
}
document.getElementById('closeAFD_AJAX_finished_'+func_id).style.display = '';
delete req;
}
}
req.send(params)
}
function closeAFD_deletePage(title, token, summary, isredirect, retry) {
document.getElementById('closeAFD_finished_wrapper').innerHTML = '<span id="closeAFD_AJAX_finished_'+closeAFD_AJAXnumber+'" style="display:none">' + document.getElementById('closeAFD_finished_wrapper').innerHTML + '</span>';
var func_id = closeAFD_AJAXnumber;
closeAFD_AJAXnumber++;
if (!isredirect && !retry) {
document.getElementById('closeAFD_status').innerHTML += '<li id="closeAFD_delete'+escape(title)+'">Deleting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
} else if(!retry) {
closeAFD_redircount++;
thisredir = closeAFD_redircount
document.getElementById('redirstart').style.display = '';
document.getElementById('redirstart').innerHTML = 'Deleting redirect ' + closeAFD_redircount + ' of ' + closeAFD_redirtotal;
}
var req = sajax_init_object();
var params = "action=delete&format=json&token="+token+"&title="+encodeURIComponent(title)+"&reason="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['delete']['title']) {
if (!isredirect) {
document.getElementById('closeAFD_delete'+escape(title)).innerHTML = 'Deleted <a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
} else {
document.getElementById('redirend').style.display = '';
document.getElementById('redirend').innerHTML = 'Deleted redirect ' + thisredir + ' of ' + closeAFD_redirtotal;
}
}
}
catch(err) {
if (response['error']['code'] == "missingtitle") {
document.getElementById('closeAFD_delete'+escape(title)).innerHTML = '<a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> does not exist';
} else if(!isredirect) {
if (retry) {
document.getElementById('closeAFD_delete'+escape(title)).innerHTML = '<span style="color:red"><b>Deletion error on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'] + '</b></span>';
} else {
closeAFD_deletePage(title, token, summary, false, true);
}
} else {
if (retry) {
document.getElementById('closeAFD_status').innerHTML += '<li><span style="color:red"><b>Deletion error on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'] + '</b></span></li>';
} else {
closeAFD_deletePage(title, token, summary, true, true);
}
}
}
document.getElementById('closeAFD_AJAX_finished_'+func_id).style.display = '';
delete req;
if (!isredirect) {
closeAFD_deletecount++;
}
if (closeAFD_deletenredirect && closeAFD_deletecount == 2) {
articletext = '';
articletext = "#REDIRECT [["+closeAFD_deletenredirect+"]]";
var AFDlink = '[['+closeAFD_PageName+']]';
token = closeAFD_getToken(false);
closeAFD_editPage(title, articletext, token, AFDlink + " closed as redirect to [["+closeAFD_deletenredirect+"]]")
}
}
}
req.send(params)
}
function closeAFD_getRedirects(page) {
document.getElementById('closeAFD_status').innerHTML += '<li id="closeAFD_getredir">Getting redirects</li>';
var url = wgScriptPath + "/api.php?action=query&format=json&action=query&list=backlinks&bltitle="+encodeURIComponent(page)+"&blfilterredir=redirects&bllimit="+closeAFD_redirectlimit
var req = sajax_init_object();
req.open("GET", url, false);
req.send(null);
var response = eval('(' + req.responseText + ')');
if (typeof(response['query-continue']) != "undefined") {
return "toomanyredir";
}
if (typeof(response['query']) == "undefined") {
return "noredir";
}
var redirects = new Array();
for (var i=0; i<response['query']['backlinks'].length; i++) {
redirects[i] = response['query']['backlinks'][i]['title'];
}
delete req;
document.getElementById('closeAFD_getredir').innerHTML = 'Got '+redirects.length+' redirects';
closeAFD_redirtotal = redirects.length;
return redirects;
}
function closeAFD_deleteRedirects(pagetitle, redirects, token) {
summary = "Deleting redirects to \""+pagetitle+"\" after [["+closeAFD_PageName+"]]";
document.getElementById('closeAFD_status').innerHTML += '<li id="redirstart" style="display:none;"></li><li id="redirend" style="display:none;"></li>';
for (var i=0; i<closeAFD_redirtotal; i++) {
setTimeout("closeAFD_deletePage('"+redirects[i].replace(/'/, "\'")/*'*/+"', '"+encodeURIComponent(token)+"', '"+summary+"', true, false)", 500*closeAFD_redircount );
}
}
function closeAFD_addLink() {
addPortletLink("p-cactions", "javascript:closeAFD_init()", "Close", "ca-closeAFD", "Close AFD");
addPortletLink("p-cactions", "javascript:closeAFD_relist()", "Relist", "ca-closeAFD-relist", "Relist AFD");
}
addOnloadHook(closeAFD_addLink);
}
////////////////////////////////////////////
//
// Yet another AfC helper script
// v.4.0.5
// Adapted from [[User:Mr.Z-man/closeAFD]]
//
////////////////////////////////////////////
if (wgPageName.indexOf('Wikipedia:Articles_for_creation/Redirects') != -1) {
var afcHelper_RedirectPageName = wgPageName.replace(/_/g, ' ');
var afcHelper_RedirectSubmissions = new Array();
var afcHelper_RedirectSections = new Array();
var afcHelper_numTotal = 0;
var afcHelper_Redirect_AJAXnumber = 0;
var afcHelper_Submissions = new Array();
var afcHelper_redirectDecline_reasonhash = {
'exists' : 'The title you suggested already exists on Wikipedia',
'blank' : 'We cannot accept empty submissions',
'notarget': ' A redirect cannot be created unless the target is an existing article. Either you have not specified the target, or the target does not exist',
'unlikely': 'The title you suggested seems unlikely. Could you provide a source showing that it is a commonly used alternate name?',
'custom': ''
};
var afcHelper_categoryDecline_reasonhash = {
'exists' : 'The category you suggested already exists on Wikipedia',
'blank' : 'We cannot accept empty submissions.',
'unlikely': 'It seems unlikely that there are enough pages to support this category. Could you show that there are a number of pages that belong to this category?',
'custom': ''
};
function afcHelper_redirect_init(){
afcHelper_RedirectSubmissions = new Array();
afcHelper_RedirectSections = new Array();
afcHelper_numTotal = 0;
var pagetext = afcHelper_redirect_getPageText(afcHelper_RedirectPageName, false);
// let the parsing begin.
// first, strip out the parts before the first section.
var section_re = /==[^=]*==/;
pagetext = pagetext.substring(pagetext.search(section_re));
// second, strip out the parts that has been mass-moderated.
// first find the place of mass moderation
var mass_re = /\{\{(?:(?:afc-c|afc top)\|\s*m|afc mm)/i;
if(mass_re.test(pagetext)){
var mass_mods = mass_re.exec(pagetext);
for(var i = 0; i < mass_mods.length; i++){
var mass_mod_start = pagetext.indexOf(mass_mods[i]);
var mass_mod_end = pagetext.substring(mass_mod_start).search(/\{\{(?:afc-c\|\s*b|afc b)/i);
mass_mod_end += mass_mod_start;
mass_mod_end = pagetext.indexOf('\}\}', mass_mod_end);
pagetext = pagetext.substring(0, mass_mod_start) + pagetext.substring(mass_mod_end + 2);
}
}
// now parse it into sections.
section_re = /==[^=]*==/g;
var section_headers = pagetext.match(section_re);
for(var i = 0; i < section_headers.length; i++){
var section_start = pagetext.indexOf(section_headers[i]);
var section_text = pagetext.substring(section_start);
if(i < section_headers.length-1){
var section_end = section_text.indexOf(section_headers[i+1]);
section_text = section_text.substring(0, section_end);
}
afcHelper_RedirectSections.push(section_text);
}
// parse the sections.
for(var i = 0; i < afcHelper_RedirectSections.length; i++){
var closed = /\{\{\s*afc(?!\s+comment)/i.test(afcHelper_RedirectSections[i]);
if(!closed){
// parse.
var header = afcHelper_RedirectSections[i].match(section_re)[0];
if(header.search(/Redirect request/i) != -1){
var wikilink_re = /\[\[[^\[\]]+\]\]/g;
var links = header.match(wikilink_re);
for(var j = 0; j < links.length; j++){
links[j]=links[j].replace(/[\[\]]/g, '');
if(links[j].charAt(0) == ':')
links[j] = links[j].substring(1);
}
var re = /Target of redirect:\s*\[\[([^\[\]]*)\]\]/i;
re.test(afcHelper_RedirectSections[i]);
var to = RegExp.$1;
var submission = {
type: 'redirect',
from: new Array(),
section: i,
to: to,
title: to
};
for(var j = 0; j < links.length; j++){
var sub = {
type: 'redirect',
to: to,
id: afcHelper_numTotal,
title: links[j],
action: ''
};
submission.from.push(sub);
afcHelper_Submissions.push(sub);
afcHelper_numTotal++;
}
afcHelper_RedirectSubmissions.push(submission);
}
else if(header.search(/Category request/i) != -1){
var wikilink_re = /\[\[[^\[\]]+\]\]/g;
var links = header.match(wikilink_re);
// figure out the parent category.
var idx = afcHelper_RedirectSections[i].substring(header.length).search(/\[\[\s*:\s*(Category:[^\]\[]*)\]\]/i);
var parent = '';
if(idx != -1)
parent = RegExp.$1;
parent = parent.replace(/:\s*/g, ':');
for(var j = 0; j < links.length; j++){
links[j]=links[j].replace(/[\[\]]/g, '');
links[j]=links[j].replace(/Category\s*:\s*/gi, 'Category:');
if(links[j].charAt(0) == ':')
links[j] = links[j].substring(1);
var submission = {
type: 'category',
title: links[j],
section: i,
id: afcHelper_numTotal,
action: '',
parent: parent
};
afcHelper_numTotal++;
afcHelper_RedirectSubmissions.push(submission);
afcHelper_Submissions.push(submission);
}
}
}
}
var text = '<h3>Reviewing AFC redirect requests</h3>';
// now layout the text.
for(var k = 0; k < afcHelper_RedirectSubmissions.length; k++){
text += '<ul>';
if(afcHelper_RedirectSubmissions[k].type == 'redirect'){
text += '<li>Redirect(s) to <a href="/wiki/' + encodeURIComponent(afcHelper_RedirectSubmissions[k].to)
+ '">' + afcHelper_RedirectSubmissions[k].to + '</a>: <ul>';
for(var l = 0; l < afcHelper_RedirectSubmissions[k].from.length; l++){
var from = afcHelper_RedirectSubmissions[k].from[l];
text += "<li>From: " + from.title
+'<br/><label for="afcHelper_redirect_action_'+ from.id+'">Action: </label>'
+ afcHelper_redirect_generateSelect('afcHelper_redirect_action_'+ from.id,
[{ label: 'Accept', value: 'accept' },
{ label: 'Decline', value: 'decline' },
{ label: 'Comment', value: 'comment' },
{ label: 'None', selected : true, value: 'none' }
], 'afcHelper_redirect_onActionChange(' + from.id + ')')
+ '<div id="afcHelper_redirect_extra_' + from.id + '"></div></li>';
}
text += '</ul></li>';
}
else{
text += '<li>Category submission: '+ afcHelper_RedirectSubmissions[k].title;
text += '<br/> <label for="afcHelper_redirect_action_'+ afcHelper_RedirectSubmissions[k].id+'">Action: </label>'
+ afcHelper_redirect_generateSelect('afcHelper_redirect_action_'+ afcHelper_RedirectSubmissions[k].id,
[{ label: 'Accept', value: 'accept' },
{ label: 'Decline', value: 'decline' },
{ label: 'Comment', value: 'comment' },
{ label: 'None', selected : true, value: 'none' }
], 'afcHelper_redirect_onActionChange(' + afcHelper_RedirectSubmissions[k].id + ')')
+ '<div id="afcHelper_redirect_extra_' + afcHelper_RedirectSubmissions[k].id + '"></div></li>';
}
text += '</ul>';
}
text += '<input type="button" id="afcHelper_redirect_done_button" name="afcHelper_redirect_done_button" value="Done" onclick="afcHelper_redirect_performActions()" />';
jsMsg(text);
}
function afcHelper_redirect_onActionChange(id){
var extra = document.getElementById("afcHelper_redirect_extra_" + id);
var selectValue = document.getElementById("afcHelper_redirect_action_"+id).value;
if(selectValue == 'none')
extra.innerHTML = '';
else if(selectValue == 'accept'){
if(afcHelper_Submissions[id].type == 'redirect'){
extra.innerHTML = '<label for="afcHelper_redirect_from_' + id + '">From: </label><input type="text" '+
'name="afcHelper_redirect_from_' + id + '" id="afcHelper_redirect_from_' + id + '" value="'
+ afcHelper_Submissions[id].title + '" />';
extra.innerHTML += ' <label for="afcHelper_redirect_to_' + id + '">To: </label><input type="text" '+
'name="afcHelper_redirect_to_' + id + '" id="afcHelper_redirect_to_' + id + '" value="'
+ afcHelper_Submissions[id].to + '" />';
extra.innerHTML += '<label for="afcHelper_redirect_append_'+ id +'">Template to append: </label>'
+ afcHelper_redirect_generateSelect('afcHelper_redirect_append_'+
id, [
{ label: 'R from alternative name', value: 'R from alternative name' },
{ label: 'R from alternative language', value: 'R from alternative language' },
{ label: 'R from alternative spelling', value: 'R from alternative spelling' },
{ label: 'R to section', value: 'R to section' },
{ label: 'R to disambiguation page', value: 'R to disambiguation page' },
{ label: 'R from title with diacritics', value: 'R from title with diacritics'},
{ label: 'Custom - prompt me', value: 'custom' },
{ label: 'None', selected : true, value: 'none' }
]);
}
else{
extra.innerHTML = '<label for="afcHelper_redirect_name_' + id + '">name: </label><input type="text" '+
'name="afcHelper_redirect_name_' + id + '" id="afcHelper_redirect_name_' + id + '" value="'
+ afcHelper_Submissions[id].title + '" />';
extra.innerHTML += '<label for="afcHelper_redirect_parent_' + id +'">Parent category:</label>'
+ '<input type="text" id="afcHelper_redirect_parent_' + id +'" name="afcHelper_redirect_parent_' + id +
'" value="' + afcHelper_Submissions[id].parent + '" />';
}
extra.innerHTML += '<label for="afcHelper_redirect_comment_' + id +'">Comment:</label>'
+ '<input type="text" id="afcHelper_redirect_comment_' + id +'" name="afcHelper_redirect_comment_' + id +'"/>';
} else if(selectValue == 'decline'){
if(afcHelper_Submissions[id].type == 'redirect'){
extra.innerHTML = '<label for="afcHelper_redirect_decline_'+ id +'">Reason for decline: </label>'
+ afcHelper_redirect_generateSelect('afcHelper_redirect_decline_'+
id, [
{ label: 'Already exists', value: 'exists' },
{ label: 'Blank request', value: 'blank' },
{ label: 'No valid target specified', value: 'notarget' },
{ label: 'Unlikely search term', value: 'unlikely' },
{ label: 'Custom - reason below', selected : true, value: 'custom' }
]);
}
else {
extra.innerHTML = '<label for="afcHelper_redirect_decline_'+ id +'">Reason for decline: </label>'
+ afcHelper_redirect_generateSelect('afcHelper_redirect_decline_'+
id, [
{ label: 'Already exists', value: 'exists' },
{ label: 'Blank request', value: 'blank' },
{ label: 'Unlikely category', value: 'unlikely' },
{ label: 'Custom - reason below', selected : true, value: 'custom' }
]);
}
extra.innerHTML += '<label for="afcHelper_redirect_comment_' + id +'">Comment:</label>'
+ '<input type="text" id="afcHelper_redirect_comment_' + id +'" name="afcHelper_redirect_comment_' + id +'"/>';
} else{
extra.innerHTML = '<label for="afcHelper_redirect_comment_' + id +'">Comment:</label>'
+ '<input type="text" id="afcHelper_redirect_comment_' + id +'" name="afcHelper_redirect_comment_' + id +'"/>';
}
}
function afcHelper_redirect_performActions(){
// Load all of the data.
for(var i = 0; i < afcHelper_Submissions.length; i++){
var action = document.getElementById("afcHelper_redirect_action_" + i).value;
afcHelper_Submissions[i].action = action;
if(action == 'none')
continue;
if(action == 'accept'){
if(afcHelper_Submissions[i].type == 'redirect'){
afcHelper_Submissions[i].title = document.getElementById("afcHelper_redirect_from_" + i).value;
afcHelper_Submissions[i].to = document.getElementById("afcHelper_redirect_to_" + i).value;
afcHelper_Submissions[i].append = document.getElementById("afcHelper_redirect_append_" + i).value;
if(afcHelper_Submissions[i].append == 'custom'){
afcHelper_Submissions[i].append = prompt("Please enter the template to append for " + afcHelper_Submissions[i].title
+ ". Do not include the curly brackets.");
}
if(afcHelper_Submissions[i].append == 'none' || afcHelper_Submissions[i].append == null)
afcHelper_Submissions[i].append = '';
else
afcHelper_Submissions[i].append = '\{\{' + afcHelper_Submissions[i].append + '\}\}';
}
else{
afcHelper_Submissions[i].title = document.getElementById("afcHelper_redirect_name_" + i).value;
afcHelper_Submissions[i].parent = document.getElementById("afcHelper_redirect_parent_" + i).value;
}
}
else if (action == 'decline'){
afcHelper_Submissions[i].reason = document.getElementById('afcHelper_redirect_decline_' + i).value;
}
afcHelper_Submissions[i].comment = document.getElementById("afcHelper_redirect_comment_" + i).value;
}
// Data loaded. Show progress screen and get edit token and WP:AFC/R page text.
jsMsg('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="/wiki/'+encodeURI(afcHelper_RedirectPageName)+'?action=purge" title="'+afcHelper_RedirectPageName+'">Reload page</a>)</b></li></span></span>';
var token = afcHelper_redirect_getToken(true);
var pagetext = afcHelper_redirect_getPageText(afcHelper_RedirectPageName, true);
var totalaccept = 0;
var totaldecline = 0;
var totalcomment = 0;
// traverse the submissions and locate the relevant sections.
for(var i = 0; i < afcHelper_RedirectSubmissions.length; i++){
var sub = afcHelper_RedirectSubmissions[i];
if(pagetext.indexOf(afcHelper_RedirectSections[sub.section]) == -1){
// Someone has modified the section in the mean time. Skip.
document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': Cannot find section. Perhaps it was modified in the mean time?</li>';
continue;
}
var text = afcHelper_RedirectSections[sub.section];
var startindex = pagetext.indexOf(afcHelper_RedirectSections[sub.section]);
var endindex = startindex + text.length;
// First deal with cats. These are easy.
if(sub.type == 'category'){
if(sub.action == 'accept'){
var cattext = '<!--Created by WP:AFC -->';
if(sub.parent != '' )
cattext = '\[\['+ sub.parent + '\]\]';
afcHelper_redirect_editPage(sub.title, cattext, token, 'Created via \[\[WP:AFC|Articles for Creation\]\] (\[\[WP:WPAFC|you can help!\]\])', true);
var talktext = '\{\{subst:WPAFC/article|class=Cat\}\}';
var talktitle = sub.title.replace(/Category:/gi, 'Category talk:');
afcHelper_redirect_editPage(talktitle, talktext, token, 'Placing WPAFC project banner', true);
var header = text.match(/==[^=]*==/)[0];
text = header + "\n\{\{AfC-c|a\}\}\n" + text.substring(header.length);
if(sub.comment != '')
text += '\n*\{\{subst:afc category|accept|2=' + sub.comment +'\}\} \~\~\~\~\n';
else
text += '\n*\{\{subst:afc category\}\} \~\~\~\~\n';
text += '\{\{AfC-c|b\}\}\n';
totalaccept ++;
}
else if (sub.action == 'decline'){
var header = text.match(/==[^=]*==/)[0];
var reason = afcHelper_categoryDecline_reasonhash[sub.reason];
if(reason == '')
reason = sub.comment;
else if (sub.comment != '')
reason = reason + ': ' + sub.comment;
if(reason == ''){
document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': No decline reason specified.</li>';
continue;
}
text = header + "\n\{\{AfC-c|d\}\}\n" + text.substring(header.length);
if(sub.comment == '')
text += '\n*\{\{subst:afc category|' + sub.reason +'\}\} \~\~\~\~\n';
else
text += '\n*\{\{subst:afc category|decline|2=' + reason +'\}\} \~\~\~\~\n';
text += '\{\{AfC-c|b\}\}\n';
totaldecline++;
}
else if (sub.action == 'comment'){
if(sub.comment != '')
text += '\n*\{\{afc comment|1=' + sub.comment +'\~\~\~\~\}\}\n';
totalcomment++;
}
}
else {
// redirects......
var acceptcomment = '';
var declinecomment = '';
var othercomment = '';
var acceptcount = 0, declinecount = 0, commentcount = 0, hascomment = false;
for(var j = 0; j < sub.from.length; j++){
var redirect = sub.from[j];
if(redirect.action == 'accept'){
var redirecttext = '#REDIRECT \[\[' + redirect.to + '\]\]\n' + redirect.append;;
afcHelper_redirect_editPage(redirect.title, redirecttext, token, 'Created via \[\[WP:AFC|Articles for Creation\]\] (\[\[WP:WPAFC|you can help!\]\])', true);
var talktext = '\{\{subst:WPAFC/redirect\}\}';
var talktitle = 'Talk:' + redirect.title;
afcHelper_redirect_editPage(talktitle, talktext, token, 'Placing WPAFC project banner', true);
acceptcomment += redirect.title + " → " + redirect.to;
if(redirect.comment != ''){
acceptcomment += ': ' + redirect.comment + '; ';
hascomment = true;
} else
acceptcomment += '; ';
acceptcount ++;
}
else if (redirect.action == 'decline'){
var reason = afcHelper_redirectDecline_reasonhash[redirect.reason];
if(reason == '')
reason = redirect.comment;
else if (redirect.comment != '')
reason = reason + ': ' + redirect.comment;
if(reason == ''){
document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + redirect.title + ': No decline reason specified.</li>';
continue;
}
declinecomment += redirect.title + " → " + redirect.to + ": " + reason + "; ";
declinecount ++;
}
else if (redirect.action == 'comment'){
othercomment += redirect.title + ": " + redirect.comment + ", ";
commentcount ++;
}
}
var reason = '';
if(acceptcount > 0)
reason += '\n*\{\{subst:afc redirect|accept|2=' + acceptcomment + ' Thank you for your contributions to Wikipedia!\}\} \~\~\~\~';
if (declinecount > 0)
reason += '\n*\{\{subst:afc redirect|decline|2=' + declinecomment + '\}\} \~\~\~\~';
if(commentcount > 0)
reason += '\n*\{\{afc comment|1=' + othercomment + '\~\~\~\~\}\}';
reason += '\n';
if(!hascomment && acceptcount == sub.from.length){
if(acceptcount > 1)
reason = '\n*\{\{subst:afc redirect|all\}\} \~\~\~\~\n';
else
reason = '\n*\{\{subst:afc redirect\}\} \~\~\~\~\n';
}
if(acceptcount + declinecount + commentcount > 0){
if(acceptcount + declinecount == sub.from.length){
// Every request disposed of. Close.
var header = text.match(/==[^=]*==/)[0];
if(acceptcount > declinecount)
text = header + "\n\{\{AfC-c|a\}\}\n" + text.substring(header.length);
else
text = header + "\n\{\{AfC-c|d\}\}\n" + text.substring(header.length);
text += reason;
text += '\{\{AfC-c|b\}\}\n';
}
else
text += reason +'\n';
}
totalaccept += acceptcount;
totaldecline += declinecount;
totalcomment += commentcount;
}
pagetext = pagetext.substring(0, startindex) + text + pagetext.substring(endindex);
}
var summary = "Updating submission status:";
if(totalaccept > 0)
summary += " accepting " + totalaccept + " request" + (totalaccept > 1 ? 's' : '');
if(totaldecline > 0){
if(totalaccept > 0)
summary += ',';
summary += " declining " + totaldecline + " request" + (totaldecline > 1 ? 's' : '');
}
if(totalcomment > 0){
if(totalaccept > 0 || totaldecline > 0)
summary += ',';
summary += " commenting on " + totalcomment + " request" + (totalcomment > 1 ? 's' : '');
}
afcHelper_redirect_editPage(afcHelper_RedirectPageName, pagetext, token, summary, false);
document.getElementById('afcHelper_finished_main').style.display = '';
}
function afcHelper_redirect_getToken(show) {
if (show) {
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_gettoken">Getting token</li>';
}
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles="+encodeURIComponent(afcHelper_RedirectPageName), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
token = response['query']['pages'][pageid]['edittoken'];
delete req;
if (show) {
document.getElementById('afcHelper_gettoken').innerHTML = 'Got token';
}
return token;
}
function afcHelper_redirect_editPage(title, newtext, token, summary, createonly) {
document.getElementById('afcHelper_finished_wrapper').innerHTML = '<span id="afcHelper_AJAX_finished_'+afcHelper_Redirect_AJAXnumber+'" style="display:none">' + document.getElementById('afcHelper_finished_wrapper').innerHTML + '</span>';
var func_id = afcHelper_Redirect_AJAXnumber;
afcHelper_Redirect_AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_edit'+escape(title)+'">Editing <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
var req = sajax_init_object();
var params = "action=edit&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&text="+encodeURIComponent(newtext)+"¬minor=1&unwatch=1&summary="+encodeURIComponent(summary);
if(createonly)
params += "&createonly=1";
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['edit']['result'] == "Success") {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
} else {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'];
}
}
catch(err) {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>';
}
document.getElementById('afcHelper_AJAX_finished_'+func_id).style.display = '';
delete req;
}
};
req.send(params);
}
function afcHelper_redirect_getPageText(title, show) {
if(show){
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_get'+escape(title)+'">Getting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
}
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
if (pageid == "-1") {
if(show){
document.getElementById('afcHelper_get'+escape(title)).innerHTML = '<a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> does not exist';
}
delete req;
return '';
}
pagetext = response['query']['pages'][pageid]['revisions'][0]['*'];
delete req;
if(show){
document.getElementById('afcHelper_get'+escape(title)).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
}
return pagetext;
}
function afcHelper_redirect_generateSelect(title, options, onchange){
var text = '<select name="' + title + '" id="' + title +'" ';
if(onchange != null)
text += 'onchange = "' + onchange + '" ';
text+= '>';
for(var i = 0; i < options.length; i ++){
var o = options[i];
text += '<option value="' + o.value + '" ';
if(o.selected)
text += 'selected="selected" ';
text += '>' + o.label + '</option>';
}
text += "</select>";
return text;
}
function afcHelper_redirect_addLink() {
addPortletLink("p-cactions", "javascript:afcHelper_redirect_init()", "Review", "ca-afcHelper", "Review");
}
addOnloadHook(afcHelper_redirect_addLink);
}
else if (wgPageName.indexOf('Wikipedia:Articles_for_creation/') != -1 || wgPageName.indexOf('Wikipedia_talk:Articles_for_creation/') != -1) {
var afcHelper_PageName = wgPageName.replace(/_/g, ' ');
var afcHelper_AJAXnumber = 0;
var afcHelper_submissionTitle = wgTitle.replace(/Articles for creation\//g, '');
var afcHelper_reasonhash = {
'v': 'submission is unsourced or contain only unreliable sources',
'blank': 'submission is blank',
'lang': 'submission is not in English',
'cv': 'submission is a copyright violation',
'exists': 'submission already exists in main space',
'dup': 'submission is a duplicate of another submission',
'coi': 'author appears to have a conflict of interest',
'redirect': 'submission is a redirect request',
'test': 'submission is a test edit',
'news': 'submission appears to be a news report of a single event',
'dict': 'submission is a dictionary definition',
'joke': 'submission appears to be a joke',
'blp': 'submission does not conform to BLP',
'neo': 'submission is a neologism',
'npov': 'submission is not written from a neutral point of view',
'adv': 'submission is written like an advertisement',
'context': 'submission provides insufficient context',
'mergeto': 'submission is too short but can be merged',
'plot': 'submission is a plot summary',
'essay': 'submission reads like an essay',
'not': 'submission is covered by WP:NOT',
'nn': 'subject appears to be non-notable',
'web': 'subject appears to be non-notable web content',
'prof': 'subject appears to be a non-notable academic',
'athlete': 'subject appears to be a non-notable athlete',
'music': 'subject appears to be a non-notable musical performer or work',
'film': 'subject appears to be a non-notable film',
'corp': 'subject appears to be a non-notable company or organization',
'bio': 'subject appears to be a non-notable person',
'reason': ''
};
function afcHelper_init() {
if (!wfSupportsAjax()) {
jsMsg('<span style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the afcHelper script v3.</span>');
return;
}
form = '<div id="afcHelper_initialform">'+
'<h3>Reviewing '+afcHelper_PageName+'</h3>'+
'<input type="button" id="afcHelper_accept_button" name="afcHelper_accept_button" value="Accept" onclick="afcHelper_prompt(\'accept\')" />'+
'<input type="button" id="afcHelper_decline_button" name="afcHelper_decline_button" value="Decline" onclick="afcHelper_prompt(\'decline\')" />'+
'<input type="button" id="afcHelper_hold_button" name="afcHelper_hold_button" value="Hold" onclick="afcHelper_prompt(\'hold\')" />'+
'<input type="button" id="afcHelper_comment_button" name="afcHelper_comment_button" value="Comment" onclick="afcHelper_prompt(\'comment\')" />'+
'<input type="button" id="afcHelper_mark_button" name="afcHelper_mark_button" value="Mark as reviewing" onclick="afcHelper_act(\'mark\')" />'+
'<div id="afcHelper_extra"></div>';
jsMsg(form);
}
function afcHelper_prompt(type) {
if(type == 'accept'){
var text = '<br /><br /> <h3>Accepting '+afcHelper_PageName+'</h3>'+
'<label for="afcHelper_movetarget">Move submission to: </label><input type="text" id="afcHelper_movetarget" name="afcHelper_movetarget" value="' +afcHelper_submissionTitle+'" />'+
'<br /><label for="afcHelper_assessment">Assessment (optional): </label>';
var assessmentSelect = afcHelper_generateSelect("afcHelper_assessment",
[{ label: 'B-class', value: 'B' },
{ label: 'C-class', value: 'C' },
{ label: 'Start-class', value: 'start' },
{ label: 'Stub-class', value: 'stub' },
{ label: 'List-class', value: 'list' },
{ label: 'Disambig-class', value: 'dab' },
{ label: 'Redirect-class', value: 'red' },
{ label: 'None', selected : true, value: '' }
], null);
text += assessmentSelect;
text += '<br /><label for="afcHelper_pageAppend">Append to page (optional): </label><textarea rows="3" cols="60" name="afcHelper_pageAppend" id="afcHelper_pageAppend"></textarea>'+
'<br /><label for="afcHelper_talkAppend">Append to talk page (optional): </label><textarea rows="3" cols="60" name="afcHelper_talkAppend" id="afcHelper_talkAppend"></textarea>';
document.getElementById('afcHelper_extra').innerHTML += text;
}
else if(type == 'decline' || type == 'hold'){
var text = '<br /><br /> <h3>' + (type == 'decline' ? 'Declining ' : 'Placing on hold ') +afcHelper_PageName+'</h3>'+
'<label for="afcHelper_reason">Reason for ' + type + ': </label>';
var reasonSelect = afcHelper_generateSelect("afcHelper_reason",
[{ label: 'v - submission is unsourced or contain only unreliable sources', value: 'v' },
{ label: 'blank - submission is blank', value: 'blank' },
{ label: 'lang - submission is not in English', value: 'lang' },
{ label: 'cv - submission is a copyright violation', value: 'cv' },
{ label: 'exists - submission already exists in main space', value: 'exists' },
{ label: 'dup - submission is a duplicate of another submission', value: 'dup' },
{ label: 'coi - author appears to have a conflict of interest', value: 'coi' },
{ label: 'redirect - submission is a redirect request', value: 'redirect' },
{ label: 'test - submission is a test edit', value: 'test' },
{ label: 'news - submission appears to be a news report of a single event', value: 'news' },
{ label: 'dict - submission is a dictionary definition', value: 'dict' },
{ label: 'joke - submission appears to be a joke', value: 'joke' },
{ label: 'blp - submission does not conform to BLP', value: 'blp' },
{ label: 'neo - submission is a neologism', value: 'neo' },
{ label: 'npov - submission is not written from a neutral point of view', value: 'npov' },
{ label: 'adv - submission is written like an advertisement', value: 'adv' },
{ label: 'context - submission provides insufficient context', value: 'context' },
{ label: 'mergeto - submission is too short but can be merged', value: 'mergeto' },
{ label: 'plot - submission is a plot summary', value: 'plot' },
{ label: 'essay - submission reads like an essay', value: 'essay' },
{ label: 'not - submission is covered by WP:NOT', value: 'not' },
{ label: 'nn - subject appears to be non-notable - consider using a more specialized decline reason', value: 'nn' },
{ label: 'web - subject appears to be non-notable web content', value: 'web' },
{ label: 'prof - subject appears to be a non-notable academic', value: 'prof' },
{ label: 'athlete - subject appears to be a non-notable athlete', value: 'athlete' },
{ label: 'music - subject appears to be a non-notable musical performer or work', value: 'music' },
{ label: 'film - subject appears to be a non-notable film', value: 'film' },
{ label: 'corp - subject appears to be a non-notable company or organization', value: 'corp' },
{ label: 'bio - subject appears to be a non-notable person', value: 'bio' },
{ label: 'Custom - reason below', selected : true, value: 'reason' }
], "afcHelper_onChange(this)");
text += reasonSelect;
text += '<br /><label for="afcHelper_comments">Additional comments (optional): </label><textarea rows="3" cols="60" name="afcHelper_comments" id="afcHelper_comments"></textarea>'+
'<label for="afcHelper_blank">Blank submission:</label><input type="checkbox" name="afcHelper_blank" id="afcHelper_blank" /><br/>' +
'<label for="afcHelper_notify">Notify author:</label><input type="checkbox" name="afcHelper_notify" id="afcHelper_notify" checked="checked" /><br/>';
document.getElementById('afcHelper_extra').innerHTML += text;
}
else if(type == 'comment'){
var text = '<br /><br /> <h3> Commenting on ' +afcHelper_PageName+'</h3>'+
'<br /><label for="afcHelper_comments">Comment: </label><textarea rows="3" cols="60" name="afcHelper_comments" id="afcHelper_comments"></textarea>';
document.getElementById('afcHelper_extra').innerHTML += text;
}
document.getElementById('afcHelper_extra').innerHTML += '<input type="button" id="afcHelper_prompt_button" name="afcHelper_prompt_button" value="Submit" onclick="afcHelper_act(\''+type+'\')" />';
}
function afcHelper_act(action) {
if(action == 'accept'){
var newtitle = document.getElementById("afcHelper_movetarget").value;
var assessment = document.getElementById("afcHelper_assessment").value;
var pageAppend = document.getElementById("afcHelper_pageAppend").value;
var talkAppend = document.getElementById("afcHelper_talkAppend").value;
jsMsg('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="/wiki/'+encodeURI(afcHelper_PageName)+'?action=purge" title="'+afcHelper_PageName+'">Reload page</a>)</b></li></span></span>';
var token = afcHelper_getToken(true);
var callback = function(){
var text = afcHelper_getPageText(newtitle);
var username ='';
// clean up page
var afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( afc_re.test( text ) ) {
var afctemplate = afc_re.exec(text)[0];
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if(author_re.test(afctemplate)){
var user = author_re.exec(afctemplate)[0];
username = user.split(/=/)[1];
username = username.replace(/\|/g,'');
var usertext = afcHelper_getPageText("User talk:"+username);
usertext += "\n== Your submission at \[\[WP:AFC|Articles for creation\]\] ==";
usertext += "\n\{\{subst:afc talk|1=" + newtitle + "|class=" + assessment + "\}\} \~\~\~\~";
afcHelper_editPage("User talk:"+username, usertext, token, 'Your submission at \[\[WP:AFC|Articles for creation\]\]');
}
}
var recenttext = afcHelper_getPageText("Wikipedia:Articles for creation/recent");
var newentry = "\{\{afc contrib|" + assessment + "|" + newtitle + "|" + username +"\}\}\n";
var lastentry = recenttext.lastIndexOf("\{\{afc contrib");
var firstentry = recenttext.indexOf("\{\{afc contrib");
recenttext = recenttext.substring(0, lastentry);
recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry);
afcHelper_editPage("Wikipedia:Articles for creation/recent", recenttext, token, 'Updating recent AFC creations');
var talktext = "\{\{talkheader\}\}\n\{\{subst:WPAFC/article|class=" + assessment + "\}\}";
talktext += "\n";
talktext += talkAppend;
afcHelper_editPage("Talk:"+newtitle, talktext, token, 'Placing WPAFC project banner');
while(afc_re.test(text)){
var startindex = text.search(afc_re);
var template = afc_re.exec(text)[0];
var endindex = startindex + template.length;
text = text.substring(0, startindex) + text.substring(endindex);
}
var cmt_re = /\{\{\s*afc comment\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
while(cmt_re.test(text)){
var startindex = text.search(cmt_re);
var template = cmt_re.exec(text)[0];
var endindex = startindex + template.length;
text = text.substring(0, startindex) + text.substring(endindex);
}
var afcindex = text.search(/\{\{afc/i);
while (afcindex != -1){
var endindex = text.indexOf("\}\}", afcindex + 2);
text = text.substring(0,afcindex) + text.substring(endindex+2);
afcindex = text.search(/\{\{afc/i);
}
if(text.indexOf("\<\!--- Important, do not remove this line before article has been created. ---\>") != -1){
var startindex = text.indexOf("\<\!--- Important, do not remove this line before article has been created. ---\>");
var endindex = text.indexOf(">", startindex);
text = text.substring(0, startindex) + text.substring(endindex+1);
}
// Remove line breaks.
text = text.replace(/----/g, '');
// Remove leading whitespace, if any.
var spaceindex = text.search(/\s/);
while(spaceindex == 0){
text = text.substring(1);
spaceindex = text.search(/\s/);
}
// Uncomment cats
text = text.replace(/\[\[:Category:/gi, "\[\[Category:");
text += '\n';
text += pageAppend;
afcHelper_editPage(newtitle, text, token, "Cleanup following AFC creation");
};
afcHelper_movePage(afcHelper_PageName, newtitle, token, 'Created via \[\[WP:AFC|Articles for Creation\]\] (\[\[WP:WPAFC|you can help!\]\])' , callback);
}
else if(action == 'decline' || action == 'hold'){
var code = document.getElementById("afcHelper_reason").value;
var reasontext = afcHelper_reasonhash[code];
var customreason = document.getElementById("afcHelper_comments").value;
var append = false;
var keep = false;
var blank = document.getElementById("afcHelper_blank").checked;
var notify = document.getElementById("afcHelper_notify").checked;
jsMsg('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="/wiki/'+encodeURI(afcHelper_PageName)+'?action=purge" title="'+afcHelper_PageName+'">Reload page</a>)</b></li></span></span>';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper_PageName);
// Find the first submission or onhold template on the page.
var afc_re = /\{\{\s*afc submission\s*\|\s*[\||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
if(afctemplate.search(/\|\s*h\s*\|/i) != -1){
if(action != 'decline'){
append = confirm( "Submission is already on hold. Do you want to add your reason as a comment?" );
if(!append){
return;
}
}
else
if(code == 'reason' && customreason == ''){
keep = true;
}
}
if (!keep) {
if(code == 'reason' && customreason == ''){
alert("You must enter a reason!");
return;
}
}
var startindex = text.indexOf(afctemplate);
var endindex = startindex + afctemplate.length;
//data is always between the first pipe and the one before the timestamp.
var firstpipe = afctemplate.indexOf('|');
var endpipe = afctemplate.indexOf('|ts');
var newtemplate = afctemplate.substring(0, firstpipe);
var summary = '';
var extra = '';
var newcomment = '';
if(code == 'cv'){
extra = prompt("Please enter the url if available, starting with http://");
}
else if(code == 'dup'){
extra = prompt("Please enter the title of the duplicate submission, if possible. Do not enter the prefix (e.g., John Doe).");
}
else if(code == 'mergeto'){
extra = prompt("Please enter the title of the article to merge to, if possible.");
}
else if(code == 'exists'){
extra = prompt("Please enter the title of the existing article, if possible.");
}
else if(code == 'plot'){
extra = prompt("Please enter the title of the existing article on the fiction, if there is one.");
}
if(extra == null){
return;
}
if(!keep && !append){
// overwrite any reason that was there.
newtemplate += '|';
newtemplate += action.substring(0, 1);
newtemplate += '|';
newtemplate += code;
if(code == 'reason'){
newtemplate += '|3=';
newtemplate += customreason;
}
else if(extra != ''){
newtemplate += '|3=';
newtemplate += extra;
}
newtemplate += afctemplate.substring(endpipe);
if(code != 'reason' && customreason != ''){
newcomment = "*\{\{afc comment|1=" + customreason + " \~\~\~\~\}\}";
}
summary = (action == 'decline' ? "Declining submission" : "Placing submission on hold");
if(code == 'reason')
summary += ': see comment therein';
else
summary += ': ' + reasontext;
}
else if (append){
//append the reason as a comment.
newcomment = "*\{\{afc comment|1=\{\{AFC submission/comments|";
newcomment += code;
if(code == 'reason'){
newcomment += '|2=';
newcomment += customreason;
}
else if(extra != ''){
newcomment += '|2=';
newcomment += extra;
}
newcomment += "\}\} \~\~\~\~ \}\}";
newcomment += '\n----\n';
summary = 'Comment on submission';
if(code == 'reason')
summary += '.';
else
summary += ': ' + reasontext;
}
else{
// keep the original reason, just change hold to decline.
var secondpipe = afctemplate.indexOf('|', firstpipe + 1);
newtemplate += '|d';
newtemplate += afctemplate.substring(secondpipe);
summary = 'Decline submission for reasons stated in hold.';
}
if(!append && notify){
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if(author_re.test(afctemplate)){
var user = author_re.exec(afctemplate)[0];
var username = user.split(/=/)[1];
username = username.replace(/[\|]/g,'');
var usertext = afcHelper_getPageText("User talk:"+username);
usertext += "\n== Your submission at \[\[WP:AFC|Articles for creation\]\] ==";
if(action == 'decline'){
usertext += "\n\{\{subst:afc decline|1=" + afcHelper_submissionTitle;
if(code == 'cv')
usertext += "| cv = yes";
usertext += "\}\} \~\~\~\~";
}
else
usertext += "\n\{\{subst:afc onhold|1=" + afcHelper_submissionTitle + "\}\} \~\~\~\~";
afcHelper_editPage("User talk:"+username, usertext, token, 'Your submission at \[\[WP:AFC|Articles for creation\]\]');
}
}
if(!blank){
var containComment = (text.indexOf('----') != -1);
if(newcomment != ''){
if(!containComment)
text = text.substring(0, startindex) + newtemplate + '\n' + newcomment + '\n----\n'+ text.substring(endindex);
else{
text = text.substring(0, startindex) + newtemplate + text.substring(endindex);
var idx = text.indexOf('----');
text = text.substring(0, idx) + newcomment +'\n' + text.substring(idx);
}
}
else
text = text.substring(0, startindex) + newtemplate + text.substring(endindex);
}
else
text = newtemplate + '\n' + newcomment + "\n\{\{afc cleared\}\}";
if(action == 'decline'){
// Comment out cats on decline.
text = text.replace(/\[\[Category:/gi, "\[\[:Category:");
}
afcHelper_editPage(afcHelper_PageName, text, token, summary);
}
else if(action == 'comment'){
var comment = document.getElementById("afcHelper_comments").value;
jsMsg('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="/wiki/'+encodeURI(afcHelper_PageName)+'?action=purge" title="'+afcHelper_PageName+'">Reload page</a>)</b></li></span></span>';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper_PageName);
var containComment = (text.indexOf('----') != -1);
var newComment = "*\{\{afc comment|1=" + comment + "\~\~\~\~\}\}";
if(comment != ''){
if(!containComment){
var afc_re = /\{\{\s*afc submission\s*\|\s*[\||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
var endindex = text.indexOf(afctemplate) + afctemplate.length;
text = text.substring(0, endindex) + '\n' + newComment + '\n----\n'+ text.substring(endindex);
}
else{
var idx = text.indexOf('----');
text = text.substring(0, idx) + newComment +'\n' + text.substring(idx);
}
afcHelper_editPage(afcHelper_PageName, text, token, "Commenting on submission");
}
}
else if(action == 'mark'){
jsMsg('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="/wiki/'+encodeURI(afcHelper_PageName)+'?action=purge" title="'+afcHelper_PageName+'">Reload page</a>)</b></li></span></span>';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper_PageName);
var afc_re = /\{\{\s*afc submission\s*\|\s*[\||h](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
var firstpipe = afctemplate.indexOf('|');
var endpipe = afctemplate.indexOf('|ts');
var newTemplate = afctemplate.substring(0, firstpipe);
newTemplate += '|r||';
newTemplate += afctemplate.substring(endpipe);
var startindex = text.indexOf(afctemplate);
var endindex = text.indexOf(afctemplate) + afctemplate.length;
text = text.substring(0, startindex) + newTemplate + text.substring(endindex);
afcHelper_editPage(afcHelper_PageName, text, token, "Marking submission as being reviewed");
}
document.getElementById('afcHelper_finished_main').style.display = '';
}
function afcHelper_getPageText(title) {
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_get'+escape(title)+'">Getting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
if (pageid == "-1") {
document.getElementById('afcHelper_get'+escape(title)).innerHTML = '<a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> does not exist';
delete req;
return '';
}
pagetext = response['query']['pages'][pageid]['revisions'][0]['*'];
delete req;
document.getElementById('afcHelper_get'+escape(title)).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
return pagetext;
}
function afcHelper_getToken(show) {
if (show) {
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_gettoken">Getting token</li>';
}
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles="+encodeURIComponent(afcHelper_PageName), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
token = response['query']['pages'][pageid]['edittoken'];
delete req;
if (show) {
document.getElementById('afcHelper_gettoken').innerHTML = 'Got token';
}
return token;
}
function afcHelper_movePage(oldtitle, newtitle, token, summary, callback){
document.getElementById('afcHelper_finished_wrapper').innerHTML = '<span id="afcHelper_AJAX_finished_'+afcHelper_AJAXnumber+'" style="display:none">' + document.getElementById('afcHelper_finished_wrapper').innerHTML + '</span>';
var func_id = afcHelper_AJAXnumber;
afcHelper_AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_move'+escape(oldtitle)+'">Moving <a href="/wiki/'+encodeURI(oldtitle)+'" title="'+oldtitle+'">'+oldtitle+'</a> to <a href="/wiki/'+encodeURI(newtitle)+'" title="'+newtitle+'">'+newtitle+'</a></li>';
var req = sajax_init_object();
var params = "action=move&format=json&token="+encodeURIComponent(token)+"&from="+encodeURIComponent(oldtitle) +"&to="+encodeURIComponent(newtitle)+"&reason="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
var error = true;
response = eval('(' + req.responseText + ')');
try {
if (typeof(response['move']) != "undefined") {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = 'Moved <a href="/wiki/'+encodeURI(oldtitle)+'" title="'+oldtitle+'">'+oldtitle+'</a>';
error = false;
} else {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = '<div style="color:red"><b>Move failed on <a href="/wiki/'+encodeURI(oldtitle)+'" title="'+oldtitle+'">'+oldtitle+'</a></b></div>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'];
}
}
catch(err) {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = '<div style="color:red"><b>Move failed on <a href="/wiki/'+encodeURI(oldtitle)+'" title="'+oldtitle+'">'+oldtitle+'</a></b></div>';
}
if(!error){
if(callback != null)
callback();
}
document.getElementById('afcHelper_AJAX_finished_'+func_id).style.display = '';
delete req;
}
};
req.send(params);
}
function afcHelper_editPage(title, newtext, token, summary) {
document.getElementById('afcHelper_finished_wrapper').innerHTML = '<span id="afcHelper_AJAX_finished_'+afcHelper_AJAXnumber+'" style="display:none">' + document.getElementById('afcHelper_finished_wrapper').innerHTML + '</span>';
var func_id = afcHelper_AJAXnumber;
afcHelper_AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_edit'+escape(title)+'">Editing <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>';
var req = sajax_init_object();
var params = "action=edit&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&text="+encodeURIComponent(newtext)+"¬minor=1&unwatch=1&summary="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['edit']['result'] == "Success") {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>';
} else {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>. Error info:' +response['error']['code'] + ' : ' + response['error']['info'];
}
}
catch(err) {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></b></div>';
}
document.getElementById('afcHelper_AJAX_finished_'+func_id).style.display = '';
delete req;
}
};
req.send(params);
}
function afcHelper_addLink() {
addPortletLink("p-cactions", "javascript:afcHelper_init()", "Review", "ca-afcHelper", "Review");
}
function afcHelper_onChange(select){
var value = select.options[select.selectedIndex].value;
if(value == 'blp' || value == 'cv'){
document.getElementById("afcHelper_blank").setAttribute("checked", "checked");
}
else
document.getElementById("afcHelper_blank").removeAttribute("checked");
}
function afcHelper_generateSelect(title, options, onchange){
var text = '<select name="' + title + '" id="' + title +'" ';
if(onchange != null)
text += 'onchange = "' + onchange + '" ';
text+= '>';
for(var i = 0; i < options.length; i ++){
var o = options[i];
text += '<option value="' + o.value + '" ';
if(o.selected)
text += 'selected="selected" ';
text += '>' + o.label + '</option>';
}
text += "</select>";
return text;
}
addOnloadHook(afcHelper_addLink);
}
importScript('User:The_Earwig/afc-helper.js'); // AfC Redirect Helper script.