Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / skins / SkinFallbackTemplate.php
1 <?php
2
3 /**
4 * Skin template for the fallback skin.
5 *
6 * The structure is copied from the example skin (mediawiki/skins/Example).
7 *
8 * @since 1.24
9 * @file
10 */
11
12 /**
13 * BaseTemplate class for the fallback skin
14 */
15 class SkinFallbackTemplate extends BaseTemplate {
16 /**
17 * @return array
18 */
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 } );
26
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 } );
33
34 return $possibleSkins;
35 }
36
37 /**
38 * Inform the user why they are seeing this skin.
39 *
40 * @return string
41 */
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 );
47
48 if ( $installedSkins ) {
49 $skinsInstalledText = array();
50 $skinsInstalledSnippet = array();
51
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 );
62 }
63 }
64
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();
76 }
77 }
78
79 /**
80 * Get the appropriate LocalSettings.php snippet to enable the given skin
81 *
82 * @param string $skin
83 * @return string
84 */
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\";";
91 }
92 }
93
94 /**
95 * Outputs the entire contents of the page. No navigation (other than search box), just the big
96 * warning message and page content.
97 */
98 public function execute() {
99 $this->html( 'headelement' ) ?>
100
101 <div class="warningbox">
102 <?php echo $this->buildHelpfulInformationMessage() ?>
103 </div>
104
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( array( "id" => "searchInput" ) ) ?>
109 <?php echo $this->makeSearchButton( 'go' ) ?>
110 </form>
111
112 <div class="mw-body" role="main">
113 <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
114
115 <div class="mw-body-content">
116 <?php $this->html( 'bodytext' ) ?>
117 <?php $this->html( 'catlinks' ) ?>
118 </div>
119 </div>
120
121 <?php $this->printTrail() ?>
122 </body></html>
123
124 <?php
125 }
126 }