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';
22 * @param OutputPage $out
24 public function initPage( OutputPage
$out ) {
25 parent
::initPage( $out );
26 $out->disableClientCache();
32 private function findInstalledSkins() {
33 $config = $this->getConfig();
34 $styleDirectory = $config->get( MainConfigNames
::StyleDirectory
);
35 // Get all subdirectories which might contains skins
36 $possibleSkins = scandir( $styleDirectory );
37 $possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
38 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
41 // Filter out skins that aren't installed
42 $possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
43 return is_file( "$styleDirectory/$skinDir/skin.json" )
44 ||
is_file( "$styleDirectory/$skinDir/$skinDir.php" );
47 return $possibleSkins;
51 * Inform the user why they are seeing this skin.
55 private function buildHelpfulInformationMessage() {
56 $config = $this->getConfig();
57 $defaultSkin = $config->get( MainConfigNames
::DefaultSkin
);
58 $installedSkins = $this->findInstalledSkins();
59 $skinFactory = MediaWikiServices
::getInstance()->getSkinFactory();
60 $enabledSkins = $skinFactory->getInstalledSkins();
61 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER
);
63 if ( $installedSkins ) {
64 $skinsInstalledText = [];
65 $skinsInstalledSnippet = [];
67 foreach ( $installedSkins as $skinKey ) {
68 $normalizedKey = strtolower( $skinKey );
69 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
71 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
72 ->params( $normalizedKey, $skinKey )->plain();
74 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
75 ->params( $normalizedKey, $skinKey )->plain();
76 $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
80 return $this->msg( 'default-skin-not-found' )->params(
82 implode( "\n", $skinsInstalledText ),
83 implode( "\n", $skinsInstalledSnippet ) )->numParams(
84 count( $skinsInstalledText ),
85 count( $skinsInstalledSnippet )
88 return $this->msg( 'default-skin-not-found-no-skins' )->params(
95 * Get the appropriate LocalSettings.php snippet to enable the given skin
100 private static function getSnippetForSkin( $skin ) {
102 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
103 return "wfLoadSkin( '$skin' );";
105 return "require_once \"\$IP/skins/$skin/$skin.php\";";
110 * Adds an `html-fallback-warning` template to inform system administrators
111 * that their mediawiki skin is incorrectly setup.
112 * It's recommended that skin developers do not add further to date here
113 * and instead work on improving SkinMustache::getTemplateData where necessary
114 * to improve flexibility of the data for all skin developers.
118 public function getTemplateData() {
119 $config = $this->getConfig();
120 $skinFactory = MediaWikiServices
::getInstance()->getSkinFactory();
121 $data = parent
::getTemplateData();
122 // If the default skin isn't configured correctly, append a warning to the
123 // subtitle to alert a sysadmin.
125 $skinFactory->getInstalledSkins()[$config->get( MainConfigNames
::DefaultSkin
)]
127 $data['html-fallback-warning'] = Html
::warningBox( $this->buildHelpfulInformationMessage() );