Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / skins / SkinFallbackTemplate.php
blobee8d8417fbda887ebaf6138aa5de0e0dba36c10f
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 // Filter out skins that aren't installed
28 $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
29 return
30 is_file( "$styleDirectory/$skinDir/skin.json" )
31 || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
32 } );
34 return $possibleSkins;
37 /**
38 * Inform the user why they are seeing this skin.
40 * @return string
42 private function buildHelpfulInformationMessage() {
43 $defaultSkin = $this->config->get( 'DefaultSkin' );
44 $installedSkins = $this->findInstalledSkins();
45 $enabledSkins = SkinFactory::getDefaultInstance()->getSkinNames();
46 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
48 if ( $installedSkins ) {
49 $skinsInstalledText = [];
50 $skinsInstalledSnippet = [];
52 foreach ( $installedSkins as $skin ) {
53 $normalizedKey = strtolower( $skin );
54 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
55 if ( $isEnabled ) {
56 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
57 ->params( $normalizedKey, $skin )->plain();
58 } else {
59 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
60 ->params( $normalizedKey, $skin )->plain();
61 $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skin );
65 return $this->getMsg( 'default-skin-not-found' )->params(
66 $defaultSkin,
67 implode( "\n", $skinsInstalledText ),
68 implode( "\n", $skinsInstalledSnippet ) )->numParams(
69 count( $skinsInstalledText ),
70 count( $skinsInstalledSnippet )
71 )->parseAsBlock();
72 } else {
73 return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
74 $defaultSkin
75 )->parseAsBlock();
79 /**
80 * Get the appropriate LocalSettings.php snippet to enable the given skin
82 * @param string $skin
83 * @return string
85 private function getSnippetForSkin( $skin ) {
86 global $IP;
87 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
88 return "wfLoadSkin( '$skin' );";
89 } else {
90 return "require_once \"\$IP/skins/$skin/$skin.php\";";
94 /**
95 * Outputs the entire contents of the page. No navigation (other than search box), just the big
96 * warning message and page content.
98 public function execute() {
99 $this->html( 'headelement' ) ?>
101 <div class="warningbox">
102 <?php echo $this->buildHelpfulInformationMessage() ?>
103 </div>
105 <form action="<?php $this->text( 'wgScript' ) ?>">
106 <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
107 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
108 <?php echo $this->makeSearchInput( [ "id" => "searchInput" ] ) ?>
109 <?php echo $this->makeSearchButton( 'go' ) ?>
110 </form>
112 <div class="mw-body" role="main">
113 <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
115 <div class="mw-body-content">
116 <?php $this->html( 'bodytext' ) ?>
117 <?php $this->html( 'catlinks' ) ?>
118 </div>
119 </div>
121 <?php $this->printTrail() ?>
122 </body></html>
124 <?php