Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / skins / SkinFallback.php
blobab046593874efb39d81c777e2532e4b7db6d0400
1 <?php
2 /**
3 * Skin file for the fallback skin.
5 * @since 1.24
6 * @file
7 */
9 use MediaWiki\Html\Html;
10 use MediaWiki\MainConfigNames;
11 use MediaWiki\MediaWikiServices;
12 use MediaWiki\Output\OutputPage;
14 /**
15 * SkinTemplate class for the fallback skin
17 class SkinFallback extends SkinMustache {
18 /** @inheritDoc */
19 public $skinname = 'fallback';
21 /**
22 * @param OutputPage $out
24 public function initPage( OutputPage $out ) {
25 parent::initPage( $out );
26 $out->disableClientCache();
29 /**
30 * @return array
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" );
39 } );
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" );
45 } );
47 return $possibleSkins;
50 /**
51 * Inform the user why they are seeing this skin.
53 * @return string
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 );
70 if ( $isEnabled ) {
71 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
72 ->params( $normalizedKey, $skinKey )->plain();
73 } else {
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(
81 $defaultSkin,
82 implode( "\n", $skinsInstalledText ),
83 implode( "\n", $skinsInstalledSnippet ) )->numParams(
84 count( $skinsInstalledText ),
85 count( $skinsInstalledSnippet )
86 )->parseAsBlock();
87 } else {
88 return $this->msg( 'default-skin-not-found-no-skins' )->params(
89 $defaultSkin
90 )->parseAsBlock();
94 /**
95 * Get the appropriate LocalSettings.php snippet to enable the given skin
97 * @param string $skin
98 * @return string
100 private static function getSnippetForSkin( $skin ) {
101 global $IP;
102 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
103 return "wfLoadSkin( '$skin' );";
104 } else {
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.
115 * @inheritDoc
116 * @return array
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.
124 if ( !isset(
125 $skinFactory->getInstalledSkins()[$config->get( MainConfigNames::DefaultSkin )]
126 ) ) {
127 $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
129 return $data;