* - safemode: Only register modules that have ORIGIN_CORE as their origin.
* This effectively disables ORIGIN_USER modules. (T185303)
* See also: OutputPage::disallowUserJs()
+ *
+ * @ingroup ResourceLoader
+ * @internal
*/
class ResourceLoaderStartUpModule extends ResourceLoaderModule {
protected $targets = [ 'desktop', 'mobile' ];
* @param ResourceLoaderContext $context
* @return array
*/
- private function getConfigSettings( $context ) {
+ private function getConfigSettings( ResourceLoaderContext $context ) {
$conf = $this->getConfig();
/**
'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 );
}
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;
return 'MediaWikiModuleStore:' . $this->getConfig()->get( 'DBname' );
}
+ /**
+ * @see $wgResourceLoaderMaxQueryLength
+ * @return int
+ */
+ private function getMaxQueryLength() : int {
+ $len = $this->getConfig()->get( 'ResourceLoaderMaxQueryLength' );
+ // - Ignore -1, which in MW 1.34 and earlier was used to mean "unlimited".
+ // - Ignore invalid values, e.g. non-int or other negative values.
+ if ( $len === false || $len < 0 ) {
+ // Default
+ $len = 2000;
+ }
+ return $len;
+ }
+
/**
* Get the key on which the JavaScript module cache (mw.loader.store) will vary.
*
// Perform replacements for mediawiki.js
$mwLoaderPairs = [
- '$VARS.reqBase' => ResourceLoader::encodeJsonForScript( $context->getReqBase() ),
- '$VARS.baseModules' => ResourceLoader::encodeJsonForScript( $this->getBaseModules() ),
- '$VARS.maxQueryLength' => ResourceLoader::encodeJsonForScript(
- $conf->get( 'ResourceLoaderMaxQueryLength' )
- ),
+ '$VARS.reqBase' => $context->encodeJson( $context->getReqBase() ),
+ '$VARS.baseModules' => $context->encodeJson( $this->getBaseModules() ),
+ '$VARS.maxQueryLength' => $context->encodeJson( $this->getMaxQueryLength() ),
// 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.groupUser' => ResourceLoader::encodeJsonForScript( $this->getGroupId( 'user' ) ),
- '$VARS.groupPrivate' => ResourceLoader::encodeJsonForScript( $this->getGroupId( 'private' ) ),
+ '$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)