MediaWiki:Gadget-updates.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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//<nowiki>

(function() {
    const conf = mw.config.get( [
        'wgTitle',
        'wgUserGroups',
        'wgAction',
        'wgNamespaceNumber'
    ] );

    function doUpdate( func ) {
        ///mw.loader.using( 'ext.gadget.updates-core', function() {
        ///    window.UPD[func]();
        ///} );

        //TEMP: debugging in user space
		var retry = 0;
		function delayLoad() {
		    if( window.UPD ) {
		        return window.UPD[func]();
		    }
		    
		    if( retry < 5 ) {
		        console.log( "window.UPD not loaded yet, retrying..." );
		        retry++;
		        setTimeout( delayLoad, 1000 );
		    } else {
		        console.error( "window.UPD not loaded after 5 seconds, giving up" );
		    }
		}
		
		mw.loader.load( 'ext.gadget.updates-core' );
        mw.loader.using( [ "oojs-ui-core", "oojs-ui-windows", "mediawiki.util" ], function() {
            // make sure core is loaded by now
            if( !window.UPD )
                delayLoad();
            else
                window.UPD[func]();
        } );
        //END TEMP
    }
	
	// if( true ) {
    if( conf.wgTitle === "Updates" || conf.wgNamespaceNumber === 100 && window.location.hash !== "#Gadget-updates" ) { // updates page or updates ns
        doUpdate( "init" );
    } else if( window.location.hash === "#Gadget-updates" ) {
        if( conf.wgAction === "edit" ) {
            doUpdate( "loadPreview" );
        } else if( conf.wgAction === "submit" ) {
            doUpdate( "hookSubmit" );
        }
	}
} )();

//</nowiki>