SkinFallback: Recommend using wfLoadSkin() if possible
authorKunal Mehta <legoktm@gmail.com>
Thu, 2 Apr 2015 17:31:24 +0000 (10:31 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 3 Apr 2015 08:07:30 +0000 (09:07 +0100)
Change-Id: I4f3841029578305ab692d853c45678f487adbc78

includes/skins/SkinFallbackTemplate.php

index 9cb4ea0..1c5f3a6 100644 (file)
@@ -24,9 +24,11 @@ class SkinFallbackTemplate extends BaseTemplate {
                        return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
                } );
 
-               // Only keep the ones that contain a .php file with the same name inside
+               // Filter out skins that aren't installed
                $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
-                       return is_file( "$styleDirectory/$skinDir/$skinDir.php" );
+                       return
+                               is_file( "$styleDirectory/$skinDir/skin.json" )
+                               || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
                } );
 
                return $possibleSkins;
@@ -56,7 +58,7 @@ class SkinFallbackTemplate extends BaseTemplate {
                                } else {
                                        $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
                                                ->params( $normalizedKey, $skin )->plain();
-                                       $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";";
+                                       $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skin );
                                }
                        }
 
@@ -72,6 +74,21 @@ class SkinFallbackTemplate extends BaseTemplate {
                }
        }
 
+       /**
+        * Get the appropriate LocalSettings.php snippet to enable the given skin
+        *
+        * @param string $skin
+        * @return string
+        */
+       private function getSnippetForSkin( $skin ) {
+               global $IP;
+               if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
+                       return "wfLoadSkin( '$skin' );";
+               } else {
+                       return  "require_once \"\$IP/skins/$skin/$skin.php\";";
+               }
+       }
+
        /**
         * Outputs the entire contents of the page. No navigation (other than search box), just the big
         * warning message and page content.