From 9ae72401fa1f05ac555d4e1fe2ba0d0e047d38e7 Mon Sep 17 00:00:00 2001 From: Tom Arrow Date: Sat, 9 Aug 2014 13:11:54 +0100 Subject: [PATCH] Split SkinFallback and SkinfallbackTemplate Change-Id: I55c866c08d4f442021c43068efe64be871afb96b --- includes/AutoLoader.php | 2 +- includes/SkinFallback.php | 99 --------------------------- includes/SkinFallbackTemplate.php | 109 ++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 100 deletions(-) create mode 100644 includes/SkinFallbackTemplate.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 6c9213979c..872e89b7cc 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -159,7 +159,7 @@ $wgAutoloadLocalClasses = array( 'Skin' => 'includes/Skin.php', 'SkinTemplate' => 'includes/SkinTemplate.php', 'SkinFallback' => 'includes/SkinFallback.php', - 'SkinFallbackTemplate' => 'includes/SkinFallback.php', + 'SkinFallbackTemplate' => 'includes/SkinFallbackTemplate.php', 'SquidPurgeClient' => 'includes/SquidPurgeClient.php', 'SquidPurgeClientPool' => 'includes/SquidPurgeClient.php', 'StatCounter' => 'includes/StatCounter.php', diff --git a/includes/SkinFallback.php b/includes/SkinFallback.php index f50eabc814..6055473b44 100644 --- a/includes/SkinFallback.php +++ b/includes/SkinFallback.php @@ -24,102 +24,3 @@ class SkinFallback extends SkinTemplate { $out->addModuleStyles( 'mediawiki.skinning.interface' ); } } - -/** - * BaseTemplate class for the fallback skin - */ -class SkinFallbackTemplate extends BaseTemplate { - /** - * @return array - */ - private function findInstalledSkins() { - $styleDirectory = $this->config->get( 'StyleDirectory' ); // @todo we should inject this directly? - // Get all subdirectories which might contains skins - $possibleSkins = scandir( $styleDirectory ); - $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) { - return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" ); - } ); - - // Only keep the ones that contain a .php file with the same name inside - $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) { - return is_file( "$styleDirectory/$skinDir/$skinDir.php" ); - } ); - - return $possibleSkins; - } - - /** - * Inform the user why they are seeing this skin. - * - * @return string - */ - private function buildHelpfulInformationMessage() { - $defaultSkin = $this->config->get( 'DefaultSkin' ); - $installedSkins = $this->findInstalledSkins(); - $enabledSkins = $this->config->get( 'ValidSkinNames' ); - $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER ); - - if ( $installedSkins ) { - $skinsInstalledText = array(); - $skinsInstalledSnippet = array(); - - foreach ( $installedSkins as $skin ) { - $normalizedKey = strtolower( $skin ); - $isEnabled = array_key_exists( $normalizedKey, $enabledSkins ); - if ( $isEnabled ) { - $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' ) - ->params( $normalizedKey, $skin )->plain(); - } else { - $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' ) - ->params( $normalizedKey, $skin )->plain(); - $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";"; - } - } - - return $this->getMsg( 'default-skin-not-found' )->params( - $defaultSkin, - implode( "\n", $skinsInstalledText ), - implode( "\n", $skinsInstalledSnippet ) - )->parseAsBlock(); - } else { - return $this->getMsg( 'default-skin-not-found-no-skins' )->params( - $defaultSkin - )->parseAsBlock(); - } - } - - /** - * Outputs the entire contents of the page. No navigation (other than search box), just the big - * warning message and page content. - */ - public function execute() { - $this->html( 'headelement' ) ?> - -
- buildHelpfulInformationMessage() ?> -
- -
- -

- makeSearchInput( array( "id" => "searchInput" ) ) ?> - makeSearchButton( 'go' ) ?> -
- -
-

- html( 'title' ) ?> -

- -
- html( 'bodytext' ) ?> - html( 'catlinks' ) ?> -
-
- - printTrail() ?> - - - config->get( 'StyleDirectory' ); // @todo we should inject this directly? + // Get all subdirectories which might contains skins + $possibleSkins = scandir( $styleDirectory ); + $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) { + return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" ); + } ); + + // Only keep the ones that contain a .php file with the same name inside + $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) { + return is_file( "$styleDirectory/$skinDir/$skinDir.php" ); + } ); + + return $possibleSkins; + } + + /** + * Inform the user why they are seeing this skin. + * + * @return string + */ + private function buildHelpfulInformationMessage() { + $defaultSkin = $this->config->get( 'DefaultSkin' ); + $installedSkins = $this->findInstalledSkins(); + $enabledSkins = $this->config->get( 'ValidSkinNames' ); + $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER ); + + if ( $installedSkins ) { + $skinsInstalledText = array(); + $skinsInstalledSnippet = array(); + + foreach ( $installedSkins as $skin ) { + $normalizedKey = strtolower( $skin ); + $isEnabled = array_key_exists( $normalizedKey, $enabledSkins ); + if ( $isEnabled ) { + $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' ) + ->params( $normalizedKey, $skin )->plain(); + } else { + $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' ) + ->params( $normalizedKey, $skin )->plain(); + $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";"; + } + } + + return $this->getMsg( 'default-skin-not-found' )->params( + $defaultSkin, + implode( "\n", $skinsInstalledText ), + implode( "\n", $skinsInstalledSnippet ) + )->parseAsBlock(); + } else { + return $this->getMsg( 'default-skin-not-found-no-skins' )->params( + $defaultSkin + )->parseAsBlock(); + } + } + + /** + * Outputs the entire contents of the page. No navigation (other than search box), just the big + * warning message and page content. + */ + public function execute() { + $this->html( 'headelement' ) ?> + +
+ buildHelpfulInformationMessage() ?> +
+ +
+ +

+ makeSearchInput( array( "id" => "searchInput" ) ) ?> + makeSearchButton( 'go' ) ?> +
+ +
+

+ html( 'title' ) ?> +

+ +
+ html( 'bodytext' ) ?> + html( 'catlinks' ) ?> +
+
+ + printTrail() ?> + + +