MediaWiki  master
SkinFallback.php
Go to the documentation of this file.
1 <?php
13 
17 class SkinFallback extends SkinMustache {
18  public $skinname = 'fallback';
19 
23  public function initPage( OutputPage $out ) {
24  parent::initPage( $out );
25  $out->disableClientCache();
26  }
27 
31  private function findInstalledSkins() {
32  $config = $this->getConfig();
33  $styleDirectory = $config->get( MainConfigNames::StyleDirectory );
34  // Get all subdirectories which might contains skins
35  $possibleSkins = scandir( $styleDirectory );
36  $possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
37  return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
38  } );
39 
40  // Filter out skins that aren't installed
41  $possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
42  return is_file( "$styleDirectory/$skinDir/skin.json" )
43  || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
44  } );
45 
46  return $possibleSkins;
47  }
48 
54  private function buildHelpfulInformationMessage() {
55  $config = $this->getConfig();
56  $defaultSkin = $config->get( MainConfigNames::DefaultSkin );
57  $installedSkins = $this->findInstalledSkins();
58  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
59  $enabledSkins = $skinFactory->getInstalledSkins();
60  $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
61 
62  if ( $installedSkins ) {
63  $skinsInstalledText = [];
64  $skinsInstalledSnippet = [];
65 
66  foreach ( $installedSkins as $skinKey ) {
67  $normalizedKey = strtolower( $skinKey );
68  $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
69  if ( $isEnabled ) {
70  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
71  ->params( $normalizedKey, $skinKey )->plain();
72  } else {
73  $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
74  ->params( $normalizedKey, $skinKey )->plain();
75  $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
76  }
77  }
78 
79  return $this->msg( 'default-skin-not-found' )->params(
80  $defaultSkin,
81  implode( "\n", $skinsInstalledText ),
82  implode( "\n", $skinsInstalledSnippet ) )->numParams(
83  count( $skinsInstalledText ),
84  count( $skinsInstalledSnippet )
85  )->parseAsBlock();
86  } else {
87  return $this->msg( 'default-skin-not-found-no-skins' )->params(
88  $defaultSkin
89  )->parseAsBlock();
90  }
91  }
92 
99  private static function getSnippetForSkin( $skin ) {
100  global $IP;
101  if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
102  return "wfLoadSkin( '$skin' );";
103  } else {
104  return "require_once \"\$IP/skins/$skin/$skin.php\";";
105  }
106  }
107 
117  public function getTemplateData() {
118  $config = $this->getConfig();
119  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
120  $data = parent::getTemplateData();
121  // If the default skin isn't configured correctly, append a warning to the
122  // subtitle to alert a sysadmin.
123  if ( !isset(
124  $skinFactory->getInstalledSkins()[$config->get( MainConfigNames::DefaultSkin )]
125  ) ) {
126  $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
127  }
128  return $data;
129  }
130 }
if(!defined( 'MEDIAWIKI')) if(ini_get( 'mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition: Setup.php:96
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
This class is a collection of static functions that serve two purposes:
Definition: Html.php:57
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:93
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.