User:EpochFail/ArticleQuality.js
Appearance
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. |
![]() | This user script seems to have a documentation page at User:EpochFail/ArticleQuality and an accompanying .css page at User:EpochFail/ArticleQuality.css. |
articleQuality = {};
(function($, mw, OO, articleQuality){
var ORES_HOST = "https://ores.wikimedia.org";
var CLASS_WEIGHTS = {Stub: 1, Start: 2, C: 3, B: 4, GA: 5, FA: 6};
var revisionNodes = $('ul.pagehistory li');
var computeWeightedSum = function(data, revId){
//console.log(["rendering", data])
var clsProba = data.enwiki.scores[revId].wp10.score.probability;
var weightedSum = 0;
for (var cls in clsProba) {
//console.log(cat)
if (clsProba.hasOwnProperty(cls)) {
var proba = clsProba[cls];
weightedSum += proba * CLASS_WEIGHTS[cls];
}
}
return weightedSum;
};
var renderQualityPrediction = function(data){
var weightedSum = computeWeightedSum(data, revId);
var prediction = data.enwiki.scores[revId].wp10.score.prediction;
var level = Math.round(weightedSum);
qualityPredictionNode.addclass("level_" + level);
qualityPredictionNode.append(it$("<div>").addClass("bar").css("width", (weightedSum/6)*100));
qualityPredictionNode.attr('title', "ORES prediction " + prediction + " (" + Math.round(weightedSum, 2) + ")");
};
var getAndRenderQualityPrediction = function(node){
var revId = node.attr('mw-data-revid');
var url = ORES_HOST + "/v3/scores/enwiki/" + revId + "/wp10";
var qualityPredictionNode = $("<div>").addClass("qualityprediction");
console.log("Requesting quality for revid=" + revId);
node.append(qualityPredictionNode);
$.ajax(url, {success: renderQualityPrediction.bind(this),
error: function(jqxmlhr, status, error){console.log(status + ": " + error)}});
};
articleQuality.getAndRenderArticleQuality = function(){
revisionNodes.each(getAndRenderQualityPrediction);
};
})(jQuery, mediaWiki, OO, articleQuality);