« MediaWiki:Common-IntersectionCategorie.js » : différence entre les versions

Contenu supprimé Contenu ajouté
Phe (discussion | contributions)
m sélectionner pour montrer le requête en cours
Phe (discussion | contributions)
mAucun résumé des modifications
Ligne 1 :
/*
* Utilise http://www.mediawiki.org/wiki/Extension:DynamicPageList_(Wikimedia)
* pour présenter l'intersectionl’intersection de catégorie aux utilisateurs. L'interfaceL’interface est
* sur http://fr.wikisource.org/wiki/Spécial:Intersection_de_catégorie
*/
var intersection_categorie = {
// TODO : la liste des catégories ne devrait pas être codée en dur
// dans le script, l'idéall’idéal serait de générer la liste à partir d'uned’une cat
// racine dont le premier (et deuxième ?) niveau de sous-catégories
// sont de bons candidats à l'intersectionl’intersection.
possible_categorypossible_author_category : [
//"Page à problème",
//"Page corrigée",
Ligne 26 :
"Bibliothécaires",
"Diplomates",
"Historiens",
"Personnalités politiques",
"Philologues",
Ligne 55 ⟶ 56 :
"Économistes"
],
 
possible_article_category : [
"Anthropologie",
"Archéologie",
"Démographie",
"Économie",
"Éducation",
"Ethnologie",
"Géographie",
"Histoire",
"Histoire de l'art",
"Linguistique",
"Philologie",
"Psychologie",
"Science politique",
"Sciences de l'information et des bibliothèques",
"Sociologie",
"Agriculture",
"Mécanique",
"Médecine",
"Logique",
"Mathématiques",
"Philosophie des sciences",
"Bouddhisme",
"Christianisme",
"Ésotérisme",
"Hindouisme",
"Islam",
"Jaïnisme",
"Judaïsme",
"Libre pensée",
"Mythologie",
"Nihilisme",
"Religieux",
"Religion celtique",
"Religion grecque antique",
"Spiritualité",
"Taoïsme",
"Théologie",
"Contes philosophiques",
"Cours de philosophie",
"Esthétique",
"Histoire de la philosophie",
"Logique",
"Morale",
"Métaphysique",
"Philosophes",
"Philosophie analytique",
"Philosophie chinoise",
"Philosophie de la religion",
"Philosophie des sciences",
"Philosophie du droit",
"Philosophie politique",
"Revue de métaphysique et de morale",
"Scepticisme",
"Stoïcisme",
"Œuvres de Platon",
"Canulars littéraires",
"Courants littéraires",
"Dictionnaires",
"Genres littéraires",
"Littératures non francophones",
"Prix littéraire",
"Droit",
"Politique",
"Architecture",
"Critiques d'art",
"Esthétique",
"Histoire de l'art",
"Illustrateurs",
"Musique",
 
"00%",
"25%",
"50%",
"75%",
"100%"
],
 
// FIXME possible_intersection and get_cat() : there is surely a more
// elegant way to do that.
// définition des possibilités d’intersections par groupe.
possible_intersection : [
"Intersection d’auteurs",
"Intersection d’articles",
],
 
get_cat : function () {
var text = $("#dropdown option:selected").text();
if (text == "Intersection d’auteurs")
return this.possible_author_category;
else if (text == "Intersection d’articles")
return this.possible_article_category;
return null;
},
 
add_dpl_result_to_page : function (datas) {
$("#bodyContentoutput_result").html($("#bodyContent").html() + datas.parse.text["*"]);
var cat = [];
var nocat = [];
this.cat_from_string(location.search, cat, nocat);
if (cat.length)
this.set_selected(cat, this.get_cat());
},
 
build_url : function (cat, not_catnocat) {
var url = mw.config.get("wgServer") + mw.config.get("wgScriptPath");
url += "/index.php?title=" + "Spécial:Intersection_de_catégorie";
for (var i = 0; i < cat.length; ++i)
url += "&cat=" + cat[i].replace(' ', '_');
for (var i = 0; i < not_catnocat.length; ++i)
url += "&notcat=" + not_catnocat[i].replace(' ', '_');
return url;
},
Ligne 89 ⟶ 185 :
for (var i = 0; i < cat.length; ++i)
text += "<option value='" + i + "'>" + cat[i] + "</option>";
return text + "</select>" + "<br /><button type='button' onclick='intersection_categorie.exec_user_query()'>Exécuter la requête</button>";
},
 
build_dpl_query : function (cat, not_catnocat) {
var text = "<DynamicPageList>count = 50\norder = sortkey\nshownamespace = false";
fortext (var+= i"\ncategory = 0;" i <+ cat.length;join("\ncategory ++i= ");
text += "\ncategorynnocategory = " + cat[i]nocat.replacejoin('"\nnocategory ',= '_'");
for (var i = 0; i < not_cat.length; ++i)
text += "\nnotcategory = " + not_cat[i].replace(' ', '_');
return text + "\n</DynamicPageList>";
},
 
dpl_query : function (cat, not_catnocat) {
var query = this.build_dpl_query(cat, not_catnocat);
var url = mw.config.get("wgServer") + mw.config.get("wgScriptPath")
+ "/api.php?action=parse&callback=intersection_categorie.add_dpl_result_to_page"
Ligne 116 ⟶ 210 :
},
 
set_selected : function (cat, possible_cat) {
for (var i = 0 ; i < cat.length; ++i) {
for (var j = 0 ; j < this.possible_categorypossible_cat.length; ++j) {
if (cat[i].replace('"_'", '" '") == this.possible_categorypossible_cat[j])
$("#select_cat option[value=" + j + "]").attr("selected", "selected");
}
Ligne 133 ⟶ 227 :
if (key_value.length == 2) {
if (key_value[0] == "cat")
cat.push(decodeURIComponent(key_value[1]).replace("_", " "));
else if (key_value[0] == "nocat")
nocat.push(decodeURIComponent(key_value[1]).replace("_", " "));
}
}
Ligne 146 ⟶ 240 :
if (cat.length)
this.dpl_query(cat, nocat);
},
 
guess_cat_group_from_url : function() {
var cat = [];
var nocat = [];
this.cat_from_string(location.search, cat, nocat);
if (cat.length) {
for (var i = 0; i < this.possible_author_category.length; ++i) {
if (cat[0].replace("_", "") == this.possible_author_category[i])
return "Intersection d’auteurs";
}
for (var i = 0; i < this.possible_article_category.length; ++i) {
if (cat[0].replace("_", "") == this.possible_article_category[i])
return "Intersection d’articles";
}
}
return this.possible_intersection[0];
},
 
dropdown_change : function() {
$("#input_listbox").html(this.build_listbox(this.get_cat()));
},
 
add_dropdown_list : function () {
var html = "<select id='dropdown' onchange='intersection_categorie.dropdown_change()''>";
for (var i = 0; i < this.possible_intersection.length; ++i)
html += "\n<option value='" + this.possible_intersection[i] + "'>" + this.possible_intersection[i] + "</option>";
html += "\n</select><br />";
$("#input_cat").html(html);
$("#dropdown").val(this.guess_cat_group_from_url());
$("#dropdown").change();
},
 
setup : function () {
$("#firstHeading").text("Intersection de catégorie");
$("#bodyContent > p").html("<div id='input_cat'></div><div id='input_listbox'></div><div id='output_result'></div>");
$("title").text("Spécial:Intersection de catégorie");
$("#bodyContent").html(this.build_listboxadd_dropdown_list(this.possible_category));
this.query_from_url();
}