Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90320
Change subject: resourceloader: Use state "error" instead of "missing" in case
of exceptions
......................................................................
resourceloader: Use state "error" instead of "missing" in case of exceptions
Changes:
* If we catch an exception while making the making the response
for a module, set its client state to "error" instead of "missing".
State "missing" should only be used if the module could not be
found in the registry.
The matches the behaviour of the client.
Clean up:
* Merge the two mw.loader.state calls into one.
* Add @throws documentation for compileLESSFile (follows-up cdc8b9e).
Change-Id: I54c3de6d836702ffbe3044bc58a38e83e758bc33
---
M includes/resourceloader/ResourceLoader.php
M includes/resourceloader/ResourceLoaderFileModule.php
2 files changed, 19 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/20/90320/1
diff --git a/includes/resourceloader/ResourceLoader.php
b/includes/resourceloader/ResourceLoader.php
index 19d019d..541ec9e 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -453,7 +453,7 @@
// Split requested modules into two groups, modules and missing
$modules = array();
- $missing = array();
+ $problemStates = array();
foreach ( $context->getModules() as $name ) {
if ( isset( $this->moduleInfos[$name] ) ) {
$module = $this->getModule( $name );
@@ -469,7 +469,7 @@
}
$modules[$name] = $module;
} else {
- $missing[] = $name;
+ $problemStates[$name] = 'missing';
}
}
@@ -514,7 +514,7 @@
}
// Generate a response
- $response = $this->makeModuleResponse( $context, $modules,
$missing );
+ $response = $this->makeModuleResponse( $context, $modules,
$problemStates );
// Prepend comments indicating exceptions
$response = $errors . $response;
@@ -527,7 +527,7 @@
}
// Save response to file cache unless there are errors
- if ( isset( $fileCache ) && !$errors && !$missing ) {
+ if ( isset( $fileCache ) && !$errors && !count( $problemStates
) ) {
// Cache single modules...and other requests if there
are enough hits
if ( ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
@@ -706,15 +706,15 @@
*
* @param $context ResourceLoaderContext: Context in which to generate
a response
* @param array $modules List of module objects keyed by module name
- * @param array $missing List of unavailable modules (optional)
- * @return String: Response data
+ * @param array $states States by module name for modules we can't
respond to.
+ * @return string: Response data
*/
public function makeModuleResponse( ResourceLoaderContext $context,
- array $modules, $missing = array()
+ array $modules, $states = array()
) {
$out = '';
$exceptions = '';
- if ( $modules === array() && $missing === array() ) {
+ if ( !count( $modules ) && !count( $states ) ) {
return '/* No modules requested. Max made me put this
here */';
}
@@ -838,8 +838,8 @@
// Add exception to the output as a comment
$exceptions .= self::formatException( $e );
- // Register module as missing
- $missing[] = $name;
+ // Respond to client with error=state instead
of module implementation
+ $states[$name] = 'error';
unset( $modules[$name] );
}
$isRaw |= $module->isRaw();
@@ -850,12 +850,14 @@
if ( $context->shouldIncludeScripts() && !$context->getRaw() &&
!$isRaw ) {
// Set the state of modules loaded as only scripts to
ready
if ( count( $modules ) && $context->getOnly() ===
'scripts' ) {
- $out .= self::makeLoaderStateScript(
- array_fill_keys( array_keys( $modules
), 'ready' ) );
+ foreach ( $modules as $module ) {
+ $states[$module] = 'ready';
+ }
}
- // Set the state of modules which were requested but
unavailable as missing
- if ( is_array( $missing ) && count( $missing ) ) {
- $out .= self::makeLoaderStateScript(
array_fill_keys( $missing, 'missing' ) );
+
+ // Set the state of modules we didn't respond to with
mw.loader.implement
+ if ( count( $states ) ) {
+ $out .= self::makeLoaderStateScript( $states );
}
}
diff --git a/includes/resourceloader/ResourceLoaderFileModule.php
b/includes/resourceloader/ResourceLoaderFileModule.php
index 9ed181e..7b85001 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -745,6 +745,8 @@
* recompiles as necessary.
*
* @since 1.22
+ * @throws Exception If Less encounters a parse error
+ * @throws MWException If Less compilation returns unexpection result
* @param string $fileName File path of LESS source
* @return string: CSS source
*/
--
To view, visit https://gerrit.wikimedia.org/r/90320
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I54c3de6d836702ffbe3044bc58a38e83e758bc33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits