MediaWiki:Common.js
From wikibase
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function () {
const endpoint = "https://query.bvh.univ-tours.fr";
const query = `
SELECT ?Categorie (COUNT(?item) AS ?Nombre)
WHERE {
VALUES (?type ?Categorie) {
(wd:Q6 "Personnes")
(wd:Q7 "Collectivités")
(wd:Q8 "Familles")
(wd:Q2 "Lieux")
}
?item wdt:P1 ?type .
}
GROUP BY ?Categorie
`;
fetch(endpoint + "?query=" + encodeURIComponent(query), {
headers: {
"Accept": "application/sparql-results+json"
}
})
.then(response => response.json())
.then(data => {
let html = "<table class='wikitable'>";
html += "<tr><th>Catégorie</th><th>Total</th></tr>";
data.results.bindings.forEach(row => {
html += `
<tr>
<td>${row.Categorie.value}</td>
<td>${row.Nombre.value}</td>
</tr>
`;
});
html += "</table>";
document.getElementById("wikibase-stats").innerHTML = html;
})
.catch(error => {
document.getElementById("wikibase-stats").innerHTML =
"Erreur chargement statistiques";
console.error(error);
});
});
