Jump to content

MediaWiki:Gadget-afchelper.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.
// <nowiki>
( function () {
	// Check that we're in a namespace that uses AFCH.
	// In the gadget, namespaces are checked by the gadgets extension, and the below check is not needed, since we defined namespaces in MediaWiki:Gadgets-definition.
	// But in server.js, we don't get this gadget check, so we need to check it below. Else you'll get AFCH appearing on the Main Page :)
	const userNamespace = 2;
	const draftNamespace = 118;
	if ( ![ draftNamespace, userNamespace ].includes( mw.config.get( 'wgNamespaceNumber' ) ) ) {
		return;
	}

	// Initialize the AFCH object
	window.AFCH = {};

	// Set up constants
	AFCH.consts = {};

	AFCH.consts.scriptpath = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' );

	// These next two statements (setting beta and baseurl) may be modified
	// by the uploading script! If you change them, check that the uploading
	// script at scripts/deploy.js doesn't break.
	AFCH.consts.beta = false;
	AFCH.consts.baseurl = AFCH.consts.scriptpath +
		'?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js';

	$.getScript( AFCH.consts.baseurl + '/core.js' ).done( () => {
		const loaded = AFCH.load( 'submissions' ); // perhaps eventually there will be more modules besides just 'submissions'
		if ( !loaded ) {
			mw.notify( 'AFCH could not be loaded: ' + ( AFCH.error || 'unknown error' ),
				{ title: 'AFCH error' } );
		}
	} );
}() );
// </nowiki>