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
$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}'.",
$registryData[$name] = [
'version' => $versionHash,
'dependencies' => $module->getDependencies( $context ),
- 'group' => $module->getGroup(),
+ 'group' => $this->getGroupId( $module->getGroup() ),
'source' => $module->getSource(),
'skip' => $skipFunction,
];
return $out;
}
- /**
- * @private For internal use by SpecialJavaScriptTest
- * @since 1.32
- * @return array
- * @codeCoverageIgnore
- */
- public function getBaseModulesInternal() {
- return $this->getBaseModules();
+ 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];
}
/**
* @return array
*/
private function getBaseModules() {
- global $wgIncludeLegacyJavaScript;
-
$baseModules = [ 'jquery', 'mediawiki.base' ];
- if ( $wgIncludeLegacyJavaScript ) {
- $baseModules[] = 'mediawiki.legacy.wikibits';
- }
-
return $baseModules;
}
),
'$VARS.storeKey' => ResourceLoader::encodeJsonForScript( $this->getStoreKey() ),
'$VARS.storeVary' => ResourceLoader::encodeJsonForScript( $this->getStoreVary( $context ) ),
+ '$VARS.groupUser' => ResourceLoader::encodeJsonForScript( $this->getGroupId( 'user' ) ),
+ '$VARS.groupPrivate' => ResourceLoader::encodeJsonForScript( $this->getGroupId( 'private' ) ),
];
$profilerStubs = [
'$CODE.profileExecuteStart();' => 'mw.loader.profiler.onExecuteStart( module );',