$module = $this->getModule( $row->md_module );
if ( $module ) {
$module->setFileDependencies( $context, ResourceLoaderModule::expandRelativePaths(
- FormatJson::decode( $row->md_deps, true )
+ json_decode( $row->md_deps, true )
) );
$modulesWithDeps[] = $row->md_module;
}
/**
* Add an error to the 'errors' array and log it.
*
- * Should only be called from within respond().
- *
+ * @private For internal use by ResourceLoader and ResourceLoaderStartUpModule.
* @since 1.29
* @param Exception $e
* @param string $msg
* @param array $context
*/
- protected function outputErrorAndLog( Exception $e, $msg, array $context = [] ) {
+ public function outputErrorAndLog( Exception $e, $msg, array $context = [] ) {
MWExceptionHandler::logException( $e );
$this->logger->warning(
$msg,
try {
return $this->getModule( $module )->getVersionHash( $context );
} catch ( Exception $e ) {
- // If modules fail to compute a version, do still consider the versions
- // of other modules - don't set an empty string E-Tag for the whole request.
- // See also T152266 and StartupModule::getModuleRegistrations().
+ // If modules fail to compute a version, don't fail the request (T152266)
+ // and still compute versions of other modules.
$this->outputErrorAndLog( $e,
'Calculating version for "{module}" failed: {exception}',
[
$out = $this->ensureNewline( $out ) . $stateScript;
}
} else {
- if ( count( $states ) ) {
- $this->errors[] = 'Problematic modules: ' .
- FormatJson::encode( $states, self::inDebugMode() );
+ if ( $states ) {
+ // Keep default escaping of slashes (e.g. "</script>") for ResourceLoaderClientHtml.
+ $this->errors[] = 'Problematic modules: ' . json_encode( $states, JSON_PRETTY_PRINT );
}
}
if ( self::inDebugMode() ) {
$scripts = new XmlJsCode( "function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
} else {
- $scripts = new XmlJsCode( 'function($,jQuery,require,module){'. $scripts->value . '}' );
+ $scripts = new XmlJsCode( 'function($,jQuery,require,module){' . $scripts->value . '}' );
}
} elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' );
* - ResourceLoader::makeLoaderSourcesScript( [ $id1 => $loadUrl, $id2 => $loadUrl, ... ] );
* Register sources with the given IDs and properties.
*
- * @param string $id Source ID
+ * @param string|array $sources Source ID
* @param string|null $loadUrl load.php url
* @return string JavaScript code
*/
- public static function makeLoaderSourcesScript( $id, $loadUrl = null ) {
- if ( is_array( $id ) ) {
- return Xml::encodeJsCall(
- 'mw.loader.addSource',
- [ $id ],
- self::inDebugMode()
- );
- } else {
- return Xml::encodeJsCall(
- 'mw.loader.addSource',
- [ $id, $loadUrl ],
- self::inDebugMode()
- );
+ public static function makeLoaderSourcesScript( $sources, $loadUrl = null ) {
+ if ( !is_array( $sources ) ) {
+ $sources = [ $sources => $loadUrl ];
}
+ return Xml::encodeJsCall(
+ 'mw.loader.addSource',
+ [ $sources ],
+ self::inDebugMode()
+ );
}
/**