X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoader.php;h=7fb2df2d3f27e5250c8b19b7806b3a0cafad9e9b;hb=f2bf73a4c491019f420ee6d6f1d8bd643659adbe;hp=8ab7c0c2de81c6571d338b5c59105aa94b732ed6;hpb=c0d604984516ff939051b7d557c10d732873170d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 8ab7c0c2de..7fb2df2d3f 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -240,8 +240,6 @@ class ResourceLoader implements LoggerAwareInterface { * @param LoggerInterface|null $logger [optional] */ public function __construct( Config $config = null, LoggerInterface $logger = null ) { - global $IP; - $this->logger = $logger ?: new NullLogger(); if ( !$config ) { @@ -254,8 +252,9 @@ class ResourceLoader implements LoggerAwareInterface { // Add 'local' source first $this->addSource( 'local', $config->get( 'LoadScript' ) ); - // Register core modules - $this->register( include "$IP/resources/Resources.php" ); + // Special module that always exists + $this->register( 'startup', [ 'class' => ResourceLoaderStartUpModule::class ] ); + // Register extension modules $this->register( $config->get( 'ResourceModules' ) ); @@ -319,8 +318,6 @@ class ResourceLoader implements LoggerAwareInterface { * @throws MWException If a duplicate module registration is attempted * @throws MWException If a module name contains illegal characters (pipes or commas) * @throws MWException If something other than a ResourceLoaderModule is being registered - * @return bool False if there were any errors, in which case one or more modules were - * not registered */ public function register( $name, $info = null ) { $moduleSkinStyles = $this->config->get( 'ResourceModuleSkinStyles' ); @@ -1160,11 +1157,9 @@ MESSAGE; // Use a linebreak between module script and state script (T162719) $out = $this->ensureNewline( $out ) . $stateScript; } - } else { - if ( $states ) { - $this->errors[] = 'Problematic modules: ' - . self::encodeJsonForScript( $states ); - } + } elseif ( $states ) { + $this->errors[] = 'Problematic modules: ' + . self::encodeJsonForScript( $states ); } return $out; @@ -1177,7 +1172,7 @@ MESSAGE; */ private function ensureNewline( $str ) { $end = substr( $str, -1 ); - if ( $end === false || $end === "\n" ) { + if ( $end === false || $end === '' || $end === "\n" ) { return $str; } return $str . "\n"; @@ -1449,7 +1444,7 @@ MESSAGE; } } - array_walk( $modules, [ 'self', 'trimArray' ] ); + array_walk( $modules, [ self::class, 'trimArray' ] ); return Xml::encodeJsCall( 'mw.loader.register', @@ -1572,7 +1567,7 @@ MESSAGE; * For example, `[ 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ]` * becomes `'foo.bar,baz|bar.baz,quux'`. * - * This process is reversed by ResourceLoaderContext::expandModuleNames(). + * This process is reversed by ResourceLoader::expandModuleNames(). * See also mw.loader#buildModulesString() which is a port of this, used * on the client-side. * @@ -1596,6 +1591,44 @@ MESSAGE; return implode( '|', $arr ); } + /** + * Expand a string of the form `jquery.foo,bar|jquery.ui.baz,quux` to + * an array of module names like `[ 'jquery.foo', 'jquery.bar', + * 'jquery.ui.baz', 'jquery.ui.quux' ]`. + * + * This process is reversed by ResourceLoader::makePackedModulesString(). + * + * @since 1.33 + * @param string $modules Packed module name list + * @return array Array of module names + */ + public static function expandModuleNames( $modules ) { + $retval = []; + $exploded = explode( '|', $modules ); + foreach ( $exploded as $group ) { + if ( strpos( $group, ',' ) === false ) { + // This is not a set of modules in foo.bar,baz notation + // but a single module + $retval[] = $group; + } else { + // This is a set of modules in foo.bar,baz notation + $pos = strrpos( $group, '.' ); + if ( $pos === false ) { + // Prefixless modules, i.e. without dots + $retval = array_merge( $retval, explode( ',', $group ) ); + } else { + // We have a prefix and a bunch of suffixes + $prefix = substr( $group, 0, $pos ); // 'foo' + $suffixes = explode( ',', substr( $group, $pos + 1 ) ); // [ 'bar', 'baz' ] + foreach ( $suffixes as $suffix ) { + $retval[] = "$prefix.$suffix"; + } + } + } + } + return $retval; + } + /** * Determine whether debug mode was requested * Order of priority is 1) request param, 2) cookie, 3) $wg setting