Remove extension function, move code into hooks
So the code only runs on requests which actually need it. Change-Id: I057f6e93b60037da2b01b1775f841726d14017ba
This commit is contained in:
@@ -76,6 +76,8 @@ class UniversalLanguageSelectorHooks {
|
|||||||
|
|
||||||
if ( is_string( $wgULSGeoService ) ) {
|
if ( is_string( $wgULSGeoService ) ) {
|
||||||
$out->addModules( 'ext.uls.geoclient' );
|
$out->addModules( 'ext.uls.geoclient' );
|
||||||
|
} elseif ( $wgULSGeoService === true ) {
|
||||||
|
$out->addScript( '<script src="//bits.wikimedia.org/geoiplookup"></script>' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self::isToolbarEnabled( $out->getUser() ) ) {
|
if ( self::isToolbarEnabled( $out->getUser() ) ) {
|
||||||
@@ -92,6 +94,35 @@ class UniversalLanguageSelectorHooks {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register conditional modules
|
||||||
|
*
|
||||||
|
* @param ResourceLoader $rl
|
||||||
|
*/
|
||||||
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$rl ) {
|
||||||
|
global $wgULSEventLogging;
|
||||||
|
// If EventLogging integration is enabled, first ensure that
|
||||||
|
// the EventLogging extension is present, then declare schema module.
|
||||||
|
// If it is not present, emit a warning and disable logging.
|
||||||
|
if ( $wgULSEventLogging ) {
|
||||||
|
if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
|
||||||
|
// NB: When updating the schema, remember also to update the version
|
||||||
|
// in the schema default in the JavaScript library.
|
||||||
|
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
|
||||||
|
$rl->register( 'schema.UniversalLanguageSelector', array(
|
||||||
|
'class' => 'ResourceLoaderSchemaModule',
|
||||||
|
'schema' => 'UniversalLanguageSelector',
|
||||||
|
'revision' => 7327441,
|
||||||
|
) );
|
||||||
|
} else {
|
||||||
|
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, '
|
||||||
|
. 'but the extension is not available. Disabling wgULSEventLogging.' );
|
||||||
|
$wgULSEventLogging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $testModules array of javascript testing modules. 'qunit' is fed
|
* @param $testModules array of javascript testing modules. 'qunit' is fed
|
||||||
* using tests/qunit/QUnitTestResources.php.
|
* using tests/qunit/QUnitTestResources.php.
|
||||||
|
|||||||
@@ -200,6 +200,8 @@ $GLOBALS['wgAutoloadClasses'] += array(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$GLOBALS['wgHooks']['BeforePageDisplay'][] = 'UniversalLanguageSelectorHooks::addModules';
|
$GLOBALS['wgHooks']['BeforePageDisplay'][] = 'UniversalLanguageSelectorHooks::addModules';
|
||||||
|
$GLOBALS['wgHooks']['ResourceLoaderRegisterModules'][] =
|
||||||
|
'UniversalLanguageSelectorHooks::onResourceLoaderRegisterModules';
|
||||||
$GLOBALS['wgHooks']['PersonalUrls'][] = 'UniversalLanguageSelectorHooks::addPersonalBarTrigger';
|
$GLOBALS['wgHooks']['PersonalUrls'][] = 'UniversalLanguageSelectorHooks::addPersonalBarTrigger';
|
||||||
$GLOBALS['wgHooks']['ResourceLoaderTestModules'][] =
|
$GLOBALS['wgHooks']['ResourceLoaderTestModules'][] =
|
||||||
'UniversalLanguageSelectorHooks::addTestModules';
|
'UniversalLanguageSelectorHooks::addTestModules';
|
||||||
@@ -217,39 +219,4 @@ $GLOBALS['wgHooks']['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGet
|
|||||||
$GLOBALS['wgHooks']['GetBetaFeaturePreferences'][] =
|
$GLOBALS['wgHooks']['GetBetaFeaturePreferences'][] =
|
||||||
'UniversalLanguageSelectorHooks::onGetBetaFeaturePreferences';
|
'UniversalLanguageSelectorHooks::onGetBetaFeaturePreferences';
|
||||||
|
|
||||||
$GLOBALS['wgExtensionFunctions'][] = function () {
|
|
||||||
global $wgHooks, $wgResourceModules, $wgULSEventLogging, $wgULSGeoService;
|
|
||||||
|
|
||||||
if ( $wgULSGeoService === true ) {
|
|
||||||
$wgHooks['BeforePageDisplay'][] = function ( &$out ) {
|
|
||||||
/** @var OutputPage $out */
|
|
||||||
$out->addScript( '<script src="//bits.wikimedia.org/geoiplookup"></script>' );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// If EventLogging integration is enabled, first ensure that
|
|
||||||
// the EventLogging extension is present, then declare schema module.
|
|
||||||
// If it is not present, emit a warning and disable logging.
|
|
||||||
if ( $wgULSEventLogging ) {
|
|
||||||
if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
|
|
||||||
// NB: When updating the schema, remember also to update the version
|
|
||||||
// in the schema default in the JavaScript library.
|
|
||||||
/// @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
|
|
||||||
$wgResourceModules['schema.UniversalLanguageSelector'] = array(
|
|
||||||
'class' => 'ResourceLoaderSchemaModule',
|
|
||||||
'schema' => 'UniversalLanguageSelector',
|
|
||||||
'revision' => 7327441,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
wfWarn( 'UniversalLanguageSelector is configured to use EventLogging, '
|
|
||||||
. 'but the extension is not available. Disabling wgULSEventLogging.' );
|
|
||||||
$wgULSEventLogging = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
require __DIR__ . '/Resources.php';
|
require __DIR__ . '/Resources.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user