User:Atama/spihelper.js

//Tim's SPI helper script stolen from User:Timotheus Canens/spihelper.js //v.1.3.0 //Adapted from User:Mr.Z-man/closeAFD if (!Array.prototype.contains) { Array.prototype.contains = function(elt) {   var len = this.length >>> 0; for (var i = 0; i < len; i++) {     if (i in this &&          this[i] === elt) return true; }   return false; }; } if(!String.prototype.trim) {	String.prototype.trim = function{ return this.replace(/^\s+/, ).replace(/\s+$/, ); } } if (wgPageName.indexOf('Wikipedia:Sockpuppet_investigations/') != -1		&& wgPageName.indexOf('Wikipedia:Sockpuppet_investigations/SPI/') == -1		&& wgPageName.indexOf('/Archive') == -1) { var spiHelper_PageName = wgPageName.replace(/_/g, ' '); var spiHelper_CaseName = spiHelper_PageName.replace(/Wikipedia:Sockpuppet investigations\//g, ''); var spiHelper_AJAXnumber = 0; var spiHelper_isAdmin = (wgUserGroups.toString.indexOf('sysop') != -1); var spiHelper_ActionsSelected = { CU_act : false, CU_new : false, Block : false, Note: false, Close: false, Archive: false }; function spiHelper_init{

var pagetext = spiHelper_getPageText(spiHelper_PageName, false); var section_re = /=====[^=]*=====/; if(!section_re.test(pagetext)) return; // Nothing to do here. var spicasestatus_re = /\{\{\s*SPI case status\s*\|?\s*(\S*?)\s*\}\}/i; var result = spicasestatus_re.exec(pagetext); var casestatus = ''; if(result != null){ casestatus = result[1]; }		var hasCURequest = (casestatus != '' && !(/^(?:close|CUdecline|CUdeclined)$/i.test(casestatus))); var canAddCURequest = (casestatus == ''); var CUActiondefault = (/^(?:CU|checkuser|request|CUrequest)$/i.test(casestatus)); var isClosed = /^close$/i.test(casestatus);

var text = ' Handling SPI case '; if(hasCURequest) text += '' + 'Act on CU request '; else if(canAddCURequest) text += '' + 'Add CU request '; text += '' + ''; text += spiHelper_isAdmin ? "Block/tag socks" : "Tag socks"; text += " (not yet implemented)" text += ' ' + 'Note/comment </li>'; if(!isClosed) text += '<li><input type="checkbox" checked="checked" name="spiHelper_Close" id="spiHelper_Close" onchange="spiHelper_toggleArchive" />' + '<label for="spiHelper_Close">Close case </li>'; else text += '<li><input type="checkbox" disabled="true" name="spiHelper_Close" id="spiHelper_Close" />' + '<label for="spiHelper_Close">Close case </li>'; if(isClosed) text += '<li><input type="checkbox" checked="checked" name="spiHelper_Archive" id="spiHelper_Archive" />' + '<label for="spiHelper_Archive">Archive case </li></ul>'; else text += '<li><input type="checkbox" checked="checked" name="spiHelper_Archive" id="spiHelper_Archive" />' + '<label for="spiHelper_Archive">Archive case </li></ul>'; text += '<input type="button" id="spiHelper_GenerateForm" name="spiHelper_GenerateForm" value="Continue" onclick="spiHelper_generateform" />'; jsMsg(text); }

function spiHelper_toggleArchive{ document.getElementById("spiHelper_Archive").disabled = !document.getElementById("spiHelper_Close").checked; if(document.getElementById("spiHelper_Archive").disabled) document.getElementById("spiHelper_Archive").checked = false; }

