3 * Skin file for the fallback skin.
9 use MediaWiki\Html\Html
;
10 use MediaWiki\MainConfigNames
;
11 use MediaWiki\MediaWikiServices
;
12 use MediaWiki\Output\OutputPage
;
15 * SkinTemplate class for the fallback skin
17 class SkinFallback
extends SkinMustache
{
19 public $skinname = 'fallback';
21 public function initPage( OutputPage
$out ) {
22 parent
::initPage( $out );
23 $out->disableClientCache();
29 private function findInstalledSkins() {
30 $config = $this->getConfig();
31 $styleDirectory = $config->get( MainConfigNames
::StyleDirectory
);
32 // Get all subdirectories which might contains skins
33 $possibleSkins = scandir( $styleDirectory );
34 $possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
35 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
38 // Filter out skins that aren't installed
39 $possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
40 return is_file( "$styleDirectory/$skinDir/skin.json" )
41 ||
is_file( "$styleDirectory/$skinDir/$skinDir.php" );
44 return $possibleSkins;
48 * Inform the user why they are seeing this skin.
52 private function buildHelpfulInformationMessage() {
53 $config = $this->getConfig();
54 $defaultSkin = $config->get( MainConfigNames
::DefaultSkin
);
55 $installedSkins = $this->findInstalledSkins();
56 $skinFactory = MediaWikiServices
::getInstance()->getSkinFactory();
57 $enabledSkins = $skinFactory->getInstalledSkins();
58 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER
);
60 if ( $installedSkins ) {
61 $skinsInstalledText = [];
62 $skinsInstalledSnippet = [];
64 foreach ( $installedSkins as $skinKey ) {
65 $normalizedKey = strtolower( $skinKey );
66 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
68 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
69 ->params( $normalizedKey, $skinKey )->plain();
71 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
72 ->params( $normalizedKey, $skinKey )->plain();
73 $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
77 return $this->msg( 'default-skin-not-found' )->params(
79 implode( "\n", $skinsInstalledText ),
80 implode( "\n", $skinsInstalledSnippet ) )->numParams(
81 count( $skinsInstalledText ),
82 count( $skinsInstalledSnippet )
85 return $this->msg( 'default-skin-not-found-no-skins' )->params(
92 * Get the appropriate LocalSettings.php snippet to enable the given skin
97 private static function getSnippetForSkin( $skin ) {
99 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
100 return "wfLoadSkin( '$skin' );";
102 return "require_once \"\$IP/skins/$skin/$skin.php\";";
107 * Adds an `html-fallback-warning` template to inform system administrators
108 * that their mediawiki skin is incorrectly setup.
109 * It's recommended that skin developers do not add further to date here
110 * and instead work on improving SkinMustache::getTemplateData where necessary
111 * to improve flexibility of the data for all skin developers.
115 public function getTemplateData() {
116 $config = $this->getConfig();
117 $skinFactory = MediaWikiServices
::getInstance()->getSkinFactory();
118 $data = parent
::getTemplateData();
119 // If the default skin isn't configured correctly, append a warning to the
120 // subtitle to alert a sysadmin.
122 $skinFactory->getInstalledSkins()[$config->get( MainConfigNames
::DefaultSkin
)]
124 $data['html-fallback-warning'] = Html
::warningBox( $this->buildHelpfulInformationMessage() );