1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
<?php
/**
* Skin file for the fallback skin.
*
* @since 1.24
* @file
*/
namespace MediaWiki\Skin;
use MediaWiki\Html\Html;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Output\OutputPage;
/**
* SkinTemplate class for the fallback skin
*/
class SkinFallback extends SkinMustache {
/** @inheritDoc */
public $skinname = 'fallback';
public function initPage( OutputPage $out ) {
parent::initPage( $out );
$out->disableClientCache();
}
/**
* @return array
*/
private function findInstalledSkins() {
$config = $this->getConfig();
$styleDirectory = $config->get( MainConfigNames::StyleDirectory );
// Get all subdirectories which might contains skins
$possibleSkins = scandir( $styleDirectory );
$possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
} );
// Filter out skins that aren't installed
$possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
return is_file( "$styleDirectory/$skinDir/skin.json" )
|| is_file( "$styleDirectory/$skinDir/$skinDir.php" );
} );
return $possibleSkins;
}
/**
* Inform the user why they are seeing this skin.
*
* @return string
*/
private function buildHelpfulInformationMessage() {
$config = $this->getConfig();
$defaultSkin = $config->get( MainConfigNames::DefaultSkin );
$installedSkins = $this->findInstalledSkins();
$skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
$enabledSkins = $skinFactory->getInstalledSkins();
$enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
if ( $installedSkins ) {
$skinsInstalledText = [];
$skinsInstalledSnippet = [];
foreach ( $installedSkins as $skinKey ) {
$normalizedKey = strtolower( $skinKey );
$isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
if ( $isEnabled ) {
$skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
->params( $normalizedKey, $skinKey )->plain();
} else {
$skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
->params( $normalizedKey, $skinKey )->plain();
$skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
}
}
return $this->msg( 'default-skin-not-found' )->params(
$defaultSkin,
implode( "\n", $skinsInstalledText ),
implode( "\n", $skinsInstalledSnippet ) )->numParams(
count( $skinsInstalledText ),
count( $skinsInstalledSnippet )
)->parseAsBlock();
} else {
return $this->msg( 'default-skin-not-found-no-skins' )->params(
$defaultSkin
)->parseAsBlock();
}
}
/**
* Get the appropriate LocalSettings.php snippet to enable the given skin
*
* @param string $skin
* @return string
*/
private static function getSnippetForSkin( $skin ) {
global $IP;
if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
return "wfLoadSkin( '$skin' );";
} else {
return "require_once \"\$IP/skins/$skin/$skin.php\";";
}
}
/**
* Adds an `html-fallback-warning` template to inform system administrators
* that their mediawiki skin is incorrectly setup.
* It's recommended that skin developers do not add further to date here
* and instead work on improving SkinMustache::getTemplateData where necessary
* to improve flexibility of the data for all skin developers.
* @inheritDoc
* @return array
*/
public function getTemplateData() {
$config = $this->getConfig();
$skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
$data = parent::getTemplateData();
// If the default skin isn't configured correctly, append a warning to the
// subtitle to alert a sysadmin.
if ( !isset(
$skinFactory->getInstalledSkins()[$config->get( MainConfigNames::DefaultSkin )]
) ) {
$data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
}
return $data;
}
}
/** @deprecated class alias since 1.44 */
class_alias( SkinFallback::class, 'SkinFallback' );
|