function spiHelper_generateform{ if (document.getElementById("spiHelper_CU_Action") != null) spiHelper_ActionsSelected.CU_act = document.getElementById("spiHelper_CU_Action").checked; else if(document.getElementById("spiHelper_CU_Request") != null) spiHelper_ActionsSelected.CU_new = document.getElementById("spiHelper_CU_Request").checked; spiHelper_ActionsSelected.Block = document.getElementById("spiHelper_BlockTag").checked; spiHelper_ActionsSelected.Note = document.getElementById("spiHelper_Comment").checked; spiHelper_ActionsSelected.Close = document.getElementById("spiHelper_Close").checked; spiHelper_ActionsSelected.Archive = document.getElementById("spiHelper_Archive").checked; var pagetext = spiHelper_getPageText(spiHelper_PageName, false); if(!(spiHelper_ActionsSelected.CU_act||spiHelper_ActionsSelected.CU_new||spiHelper_ActionsSelected.Note ||spiHelper_ActionsSelected.Close||spiHelper_ActionsSelected.Archive ||spiHelper_ActionsSelected.Block)){ jsMsg(""); return; }		var text = ' Handling SPI case '; if(spiHelper_ActionsSelected.CU_act){ text += ' Handling Checkuser request ' + '<ul><li><label for="spiHelper_CUAction">Checkuser request: ' + spiHelper_generateSelect('spiHelper_CUAction',						[						 { label: 'No action', selected : true, value: 'noaction' },						 { label: 'Endorse for CU attention', value: 'endorse' },						 { label: 'Decline CU', value: 'decline' },						 { label: 'Place case on hold', value: 'hold' },						 { label: 'Relist for another check', value: 'relist' },						 { label: 'Request more information', value: 'moreinfo' },						 { label: 'Mark as checked', value: 'checked' }						 ]) + '</li>' + '<li><label for="spiHelper_CUComment">Comment: ' + '<input type="text" name="spiHelper_CUComment" id="spiHelper_CUComment" /></li></ul>'; }		if(spiHelper_ActionsSelected.CU_new){ text += ' Adding Checkuser request ' + '<ul><li><label for="spiHelper_CUComment">Comment: ' + '<input type="text" name="spiHelper_CUComment" id="spiHelper_CUComment" /></li>' +'<li><input type="checkbox" checked="checked" name="spiHelper_CUSelf" id="spiHelper_CUSelf" /><label for="spiHelper_CUSelf">Mark request as endorsed </ul>'; }		if(spiHelper_ActionsSelected.Block ){ if(spiHelper_isAdmin) text += ' Blocking and tagging socks <ul>'; else text += ' Tagging socks <ul>'; var checkuser_re = /\{\{\s*check(user|ip)\s*\|\s*(?:1=)?\s*([^\|\}]*?)\s*\}\}/gi; var results = pagetext.match(checkuser_re); var likelyusers = new Array, likelyips = new Array, possibleusers = new Array, possibleips = new Array; for(var i = 0; results != null && i < results.length; i++){ var username = results[i].replace(checkuser_re, "$2"); if(results[i].toUpperCase.indexOf("CHECKUSER") != -1 && !likelyusers.contains(username)) likelyusers.push(username); else if(!likelyips.contains(username)) likelyips.push(username); }			var user_re = /\{\{\s*(?:user|vandal|IP)[^\|\}\{]*?\s*\|\s*(?:1=)?\s*([^\|\}]*?)\s*\}\}/gi; var userresults = pagetext.match(user_re); for(var i = 0; userresults != null && i < userresults.length; i++){ var username = userresults[i].replace(user_re, "$1"); if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(username) && !possibleips.contains(username)						&& !likelyips.contains(username)) possibleips.push(username); else if(!possibleusers.contains(username) && !likelyusers.contains(username)) possibleusers.push(username);

}

for(var i = 0; i < likelyusers.length; i++) text += '<li>' + likelyusers[i] + '</li>'; for(var i = 0; i < likelyips.length; i++) text += '<li>' + likelyips[i] + '</li>'; for(var i = 0; i < possibleusers.length; i++) text += '<li>' + possibleusers[i] + '</li>'; for(var i = 0; i < possibleips.length; i++) text += '<li>' + possibleips[i] + '</li>'; text += '</ul>'; text += 'This function has not been implemented yet. ';		}		if(spiHelper_ActionsSelected.Note){ text += ' Commenting on case ' + '<ul><li><label for="spiHelper_CommentType">Comment label: ' + spiHelper_generateSelect('spiHelper_CommentType',						[						 { label: 'None', selected : true, value: 'none' },						 { label: 'Clerk note', value: 'clerknote' },						 { label: 'Administrator note', value: 'adminnote' },						 { label: 'Note', value: 'takenote' }						 ]) + '</li>' + '<li><label for="spiHelper_CommentText">Comment: ' + '<input type="text" name="spiHelper_CommentText" id="spiHelper_CommentText" /></li></ul>'; }		if(spiHelper_ActionsSelected.Close){ text += ' Marking case as closed ' + '<ul><li><input type="checkbox" checked="checked" name="spiHelper_CloseCase" id="spiHelper_CloseCase" />' + '<label for="spiHelper_CloseCase">Close this SPI case </li>' + '<li><label for="spiHelper_Close_Comment">Closing comment: ' + '<input type="text" name="spiHelper_Close_Comment" id="spiHelper_Close_Comment" /></li></ul>'; }		if(spiHelper_ActionsSelected.Archive){ text += ' Archiving case ' + '<ul><li><input type="checkbox" checked="checked" name="spiHelper_ArchiveCase" id="spiHelper_ArchiveCase" />' + '<label for="spiHelper_ArchiveCase">Archive this SPI case </li>'; if(spiHelper_ActionsSelected.Block||spiHelper_ActionsSelected.CU_act||spiHelper_ActionsSelected.Close||spiHelper_ActionsSelected.Note) text += '<li><input type="checkbox" name="spiHelper_ArchiveSingle" id="spiHelper_ArchiveSingle" />' + '<label for="spiHelper_ArchiveSingle">Perform the above action and archiving in a single edit </li>'; text += '</ul>'; }		text += '<input type="button" id="spiHelper_performActions" name="spiHelper_performActions" value="Done" onclick="spiHelper_performActions" />'; jsMsg(text); }

