MediaWiki:Gadget-afchelper.js: Difference between revisions

>Enterprisey
Updating AFCH: master @ c9ba43
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Uploaded from https://github.com/WPAFC/afch-rewrite, commit: c9ba43e1d5672f35dd3fcd4138d9378ffa9defa1 (master) */
// <nowiki>
//<nowiki>
( function () {
( function () {
// Check that we're in the right namespace and on the right page
// Check that we're in a namespace that uses AFCH.
switch ( mw.config.get( 'wgNamespaceNumber' ) ) {
// 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.
case 4: // Wikipedia
// 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 :)
case 5: // Wikipedia talk
const userNamespace = 2;
var i = -1;
const draftNamespace = 118;
var pageName = mw.config.get( 'wgTitle' );
if ( ![ draftNamespace, userNamespace ].includes( mw.config.get( 'wgNamespaceNumber' ) ) ) {
while ( ++i < 22 ) { // 'Articles for creation/'.length === 22
return;
if ( pageName.charCodeAt( i ) !== 'Articles for creation/'.charCodeAt( i ) ) {
return;
}
}
if ( pageName === 'Wikipedia:Articles_for_creation/Redirects' ) {
return;
}
break;
case 2: // User
case 118: // Draft
break;
default:
return;
}
}


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


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

Latest revision as of 11:01, 1 May 2026

// <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>