var cpeSpecialPage = "Spécial:Portail-éval";
$(function () {
mw.loader.using( 'mediawiki.util', function () {
mw.util.addPortletLink('p-tb', mw.config.get("wgArticlePath").replace(/\$1/, cpeSpecialPage), 'Portail-éval', 'r-cpe', 'Portail-éval');
});
});
if (mw.config.get("wgPageName") == cpeSpecialPage) {
/* Génération de la liste */
function cpeArticleLink(article) {
return "<a href=\"" + mw.config.get("wgArticlePath").replace(/\$1/, encodeURIComponent(article)) + "\">" + mw.html.escape(article) + "</a>";
}
function cpeReadCat(categ, callbackFun, progressFun) {
var query = {format: 'json', action: 'query', list: 'categorymembers', cmtitle: categ, cmlimit: 500, rawcontinue: ''};
var catMembers = ;
function readCatLoop(obj) {
$.merge(catMembers, obj.query.categorymembers);
progressFun(catMembers.length);
if (obj) {
query.cmcontinue = obj.categorymembers.cmcontinue;
$.getJSON(mw.util.wikiScript('api'), query, readCatLoop);
} else {
callbackFun(catMembers);
}
}
$.getJSON(mw.util.wikiScript('api'), query, readCatLoop);
}
function cpeComputeLists(portail, callbackFun) {
var cpeImp = ;
var cpeListePortail = new Object;
var cpeListeEval = new Object;
function initReadInfo(cat) {
$("#cpeResult").html("Lecture de <tt>" + mw.html.escape(cat) + "</tt> <span id=\"cpeCatReadCount\"></span>");
}
function updateReadInfo(size) {
$("#cpeCatReadCount").text("(" + size + " lus)");
}
function listeEval(index) {
if (index < cpeImp.length) {
var category = 'Catégorie:Article du projet ' + portail + " d'importance " + cpeImp;
initReadInfo(category);
cpeReadCat(category,
function (catMembers) {
for (var i = 0; i < catMembers.length; i++) {
if (catMembers.ns == 1) {
var talkTitle = catMembers.title;
var title = talkTitle.substr(talkTitle.indexOf(":") + 1);
cpeListeEval = true;
}
}
listeEval(index + 1);
}, updateReadInfo
);
} else {
callbackFun(cpeListePortail, cpeListeEval);
}
}
initReadInfo("Catégorie:Portail:" + portail + "/Articles liés");
cpeReadCat("Catégorie:Portail:" + portail + "/Articles liés",
function (catMembers) {
for (var i = 0; i < catMembers.length; i++) {
cpeListePortail.title] = true;
}
listeEval(0);
}, updateReadInfo
);
}
/* Formulaire */
function cpeCompute() {
var portail = $('#cpePortail').val();
portail = portail.substr(0, 1).toUpperCase() + portail.substr(1);
if (portail == "") {
$("#cpeResult").text("Erreur : le champ 'Portail' est vide.");
return;
}
$("#cpeCompute").attr("disabled", "disabled");
cpeComputeLists(portail,
function (listePortail, listeEval) {
var directLink = location.protocol + mw.config.get("wgServer") + mw.config.get("wgScript")
+ "?title=" + encodeURIComponent(cpeSpecialPage)
+ "&portail=" + encodeURIComponent(portail);
var html = "<p><small>Lien direct pour revenir à cette requête : <a href=\"" + mw.html.escape(directLink) + "\">" + mw.html.escape(directLink) + "</a></small></p>";
html += '<p><a href="#" id="cpeDisplayWikicode" class="cpe-closed">Version en wikicode à copier-coller</a></p>';
var list1 = '', list2 = '';
var wikicodeList1 = '', wikicodeList2 = '';
var listCount1 = 0, listCount2 = 0, maxListCount = 500;
for (article in listePortail) {
if (!listeEval) {
listCount1++;
if (listCount1 <= maxListCount) {
list1 += "<li>" + cpeArticleLink(article);
wikicodeList1 += '*]\n';
}
}
}
for (article in listeEval) {
if (!listePortail) {
listCount2++;
if (listCount2 <= maxListCount) {
list2 += "<li>" + cpeArticleLink(article);
wikicodeList2 += '*]\n';
}
}
}
function formatCount(c) {
if (c == 0) {
return "Aucun article";
} else if (c == 1) {
return "1 article";
} else if (c <= maxListCount) {
return c + " articles";
} else {
return c + " articles (seulement " + maxListCount + " affichés)";
}
}
html += "<h2>Articles du portail non évalués</h2>"
+ "<p>" + formatCount(listCount1) + "</p><ul>" + list1 + "</ul>"
+ "<h2>Articles évalués sans le portail</h2>"
+ "<p>" + formatCount(listCount2) + "</p><ul>" + list2 + "</ul>";
$("#cpeResult").html(html);
$("#cpeCompute").prop("disabled", false);
$("#cpeDisplayWikicode").click(function() {
var link = $(this);
link.toggleClass('cpe-closed cpe-opened');
if (link.hasClass('cpe-opened')) {
link.after('<div id="cpeWikicodeDiv"><textarea id="cpeWikicode" cols="80" rows="25" readonly></textarea></div>');
$('#cpeWikicode').val('== Articles du portail non évalués ==\n' + wikicodeList1 + '\n== Articles évalués sans le portail ==\n' + wikicodeList2);
} else {
$('#cpeWikicodeDiv').remove();
}
});
}
);
}
function cpeInitForm(portail) {
$('head').append('<style>'
+ '.cpe-closed {padding: 0 0 0 16px; background: url(//upload.wikimedia.org/wikipedia/commons/4/41/MediaWiki_Vector_skin_right_arrow.png) no-repeat left center;}'
+ '.cpe-opened {padding: 0 0 0 16px; background: url(//upload.wikimedia.org/wikipedia/commons/1/10/MediaWiki_Vector_skin_action_arrow.png) no-repeat left center;}'
+ '</style>');
html = '<p>Ce formulaire sert à calculer la liste des articles qui ont un portail mais pas une évaluation, et réciproquement.</p>'
+ '<p>Portail (par exemple <i>Chemin de fer</i>)<br /><input id="cpePortail" size="64" value="'
+ mw.html.escape(portail) + '" /></p>'
+ '<p><input type="button" id="cpeCompute" onclick="cpeCompute();" value="Calculer" /></p><div id="cpeResult"></div>'
$("#bodyContent").html(html);
mw.loader.using(, function () {
var inputPortail = $("#cpePortail");
inputPortail.autocomplete({source:
function (request, response) {
if (/]/.test(request.term)) {
response();
return;
}
var commonPrefix = 'Évaluation des articles du projet ';
var prefix = commonPrefix + request.term.substr(0, 1).toUpperCase() + request.term.substr(1);
var query = {format: 'json', action: 'query', list: 'allpages', apprefix: prefix, apnamespace: 14, rawcontinue: ''};
$.getJSON(mw.util.wikiScript('api'), query, function (obj) {
var portails = ;
for (var i = 0; i < obj.query.allpages.length; i++) {
var category = obj.query.allpages.title;
portails.push(category.substr(category.indexOf(':') + 1 + commonPrefix.length));
}
if (portails.length == 1 && portails == request.term) {
response();
} else {
response(portails);
}
});
}
});
});
}
$(function () {
var title = "Comparaison portail et articles évalués";
var portail = "";
window.document.title = title;
$('#firstHeading').html(title);
var params = location.search.substr(1).split("&");
for (var i = 0; i < params.length; i++) {
var nameVal = params.split("=");
if (nameVal.length < 2) continue;
if (nameVal == "portail") {
portail = decodeURIComponent(nameVal);
}
}
cpeInitForm(portail);
});
}