MediaWiki master
SkinFallback.php
Go to the documentation of this file.
1<?php
13
19 public $skinname = 'fallback';
20
24 public function initPage( OutputPage $out ) {
25 parent::initPage( $out );
26 $out->disableClientCache();
27 }
28
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 } );
40
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 } );
46
47 return $possibleSkins;
48 }
49
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 );
62
63 if ( $installedSkins ) {
64 $skinsInstalledText = [];
65 $skinsInstalledSnippet = [];
66
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 );
77 }
78 }
79
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();
91 }
92 }
93
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\";";
106 }
107 }
108
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() );
128 }
129 return $data;
130 }
131}
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:105
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:56
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.
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.