Merge "Some cleanups to MWExceptionHandler::handleException"
[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 )
69 )->parseAsBlock();
70 } else {
71 return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
72 $defaultSkin
73 )->parseAsBlock();
74 }
75 }
76
77 /**
78 * Get the appropriate LocalSettings.php snippet to enable the given skin
79 *
80 * @param string $skin
81 * @return string
82 */
83 private function getSnippetForSkin( $skin ) {
84 global $IP;
85 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
86 return "wfLoadSkin( '$skin' );";
87 } else {
88 return "require_once \"\$IP/skins/$skin/$skin.php\";";
89 }
90 }
91
92 /**
93 * Outputs the entire contents of the page. No navigation (other than search box), just the big
94 * warning message and page content.
95 */
96 public function execute() {
97 $this->html( 'headelement' ) ?>
98
99 <div class="warningbox">
100 <?php echo $this->buildHelpfulInformationMessage() ?>
101 </div>
102
103 <form action="<?php $this->text( 'wgScript' ) ?>">
104 <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
105 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
106 <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ) ?>
107 <?php echo $this->makeSearchButton( 'go' ) ?>
108 </form>
109
110 <div class="mw-body" role="main">
111 <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
112
113 <div class="mw-body-content">
114 <?php $this->html( 'bodytext' ) ?>
115 <?php $this->html( 'catlinks' ) ?>
116 </div>
117 </div>
118
119 <?php $this->printTrail() ?>
120 </body></html>
121
122 <?php
123 }
124 }