Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / skins / SkinFallbackTemplate.php
blob9cb4ea0d2f28438bc8ae6694a768260a206995c1
1 <?php
3 /**
4 * Skin template for the fallback skin.
6 * The structure is copied from the example skin (mediawiki/skins/Example).
8 * @since 1.24
9 * @file
12 /**
13 * BaseTemplate class for the fallback skin
15 class SkinFallbackTemplate extends BaseTemplate {
16 /**
17 * @return array
19 private function findInstalledSkins() {
20 $styleDirectory = $this->config->get( 'StyleDirectory' );
21 // Get all subdirectories which might contains skins
22 $possibleSkins = scandir( $styleDirectory );
23 $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
24 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
25 } );
27 // Only keep the ones that contain a .php file with the same name inside
28 $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
29 return is_file( "$styleDirectory/$skinDir/$skinDir.php" );
30 } );
32 return $possibleSkins;
35 /**
36 * Inform the user why they are seeing this skin.
38 * @return string
40 private function buildHelpfulInformationMessage() {
41 $defaultSkin = $this->config->get( 'DefaultSkin' );
42 $installedSkins = $this->findInstalledSkins();
43 $enabledSkins = SkinFactory::getDefaultInstance()->getSkinNames();
44 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
46 if ( $installedSkins ) {
47 $skinsInstalledText = array();
48 $skinsInstalledSnippet = array();
50 foreach ( $installedSkins as $skin ) {
51 $normalizedKey = strtolower( $skin );
52 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
53 if ( $isEnabled ) {
54 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
55 ->params( $normalizedKey, $skin )->plain();
56 } else {
57 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
58 ->params( $normalizedKey, $skin )->plain();
59 $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";";
63 return $this->getMsg( 'default-skin-not-found' )->params(
64 $defaultSkin,
65 implode( "\n", $skinsInstalledText ),
66 implode( "\n", $skinsInstalledSnippet )
67 )->parseAsBlock();
68 } else {
69 return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
70 $defaultSkin
71 )->parseAsBlock();
75 /**
76 * Outputs the entire contents of the page. No navigation (other than search box), just the big
77 * warning message and page content.
79 public function execute() {
80 $this->html( 'headelement' ) ?>
82 <div class="warningbox">
83 <?php echo $this->buildHelpfulInformationMessage() ?>
84 </div>
86 <form action="<?php $this->text( 'wgScript' ) ?>">
87 <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
88 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
89 <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ) ?>
90 <?php echo $this->makeSearchButton( 'go' ) ?>
91 </form>
93 <div class="mw-body" role="main">
94 <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
96 <div class="mw-body-content">
97 <?php $this->html( 'bodytext' ) ?>
98 <?php $this->html( 'catlinks' ) ?>
99 </div>
100 </div>
102 <?php $this->printTrail() ?>
103 </body></html>
105 <?php