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