Jump to content

MediaWiki:Gadget-GlobalRenameQueueHomewikiHelper.js

From Meta, a Wikimedia project coordination wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
( function( $, mw ) {

	var api;

	function getHomeWiki( username, username2, callback ) {
		api.get( {
			action: 'query',
			meta: 'globaluserinfo',
			guiuser: username
		} ).done( function( data ) {
			var userData = data.query.globaluserinfo;

			if ( userData.missing !== "" ) {
				callback( userData.home );
			} else if ( username2 ) {
				getHomeWiki( username2, null, callback );
			}
		} );
	}

	$( function () {
		if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'GlobalRenameQueue' ) {
			return;
		}

		api = new mw.Api();

		$( '.mw-datatable > tbody > tr' ).each( function () {
			var $this = $( this ),
				username = $this.find( '.TablePager_col_rq_name' ).text(),
				newUsername = $this.find( '.TablePager_col_rq_newname' ).text();

			getHomeWiki( username, newUsername, function ( homewiki ) {
				$this.find( '.TablePager_col_rq_wiki' ).text( homewiki );
			} );
		} );
	} );
})( jQuery, mediaWiki );