User:Public Juju/test script.js

// // This is a testing version of User:Jujutacular/closeFPC.js *** DO NOT USE THIS VERSION *** // This code is largely based on User:Mr.Z-man/closeAFD

//if (wgPageName.indexOf('Wikipedia:Featured_picture_candidates/') != -1) {

var closeFPC_PageName = wgPageName.replace(/_/g, ' '); var closeFPC_AJAXnumber = 0;

var isDelist = closeFPC_PageName.replace(/^.*\b(delist)\b.*$/,"$1");

function closeFPC_init { if (!wfSupportsAjax) { jsMsg(' Your browser does not seem to support AJAX, which is required for the closeFPC script. '); return; }

if (isDelist == "delist") { jsMsg(' Delist nominations are not supported by this script. '); return; }

form = ''+ ' Closing '+closeFPC_PageName+' '+ ' For promotion: '+ 'Nominator:  '+ 'Nominator 2 (if applicable):  '+ //'Creator (if non-Wikipedian):  '+ 'Creator (if Wikipedian):  '+ 'Image editor/Restorer:  '+ 'Image editor/Restorer 2:  '+ 'Promoted file (without "File:"):  '+ 'Name of nomination: <input type="text" id="closeFPC_name" name="closeFPC_name" /> '+ '<label for="closeFPC_cat">Main category: <input type="text" id="closeFPC_cat" name="closeFPC_cat" /> '+ //'<label for="closeFPC_subcat">Subcategory: <input type="text" id="closeFPC_subcat" name="closeFPC_subcat" /> '+ '<label for="closeFPC_reason">Additional closing rationale (optional): <input type="text" id="closeFPC_reason" name="closeFPC_reason" /> '+ '<input type="button" id="closeFPC_promote_button" name="closeFPC_promote_button" value="Promote" onclick="closeFPC_close(\'promote\')" />'+ '<input type="button" id="closeFPC_nopromote_button" name="closeFPC_nopromote_button" value="No Promote" onclick="closeFPC_close(\'nopromote\')" /> '; jsMsg(form); }

function closeFPC_close(close) { closetype = close; var nominator = document.getElementById('closeFPC_nominator').value; var nominator2 = document.getElementById('closeFPC_nominator2').value; //var creator_nonwiki = document.getElementById('closeFPC_creator_nonwiki').value; var creator_wiki = document.getElementById('closeFPC_creator_wiki').value; var editor = document.getElementById('closeFPC_editor').value; var editor2 = document.getElementById('closeFPC_editor2').value; var promoted_file = document.getElementById('closeFPC_promoted_file').value; var nom_name = document.getElementById('closeFPC_name').value; var cat = document.getElementById('closeFPC_cat').value; //var subcat = document.getElementById('closeFPC_subcat').value; var reason = document.getElementById('closeFPC_reason').value; var FPClink = +closeFPC_PageName+;

var today = new Date; var monthnames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var month = monthnames[today.getUTCMonth]; var day = today.getUTCDate; var year = today.getUTCFullYear; var abbr_month; if (month == "January") { abbr_month = "Jan"; } else if (month == "February") { abbr_month = "Feb"; } else if (month == "March") { abbr_month = "Mar"; } else if (month == "April") { abbr_month = "Apr"; } else if (month == "May") { abbr_month = "May"; } else if (month == "June") { abbr_month = "June"; } else if (month == "July") { abbr_month = "July"; } else if (month == "August") { abbr_month = "Aug"; } else if (month == "September") { abbr_month = "Sep"; } else if (month == "October") { abbr_month = "Oct"; } else if (month == "November") { abbr_month = "Nov"; } else if (month == "December") { abbr_month = "Dec"; }

var PageName_actual = closeFPC_PageName.replace(/Wikipedia:Featured picture candidates\//,''); if (reason != '') { reason = "\n*"+reason+" "+""; } jsMsg('<ul id="closeFPC_status"></ul><ul id="closeFPC_finish"></ul>'); document.getElementById('closeFPC_finish').innerHTML += '<span id="closeFPC_finished_wrapper"><span id="closeFPC_finished_main" style="display:none"><li id="closeFPC_done">Done (<a href="/wiki/'+encodeURI(closeFPC_PageName)+'?action=purge" title="'+closeFPC_PageName+'">Reload page</a>)</li> '; var FPCpage = closeFPC_getPageText(closeFPC_PageName); var isClosed = FPCpage.match(/{{FPCresult\|/); if (isClosed == "{{FPCresult|") { jsMsg(' It seems that this nomination has already been closed. '); return; } token = closeFPC_getToken(true); if (closetype == "promote") { // Checks for missing information if (nominator == '') { jsMsg(' A nominator has not been specified. A nominator is required for promotion. '); return; }   //if (creator_nonwiki ==  && creator_wiki == ) { // jsMsg(' A creator has not been specified. A creator is required for promotion. Use "Unknown" under non-Wikipedian if creator is unknown. '); // return; //}   if (promoted_file == '') { jsMsg(' A file name has not been specified. A file name is required for promotion. '); return; }   if (nom_name == '') { jsMsg(' A name for the nomination has not been specified. A name is required for promotion. '); return; }   if (cat == '') { jsMsg(' A category for the nomination has not been specified. A category is required for promotion. '); return; }   var promoted_file_error = promoted_file.match(/File:/); if (promoted_file_error == "File:") { jsMsg(' Error: filename entered contains "File:". '); return; }   var username_error1 = nominator.match(/User:/); var username_error2 = nominator2.match(/User:/); var username_error3 = creator_wiki.match(/User:/); var username_error4 = editor.match(/User:/); var username_error5 = editor2.match(/User:/); if (username_error1 == "User:" || username_error2 == "User:" || username_error3 == "User:" || username_error4 == "User:" || username_error5 == "User:") { jsMsg(' Error: username entered contains "User:". '); return; }

// Closes nomination as promote FPCpage = FPCpage.replace(/\n/, "\n{"+"{FPCresult|Promoted|File:"+promoted_file+"}} --"+""+reason+"\n"); closeFPC_editPage(closeFPC_PageName, FPCpage, token, "Closed, promoted File:"+promoted_file+"");

} if (closetype == "nopromote") {

}

// Moves transclusion to 'recently closed' section of WP:FPC var closeFPC_FPC = "User:Public Juju/FPC"; //Fix for final var FPClist = closeFPC_getPageText(closeFPC_FPC); FPClist = FPClist.replace('{{' + closeFPC_PageName + '}}\n', ''); FPClist = FPClist.replace(//,"\n{{"+closeFPC_PageName+"}}"); closeFPC_editPage(closeFPC_FPC, FPClist, token, "Closed "+closeFPC_PageName+"");

document.getElementById('closeFPC_finished_main').style.display = ''; }

function closeFPC_getPageText(title) { document.getElementById('closeFPC_status').innerHTML += '<li id="closeFPC_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('closeFPC_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('closeFPC_get'+escape(title)).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; return pagetext; }

var GOtitle = "Wikipedia:Goings on"; var FPtitle = "Wikipedia:Featured pictures"; function closeFPC_informManual { document.getElementById('closeFPC_status').innerHTML += '<li id="closeFPC_manual">*** You must manually make edits to <a href="/wiki/'+encodeURI(GOtitle)+'" GOtitle="'+GOtitle+'">'+GOtitle+'</a> and the proper sub-page of <a href="/wiki/'+encodeURI(FPtitle)+'" FPtitle="'+FPtitle+'">'+FPtitle+'</a> ***</li>'; }

function closeFPC_getToken(show) { if (show) { document.getElementById('closeFPC_status').innerHTML += '<li id="closeFPC_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(closeFPC_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('closeFPC_gettoken').innerHTML = 'Got token'; } return token; }

function closeFPC_editPage(title, newtext, token, summary) { document.getElementById('closeFPC_finished_wrapper').innerHTML = '<span id="closeFPC_AJAX_finished_'+closeFPC_AJAXnumber+'" style="display:none">' + document.getElementById('closeFPC_finished_wrapper').innerHTML + ' '; var func_id = closeFPC_AJAXnumber; closeFPC_AJAXnumber++; document.getElementById('closeFPC_status').innerHTML += '<li id="closeFPC_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 = 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('closeFPC_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; } else { document.getElementById('closeFPC_edit'+escape(title)).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>. Error info:' +response['error']['code'] + ' : ' + response['error']['info']; }     }      catch(err) { document.getElementById('closeFPC_edit'+escape(title)).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> '; }     document.getElementById('closeFPC_AJAX_finished_'+func_id).style.display = ''; delete req; } }  req.send(params) }

function closeFPC_addLink { mw.util.addPortletLink("p-cactions", "javascript:closeFPC_init", "Close FPC", "ca-closeFPC", "Close FPC"); }

addOnloadHook(closeFPC_addLink); //} //