Being a raw module means that when it is requested from load.php with
"only=scripts" set, then the output is *not* wrapped in an
'mw.loader.implement' closure *and* there no 'mw.loader.state()' appendix.
Instead, it is served "raw".
Before 2018, the modules 'mediawiki' and 'jquery' were raw modules.
They were needed before the client could define 'mw.loader.implement', and
could never be valid dependencies. Module 'mediawiki' merged to 'startup',
and 'jquery' became a regular module (T192623). Based on the architecture
of modules being deliverable bundles, it doesn't make sense for there to
ever be raw modules again. Anything that 'startup' needs should be bundled
with it. Anything else is a regular module.
On top of that, we never actually needed this feature because specifying
the 'only=scripts' and 'raw=1' parameters does the same thing.
The only special bit about marking modules (not requests) as "raw" was that
it allowed the client to forget to specify "raw=1" and the server would
automatically omit the 'mw.loader.state()' appendix based on whether the
module is marked as raw. As of Ie4564ec8e26ad53f2, the two remaining use
cases for raw responses now specify the 'raw=1' request parameter, and we
can get rid of the "raw module" feature and all the complexity around it.
== Startup module
In the startup module there was an interesting use of isRaw() that has
little to do with the above. The "ATTENTION" warning there applies to the
startup module only, not raw modules in general. This is now fixed by
explicitly checking for StartupModule.
Above that warning, it talked about saving bytes, which was an optimisation
given that "raw" modules don't communicate with mw.loader, they also don't
need to be registered there because even if mw.loader would try to load
them, the server would never inform mw.loader about the module having
arrived. There are now no longer any such modules.
Bug: T201483
Change-Id: I8839036e7b2b76919b6cd3aa42ccfde4d1247899
$states[$name] = 'missing';
}
$states[$name] = 'missing';
}
- // Generate output
- $isRaw = false;
-
$filter = $context->getOnly() === 'styles' ? 'minify-css' : 'minify-js';
foreach ( $modules as $name => $module ) {
$filter = $context->getOnly() === 'styles' ? 'minify-css' : 'minify-js';
foreach ( $modules as $name => $module ) {
$states[$name] = 'error';
unset( $modules[$name] );
}
$states[$name] = 'error';
unset( $modules[$name] );
}
- $isRaw |= $module->isRaw();
}
// Update module states
}
// Update module states
- if ( $context->shouldIncludeScripts() && !$context->getRaw() && !$isRaw ) {
- if ( count( $modules ) && $context->getOnly() === 'scripts' ) {
+ if ( $context->shouldIncludeScripts() && !$context->getRaw() ) {
+ if ( $modules && $context->getOnly() === 'scripts' ) {
// Set the state of modules loaded as only scripts to ready as
// they don't have an mw.loader.implement wrapper that sets the state
foreach ( $modules as $name => $module ) {
// Set the state of modules loaded as only scripts to ready as
// they don't have an mw.loader.implement wrapper that sets the state
foreach ( $modules as $name => $module ) {
}
// Set the state of modules we didn't respond to with mw.loader.implement
}
// Set the state of modules we didn't respond to with mw.loader.implement
- if ( count( $states ) ) {
$stateScript = self::makeLoaderStateScript( $states );
if ( !$context->getDebug() ) {
$stateScript = self::filter( 'minify-js', $stateScript );
$stateScript = self::makeLoaderStateScript( $states );
if ( !$context->getDebug() ) {
$stateScript = self::filter( 'minify-js', $stateScript );
private static function makeContext( ResourceLoaderContext $mainContext, $group, $type,
array $extraQuery = []
) {
private static function makeContext( ResourceLoaderContext $mainContext, $group, $type,
array $extraQuery = []
) {
- // Create new ResourceLoaderContext so that $extraQuery may trigger isRaw().
+ // Create new ResourceLoaderContext so that $extraQuery is supported (eg. for 'sync=1').
$req = new FauxRequest( array_merge( $mainContext->getRequest()->getValues(), $extraQuery ) );
// Set 'only' if not combined
$req->setVal( 'only', $type === ResourceLoaderModule::TYPE_COMBINED ? null : $type );
$req = new FauxRequest( array_merge( $mainContext->getRequest()->getValues(), $extraQuery ) );
// Set 'only' if not combined
$req->setVal( 'only', $type === ResourceLoaderModule::TYPE_COMBINED ? null : $type );
- // See if we have one or more raw modules
- $isRaw = false;
- foreach ( $moduleSet as $key => $module ) {
- $isRaw |= $module->isRaw();
- }
-
// Special handling for the user group; because users might change their stuff
// on-wiki like user pages, or user preferences; we need to find the highest
// timestamp of these user-changeable modules so we can ensure cache misses on change
// Special handling for the user group; because users might change their stuff
// on-wiki like user pages, or user preferences; we need to find the highest
// timestamp of these user-changeable modules so we can ensure cache misses on change
// Decide whether to use 'style' or 'script' element
if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
$chunk = Html::linkedStyle( $url );
// Decide whether to use 'style' or 'script' element
if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
$chunk = Html::linkedStyle( $url );
- } elseif ( $context->getRaw() || $isRaw ) {
+ } elseif ( $context->getRaw() ) {
+ // This request is asking for the module to be delivered standalone,
+ // (aka "raw") without communicating to any mw.loader client.
+ // Use cases:
+ // - startup (naturally because this is what will define mw.loader)
+ // - html5shiv (loads synchronously in old IE before the async startup module arrives)
+ // - QUnit (needed in SpecialJavaScriptTest before async startup)
$chunk = Html::element( 'script', [
$chunk = Html::element( 'script', [
- // In SpecialJavaScriptTest, QUnit must load synchronous
+ // The 'sync' option is only supported in combination with 'raw'.
'async' => !isset( $extraQuery['sync'] ),
'src' => $url
] );
'async' => !isset( $extraQuery['sync'] ),
'src' => $url
] );
/** @var bool Link to raw files in debug mode */
protected $debugRaw = true;
/** @var bool Link to raw files in debug mode */
protected $debugRaw = true;
- /** @var bool Whether mw.loader.state() call should be omitted */
- protected $raw = false;
-
protected $targets = [ 'desktop' ];
/** @var bool Whether CSSJanus flipping should be skipped for this module */
protected $targets = [ 'desktop' ];
/** @var bool Whether CSSJanus flipping should be skipped for this module */
break;
// Single booleans
case 'debugRaw':
break;
// Single booleans
case 'debugRaw':
case 'noflip':
$this->{$member} = (bool)$option;
break;
case 'noflip':
$this->{$member} = (bool)$option;
break;
- /**
- * @return bool
- */
- public function isRaw() {
- return $this->raw;
- }
-
/**
* Disable module content versioning.
*
/**
* Disable module content versioning.
*
'templates',
'skipFunction',
'debugRaw',
'templates',
'skipFunction',
'debugRaw',
] as $member ) {
$options[$member] = $this->{$member};
}
] as $member ) {
$options[$member] = $this->{$member};
}
|| $this->dependencies
|| $this->messages
|| $this->skipFunction
|| $this->dependencies
|| $this->messages
|| $this->skipFunction
);
return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
}
);
return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
}
- /**
- * Whether this module's JS expects to work without the client-side ResourceLoader module.
- * Returning true from this function will prevent mw.loader.state() call from being
- * appended to the bottom of the script.
- *
- * @return bool
- */
- public function isRaw() {
- return false;
- }
-
/**
* Get a list of modules this module depends on.
*
/**
* Get a list of modules this module depends on.
*
- if ( $module->isRaw() ) {
- // Don't register "raw" modules (like 'startup') client-side because depending on them
- // is illegal anyway and would only lead to them being loaded a second time,
- // causing any state to be lost.
+ if ( $module instanceof ResourceLoaderStartUpModule ) {
+ // Don't register 'startup' to the client because loading it lazily or depending
+ // on it doesn't make sense, because the startup module *is* the client.
+ // Registering would be a waste of bandwidth and memory and risks somehow causing
+ // it to load a second time.
// ATTENTION: Because of the line below, this is not going to cause infinite recursion.
// Think carefully before making changes to this code!
// ATTENTION: Because of the line below, this is not going to cause infinite recursion.
// Think carefully before making changes to this code!
- /**
- * @return bool
- */
- public function isRaw() {
- return true;
- }
-
/**
* @private For internal use by SpecialJavaScriptTest
* @since 1.32
/**
* @private For internal use by SpecialJavaScriptTest
* @since 1.32
'scripts' => [
'resources/lib/html5shiv/html5shiv.js'
],
'scripts' => [
'resources/lib/html5shiv/html5shiv.js'
],
-] );',
- ] ],
- [ [
- 'msg' => 'Omit raw modules from registry',
- 'modules' => [
- 'test.raw' => new ResourceLoaderTestModule( [ 'isRaw' => true ] ),
- 'test.blank' => new ResourceLoaderTestModule(),
- ],
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );
-mw.loader.register( [
- [
- "test.blank",
- "{blankVer}"
- ]
'simple scripts' => [ true,
[ 'scripts' => 'example.js' ]
],
'simple scripts' => [ true,
[ 'scripts' => 'example.js' ]
],
- 'simple scripts, raw and targets' => [ true, [
+ 'simple scripts with targets' => [ true, [
'scripts' => [ 'a.js', 'b.js' ],
'scripts' => [ 'a.js', 'b.js' ],
'targets' => [ 'desktop', 'mobile' ],
] ],
'FileModule' => [ true,
'targets' => [ 'desktop', 'mobile' ],
] ],
'FileModule' => [ true,
- * Verify that nothing explicitly depends on raw modules (such as "query").
+ * Verify that nothing depends on "startup".
- * Depending on them is unsupported as they are not registered client-side by the startup module.
+ * Depending on it is unsupported as it cannot be loaded by the client.
*
* @todo Modules can dynamically choose dependencies based on context. This method does not
* test such dependencies. The same goes for testMissingDependencies() and
*
* @todo Modules can dynamically choose dependencies based on context. This method does not
* test such dependencies. The same goes for testMissingDependencies() and
$illegalDeps = [];
foreach ( $data['modules'] as $moduleName => $module ) {
$illegalDeps = [];
foreach ( $data['modules'] as $moduleName => $module ) {
- if ( $module->isRaw() ) {
+ if ( $module instanceof ResourceLoaderStartUpModule ) {
$illegalDeps[] = $moduleName;
}
}
$illegalDeps[] = $moduleName;
}
}