private function getConfigSettings( $context ) {
$conf = $this->getConfig();
- // We can't use Title::newMainPage() if 'mainpage' is in
- // $wgForceUIMsgAsContentMsg because that will try to use the session
- // user's language and we have no session user. This does the
- // equivalent but falling back to our ResourceLoaderContext language
- // instead.
- $mainPage = Title::newFromText( $context->msg( 'mainpage' )->inContentLanguage()->text() );
- if ( !$mainPage ) {
- $mainPage = Title::newFromText( 'Main Page' );
- }
-
/**
* Namespace related preparation
* - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
$namespaceIds = $contLang->getNamespaceIds();
$caseSensitiveNamespaces = [];
- foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) {
+ $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+ foreach ( $nsInfo->getCanonicalNamespaces() as $index => $name ) {
$namespaceIds[$contLang->lc( $name )] = $index;
- if ( !MWNamespace::isCapitalized( $index ) ) {
+ if ( !$nsInfo->isCapitalized( $index ) ) {
$caseSensitiveNamespaces[] = $index;
}
}
// Build list of variables
$skin = $context->getSkin();
$vars = [
- 'wgLoadScript' => wfScript( 'load' ),
+ 'wgLoadScript' => $conf->get( 'LoadScript' ),
'debug' => $context->getDebug(),
'skin' => $skin,
'stylepath' => $conf->get( 'StylePath' ),
'wgUrlProtocols' => wfUrlProtocols(),
'wgArticlePath' => $conf->get( 'ArticlePath' ),
'wgScriptPath' => $conf->get( 'ScriptPath' ),
- 'wgScript' => wfScript(),
+ 'wgScript' => $conf->get( 'Script' ),
'wgSearchType' => $conf->get( 'SearchType' ),
'wgVariantArticlePath' => $conf->get( 'VariantArticlePath' ),
// Force object to avoid "empty" associative array from
'wgVersion' => $conf->get( 'Version' ),
'wgEnableAPI' => true, // Deprecated since MW 1.32
'wgEnableWriteAPI' => true, // Deprecated since MW 1.32
- 'wgMainPageTitle' => $mainPage->getPrefixedText(),
'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(),
'wgNamespaceIds' => $namespaceIds,
- 'wgContentNamespaces' => MWNamespace::getContentNamespaces(),
+ 'wgContentNamespaces' => $nsInfo->getContentNamespaces(),
'wgSiteName' => $conf->get( 'Sitename' ),
'wgDBname' => $conf->get( 'DBname' ),
'wgExtraSignatureNamespaces' => $conf->get( 'ExtraSignatureNamespaces' ),
*
* @param array $registryData
* @param string $moduleName
+ * @param string[] $handled Internal parameter for recursion. (Optional)
* @return array
+ * @throws ResourceLoaderCircularDependencyError
*/
- protected static function getImplicitDependencies( array $registryData, $moduleName ) {
+ protected static function getImplicitDependencies(
+ array $registryData,
+ $moduleName,
+ array $handled = []
+ ) {
static $dependencyCache = [];
- // The list of implicit dependencies won't be altered, so we can
- // cache them without having to worry.
+ // No modules will be added or changed server-side after this point,
+ // so we can safely cache parts of the tree for re-use.
if ( !isset( $dependencyCache[$moduleName] ) ) {
if ( !isset( $registryData[$moduleName] ) ) {
- // Dependencies may not exist
- $dependencyCache[$moduleName] = [];
+ // Unknown module names are allowed here, this is only an optimisation.
+ // Checks for illegal and unknown dependencies happen as PHPUnit structure tests,
+ // and also client-side at run-time.
+ $flat = [];
} else {
$data = $registryData[$moduleName];
- $dependencyCache[$moduleName] = $data['dependencies'];
+ $flat = $data['dependencies'];
+ // Prevent recursion
+ $handled[] = $moduleName;
foreach ( $data['dependencies'] as $dependency ) {
- // Recursively get the dependencies of the dependencies
- $dependencyCache[$moduleName] = array_merge(
- $dependencyCache[$moduleName],
- self::getImplicitDependencies( $registryData, $dependency )
- );
+ if ( in_array( $dependency, $handled, true ) ) {
+ // If we encounter a circular dependency, then stop the optimiser and leave the
+ // original dependencies array unmodified. Circular dependencies are not
+ // supported in ResourceLoader. Awareness of them exists here so that we can
+ // optimise the registry when it isn't broken, and otherwise transport the
+ // registry unchanged. The client will handle this further.
+ throw new ResourceLoaderCircularDependencyError();
+ } else {
+ // Recursively add the dependencies of the dependencies
+ $flat = array_merge(
+ $flat,
+ self::getImplicitDependencies( $registryData, $dependency, $handled )
+ );
+ }
}
}
+
+ $dependencyCache[$moduleName] = $flat;
}
return $dependencyCache[$moduleName];
public static function compileUnresolvedDependencies( array &$registryData ) {
foreach ( $registryData as $name => &$data ) {
$dependencies = $data['dependencies'];
- foreach ( $data['dependencies'] as $dependency ) {
- $implicitDependencies = self::getImplicitDependencies( $registryData, $dependency );
- $dependencies = array_diff( $dependencies, $implicitDependencies );
+ try {
+ foreach ( $data['dependencies'] as $dependency ) {
+ $implicitDependencies = self::getImplicitDependencies( $registryData, $dependency );
+ $dependencies = array_diff( $dependencies, $implicitDependencies );
+ }
+ } catch ( ResourceLoaderCircularDependencyError $err ) {
+ // Leave unchanged
+ $dependencies = $data['dependencies'];
}
+
// Rebuild keys
$data['dependencies'] = array_values( $dependencies );
}
}
if ( $versionHash !== '' && strlen( $versionHash ) !== 7 ) {
- $context->getLogger()->warning(
+ $this->getLogger()->warning(
"Module '{module}' produced an invalid version hash: '{version}'.",
[
'module' => $name,
return true;
}
- /**
- * Internal modules used by ResourceLoader that cannot be depended on.
- *
- * These module(s) should have isRaw() return true, and are not
- * legal dependencies (enforced by structure/ResourcesTest).
- *
- * @deprecated since 1.32 No longer used.
- * @return array
- */
- public static function getStartupModules() {
- wfDeprecated( __METHOD__, '1.32' );
- return [];
- }
-
- /**
- * @deprecated since 1.32 No longer used.
- * @return array
- */
- public static function getLegacyModules() {
- wfDeprecated( __METHOD__, '1.32' );
- return [];
- }
-
/**
* @private For internal use by SpecialJavaScriptTest
* @since 1.32