Merge "Allow skins/extensions to define custom OOUI themes"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderImage.php
index 7829b71..9003951 100644 (file)
@@ -95,9 +95,9 @@ class ResourceLoaderImage {
 
                // Ensure that all files have common extension.
                $extensions = [];
-               $descriptor = (array)$this->descriptor;
+               $descriptor = is_array( $this->descriptor ) ? $this->descriptor : [ $this->descriptor ];
                array_walk_recursive( $descriptor, function ( $path ) use ( &$extensions ) {
-                       $extensions[] = pathinfo( $path, PATHINFO_EXTENSION );
+                       $extensions[] = pathinfo( $this->getLocalPath( $path ), PATHINFO_EXTENSION );
                } );
                $extensions = array_unique( $extensions );
                if ( count( $extensions ) !== 1 ) {
@@ -150,31 +150,43 @@ class ResourceLoaderImage {
         */
        public function getPath( ResourceLoaderContext $context ) {
                $desc = $this->descriptor;
-               if ( is_string( $desc ) ) {
-                       return $this->basePath . '/' . $desc;
+               if ( !is_array( $desc ) ) {
+                       return $this->getLocalPath( $desc );
                }
                if ( isset( $desc['lang'] ) ) {
                        $contextLang = $context->getLanguage();
                        if ( isset( $desc['lang'][$contextLang] ) ) {
-                               return $this->basePath . '/' . $desc['lang'][$contextLang];
+                               return $this->getLocalPath( $desc['lang'][$contextLang] );
                        }
                        $fallbacks = Language::getFallbacksFor( $contextLang, Language::STRICT_FALLBACKS );
                        foreach ( $fallbacks as $lang ) {
                                if ( isset( $desc['lang'][$lang] ) ) {
-                                       return $this->basePath . '/' . $desc['lang'][$lang];
+                                       return $this->getLocalPath( $desc['lang'][$lang] );
                                }
                        }
                }
                if ( isset( $desc[$context->getDirection()] ) ) {
-                       return $this->basePath . '/' . $desc[$context->getDirection()];
+                       return $this->getLocalPath( $desc[$context->getDirection()] );
                }
                if ( isset( $desc['default'] ) ) {
-                       return $this->basePath . '/' . $desc['default'];
+                       return $this->getLocalPath( $desc['default'] );
                } else {
                        throw new MWException( 'No matching path found' );
                }
        }
 
+       /**
+        * @param string|ResourceLoaderFilePath $path
+        * @return string
+        */
+       protected function getLocalPath( $path ) {
+               if ( $path instanceof ResourceLoaderFilePath ) {
+                       return $path->getLocalPath();
+               }
+
+               return "{$this->basePath}/$path";
+       }
+
        /**
         * Get the extension of the image.
         *