Merge "Remove 'Browser default' editfont option"
[lhc/web/wiklou.git] / includes / skins / SkinFallbackTemplate.php
index 9cb4ea0..ee8d841 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;
@@ -44,8 +46,8 @@ class SkinFallbackTemplate extends BaseTemplate {
                $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
 
                if ( $installedSkins ) {
-                       $skinsInstalledText = array();
-                       $skinsInstalledSnippet = array();
+                       $skinsInstalledText = [];
+                       $skinsInstalledSnippet = [];
 
                        foreach ( $installedSkins as $skin ) {
                                $normalizedKey = strtolower( $skin );
@@ -56,14 +58,16 @@ 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 );
                                }
                        }
 
                        return $this->getMsg( 'default-skin-not-found' )->params(
                                $defaultSkin,
                                implode( "\n", $skinsInstalledText ),
-                               implode( "\n", $skinsInstalledSnippet )
+                               implode( "\n", $skinsInstalledSnippet ) )->numParams(
+                                       count( $skinsInstalledText ),
+                                       count( $skinsInstalledSnippet )
                        )->parseAsBlock();
                } else {
                        return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
@@ -72,6 +76,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.
@@ -86,7 +105,7 @@ class SkinFallbackTemplate extends BaseTemplate {
                <form action="<?php $this->text( 'wgScript' ) ?>">
                        <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
                        <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
-                       <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ) ?>
+                       <?php echo $this->makeSearchInput( [ "id" => "searchInput" ] ) ?>
                        <?php echo $this->makeSearchButton( 'go' ) ?>
                </form>