ViquiFilter. Si teniu propostes per l'aplicació, poseu-les aquí.
HTML
Javascript (amb jQuery)
Aquesta secció informarà de les novetats de l'aplicació Codi
S'inclou el codi utilitzat en la versió v1.1.HTML
Codi:
<input type="hidden" class="app-identifier" value="ViquiFilter"/>
<h2>ViquiFilter</h2><br/>
<p><b>ViquiFilter</b> és una aplicació que utilitza la <a class="external_link" href="https://wikitech.wikimedia.org/wiki/Analytics/AQS/Pageviews">Pageview API</a> i
la <a class="external_link" href="https://www.mediawiki.org/wiki/API:Langlinks">Langlinks API</a> de <a class="external_link" href="https://www.mediawiki.org/wiki/MediaWiki"><b>Mediawiki</b></a> per
obtenir els articles més populars d'un determinat idioma i comparar-ne l'accessebilitat amb un altre idioma.</p>
<table class="filter_dates">
<tr><td>Des de:</td><td>Any <select name="selected_id" id="s_year"></select></td><td>Mes <select name="selected_id" id="s_month"></select></td><td>Dia <select name="selected_id" id="s_day"></select></td></tr>
<tr><td>Fins a:</td><td>Any <select name="selected_id" id="e_year"></select></td><td>Mes <select name="selected_id" id="e_month"></select></td><td>Dia <select name="selected_id" id="e_day"></select></td></tr>
</table><br/>
<label>Nombre de populars: <input id="top_n" type="number" value="3" min="1" max="99"/></label><br/><br/>
<table class="filter_langs">
<tr><td>Idioma font:</td><td><select name="selected_id" id="filter_lang_a">
<option value="de">Alemany</option>
<option value="en" selected="selected">Anglès</option>
<option value="ar">Àrab</option>
<option value="arz">Àrab egipci</option>
<option value="ca">Català</option>
<option value="ceb">Cebuà</option>
<option value="es">Espanyol</option>
<option value="fr">Francès</option>
<option value="it">Italià</option>
<option value="jp">Japonès</option>
<option value="nl">Neerlandès</option>
<option value="fa">Persa</option>
<option value="pl">Polonès</option>
<option value="pt">Portuguès</option>
<option value="ru">Rus</option>
<option value="sv">Suec</option>
<option value="uk">Ucraïnès</option>
<option value="vi">Vietnamita</option>
<option value="war">Waray-waray</option>
<option value="zh">Xinès</option>
</select></td></tr>
<tr><td>Idioma comparat:</td><td><select name="selected_id" id="filter_lang_b">
<option value="de">Alemany</option>
<option value="en">Anglès</option>
<option value="ar">Àrab</option>
<option value="arz">Àrab egipci</option>
<option value="ca" selected="selected">Català</option>
<option value="ceb">Cebuà</option>
<option value="es">Espanyol</option>
<option value="fr">Francès</option>
<option value="it">Italià</option>
<option value="jp">Japonès</option>
<option value="nl">Neerlandès</option>
<option value="fa">Persa</option>
<option value="pl">Polonès</option>
<option value="pt">Portuguès</option>
<option value="ru">Rus</option>
<option value="sv">Suec</option>
<option value="uk">Ucraïnès</option>
<option value="vi">Vietnamita</option>
<option value="war">Waray-waray</option>
<option value="zh">Xinès</option>
</select></td></tr>
</table><br/>
<input class="button2" type="submit" name="filter_apply" value="Aplicar" tabindex="5"/>
<input class="button2" type="submit" name="filter_clear" value="Netejar" tabindex="5"/><br/><br/>
<h4>Registre de canvis</h4>
<p>
05-02-2021 - v1.0 - Plataforma bàsica per comparar entre idiomes<br/>
08-02-2021 - v1.1 - Ampliació del llistat d'idiomes: <a class="external_link" href="https://en.wikipedia.org/wiki/List_of_Wikipedias#Detailed_list">20 amb més articles</a>
</p>
<h4>Enllaços relacionats</h4>
<p>
Viquipèdia - <a class="external_link" href="https://ca.wikipedia.org/wiki/Ajuda:Com_iniciar_una_p%C3%A0gina">Iniciar un article</a><br/>
</p>
<p>Aquesta aplicació ha estat creada per l'usuari <b><a class="external_link" href="https://ca.wikipedia.org/w/index.php?title=Usuari:Wecoc">Wecoc</a></b> mitjançant la plataforma <i>Forumotion</i>.</p><br/>
<p class="filter_state"> </p><br/>
<table class="filter_table"></table>
Javascript (amb jQuery)
Codi:
$(document).ready(function(){
var app = document.querySelector('.app-identifier');
if (app == null) { return; }
if (app.value !== "ViquiFilter") { return; }
var articles_seen = [];
var cleaning_mode = false;
set_filter_dates();
function set_filter_dates() {
// Get selectors
var s_year = document.querySelector('#s_year'), e_year = document.querySelector('#e_year');
var s_month = document.querySelector('#s_month'), e_month = document.querySelector('#e_month');
var s_day = document.querySelector('#s_day'), e_day = document.querySelector('#e_day');
var date = new Date(), i;
// Set year options
for(i = 2001; i <= date.getFullYear(); i++){
s_year.innerHTML = s_year.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
e_year.innerHTML = e_year.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
}
s_year.value = date.getFullYear();
e_year.value = date.getFullYear();
// Set month options
for(i = 1; i <= 12; i++){
s_month.innerHTML = s_month.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
e_month.innerHTML = e_month.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
}
s_month.value = 1;
e_month.value = 2;
// Set day options
for(i = 1; i <= 31; i++){
s_day.innerHTML = s_day.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
e_day.innerHTML = e_day.innerHTML + "<option value=\"" + i + "\">" + i + "</option>";
}
s_day.value = 1;
e_day.value = 1;
}
// Set button functions
var apply_button = document.querySelector('.button2[name=filter_apply]');
var clear_button = document.querySelector('.button2[name=filter_clear]');
apply_button.onclick = function(){ filter_get_data() };
clear_button.onclick = function(){ cleaning_mode = true; filter_clear_data(); };
function filter_get_data() {
// Clear current data
filter_clear_data();
cleaning_mode = false;
// Get dates
var s_year = document.querySelector('#s_year'), e_year = document.querySelector('#e_year');
var s_month = document.querySelector('#s_month'), e_month = document.querySelector('#e_month');
var s_day = document.querySelector('#s_day'), e_day = document.querySelector('#e_day');
var s = new Date(s_year.value + '-' + s_month.value + '-' + s_day.value);
var e = new Date(e_year.value + '-' + e_month.value + '-' + e_day.value);
var d = new Date(s), total_days = datediff(s, e);
if (total_days < 0) return;
// Get langs
var lang_a = document.querySelector('#filter_lang_a').value,
lang_b = document.querySelector('#filter_lang_b').value;
// Get Top N
var top_n = document.querySelector('#top_n').value;
// Loop through days
get_data_from_day(d, e, lang_a, lang_b, top_n);
}
function get_data_from_day(d, e, lang_a, lang_b, top_n){
// Change state to Processing
var filter_state = document.querySelector('.filter_state');
filter_state.setAttribute("value", "processing");
filter_state.innerText = "Buscant dades ....";
// Get Pageview url
var year = d.getFullYear();
var month = zeroPad((d.getMonth() + 1), 2);
var day = zeroPad(d.getDate(), 2);
var url = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/top/' + lang_a +
'.wikipedia/all-access/' + year + '/' + month + '/' + day;
$.ajax({
url: url,
success: function(data) {
// Return if cleaning
if (cleaning_mode) { filter_clear_data(); return; }
// Load articles list
var articles = data.items[0].articles.splice(1, 99), a;
// Filter out special cases
for(a in articles) { if(articles[a].article.includes(":")){ delete articles[a]; } }
for(a in articles) { if(articles[a].article == '404.php'){ delete articles[a]; } }
for(a in articles) { if(articles_seen.includes(articles[a].article)) { delete articles[a]; } }
// Get the correct amount of articles
var result = [], keys = Object.keys(articles).splice(0, top_n);
for(var k in keys) { result = result.concat(articles[parseInt(keys[k])]); }
// Store result to already seen articles
for(var seen in result){ articles_seen = articles_seen.concat(result[seen].article); }
// Change to next day
var next_d = d.setDate(d.getDate() + 1);
d = new Date(next_d);
if (d.getTime() == e.getTime()) {
load_data_into_table(lang_a, lang_b, top_n);
} else {
get_data_from_day(d, e, lang_a, lang_b, top_n);
}
}
});
}
function filter_clear_data(){
// Clear storage
articles_seen = [];
// Clear table
var table = document.querySelector('.filter_table');
table.innerHTML = "";
// Set state to null
var filter_state = document.querySelector('.filter_state');
filter_state.setAttribute("value", "null");
filter_state.innerText = "";
}
function load_data_into_table(lang_a, lang_b, top_n){
var i = 0;
store_into_table(i, lang_a, lang_b, top_n);
}
function store_into_table(i, lang_a, lang_b, top_n) {
// Change state to Processing
var filter_state = document.querySelector('.filter_state');
filter_state.setAttribute("value", "processing");
filter_state.innerText = "Creant taula .... " + i + " / " + articles_seen.length;
// Get Langlinks url
var url = "https://" + lang_a + ".wikipedia.org/w/api.php?action=query&titles=" + articles_seen[i] +
"&prop=langlinks&lllimit=500&format=json";
$.ajax({
crossOrigin: true,
dataType: 'jsonp',
url: url,
success: function(lang_a_data) {
// Return if cleaning
if (cleaning_mode) { filter_clear_data(); return; }
// Get page info
var pageid = Object.keys(lang_a_data.query.pages)[0];
var lang_a_title = lang_a_data.query.pages[pageid].title;
var lang_a_url = (lang_a_data.query.normalized) ? lang_a_data.query.normalized[0].from : lang_a_title;
var table = document.querySelector('.filter_table');
lang_a_url = "https://" + lang_a + ".wikipedia.org/wiki/" + lang_a_url;
var lang_links = lang_a_data.query.pages[pageid].langlinks;
var row_class = ((i > 0) && (i % top_n == 0)) ? " sep_row" : "";
if (lang_links) {
var lang_keys = Object.keys(lang_links);
var lang_found = false;
for (var k in lang_keys) {
if (lang_links[k].lang == lang_b) {
var lang_b_title = lang_links[k]['*'];
var lang_b_url = lang_b_title.replace(/\s+/g, '_');
lang_b_url = "https://" + lang_b + ".wikipedia.org/wiki/" + lang_b_url;
// Create row (Found)
var html = "<tr class=\"found" + row_class + "\">" +
"<td><a class=\"wiki\" href=\"" + lang_a_url + "\">" + lang_a_title + "</a></td>" +
"<td><a class=\"wiki\" href=\"" + lang_b_url + "\">" + lang_b_title + "</a></td></tr>";
table.innerHTML = table.innerHTML + html;
lang_found = true;
break;
}
}
if (lang_found == false) {
// Create row (Not found)
var html = "<tr class=\"not_found" + row_class + "\">" +
"<td><a class=\"wiki\" href=\"" + lang_a_url + "\">" + lang_a_title + "</a></td>" +
"<td>-</td></tr>";
table.innerHTML = table.innerHTML + html;
}
} else {
// Create row (No Wikidata)
var html = "<tr class=\"no_wikidata" + row_class +"\">" +
"<td><a class=\"wiki\" href=\"" + lang_a_url + "\">" + lang_a_title + "</a></td>" +
"<td>(Sense Wikidata)</td></tr>";
table.innerHTML = table.innerHTML + html;
}
i = i + 1;
if (i < articles_seen.length){
store_into_table(i, lang_a, lang_b, top_n);
} else {
// Change state to Complete
var filter_state = document.querySelector('.filter_state');
filter_state.setAttribute("value", "complete");
filter_state.innerText = "Procés completat!";
}
}
});
}
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
function datediff(first, second) {
return Math.round((second-first)/(1000*60*60*24));
}
});