Ajuda:Página de testes/2
Aspeto
A traduzir
- en:Boolean algebra (logic)
- en:Classification of finite simple groups
- en:Coding theory
- en:Commutative diagram
- en:Differential calculus
- en:Fourier analysis
- en:Homology theory
- en:Markov's principle
- en:Mathematician
- en:Symmetry in mathematics
- en:Theoretical computer science
- en:Two-dimensional space
Tabela
Script
function getArticles() {
var enCat = 'Category:Top-Priority mathematics articles',
total, done = 0,
titlesPt = [],
errors = [],
toTranslate = [],
table = [];
$.ajax({
url: '//en.wikipedia.org/w/api.php',
dataType: 'jsonp',
data: {
'format': 'json',
'action': 'query',
'list': 'categorymembers',
'cmtitle': enCat,
'cmnamespace': '1',
'cmtype': 'page',
'cmlimit': 500
},
success: function (data) {
var pages;
try {
pages = data.query.categorymembers;
} catch (err) {
console.debug('Não foi possível possível obter a lista de artigos da ' + enCat);
return false;
}
if (!pages) {
console.debug('A categoria estava vazia.');
return false;
}
total = pages.length;
//console.debug('total=', total);
$.each(pages, function (id, value) {
var title = value.title.replace(/^Talk:/g, '');
$.ajax({
url: '//en.wikipedia.org/w/api.php',
dataType: 'jsonp',
data: {
'format': 'json',
'action': 'query',
'prop': 'langlinks',
'titles': title,
'lllang': 'pt',
'indexpageids': true
},
success: function (data) {
var pagePt, someTitles;
done++;
try {
pagePt = data.query.pages[data.query.pageids[0]].langlinks[0]['*'];
} catch (err) {
toTranslate.push(data.query.pages[data.query.pageids[0]].title);
//console.debug('Parece que o artigo "' + data.query.pages[ data.query.pageids[0] ].title + '" não existe em português');
return false;
}
titlesPt.push(pagePt);
if (done === total) {
console.debug('==A traduzir==\n* [[:en:' + toTranslate.join(']]\n* [[:en:') + ']]');
var processPages = function (data) {
var pagePt, sizePt;
console.debug('{| class="wikitable sortable"\n|-\n! Artigo !! Bytes');
//console.debug('data.query.pageids.length=', data.query.pageids.length);
$.each(data.query.pageids, function (id, value) {
pagePt = data.query.pages[value].title;
sizePt = data.query.pages[value].revisions[0].size;
console.debug('| [[:-\n| [[' + pagePt + ']]]] || ' + sizePt);
table.push([pagePt, sizePt]);
});
//console.debug('|}');
};
while (titlesPt.length > 50) {
someTitles = titlesPt.slice(0, 50).join('|');
$.getJSON(
mw.util.wikiScript('api'), {
'format': 'json',
'action': 'query',
'titles': someTitles,
'prop': 'revisions',
'rvprop': 'size',
'indexpageids': '1'
}, processPages
);
titlesPt = titlesPt.slice(50);
}
// console.debug( titlesPt.join('|') );
}
},
error: function (data) {
done++;
errors.push(title);
}
});
});
}
});
}
getArticles();