User:Glaisher/setGlobalPrefs.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/**
* This can be used to change preferences across all the CentralAuth wikis where you have an attached account.
* It will fail on the wiki where it's run (but you can change that manually).
* To execute this, go Special:BlankPage and run this script on your browser console
* after changing "change" parameter in changePrefs() function's API request.
* See https://meta.wikimedia.org/w/api.php?action=query&meta=userinfo&uiprop=options
* for an (incomplete) list of available options.
* Options API help: https://meta.wikimedia.org/w/api.php?action=help&modules=options
*/
mw.loader.using( 'mediawiki.ForeignApi', function() {
function getAttachedWikis() {
return new mw.Api().get( {
action: 'query',
meta: 'globaluserinfo',
guiprop: 'merged',
} ).then( function( result ) {
return result.query.globaluserinfo.merged;
}, function() {
return null;
} );
}
function changePrefs( wikiInfo ) {
var api = new mw.ForeignApi( wikiInfo.url + '/w/api.php' );
api.postWithToken( 'csrf', {
action: 'options',
change: 'gender=unknown'
} ).done( function ( data ) {
if ( data.warnings ) {
onError( data, wikiInfo.wiki );
return;
}
$( '#mw-content-text' ).append( 'Done at ' + wikiInfo.wiki + '<br/>');
} ).fail( function( data ) {
onError( data, wikiInfo.wiki );
} );
}
function onError( data, wikiName ) {
console.log( wikiName, data );
$( '#mw-content-text' ).append( 'Failed at ' + wikiName + ' <br/>');
}
function init() {
getAttachedWikis().done( function( mergedWikis ) {
$.each( mergedWikis, function( i, data ) {
// Requests rate is throttled
setTimeout( function() {
changePrefs( data ) }, i * 500 );
} );
} );
}
init();
} );