User:X!/closeRFA.js

if (mw.config.get('wgPageName').indexOf('Wikipedia:Requests for Adminship/') != -1 && mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion/Header') == -1) { var closeRFA_PageName = mw.config.get('wgPageName').replace(/_/g, ' '); var closeRFA_isCrat = (mw.config.get('wgUserGroups').toString.indexOf('bureaucrat') != -1); var closeRFA_AJAXnumber = 0; function closeRFA_init { if (!wfSupportsAjax) { jsMsg(' Your browser does not seem to support AJAX, which is required for the closeRFA script. '); return; } form = ''+ ' Closing '+closeRFA_PageName+' '+ ''+ ''+ ''+ ''+ ''+ ''+ ' '; jsMsg(form); if (!closeRFA_isCrat) { //document.getElementById('closeRFA_promote_button').disabled = true; document.getElementById('closeRFA_withdrawncrat_button').disabled = true; } }

//function closeRFA_otherkeep { // close = document.getElementById('closeRFA_otherclose').value; // closeRFA_close(close); //} function closeRFA_close(close) { closetype = close; var dopromote = false; if (closetype == "promote" || document.getElementById('closeRFA_dopromote').value == 1) { dopromote = true; }

jsMsg('');

document.getElementById('closeRFA_finish').innerHTML += 'Done (Reload page</a>)</li> ';

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

var RFApage = closeRFA_getPageText(closeRFA_PageName); nomdate = /\d{1,2} \D{4,9} \d{4} \(UTC\)/.exec(RFApage); RFApage = RFApage.replace(/\<span class=\"plainlinks\"\>\'\'\'\[\{\{fullurl:Wikipedia:Requests for adminship\/(\w|\?)\|action=edit&section=4\}\} Voice your opinion\]\'\'\'\<\/span\> \(\[\[Wikipedia talk:Requests for adminship\/(\w|\?)\|talk page\]\]\)/i,"");

RFApage = RFApage.replace(/\'\'\'\((\d*)\/(\d*)\/(\d*)\)\; Scheduled to end \d{2}:\d{2}\, \[\[\d* \w\]\] \[\[\d{4}\]\] \(UTC\)\'\'\'/i,"Final ($1/$2/$3); Closed by "+mw.config.get('wgUserName')+" at "+"~"+""); if (closeRFA_isCrat) { RFApage = RFApage.replace(/\'\'\'\((\d*)\/(\d*)\/(\d*)\)\; Scheduled to end \d{2}:\d{2}\, \[\[\d* \w\]\] \[\[\d{4}\]\] \(UTC\)\'\'\'/i,"Final ($1/$2/$3); Closed by "+mw.config.get('wgUserName')+" at "+"~"+""); } else { RFApage = RFApage.replace(/\'\'\'\((\d*)\/(\d*)\/(\d*)\)\; Scheduled to end \d{2}:\d{2}\, \[\[\d* \w\]\] \[\[\d{4}\]\] \(UTC\)\'\'\'/i,"Final ($1/$2/$3); Closed by "+mw.config.get('wgUserName')+" at "+"~"+" (non-admin closure)"); }

if (dopromote) { RFApage = "{"+"{subst:rfap}} \n" + RFApage + '\n{'+'{subst:rfab}}'; } else { RFApage = "{"+"{subst:rfaf}} \n" + RFApage + '\n{'+'{subst:rfab}}'; }

token = closeRFA_getToken; closeRFA_editPage(closeRFA_PageName, RFApage, token, "Closing RfA, result was " + close);

var rfauser = closeRFA_getPageText(closeRFA_PageName);

rfauser = rfauser.replace(/===\[\[Wikipedia:Requests for adminship\/(\w|\?)\|(\w|\?)\]\]===/i,"$2"); var RFAlink = +closeRFA_PageName+;

if (dopromote) { closeRFA_promoteUser(rfauser, token, RFAlink); }

document.getElementById('closeRFA_finished_main').style.display = ''; } function closeRFA_getPageText(title) { document.getElementById('closeRFA_status').innerHTML += '<li id="closeRFA_get'+escape(title)+'">Getting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>'; var req = sajax_init_object; req.open("GET", mw.config.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('closeRFA_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('closeRFA_get'+escape(title)).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; return pagetext; } function closeRFA_getToken { document.getElementById('closeRFA_status').innerHTML += '<li id="closeRFA_gettoken">Getting token</li>'; var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles="+encodeURIComponent(closeRFA_PageName), false); req.send(null); var response = eval('(' + req.responseText + ')'); pageid = response['query']['pageids'][0]; token = response['query']['pages'][pageid]['edittoken']; delete req; document.getElementById('closeRFA_gettoken').innerHTML = 'Got token'; return token; } function closeRFA_getOldLog { var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&format=json&list=backlinks&blfilterredir=nonredirects&blnamespace=4&bllimit=500&bltitle="+encodeURIComponent(closeRFA_PageName), false); req.send(null); var response = eval('(' + req.responseText + ')'); var logpage = '' for (var i=0; i<response['query']['backlinks'].length; i++) { if (response['query']['backlinks'][i]['title'].indexOf('Wikipedia:Articles for deletion/Log/') != -1) { logpage = response['query']['backlinks'][i]['title']; } }  delete req; return logpage; } function closeRFA_editPage(title, newtext, token, summary) { document.getElementById('closeRFA_finished_wrapper').innerHTML = '<span id="closeRFA_AJAX_finished_'+closeRFA_AJAXnumber+'" style="display:none">' + document.getElementById('closeRFA_finished_wrapper').innerHTML + ' '; var func_id = closeRFA_AJAXnumber; closeRFA_AJAXnumber++; document.getElementById('closeRFA_status').innerHTML += '<li id="closeRFA_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)+"&notminor=1&summary="+encodeURIComponent(summary); url = mw.config.get('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('closeRFA_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; } else { document.getElementById('closeRFA_edit'+escape(title)).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> '; }     }      catch(err) { document.getElementById('closeRFA_edit'+escape(title)).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> '; }     document.getElementById('closeRFA_AJAX_finished_'+func_id).style.display = ''; delete req; } }  req.send(params) } function closeRFA_deletePage(title, token, summary) { document.getElementById('closeRFA_finished_wrapper').innerHTML = '<span id="closeRFA_AJAX_finished_'+closeRFA_AJAXnumber+'" style="display:none">' + document.getElementById('closeRFA_finished_wrapper').innerHTML + ' '; var func_id = closeRFA_AJAXnumber; closeRFA_AJAXnumber++; document.getElementById('closeRFA_status').innerHTML += '<li id="closeRFA_delete'+escape(title)+'">Deleting <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>'; var req = sajax_init_object; var params = "action=delete&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&reason="+encodeURIComponent(summary); url = mw.config.get('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']) { document.getElementById('closeRFA_delete'+escape(title)).innerHTML = 'Deleted <a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; }     }      catch(err) { if (response['error']['code'] == "missingtitle") { document.getElementById('closeRFA_delete'+escape(title)).innerHTML = '<a class="new" href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> does not exist'; } else { document.getElementById('closeRFA_delete'+escape(title)).innerHTML = ' '''Deletion error on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>. Error info:' +response['error']['info'] + ' : ' + response['error']['info'] +  '; }     }      document.getElementById('closeRFA_AJAX_finished_'+func_id).style.display = ''; delete req; } }  req.send(params) } function closeRFA_addLink { mw.util.addPortletLink("p-cactions", "javascript:closeRFA_init", "Close", "ca-closeRFA", "Close AFD"); mw.util.addPortletLink("p-cactions", "javascript:closeRFA_relist", "Relist", "ca-closeRFA-relist", "Relist AFD"); } addOnloadHook(closeRFA_addLink); }