User:Eraserhead1/rfppClerk.js

/** * Semi-automated clerking of WP:RFPP. * See User:Rami R/rfppClerk for instructions. */

var pr_timeout=6;//time until being moved to fulfilled section (in hours) var fr_timeout=12;//time until being removed from fulfilled section (in hours) var rpc_now;//will hold the current date var rpc_offset=0;//timezone offset to GMT/UTC (in mili-seconds) var rpc_backlog=10;//backlog threshold var rpc_nobacklog=4;//backlog cleared threshold

$(function {	if(wgPageName=="Wikipedia:Requests_for_page_protection" && (wgAction=='edit' || wgAction=='submit'))		addPortletLink('p-tb', 'javascript:rfppClerk', 'RFPP clerk', 't-rfpp-clerk', 'WP:RFPP semi-automatic clerk', , ); });

function rfppClerk{ var text = document.getElementById('wpTextbox1').value; var pr_start=text.indexOf("\n====",text.search(/==\s*Current requests for protection\s*==/)); var pr_end=text.search(/\n==\s*Current requests for unprotection\s*==/); var ur_start=text.indexOf('\n====',pr_end); var ur_end=text.search(/\n==\s*Current requests for edits to a protected pa/); var rfse_start=text.indexOf('\n====',ur_end); var rfse_end=text.search(/\n==\s*Fulfilled/denied requests\s*==/); var fr_start=rfse_end+30; if(pr_start>pr_end || pr_start<0) pr_start=pr_end; if(ur_start>ur_end || ur_start<0) ur_start=ur_end; if(rfse_start>rfse_end || rfse_start<0) rfse_start=rfse_end;

rpc_now=new Date; rpc_offset=rpc_now.getTimezoneOffset*60000; var pr_section=text.substring(pr_start,pr_end); var pr_ls=text2list(pr_section); var ur_section=text.substring(ur_start,ur_end); var ur_ls=text2list(ur_section); var rfse_section=text.substring(rfse_start,rfse_end); var rfse_ls=text2list(rfse_section); var fr_section=text.substring(fr_start); var fr_ls=text2list(fr_section); var tmp; var from_pr_ls; var from_ur_ls; var from_rfse_ls; var from_fr_ls; var pending; var backlogmsg=""; tmp=findExpired(pr_ls,pr_timeout); pending=tmp[0]; from_pr_ls=tmp[1]; pr_ls=tmp[2];

tmp=findExpired(ur_ls,pr_timeout); pending+=tmp[0]; from_ur_ls=tmp[1]; ur_ls=tmp[2]; tmp=findExpired(rfse_ls,pr_timeout); pending+=tmp[0]; from_rfse_ls=tmp[1]; rfse_ls=tmp[2]; tmp=findExpired(fr_ls,fr_timeout); pending+=tmp[0]; from_fr_ls=tmp[1]; fr_ls=tmp[2]; var end_text= text.substring(0,pr_start); for(var x=0;x<pr_ls.length;x++) end_text+=pr_ls[x]; end_text+=text.substring(pr_end,ur_start); for(var x=0;x=rpc_backlog){ if(text.indexOf("")>0){ end_text=end_text.replace("",""); backlogmsg=", noticeboard is backlogged"; }	}	else if(pending<=rpc_nobacklog && text.indexOf("")>0){ end_text=end_text.replace("",""); backlogmsg=", backlog cleared"; }	document.getElementById('wpTextbox1').value=end_text; //now for the edit summary: document.getElementById('wpSummary').value= "Semi-auto-clerking: [PR: "+from_pr_ls.length+ " | UR: "+from_ur_ls.length+ " | RfSE: "+from_rfse_ls.length+ " | FR: "+from_fr_ls.length+ "] ("+pending+" reports pending"+		backlogmsg+")"; }

function findExpired(ls,timeout){ var noresponse=0; var done_ls=new Array; var not_done_ls=new Array; for(var x=0;x0){ if((rpc_now-getLastDate(ls[x])+rpc_offset)>timeout*3600000) done_ls.push(ls[x]); else not_done_ls.push(ls[x]); }		else{ noresponse++; not_done_ls.push(ls[x]); }	}	return [noresponse, done_ls, not_done_ls]; }

function getLastDate(section){ var pat=/(\d\d):(\d\d), (\d\d?) (\S+) (\d\d\d\d) \(UTC\)/g; var result=0; var dates=section.match(pat); for(var x=0;xresult) result=date; }	return result; }

/** * parses the date. * @param txt the date as a string. expected to match standard en.wiki format * @return the date as a Date object */ function parseDate(txt){ var hhmm=txt.substring(0,5); var second_space=txt.indexOf(' ',7); var third_space=txt.indexOf(' ',second_space+1); var day=txt.substring(7,second_space); var month=txt.substring(second_space,third_space); var year=txt.substring(third_space+1,third_space+5); return new Date(month+" "+day+", "+year+" "+hhmm+":00"); }

/** * breakup a large text section into its subsections * (assumed to be 4th level). * @param text the text. * @return an array of subsections. */ function text2list(text){ var list=new Array; var start_index=text.indexOf('\n===='); var end_index=text.indexOf('\n====',start_index+1);; while(end_index>0){ list.push(text.substring(start_index,end_index)); start_index=end_index; end_index=text.indexOf('\n====',start_index+1); }	if(start_index>=0) list.push(text.substring(start_index)); return list; }