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' ),
110 'wgWikiID' => WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ),
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,
119 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
120 'wgIllegalFileChars' => Title::convertByteClassToUnicodeClass( $illegalFileChars ),
121 'wgForeignUploadTargets' => $conf->get(
'ForeignUploadTargets' ),
122 'wgEnableUploads' => $conf->get(
'EnableUploads' ),
123 'wgCommentByteLimit' =>
null,
124 'wgCommentCodePointLimit' => CommentStore::COMMENT_CHARACTER_LIMIT,
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];
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 );
423 $conf = $this->getConfig();
425 if (
$context->getOnly() !==
'scripts' ) {
426 return '/* Requires only=script */';
429 $startupCode = file_get_contents(
"$IP/resources/src/startup/startup.js" );
433 $mwLoaderCode = file_get_contents(
"$IP/resources/src/startup/mediawiki.js" ) .
434 file_get_contents(
"$IP/resources/src/startup/mediawiki.requestIdleCallback.js" );
436 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/mediawiki.log.js" );
438 if ( $conf->get(
'ResourceLoaderEnableJSProfiler' ) ) {
439 $mwLoaderCode .= file_get_contents(
"$IP/resources/src/startup/profiler.js" );
445 '$VARS.baseModules' =>
$context->encodeJson( $this->getBaseModules() ),
446 '$VARS.maxQueryLength' =>
$context->encodeJson( $this->getMaxQueryLength() ),
449 '$VARS.storeEnabled' =>
$context->encodeJson(
450 $conf->get(
'ResourceLoaderStorageEnabled' ) && !
$context->getDebug()
452 '$VARS.wgLegacyJavaScriptGlobals' =>
$context->encodeJson(
453 $conf->get(
'LegacyJavaScriptGlobals' )
455 '$VARS.storeKey' =>
$context->encodeJson( $this->getStoreKey() ),
456 '$VARS.storeVary' =>
$context->encodeJson( $this->getStoreVary(
$context ) ),
457 '$VARS.groupUser' =>
$context->encodeJson( $this->getGroupId(
'user' ) ),
458 '$VARS.groupPrivate' =>
$context->encodeJson( $this->getGroupId(
'private' ) ),
461 '$CODE.profileExecuteStart();' =>
'mw.loader.profiler.onExecuteStart( module );',
462 '$CODE.profileExecuteEnd();' =>
'mw.loader.profiler.onExecuteEnd( module );',
463 '$CODE.profileScriptStart();' =>
'mw.loader.profiler.onScriptStart( module );',
464 '$CODE.profileScriptEnd();' =>
'mw.loader.profiler.onScriptEnd( module );',
466 if ( $conf->get(
'ResourceLoaderEnableJSProfiler' ) ) {
468 $mwLoaderPairs += $profilerStubs;
471 $mwLoaderPairs += array_fill_keys( array_keys( $profilerStubs ),
'' );
473 $mwLoaderCode = strtr( $mwLoaderCode, $mwLoaderPairs );
477 '$VARS.configuration' =>
$context->encodeJson(
478 $this->getConfigSettings(
$context )
481 '$CODE.registrations();' => trim( $this->getModuleRegistrations(
$context ) ),
482 '$CODE.defineLoader();' => $mwLoaderCode,
484 $startupCode = strtr( $startupCode, $pairs );