User:Yair rand/GetArbPrinciples.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Yair rand/GetArbPrinciples. |
// Run this from the JS console on an enwiki page, it will generate (to log)
// [[Wikipedia:Arbitration/Index/Principles]] from all pages under
// WP:Arbitration/Requests/Case/. Is quite messy (no var names, etc), as it was
// primarily built with one-time-use in mind, but it should still work for later
// updates as necessary. Note that principles from courtesy-blanked cases will
// be removed in updates.
( async function () {
var x = await ( new mw.Api() ).get( {
action: 'query', list: 'allpages', apfrom:'Arbitration/Requests/Case/',
apnamespace: 4, aplimit: 500, apfilterredir: 'nonredirects'
} )
.then( x => { return x.query.allpages; } );
var xx = x.map( x => x.title ).filter( x => x.match(/\//g).length === 3 );
var ap = xx.slice( 0 );
function gp() {
return (new mw.Api()).get({action:'query',prop:'revisions',rvslots:'*',rvprop:'content',titles:ap.splice(0,50)}).then( x => {
if ( ap.length ) {
return gp().then( y => [ x, ...y ] );
} else {
return [ x ];
}
} );
}
var xxx = await gp();
var aw = xxx.map( x => Object.values( x.query.pages ) ).flat();
function alphabetically( a, b ) {
return a === b ? 0 : a < b ? -1 : 1;
}
var qq = Object.values( aw ).map( t => {
var page = t.revisions[ 0 ].slots.main["*"],
m = page.match(/\n==\s*Principles\s*==\n([\s\S]*?)\n==[^=]/),
closeString = page.match( /<big>'''Case closed''' on \d\d\:\d\d\, ([^(]+)/i),
closeDString = closeString && new Date( closeString[ 1 ].trim() ),
closeDate = closeDString && closeDString.getFullYear() + '-' + ( closeDString.getMonth() + 1 ).toString().padStart(2,0);
if ( !closeDString ) { console.error( t.title ); return []; }
if ( m && m[ 1 ] ) {
var b = m[ 1 ],
r = [ ...b.matchAll( /(?:^|\n)===+\s*([^\n]+?)===+\n[\dA-Z]+(?:\.\d+)?\)\s*([\s\S]*?)(?=\n==|$)/g ) ]
.map( x => [
x[ 1 ].trim().replace( /\s*\((?:\d+|[Aa]lternate|I+V?|V)\)$/, '' ), // header
x[ 2 ].replace( /<p>/g, '' ).replace(/\n\:+\s*(?:\'\')?\s*Passed.+[\n\s]*$/, '' ).replace( / /g, ' ' ).trim(),
t.title,
x[ 1 ].trim(), // anchor
closeDate
] );
return r;
}
} ).flat().sort( ( a, b ) => alphabetically( a[ 0 ], b[ 0 ] ) || alphabetically( a[ 4 ] || b[ 4 ] ) ).filter(x=>x);
var result = [...new Set(qq.map(x=>x[0]))].map( header =>{
var h = '==' + header + '==\n',
g = qq.filter( y => y[ 0 ] === header ),
// by paragraph
p = [ ...new Set( g.map( x => x[ 1 ] ) ) ],
// paragraph groups
l = p.map( pp => {
var ppp = g.filter( x => x[ 1 ] === pp );
return pp + ' <small> -' + ppp.sort( ( a, b ) => alphabetically( a[ 4 ], b[ 4 ] ) ).map( ( x, i ) => '[[' + x[ 2 ] + '#' + x[ 3 ] + '|' + (x[ 4 ]) + ']]' ).join(', ') + '</small>'; } );
return h + l.join('\n----\n');
} ).join('\n');
console.log( result );
return result;
} )();