Merge "Use a special fallback skin when selected skin is unavailable"
[lhc/web/wiklou.git] / includes / SkinFallback.php
1 <?php
2 /**
3 * Skin file for the fallback skin.
4 *
5 * The structure is copied from the example skin (mediawiki/skins/Example).
6 *
7 * @since 1.24
8 * @file
9 */
10
11 /**
12 * SkinTemplate class for the fallback skin
13 */
14 class SkinFallback extends SkinTemplate {
15 var $skinname = 'fallback', $template = 'SkinFallbackTemplate';
16
17 /**
18 * Add CSS via ResourceLoader
19 *
20 * @param $out OutputPage
21 */
22 function setupSkinUserCss( OutputPage $out ) {
23 parent::setupSkinUserCss( $out );
24 $out->addModuleStyles( 'mediawiki.skinning.interface' );
25 }
26 }
27
28 /**
29 * BaseTemplate class for the fallback skin
30 */
31 class SkinFallbackTemplate extends BaseTemplate {
32 /**
33 * @return array
34 */
35 private function findInstalledSkins() {
36 global $wgStyleDirectory;
37
38 // Get all subdirectories which might contains skins
39 $possibleSkins = scandir( $wgStyleDirectory );
40 $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) {
41 global $wgStyleDirectory;
42 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$wgStyleDirectory/$maybeDir" );
43 } );
44
45 // Only keep the ones that contain a .php file with the same name inside
46 $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) {
47 global $wgStyleDirectory;
48 return is_file( "$wgStyleDirectory/$skinDir/$skinDir.php" );
49 } );
50
51 return $possibleSkins;
52 }
53
54 /**
55 * Inform the user why they are seeing this skin.
56 *
57 * @return string
58 */
59 private function buildHelpfulInformationMessage() {
60 global $wgDefaultSkin, $wgValidSkinNames;
61
62 $installedSkins = $this->findInstalledSkins();
63 $enabledSkins = $wgValidSkinNames;
64 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
65
66 if ( $installedSkins ) {
67 $skinsInstalledText = array();
68 $skinsInstalledSnippet = array();
69
70 foreach ( $installedSkins as $skin ) {
71 $normalizedKey = strtolower( $skin );
72 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
73 if ( $isEnabled ) {
74 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
75 ->params( $normalizedKey, $skin )->plain();
76 } else {
77 $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
78 ->params( $normalizedKey, $skin )->plain();
79 $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";";
80 }
81 }
82
83 return $this->getMsg( 'default-skin-not-found' )->params(
84 $wgDefaultSkin,
85 implode( "\n", $skinsInstalledText ),
86 implode( "\n", $skinsInstalledSnippet )
87 )->parseAsBlock();
88 } else {
89 return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
90 $wgDefaultSkin
91 )->parseAsBlock();
92 }
93 }
94
95 /**
96 * Outputs the entire contents of the page. No navigation (other than search box), just the big
97 * warning message and page content.
98 */
99 public function execute() {
100 $this->html( 'headelement' ) ?>
101
102 <div class="warningbox">
103 <?php echo $this->buildHelpfulInformationMessage() ?>
104 </div>
105
106 <form action="<?php $this->text( 'wgScript' ) ?>">
107 <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
108 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
109 <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ) ?>
110 <?php echo $this->makeSearchButton( 'go' ) ?>
111 </form>
112
113 <div class="mw-body" role="main">
114 <h1 class="firstHeading">
115 <span dir="auto"><?php $this->html( 'title' ) ?></span>
116 </h1>
117
118 <div class="mw-body-content">
119 <?php $this->html( 'bodytext' ) ?>
120 <?php $this->html( 'catlinks' ) ?>
121 </div>
122 </div>
123
124 <?php $this->printTrail() ?>
125 </body></html>
126
127 <?php
128 }
129 }