Created
June 22, 2016 23:58
-
-
Save jdlrobson/1ab2097d44a0da272f3b14e05d262a61 to your computer and use it in GitHub Desktop.
Query all main pages belonging to a Wikimedia project to see if they are special casing the main page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Usage: | |
> node index.js 'meta.wikimedia.org' 1 | |
> node index.js 'wikipedia.org' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fetch = require( 'node-fetch' ); | |
var errors = []; | |
var legacy = []; | |
var clean = []; | |
var pending = 0; | |
var unknowns = []; | |
var missing = []; | |
function report() { | |
if ( pending === 0 ) { | |
console.log( 'Missing' ); | |
console.log( JSON.stringify( missing ) ); | |
console.log( 'Errors' ); | |
console.log( JSON.stringify( errors ) ); | |
console.log( 'Legacy:' ); | |
console.log( JSON.stringify( legacy ) ); | |
console.log( 'Clean:' ); | |
console.log( JSON.stringify( clean ) ); | |
console.log( 'Unknown (page doesnt exist):' ); | |
console.log( JSON.stringify( unknowns ) ); | |
} | |
} | |
function test( lang, project, title ) { | |
title = title || 'Main Page'; | |
title = encodeURIComponent( title ); | |
var prefix = lang ? lang + '.' : ''; | |
var host = 'https://' + prefix + project; | |
var url = host + '/w/api.php?action=mobileview&format=json&page=' + title + '&redirect=yes&formatversion=2'; | |
return fetch( url ) | |
.then( function ( resp ) { | |
if ( resp.status !== 200 || resp.url.indexOf( 'incubator' ) > -1 ) { | |
missing.push( lang ); | |
return Promise.reject(); | |
} else { | |
return resp.json(); | |
} | |
}, function () { | |
console.log(url); | |
errors.push( lang ); | |
}).then( function ( json ) { | |
if ( json.error ) { | |
if ( json.error.code === 'missingtitle' ) { | |
unknowns.push( lang ); | |
} | |
} else { | |
try { | |
var sections = json.mobileview.sections; | |
var text = []; | |
sections.forEach( function ( section ) { | |
text.push( section.text || '' ); | |
}) | |
text = text.join( '\n' ); | |
if ( text.match( /id=\"mf-/ ) ) { | |
legacy.push( lang ); | |
} else { | |
clean.push( lang ); | |
} | |
} catch ( e ) { | |
console.log(e, lang, json); | |
errors.push( lang ); | |
} | |
} | |
}); | |
} | |
var langs = ["ab","ace","ady","af","ak","sq","als","am","ang","ar","an","hy","roa-rup","as","ast","av","ay","az","bm","bjn","map-bms","ba","eu","bar","be","be-x-old","bn","bh","bpy","bi","bs","br","bug","bg","my","bxr","zh-yue","ca","ceb","bcl","ch","ce","chr","chy","ny","zh","cv","zh-classical","kw","co","cr","crh","hr","cs","da","dv","nl","nds-nl","dz","arz","eml","en","myv","eo","et","ee","fo","hif","fj","fi","frp","fr","fur","ff","gag","gl","gan","ka","de","glk","gom","got","el","kl","gn","gu","ht","hak","ha","haw","he","mrj","hi","hu","is","io","ig","ilo","id","ia","ie","iu","ik","ga","it","ja","jv","kbd","kab","xal","kn","pam","krc","kaa","ks","csb","km","ki","rw","rn","kv","koi","kg","ko","ku","ky","lad","lbe","lo","ltg","la","lv","lez","lij","li","ln","lt","jbo","lmo","nds","dsb","lg","lb","mk","mai","mg","ms","ml","mt","gv","mr","mzn","mhr","cdo","zh-min-nan","min","xmf","mwl","mdf","mn","mi","na","nv","nap","ne","new","pih","nrm","frr","lrc","se","nso","no","nn","nov","nah","oc","cu","or","om","os","pfl","pi","pag","pap","ps","pdc","fa","pcd","pms","pl","pnt","pt","pa","qu","ksh","ro","rm","ru","rue","sah","sm","bat-smg","sg","sa","sc","stq","sco","gd","sr","sh","st","sn","scn","szl","simple","sd","si","sk","sl","so","ckb","azb","es","srn","su","sw","ss","sv","arc","tl","ty","tg","ta","roa-tara","tt","te","tet","th","bo","ti","tpi","to","ts","tn","tum","tr","tk","tyv","tw","udm","uk","hsb","ur","ug","uz","ve","vec","vep","vi","rmy","vo","fiu-vro","wa","war","cy","vls","fy","pnb","wo","wuu","xh","yi","yo","cbk-zam","diq","zea","za","zu"]; | |
var project = process.argv[2]; | |
console.log( 'Running for ' + project ); | |
if ( process.argv[3] ) { | |
langs = [ false ]; | |
} | |
langs.forEach( function ( lang ) { | |
pending++; | |
test( lang, project ).then( function () { | |
pending--; | |
report(); | |
}, function () { | |
pending--; | |
report(); | |
}); | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment