class ResourceLoaderStartUpModule extends ResourceLoaderModule {
protected $targets = [ 'desktop', 'mobile' ];
+ private $groupIds = [
+ // These reserved numbers MUST start at 0 and not skip any. These are preset
+ // for forward compatiblity so that they can be safely referenced by mediawiki.js,
+ // even when the code is cached and the order of registrations (and implicit
+ // group ids) changes between versions of the software.
+ 'user' => 0,
+ 'private' => 1,
+ ];
+
/**
* @param ResourceLoaderContext $context
* @return array
'wgContentNamespaces' => $nsInfo->getContentNamespaces(),
'wgSiteName' => $conf->get( 'Sitename' ),
'wgDBname' => $conf->get( 'DBname' ),
+ 'wgWikiID' => WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ),
'wgExtraSignatureNamespaces' => $conf->get( 'ExtraSignatureNamespaces' ),
'wgExtensionAssetsPath' => $conf->get( 'ExtensionAssetsPath' ),
// MediaWiki sets cookies to have this prefix by default
'wgCommentCodePointLimit' => CommentStore::COMMENT_CHARACTER_LIMIT,
];
- Hooks::run( 'ResourceLoaderGetConfigVars', [ &$vars, $skin ] );
+ Hooks::run( 'ResourceLoaderGetConfigVars', [ &$vars, $skin, $conf ] );
return $vars;
}
$states[$name] = 'error';
}
- if ( $versionHash !== '' && strlen( $versionHash ) !== 7 ) {
+ if ( $versionHash !== '' && strlen( $versionHash ) !== ResourceLoader::HASH_LENGTH ) {
$e = new RuntimeException( "Badly formatted module version hash" );
$resourceLoader->outputErrorAndLog( $e,
"Module '{module}' produced an invalid version hash: '{version}'.",
}
$skipFunction = $module->getSkipFunction();
- if ( $skipFunction !== null && !ResourceLoader::inDebugMode() ) {
+ if ( $skipFunction !== null && !$context->getDebug() ) {
$skipFunction = ResourceLoader::filter( 'minify-js', $skipFunction );
}
$registryData[$name] = [
'version' => $versionHash,
'dependencies' => $module->getDependencies( $context ),
- 'group' => $module->getGroup(),
+ 'group' => $this->getGroupId( $module->getGroup() ),
'source' => $module->getSource(),
'skip' => $skipFunction,
];
self::compileUnresolvedDependencies( $registryData );
// Register sources
- $out .= ResourceLoader::makeLoaderSourcesScript( $resourceLoader->getSources() );
+ $out .= ResourceLoader::makeLoaderSourcesScript( $context, $resourceLoader->getSources() );
// Figure out the different call signatures for mw.loader.register
$registrations = [];
}
// Register modules
- $out .= "\n" . ResourceLoader::makeLoaderRegisterScript( $registrations );
+ $out .= "\n" . ResourceLoader::makeLoaderRegisterScript( $context, $registrations );
if ( $states ) {
- $out .= "\n" . ResourceLoader::makeLoaderStateScript( $states );
+ $out .= "\n" . ResourceLoader::makeLoaderStateScript( $context, $states );
}
return $out;
}
+ private function getGroupId( $groupName ) {
+ if ( $groupName === null ) {
+ return null;
+ }
+
+ if ( !array_key_exists( $groupName, $this->groupIds ) ) {
+ $this->groupIds[$groupName] = count( $this->groupIds );
+ }
+
+ return $this->groupIds[$groupName];
+ }
+
/**
* Base modules implicitly available to all modules.
*
* @return array
*/
private function getBaseModules() {
- global $wgIncludeLegacyJavaScript;
-
$baseModules = [ 'jquery', 'mediawiki.base' ];
- if ( $wgIncludeLegacyJavaScript ) {
- $baseModules[] = 'mediawiki.legacy.wikibits';
- }
-
return $baseModules;
}
// Perform replacements for mediawiki.js
$mwLoaderPairs = [
- '$VARS.reqBase' => ResourceLoader::encodeJsonForScript( $context->getReqBase() ),
- '$VARS.baseModules' => ResourceLoader::encodeJsonForScript( $this->getBaseModules() ),
- '$VARS.maxQueryLength' => ResourceLoader::encodeJsonForScript(
+ '$VARS.reqBase' => $context->encodeJson( $context->getReqBase() ),
+ '$VARS.baseModules' => $context->encodeJson( $this->getBaseModules() ),
+ '$VARS.maxQueryLength' => $context->encodeJson(
$conf->get( 'ResourceLoaderMaxQueryLength' )
),
// The client-side module cache can be disabled by site configuration.
// It is also always disabled in debug mode.
- '$VARS.storeEnabled' => ResourceLoader::encodeJsonForScript(
+ '$VARS.storeEnabled' => $context->encodeJson(
$conf->get( 'ResourceLoaderStorageEnabled' ) && !$context->getDebug()
),
- '$VARS.wgLegacyJavaScriptGlobals' => ResourceLoader::encodeJsonForScript(
+ '$VARS.wgLegacyJavaScriptGlobals' => $context->encodeJson(
$conf->get( 'LegacyJavaScriptGlobals' )
),
- '$VARS.storeKey' => ResourceLoader::encodeJsonForScript( $this->getStoreKey() ),
- '$VARS.storeVary' => ResourceLoader::encodeJsonForScript( $this->getStoreVary( $context ) ),
+ '$VARS.storeKey' => $context->encodeJson( $this->getStoreKey() ),
+ '$VARS.storeVary' => $context->encodeJson( $this->getStoreVary( $context ) ),
+ '$VARS.groupUser' => $context->encodeJson( $this->getGroupId( 'user' ) ),
+ '$VARS.groupPrivate' => $context->encodeJson( $this->getGroupId( 'private' ) ),
];
$profilerStubs = [
'$CODE.profileExecuteStart();' => 'mw.loader.profiler.onExecuteStart( module );',
// Perform string replacements for startup.js
$pairs = [
- '$VARS.configuration' => ResourceLoader::encodeJsonForScript(
+ '$VARS.configuration' => $context->encodeJson(
$this->getConfigSettings( $context )
),
// Raw JavaScript code (not JSON)