MediaWiki master
SkinFallback.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Skin;
10
15
21 public $skinname = 'fallback';
22
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', $defaultSkin )
88 ->parseAsBlock();
89 }
90 }
91
98 private static function getSnippetForSkin( $skin ) {
99 global $IP;
100 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
101 return "wfLoadSkin( '$skin' );";
102 } else {
103 return "require_once \"\$IP/skins/$skin/$skin.php\";";
104 }
105 }
106
116 public function getTemplateData() {
117 $config = $this->getConfig();
118 $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
119 $data = parent::getTemplateData();
120 // If the default skin isn't configured correctly, append a warning to the
121 // subtitle to alert a sysadmin.
122 if ( !isset(
123 $skinFactory->getInstalledSkins()[$config->get( MainConfigNames::DefaultSkin )]
124 ) ) {
125 $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
126 }
127 return $data;
128 }
129}
130
132class_alias( SkinFallback::class, 'SkinFallback' );
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:90
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:43
A class containing constants representing the names of configuration variables.
const DefaultSkin
Name constant for the DefaultSkin setting, for use with Config::get()
const StyleDirectory
Name constant for the StyleDirectory setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
This is one of the Core classes and should be read at least once by any new developers.
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...
Generic template for use with Mustache templates.