Jump to content

User:Qwerfjkl/scripts/allredirects.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
	get_allredirects.js

	MediaWiki API Demos
	Demo of `Allredirects` module: Get the first three unique
	pages containing redirects to the main namespace.

	MIT License
*/

var params = {
		action: 'query',
		format: 'json',
		list: 'allredirects',
		arunique: '1',
		arnamespace: '0',
		arlimit: '3'
	},
	api = new mw.Api();
var redirects = [];
api.get( params ).done( function ( data ) {
	var redirects = data.query.allredirects,
		r;
	for ( r in redirects ) {
		redirects.push( redirects[ r ].title );
	}
} );
alert(redirects);