Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using(['mediawiki.util','mediawiki.ui.button','mediawiki.api.edit'],function(){if(($('table.diff').length!=0)&&($('td.diff-ntitle span.mw-tag-marker-visualeditor').length!=0)){// Globalsvarnumber_of_pending_tallies=0;varcurrent_diff=''varoldid=mw.config.get('wgRevisionId');varuser=mw.config.get('wgUserName');vardiff_has_been_reviewed=false;// Script parametersvartally_page='Wikipedia:VisualEditor/Feedback/Diffs'vardiff_types=['diff_ok','diff_user_error','diff_borderline','diff_bug','diff_unknown'];// Wait for the page to be parsed$(document).ready(function(){// Retrieve pending talliesif(localStorage.vediffs){varpending_tallies=JSON.parse(localStorage['vediffs']);for(categoryinpending_tallies){number_of_pending_tallies+=pending_tallies[category].length;};};// Prepare the tagging barvardiff_buttons='<div id="tagbar">';diff_buttons+='<div class="mw-ui-button-group" id="diff_buttons">';diff_buttons+='<div class="mw-ui-button diff_button" id="diff_ok">OK</div>';diff_buttons+='<div class="mw-ui-button diff_button" id="diff_user_error">User error</div>';diff_buttons+='<div class="mw-ui-button diff_button" id="diff_borderline">User error: improvable UX</div>';diff_buttons+='<div class="mw-ui-button diff_button" id="diff_bug">VE/Parsoid bug</div>';diff_buttons+='<div class="mw-ui-button diff_button" id="diff_unknown">unknown</div></div><div style="clear:both"></div>';diff_buttons+=' <input type="text" placeholder="optional comment" id="diff_comment" maxlength="140" class="mw-ui-input mw-ui-input-inline" /> ';diff_buttons+='<button class="mw-ui-button mw-ui-constructive" id="submit_review">Submit review</button>';diff_buttons+='</div><div style="clear:both"></div>';vartally_buttons='<div id="tally_buttons">';tally_buttons+='<button class="mw-ui-button mw-ui-destructive tally_button" id="discard_tallies" disabled>Discard the set of reviews</button>';tally_buttons+=' [<span id="number_pending">0</span> reviews in this set] 'tally_buttons+='<button class="mw-ui-button mw-ui-constructive tally_button" id="save_tallies" disabled>Save the set of reviews</button>'tally_buttons+='</div><div style="clear:both"></div>';// Add the buttons to the page$('#siteSub').before(tally_buttons);$('#mw-content-text').before(diff_buttons);$('#tally_buttons').css('float','right');$('#tagbar').css('display','table');$('#tagbar').css('margin','0 auto');$('#tagbar').css('text-align','center');// Enable the tally buttons if we have pending talliesif(number_of_pending_tallies){$(".tally_button").prop("disabled",false);$('#number_pending').html(number_of_pending_tallies);}else{$(".tally_button").prop("disabled",true);};// We can't review until we've tagged$("#submit_review").prop("disabled",true);// Attach events to diff buttons$('.diff_button').click(function(){tag_tally(this.id);});$("#submit_review").click(function(){record_tally();});// Attach events to tally buttons$("#discard_tallies").click(function(){discard_tallies();});$("#save_tallies").click(function(){save_tallies(diff_types,tally_page);});});functiontag_tally(diff_type){if(!diff_has_been_reviewed){if(current_diff){$('#'+current_diff).removeClass('mw-ui-progressive');};$('#'+diff_type).addClass('mw-ui-progressive');current_diff=diff_type;$("#submit_review").prop("disabled",false);};}functionrecord_tally(){vardate=Date();// Retrieve the review comment, clean it upvarcomment=escape_html($('#diff_comment').val());console.log('recorded: '+oldid+' // '+current_diff+' // '+user+' // '+date+' // '+comment)// Get or initialize the pending tallies.varpending_tallies=[];if(localStorage.vediffs){pending_tallies=JSON.parse(localStorage['vediffs']);}else{pending_tallies={"diff_ok":[],"diff_user_error":[],"diff_borderline":[],"diff_bug":[],"diff_unknown":[]};};// Add the current diff to the appropriate sublist.pending_tallies[current_diff].push({"oldid":oldid,"user":user,"date":date,"comment":comment});// Save to localStoragelocalStorage["vediffs"]=JSON.stringify(pending_tallies);// Feedback and cleanup$("#submit_review").text('Submitted!');$('.tally_button').prop("disabled",false);number_of_pending_tallies++;$('#number_pending').html(number_of_pending_tallies);// Disable the tool$("#submit_review").prop("disabled",true);$('.diff_button').removeClass('mw-ui-progressive');diff_has_been_reviewed=true;}functiondiscard_tallies(){if(localStorage.vediffs){localStorage.removeItem('vediffs');}$('.tally_button').prop("disabled",true);number_of_pending_tallies=0;$('#number_pending').html(number_of_pending_tallies);$('.diff_button').removeClass('mw-ui-progressive');$('#submit_review').prop('disabled',true);// Re-enable the tool since we've discarded the talliesdiff_has_been_reviewed=false;current_diff=''}functionsave_tallies(diff_types,tally_page){if(localStorage.vediffs){varpending_tallies=JSON.parse(localStorage['vediffs']);// Make a few calculationsvartotal_diffs=0;for(categoryinpending_tallies){total_diffs+=pending_tallies[category].length;};// prepare the wikitext to be posted on the wikivarwikitext='\n== '+Date();wikitext+=', [[user:'+user+'|'+user+']] ';wikitext+='==\n\n{| class="wikitable sortable"\n|-\n';wikitext+='! Category !! Tally !! Percentage !! Diffs\n|-\n';for(i=0;i<diff_types.length;i++){vartype=diff_types[i];wikitext+='| '+type+' || '+pending_tallies[type].length+' || ';wikitext+=Math.round(pending_tallies[type].length*100/total_diffs);wikitext+='% || ';for(j=0;j<pending_tallies[type].length;j++){varoldid=pending_tallies[type][j]['oldid'];varcomment=pending_tallies[type][j]['comment'];wikitext+='[[Special:Diff/'+oldid+'|'+oldid+']]';if(comment){wikitext+=' <small>('+comment+')</small>';};wikitext+=' · '};wikitext+='\n|-\n';};wikitext+='|}';console.log(wikitext);publish_wikitext(tally_page,wikitext);}}functionpublish_wikitext(tally_page,wikitext){newmw.Api().postWithEditToken({action:'edit',minor:'false',title:tally_page,appendtext:wikitext,summary:'Saving tallies using [[User:Guillaume (WMF)/vediffs.js|vediffs.js]]'}).done(function(){// Clean up a bitlocalStorage.removeItem('vediffs');$('.tally_button').prop("disabled",true);number_of_pending_tallies=0;varcurrent_diff=''// Give feedbackvarsuccess='<div class="successbox">Saved reviewed successfully at <a href="';success+=mw.config.get('wgArticlePath').replace('$1',mw.util.wikiUrlencode(tally_page));success+='" title="'+tally_page+'">'+tally_page+'</a>'success+='</div>'$("#save_tallies").after(success);}).fail(function(code,result){$("#tally_buttons").after('<div class="errorbox">An error occurred:\n<br>'+code+'\n'+result+'</div>');});}functionescape_html(str){return$("<a>").text(str).html()};};});