MediaWiki  master
SkinFallback.php
Go to the documentation of this file.
1 <?php
10 
14 class SkinFallback extends SkinMustache {
15  public $skinname = 'fallback';
16 
20  public function initPage( OutputPage $out ) {
21  parent::initPage( $out );
22  $out->disableClientCache();
23  }
24 
28  private function findInstalledSkins() {
29  $config = $this->getConfig();
30  $styleDirectory = $config->get( MainConfigNames::StyleDirectory );
31  // Get all subdirectories which might contains skins
32  $possibleSkins = scandir( $styleDirectory );
33  $possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
34  return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
35  } );
36 
37  // Filter out skins that aren't installed
38  $possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
39  return is_file( "$styleDirectory/$skinDir/skin.json" )
40  || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
41  } );
42 
43  return $possibleSkins;
44  }
45 
51  private function buildHelpfulInformationMessage() {
52  $config = $this->getConfig();
53  $defaultSkin = $config->get( MainConfigNames::DefaultSkin );
54  $installedSkins = $this->findInstalledSkins();
55  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
56  $enabledSkins = $skinFactory->getInstalledSkins();
57  $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
58 
59  if ( $installedSkins ) {
60  $skinsInstalledText = [];
61  $skinsInstalledSnippet = [];
62 
63  foreach ( $installedSkins as $skinKey ) {
64  $normalizedKey = strtolower( $skinKey );
65  $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
66  if ( $isEnabled ) {
67  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
68  ->params( $normalizedKey, $skinKey )->plain();
69  } else {
70  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
71  ->params( $normalizedKey, $skinKey )->plain();
72  $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
73  }
74  }
75 
76  return $this->msg( 'default-skin-not-found' )->params(
77  $defaultSkin,
78  implode( "\n", $skinsInstalledText ),
79  implode( "\n", $skinsInstalledSnippet ) )->numParams(
80  count( $skinsInstalledText ),
81  count( $skinsInstalledSnippet )
82  )->parseAsBlock();
83  } else {
84  return $this->msg( 'default-skin-not-found-no-skins' )->params(
85  $defaultSkin
86  )->parseAsBlock();
87  }
88  }
89 
96  private static function getSnippetForSkin( $skin ) {
97  global $IP;
98  if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
99  return "wfLoadSkin( '$skin' );";
100  } else {
101  return "require_once \"\$IP/skins/$skin/$skin.php\";";
102  }
103  }
104 
114  public function getTemplateData() {
115  $config = $this->getConfig();
116  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
117  $data = parent::getTemplateData();
118  // If the default skin isn't configured correctly, append a warning to the
119  // subtitle to alert a sysadmin.
120  if ( !isset(
121  $skinFactory->getInstalledSkins()[$config->get( MainConfigNames::DefaultSkin )]
122  ) ) {
123  $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
124  }
125  return $data;
126  }
127 }
if(!defined( 'MEDIAWIKI')) if(ini_get( 'mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition: Setup.php:91
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:775
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:56
disableClientCache()
Force the page to send nocache headers.
SkinTemplate class for the fallback skin.
getTemplateData()
Adds an html-fallback-warning template to inform system administrators that their mediawiki skin is i...
initPage(OutputPage $out)
Generic template for use with Mustache templates.