MediaWiki  master
SkinFallback.php
Go to the documentation of this file.
1 <?php
9 
13 class SkinFallback extends SkinMustache {
14  public $skinname = 'fallback';
15 
19  public function initPage( OutputPage $out ) {
20  parent::initPage( $out );
21  $out->enableClientCache( false );
22  }
23 
27  private function findInstalledSkins() {
28  $config = $this->getConfig();
29  $styleDirectory = $config->get( 'StyleDirectory' );
30  // Get all subdirectories which might contains skins
31  $possibleSkins = scandir( $styleDirectory );
32  $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
33  return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
34  } );
35 
36  // Filter out skins that aren't installed
37  $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
38  return is_file( "$styleDirectory/$skinDir/skin.json" )
39  || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
40  } );
41 
42  return $possibleSkins;
43  }
44 
50  private function buildHelpfulInformationMessage() {
51  $config = $this->getConfig();
52  $defaultSkin = $config->get( 'DefaultSkin' );
53  $installedSkins = $this->findInstalledSkins();
54  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
55  $enabledSkins = $skinFactory->getSkinNames();
56  $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
57 
58  if ( $installedSkins ) {
59  $skinsInstalledText = [];
60  $skinsInstalledSnippet = [];
61 
62  foreach ( $installedSkins as $skinKey ) {
63  $normalizedKey = strtolower( $skinKey );
64  $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
65  if ( $isEnabled ) {
66  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
67  ->params( $normalizedKey, $skinKey )->plain();
68  } else {
69  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
70  ->params( $normalizedKey, $skinKey )->plain();
71  $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
72  }
73  }
74 
75  return $this->msg( 'default-skin-not-found' )->params(
76  $defaultSkin,
77  implode( "\n", $skinsInstalledText ),
78  implode( "\n", $skinsInstalledSnippet ) )->numParams(
79  count( $skinsInstalledText ),
80  count( $skinsInstalledSnippet )
81  )->parseAsBlock();
82  } else {
83  return $this->msg( 'default-skin-not-found-no-skins' )->params(
84  $defaultSkin
85  )->parseAsBlock();
86  }
87  }
88 
95  private static function getSnippetForSkin( $skin ) {
96  global $IP;
97  if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
98  return "wfLoadSkin( '$skin' );";
99  } else {
100  return "require_once \"\$IP/skins/$skin/$skin.php\";";
101  }
102  }
103 
113  public function getTemplateData() {
114  $config = $this->getConfig();
115  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
116  $data = parent::getTemplateData();
117  // If the default skin isn't configured correctly, append a warning to the
118  // subtitle to alert a sysadmin.
119  if ( !isset( $skinFactory->getSkinNames()[$config->get( 'DefaultSkin' )] ) ) {
120  $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
121  }
122  return $data;
123  }
124 }
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
OutputPage\enableClientCache
enableClientCache( $state)
Use enableClientCache(false) to force it to send nocache headers.
Definition: OutputPage.php:2179
SkinFallback\findInstalledSkins
findInstalledSkins()
Definition: SkinFallback.php:27
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:726
SkinFallback\getTemplateData
getTemplateData()
Adds an html-fallback-warning template to inform system administrators that their mediawiki skin is i...
Definition: SkinFallback.php:113
SkinFallback
SkinTemplate class for the fallback skin.
Definition: SkinFallback.php:13
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:47
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
SkinFallback\initPage
initPage(OutputPage $out)
Definition: SkinFallback.php:19
SkinMustache
Generic template for use with Mustache templates.
Definition: SkinMustache.php:26
$IP
$IP
Definition: WebStart.php:49
SkinFallback\$skinname
$skinname
Definition: SkinFallback.php:14
SkinFallback\getSnippetForSkin
static getSnippetForSkin( $skin)
Get the appropriate LocalSettings.php snippet to enable the given skin.
Definition: SkinFallback.php:95
SkinFallback\buildHelpfulInformationMessage
buildHelpfulInformationMessage()
Inform the user why they are seeing this skin.
Definition: SkinFallback.php:50