User:Sander Säde/assess.js

// // var tForm = "\n " + " Importance: \n" + " \n" + "   Top \n" + "   High \n" + "   Mid \n" + "   Low \n" + "   No \n" + " \n" + "  \n" + "  Quality: \n" + " \n" + "   FA \n" + "   A \n" + "   GA \n" + "   B \n" + "   Start \n" + "   Stub \n" + "   <option value='No'>No \n" + "   <option value='List'>List \n" + "   <option value='Category'>Category \n" + "   <option value='File'>File \n" + "   <option value='Template'>Template \n" + "   <option value='Disambig'>Disambig \n" + " \n" + "  \n" + " <label for='comment'>Comment: \n" + " <input type='text' name='comment' id='comment' maxlength='128' width='300'>\n" + " \n" + " <span style='font-family:Geneva, Arial, Helvetica, sans-serif; font-size:xx-small; color:#993300' id='assesshelp'> \n" + " \n" + " <input name='Assess' type='Button' id='btAssess' style='background-color:#888888; height:18px' value='Assess' onClick='doAssess'>\n" + " ";

var sub = ""; var nested = false; $(AssessButton); function AssessButton { if ((document.URL.indexOf(':', 8) != -1) && (document.URL.indexOf('Talk:') == -1) && (document.URL.indexOf('/Category') == -1)) return; if (document.URL.indexOf('/wiki/') == -1) return; addPortletLink( "p-cactions", "javascript:assessEst", "wpe: Assess"); } function WriteStatus(sText) { document.getElementById("contentSub").innerHTML += ' ' + sText + " "; } function assessEst { if (document.URL.indexOf('/wiki/Category') != -1) { WriteStatus('Category: assessing automagically to Cat/NA'); } WriteStatus('Getting talk page contents...'); if (document.URL.indexOf('/wiki/Category') != -1) { wgPageName = mw.config.get('wgPageName').replace('Category:', 'Category_talk:'); } else if (mw.config.get('wgPageName').indexOf('Talk:') == -1) wgPageName = 'Talk:' + mw.config.get('wgPageName'); ar=sajax_init_object(null); ar.open("GET", mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + wgPageName + "&action=raw", true); ar.onreadystatechange = function {   if(ar.readyState != 4) return; textAssessReceived(ar.responseText, wgPageName); }; ar.send(null); } var bTag; var sPage; var sPageText; function textAssessReceived(sText, oPage) { bTag = false; sPage = oPage; sPageText = sText; WriteStatus('Page contents received: ' + oPage); if (sText.indexOf('Image:Flag of Estonia.svg|thumb|center')!= -1) { WriteStatus('Tagged with old template, will replace the template'); } if (sText.indexOf('{{' + 'WikiProject Estonia') != -1) { sub = sText.substr(sText.indexOf('{{' + 'WikiProject Estonia')); sub = sub.substr(0, sub.indexOf('}}') + 2); if (sub.indexOf('|') != -1) { if (sub.indexOf('nested=') != -1) { nested = true; WriteStatus('Article nested.'); }	WriteStatus('Article probably assessed...'); sub.replace(/= /g,"="); var srclass = 'unassessed'; if (sub.indexOf('class=') != -1) { sclass = sub.substr(sub.indexOf('class=') + 6, 3); if (sclass.substr(0, 2).toLowerCase == 'fa') srclass = 'FA'; if (sclass.substr(0, 1).toLowerCase == 'a') srclass = 'A'; if (sclass.substr(0, 2).toLowerCase == 'ga') srclass = 'GA'; if (sclass.substr(0, 1).toLowerCase == 'b') srclass = 'B'; if (sclass.toLowerCase == 'sta') srclass = 'Start'; if (sclass.toLowerCase == 'stu') srclass = 'Stub'; if (sclass.substr(0, 2).toLowerCase == 'no') srclass = 'No-class'; }  WriteStatus("Quality: " + srclass + ""); srclass = "unknown"; if (sub.indexOf('importance=') != -1) { sclass = sub.substr(sub.indexOf('importance=') + 11, 1); if (sclass.toLowerCase == 't') srclass = 'Top'; if (sclass.toLowerCase == 'h') srclass = 'High'; if (sclass.toLowerCase == 'm') srclass = 'Mid'; if (sclass.toLowerCase == 'b') srclass = 'B'; if (sclass.toLowerCase == 'l') srclass = 'Low'; if (sclass.toLowerCase == 'n') srclass = 'No-importance'; }  WriteStatus("Importance: " + srclass + ""); alreadyAssessed = true; createAssessForm; return; } }

if (sText == "") { WriteStatus("Talk page doesn't exist, ready to tag and assess."); bTag = true; } if (sText.indexOf('{{' + 'WikiProject Estonia}}') == -1) { WriteStatus('Article untagged. Ready to tag and assess.'); bTag = true;

} else { WriteStatus('Article tagged and unassessed. Ready to assess.'); sub='{{' + 'WikiProject Estonia}}' } if (document.URL.indexOf('/wiki/Category') != -1) { tagCategory; return; }

createAssessForm; } function tagCategory { tagPage('NA','Cat',''); } function createAssessForm { document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + tForm; } function ImportanceChange(s) { var st = ""; switch(s){ case "Top": st = "Subject is a must-have for a concise print encyclopedia or other reference work on Estonia." break; case "High": st = "Subject contributes a depth of knowledge to the encyclopaedia." break; case "Mid": st = "Subject fills in more minor details." break; case "Low": st = "Subject is peripheral knowledge, possibly trivial." break; case "No": st = "Subject is barely worthy of inclusion to Wikipedia." break; default: st = ""; } document.getElementById("assesshelp").innerHTML = st; } function QualityChange(s) { var st = ""; switch(s){ case "FA": st = "Reserved exclusively for articles that have received 'Featured article' status." break; case "A": st = "Provides a well-written, reasonably clear and complete description of the topic." break; case "GA": st = "The article has passed through the Good article nomination and been granted GA status." break; case "B": st = "Several elements described in 'start', usually a majority of the material needed for a completed article." break; case "Start": st = "The article has a meaningful amount of good content, but it is still weak in many areas, and may lack a key element." break; case "Stub": st = "The article is either a very short article or a rough collection of information that will need much work to bring it to A-Class level." break; case "No": st = "Unknown or very low quality." break; default: st = ""; } document.getElementById("assesshelp").innerHTML = st; } function doAssess { tagPage(document.getElementById("importance").value,document.getElementById("quality").value,document.getElementById("comment").value ); } function tagPage(sImp, sQuality, sComment) { var xmlhttp = sajax_init_object(null); xmlhttp.overrideMimeType('text/xml'); WriteStatus("Grabbing edit form..."); xmlhttp.open( 'GET', 'http://en.wikipedia.org/w/index.php?title=' + sPage + '&action=submit', true); xmlhttp.onreadystatechange = function {   if(xmlhttp.readyState != 4) return; assertFormReceived(xmlhttp.responseXML, sImp, sQuality, sComment); }; xmlhttp.send(null) } function assertFormReceived(pg, sImp, sQuality, sComment) { form = pg.getElementById('editform'); if(!form ) { WriteStatus( 'Couldn\'t grab element "editform", aborting, this could indicate failed response from the server'); return; } else WriteStatus('Got the edit form'); var text; var tag; tag = "\n" + sPageText; else { if (nested) tag += "|nested=yes}}"; else tag += "}}" text = sPageText.replace(sub, tag); }  var iStart = text.indexOf('{| class="messagebox standard-talk"'); var iEnd = text.indexOf("|}", iStart); text = text.replace(text.slice(iStart, iEnd + 2), ""); var summary = 'Assessed importance for WikiProject Estonia; class: ' + sQuality + "; importance: " + sImp; if (sComment != "") summary += "; comments: " + sComment; var postData = { 'wpMinoredit': form.wpMinoredit.checked, 'wpWatchthis': form.wpWatchthis.checked, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text }; WriteStatus( 'Submitting the form...' ); var xmlhttp = sajax_init_object(null); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + sPage + "&action=submit", true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function { WriteStatus('Form submitted'); } xmlhttp.send( QueryString.create(postData)); } // //