function spiHelper_performActions{ if(spiHelper_ActionsSelected.CU_act){ spiHelper_ActionsSelected.CUAction = document.getElementById('spiHelper_CUAction').value; spiHelper_ActionsSelected.CUComment = document.getElementById('spiHelper_CUComment').value; }   	else if(spiHelper_ActionsSelected.CU_new){ spiHelper_ActionsSelected.CUComment = document.getElementById('spiHelper_CUComment').value; spiHelper_ActionsSelected.CUSelf = document.getElementById('spiHelper_CUSelf').checked; }   	if(spiHelper_ActionsSelected.Note){ spiHelper_ActionsSelected.CommentType = document.getElementById('spiHelper_CommentType').value; spiHelper_ActionsSelected.Comment = document.getElementById('spiHelper_CommentText').value; }   	if(spiHelper_ActionsSelected.Close){ spiHelper_ActionsSelected.Close = document.getElementById('spiHelper_CloseCase').checked; spiHelper_ActionsSelected.CloseComment = document.getElementById('spiHelper_Close_Comment').value; }   	if(spiHelper_ActionsSelected.Archive){ spiHelper_ActionsSelected.Archive = document.getElementById('spiHelper_ArchiveCase').checked; if(document.getElementById('spiHelper_ArchiveSingle') != null) spiHelper_ActionsSelected.ArchiveSingle = document.getElementById('spiHelper_ArchiveSingle').checked; else spiHelper_ActionsSelected.ArchiveSingle = true; }   	jsMsg('<ul id="spiHelper_status"></ul><ul id="spiHelper_finish"></ul>'); document.getElementById('spiHelper_finish').innerHTML += '<span id="spiHelper_finished_wrapper"><span id="spiHelper_finished_main" style="display:none"><li id="spiHelper_done">Done (<a href="/wiki/'+encodeURI(spiHelper_PageName)+'?action=purge" title="'+spiHelper_PageName+'">Reload page</a>)</li> '; var token = spiHelper_getToken(true); var pagetext = spiHelper_getPageText(spiHelper_PageName, true); var editsummary = "";

var spicasestatus_re = /\{\{\s*SPI case status\s*\|?\s*(\S*?)\s*\}\}/i; var result = spicasestatus_re.exec(pagetext); if(result == null){ pagetext = pagetext.replace("=====", "\{\{SPI case status\}\}\n====="); result = spicasestatus_re.exec(pagetext); }		var casestatustext = result[0], casestatus = result[1]; if(spiHelper_ActionsSelected.CU_act){ var CUAction = spiHelper_ActionsSelected.CUAction; var CUComment = spiHelper_ActionsSelected.CUComment; if(CUAction != 'noaction') casestatus = CUAction; if(CUAction == "checked"){ editsummary = "Marking request as checked"; }   		else if(CUAction == "decline"){ if(!/\{\{Decline\}\}/i.test(CUComment)) CUComment = "\{\{Decline\}\} - " + CUComment; editsummary = "Declining checkuser"; }   		else if(CUAction == "endorse"){ if(!/\{\{Endorse\}\}/i.test(CUComment)) CUComment = "\{\{Endorse\}\} - " + CUComment; editsummary = "Endorsing for checkuser attention"; }   		else if(CUAction == "moreinfo"){ if(!/\{\{moreinfo\}\}/i.test(CUComment)) CUComment = "\{\{moreinfo\}\} - " + CUComment; editsummary = "Requesting additional information"; }   		else if(CUAction == "relist"){ if(!/\{\{relisted\}\}/i.test(CUComment)) CUComment = "\{\{relisted\}\} - " + CUComment; editsummary = "Relisting case for another check"; }   		else if(CUAction == "hold"){ if(!/\{\{onhold\}\}/i.test(CUComment)) CUComment = "\{\{onhold\}\} - " + CUComment; editsummary = "Placing checkuser request on hold"; }   		if(CUComment != ''){ CUComment += " \~\~\~\~"; if(pagetext.indexOf("\n") == -1) pagetext += "\n"; pagetext = pagetext.replace(/\s*\n/, '\n*' + CUComment + '\n'); }   	}    	if(spiHelper_ActionsSelected.CU_new){ var CUComment = spiHelper_ActionsSelected.CUComment; if(spiHelper_ActionsSelected.CUSelf){ casestatus = "endorse"; editsummary = "Adding checkuser request (self-endorsed for checkuser attention)"; }   		else { casestatus = "CUrequest"; editsummary = "Adding checkuser request"; }   		var newtext = ''; if(CUComment != ''){ newtext = '\n*' + CUComment + " \~\~\~\~"; }   		if(pagetext.indexOf("\n") == -1) pagetext += "\n"; pagetext = pagetext.replace(/\s*\n/, newtext + '\n'); }   	if(spiHelper_ActionsSelected.Note){ if(pagetext.indexOf("\n") == -1) pagetext += "\n"; if(spiHelper_ActionsSelected.Comment != ''){ var newtext = '\n*'; if(spiHelper_ActionsSelected.CommentType != 'none') newtext += "\{\{" + spiHelper_ActionsSelected.CommentType + "\}\} "; newtext += spiHelper_ActionsSelected.Comment + " \~\~\~\~\n"; pagetext = pagetext.replace(/\s*\n/, newtext + ''); if(editsummary != "") editsummary += ", comment"; else editsummary = "Comment"; }

}   	if(spiHelper_ActionsSelected.Close){ if(pagetext.indexOf("\n") == -1) pagetext += "\n"; var newtext = '\n'; if(spiHelper_ActionsSelected.CloseComment != '') newtext += '*' + spiHelper_ActionsSelected.CloseComment + " \~\~\~\~\n"; casestatus = 'close'; pagetext = pagetext.replace(/\s*\n/, newtext + ''); if(editsummary != "") editsummary += ", marking case as closed"; else editsummary = "Marking case as closed"; }   	pagetext = pagetext.replace(casestatustext, "\{\{SPI case status|" + casestatus + "\}\}"); casestatustext = "\{\{SPI case status|" + casestatus + "\}\}"; if(spiHelper_ActionsSelected.Archive){ if(spiHelper_ActionsSelected.ArchiveSingle){ pagetext = pagetext.replace(casestatustext, ''); var section_re = /=====[^=]*=====/; var header = pagetext.substring(0, pagetext.search(section_re)); header = header.replace(//g, '').trim; var newarchivetext = pagetext.substring(pagetext.search(section_re)); var archivename = spiHelper_PageName + "/Archive"; if(editsummary != "") editsummary += ", archiving case to " + archivename + ""; else editsummary = "Archiving case to " + archivename + ""; spiHelper_editPage(spiHelper_PageName, header, token, editsummary, false, null); var archivetext = spiHelper_getPageText(archivename, true); if(archivetext == "") archivetext = "__" + "TOC__\n\{\{SPIarchive notice|1=" + spiHelper_CaseName + "\}\}\n\{\{SPIpriorcases\}\}"; else archivetext = archivetext.replace(/<br\s*\/>\s*\{\{SPIpriorcases\}\}/gi, "\n\{\{SPIpriorcases}}"); // fmt fix whenever needed. archivetext += "\n" + newarchivetext; spiHelper_editPage(archivename, archivetext, token, "Archiving case from " + spiHelper_PageName + "", false, null); }   		else{ var onComplete = function { var newpagetext = pagetext; newpagetext = newpagetext.replace(casestatustext, ''); var section_re = /=====[^=]*=====/; var header = newpagetext.substring(0, newpagetext.search(section_re)); header = header.replace(//g, '').trim; var newarchivetext = newpagetext.substring(newpagetext.search(section_re)).trim; var archivename = spiHelper_PageName + "/Archive"; var summary = "Archiving case to " + archivename + ""; spiHelper_editPage(spiHelper_PageName, header, token, summary, false, null); var archivetext = spiHelper_getPageText(archivename, true); if(archivetext == "") archivetext = "__" + "TOC__\n\{\{SPIarchive notice|1=" + spiHelper_CaseName + "\}\}\n" + "\{\{SPIpriorcases\}\}"; archivetext += "\n" + newarchivetext; spiHelper_editPage(archivename, archivetext, token, "Archiving case from " + spiHelper_PageName + "", false, null); document.getElementById('spiHelper_finished_main').style.display = ''; };   			spiHelper_editPage(spiHelper_PageName, pagetext, token, editsummary, false, onComplete); }   	}    	else spiHelper_editPage(spiHelper_PageName, pagetext, token, editsummary, false, null); if(!spiHelper_ActionsSelected.Archive || spiHelper_ActionsSelected.ArchiveSingle) document.getElementById('spiHelper_finished_main').style.display = ''; }

function spiHelper_getToken(show) { if (show) { document.getElementById('spiHelper_status').innerHTML += '<li id="spiHelper_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(spiHelper_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('spiHelper_gettoken').innerHTML = 'Got token'; }       return token; }

function spiHelper_editPage(title, newtext, token, summary, createonly, onComplete) { document.getElementById('spiHelper_finished_wrapper').innerHTML = '<span id="spiHelper_AJAX_finished_'+spiHelper_AJAXnumber+'" style="display:none">' + document.getElementById('spiHelper_finished_wrapper').innerHTML + ' '; var func_id = spiHelper_AJAXnumber; spiHelper_AJAXnumber++; document.getElementById('spiHelper_status').innerHTML += '<li id="spiHelper_edit'+func_id+'">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); 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('spiHelper_edit'+func_id).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; if(onComplete != null) onComplete; } else { document.getElementById('spiHelper_edit'+func_id).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('spiHelper_edit'+func_id).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> '; }               document.getElementById('spiHelper_AJAX_finished_'+func_id).style.display = ''; delete req; }       };        req.send(params); } /*   function spiHelper_blockUser(user, duration, token, reason, reblock, settings){ var anononly, accountcreation, autoblock, talkpage, email; var setting = settings.toUpperCase; anononly = (setting.indexof("AO") != -1); accountcreation = (setting.indexof("ACB") == -1); autoblock = (setting.indexof("ABD") != -1); talkpage = (setting.indexof("TPD") == -1); email = (setting.indexof("EMD") == -1); spiHelper_blockuser(user, duration, token, reason, reblock, anononly, accountcreation, autoblock, talkpage, email); }

function spiHelper_blockUser(user, duration, token, reason, reblock, anononly, accountcreation, autoblock, talkpage, email ) { document.getElementById('spiHelper_finished_wrapper').innerHTML = '<span id="spiHelper_AJAX_finished_'+spiHelper_AJAXnumber+'" style="display:none">' + document.getElementById('spiHelper_finished_wrapper').innerHTML + ' '; var func_id = spiHelper_AJAXnumber; spiHelper_AJAXnumber++; document.getElementById('spiHelper_status').innerHTML += '<li id="spiHelper_edit'+escape(title)+'">Editing <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a></li>'; var req = sajax_init_object; var params = "action=block&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&text="+encodeURIComponent(newtext)+"&notminor=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('spiHelper_edit'+escape(title)).innerHTML = 'Saved <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; } else { document.getElementById('spiHelper_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('spiHelper_edit'+escape(title)).innerHTML = ' Edit failed on <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a> '; }               document.getElementById('spiHelper_AJAX_finished_'+func_id).style.display = ''; delete req; }       };        req.send(params); }	 */	function spiHelper_getPageText(title, show) { var func_id = spiHelper_AJAXnumber; spiHelper_AJAXnumber++; if(show){ document.getElementById('spiHelper_status').innerHTML += '<li id="spiHelper_get'+func_id+'">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('spiHelper_get'+func_id).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('spiHelper_get'+func_id).innerHTML = 'Got <a href="/wiki/'+encodeURI(title)+'" title="'+title+'">'+title+'</a>'; }		return pagetext; }

function spiHelper_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 + ' '; }		text += " "; return text; }

function spiHelper_addLink { mw.util.addPortletLink("p-cactions", "javascript:spiHelper_init", "SPI", "ca-spiHelper", "SPI"); }	addOnloadHook(spiHelper_addLink); }