69 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
70 $namespaceIds = $contLang->getNamespaceIds();
71 $caseSensitiveNamespaces = [];
72 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
73 foreach ( $nsInfo->getCanonicalNamespaces() as $index =>
$name ) {
74 $namespaceIds[$contLang->lc(
$name )] = $index;
75 if ( !$nsInfo->isCapitalized( $index ) ) {
76 $caseSensitiveNamespaces[] = $index;
80 $illegalFileChars = $conf->get(
'IllegalFileChars' );
87 'stylepath' => $conf->get(
'StylePath' ),
89 'wgArticlePath' => $conf->get(
'ArticlePath' ),
90 'wgScriptPath' => $conf->get(
'ScriptPath' ),
91 'wgScript' => $conf->get(
'Script' ),
92 'wgSearchType' => $conf->get(
'SearchType' ),
93 'wgVariantArticlePath' => $conf->get(
'VariantArticlePath' ),
96 'wgActionPaths' => (object)$conf->get(
'ActionPaths' ),
97 'wgServer' => $conf->get(
'Server' ),
98 'wgServerName' => $conf->get(
'ServerName' ),
99 'wgUserLanguage' =>
$context->getLanguage(),
100 'wgContentLanguage' => $contLang->getCode(),
101 'wgTranslateNumerals' => $conf->get(
'TranslateNumerals' ),
102 'wgVersion' => $conf->get(
'Version' ),
103 'wgEnableAPI' =>
true,
104 'wgEnableWriteAPI' =>
true,
105 'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(),
106 'wgNamespaceIds' => $namespaceIds,
107 'wgContentNamespaces' => $nsInfo->getContentNamespaces(),
108 'wgSiteName' => $conf->get(
'Sitename' ),
109 'wgDBname' => $conf->get(
'DBname' ),
111 'wgExtraSignatureNamespaces' => $conf->get(
'ExtraSignatureNamespaces' ),
112 'wgExtensionAssetsPath' => $conf->get(
'ExtensionAssetsPath' ),
114 'wgCookiePrefix' => $conf->get(
'CookiePrefix' ),
115 'wgCookieDomain' => $conf->get(
'CookieDomain' ),
116 'wgCookiePath' => $conf->get(
'CookiePath' ),
117 'wgCookieExpiration' => $conf->get(
'CookieExpiration' ),
118 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
121 'wgForeignUploadTargets' => $conf->get(
'ForeignUploadTargets' ),
122 'wgEnableUploads' => $conf->get(
'EnableUploads' ),
123 'wgCommentByteLimit' =>
null,
127 Hooks::run(
'ResourceLoaderGetConfigVars', [ &$vars, $skin, $conf ] );
146 static $dependencyCache = [];
150 if ( !isset( $dependencyCache[$moduleName] ) ) {
151 if ( !isset( $registryData[$moduleName] ) ) {
157 $data = $registryData[$moduleName];
158 $flat = $data[
'dependencies'];
161 $handled[] = $moduleName;
162 foreach ( $data[
'dependencies'] as $dependency ) {
163 if ( in_array( $dependency, $handled,
true ) ) {
174 self::getImplicitDependencies( $registryData, $dependency, $handled )
180 $dependencyCache[$moduleName] = $flat;
183 return $dependencyCache[$moduleName];
205 foreach ( $registryData as
$name => &$data ) {
206 $dependencies = $data[
'dependencies'];
208 foreach ( $data[
'dependencies'] as $dependency ) {
210 $dependencies = array_diff( $dependencies, $implicitDependencies );
214 $dependencies = $data[
'dependencies'];
218 $data[
'dependencies'] = array_values( $dependencies );
232 $target =
$context->getRequest()->getRawVal(
'target',
'desktop' );
233 $safemode =
$context->getRequest()->getRawVal(
'safemode' ) ===
'1';
236 $byPassTargetFilter = $this->
getConfig()->get(
'EnableJavaScriptTest' ) && $target ===
'test';
247 }
catch ( Exception $e ) {
251 'Preloading module info from startup failed: {exception}',
252 [
'exception' => $e ]
257 foreach ( $moduleNames as
$name ) {
259 $moduleTargets = $module->getTargets();
261 ( !$byPassTargetFilter && !in_array( $target, $moduleTargets ) )
262 || ( $safemode && $module->getOrigin() > ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL )
284 }
catch ( Exception $e ) {
288 'Calculating version for "{module}" failed: {exception}',
295 $states[
$name] =
'error';
299 $e =
new RuntimeException(
"Badly formatted module version hash" );
301 "Module '{module}' produced an invalid version hash: '{version}'.",
312 $skipFunction = $module->getSkipFunction();
313 if ( $skipFunction !==
null && !
$context->getDebug() ) {
314 $skipFunction = ResourceLoader::filter(
'minify-js', $skipFunction );
317 $registryData[
$name] = [
319 'dependencies' => $module->getDependencies(
$context ),
320 'group' => $this->
getGroupId( $module->getGroup() ),
321 'source' => $module->getSource(),
322 'skip' => $skipFunction,
333 foreach ( $registryData as
$name => $data ) {
338 $data[
'dependencies'],
341 $data[
'source'] ===
'local' ? null : $data[
'source'],
347 $out .=
"\n" . ResourceLoader::makeLoaderRegisterScript(
$context, $registrations );
350 $out .=
"\n" . ResourceLoader::makeLoaderStateScript(
$context, $states );
357 if ( $groupName ===
null ) {
361 if ( !array_key_exists( $groupName, $this->groupIds ) ) {
362 $this->groupIds[$groupName] = count( $this->groupIds );
365 return $this->groupIds[$groupName];
374 $baseModules = [
'jquery',
'mediawiki.base' ];
385 return 'MediaWikiModuleStore:' . $this->
getConfig()->get(
'DBname' );
395 return implode(
':', [
397 $this->
getConfig()->get(
'ResourceLoaderStorageVersion' ),
410 if ( $context->
getOnly() !==
'scripts' ) {
411 return '/* Requires only=script */';
414 $startupCode = file_get_contents(
"$IP/resources/src/startup/startup.js" );
418 $mwLoaderCode = file_get_contents(
"$IP/resources/src/startup/mediawiki.js" ) .
419 file_get_contents(
"$IP/resources/src/startup/mediawiki.requestIdleCallback.js" );
421 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/mediawiki.log.js" );
423 if ( $conf->get(
'ResourceLoaderEnableJSProfiler' ) ) {
424 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/profiler.js" );
430 '$VARS.baseModules' =>
$context->encodeJson( $this->getBaseModules() ),
431 '$VARS.maxQueryLength' =>
$context->encodeJson(
432 $conf->get(
'ResourceLoaderMaxQueryLength' )
436 '$VARS.storeEnabled' =>
$context->encodeJson(
437 $conf->get(
'ResourceLoaderStorageEnabled' ) && !
$context->getDebug()
439 '$VARS.wgLegacyJavaScriptGlobals' =>
$context->encodeJson(
440 $conf->get(
'LegacyJavaScriptGlobals' )
442 '$VARS.storeKey' =>
$context->encodeJson( $this->getStoreKey() ),
443 '$VARS.storeVary' =>
$context->encodeJson( $this->getStoreVary(
$context ) ),
444 '$VARS.groupUser' =>
$context->encodeJson( $this->getGroupId(
'user' ) ),
445 '$VARS.groupPrivate' =>
$context->encodeJson( $this->getGroupId(
'private' ) ),
448 '$CODE.profileExecuteStart();' =>
'mw.loader.profiler.onExecuteStart( module );',
449 '$CODE.profileExecuteEnd();' =>
'mw.loader.profiler.onExecuteEnd( module );',
450 '$CODE.profileScriptStart();' =>
'mw.loader.profiler.onScriptStart( module );',
451 '$CODE.profileScriptEnd();' =>
'mw.loader.profiler.onScriptEnd( module );',
453 if ( $conf->get(
'ResourceLoaderEnableJSProfiler' ) ) {
455 $mwLoaderPairs += $profilerStubs;
458 $mwLoaderPairs += array_fill_keys( array_keys( $profilerStubs ),
'' );
460 $mwLoaderCode = strtr( $mwLoaderCode, $mwLoaderPairs );
464 '$VARS.configuration' =>
$context->encodeJson(
469 '$CODE.defineLoader();' => $mwLoaderCode,
471 $startupCode = strtr( $startupCode, $pairs );