MediaWiki 1.40.4
SkinFallback.php
Go to the documentation of this file.
1<?php
12
17 public $skinname = 'fallback';
18
22 public function initPage( OutputPage $out ) {
23 parent::initPage( $out );
24 $out->disableClientCache();
25 }
26
30 private function findInstalledSkins() {
31 $config = $this->getConfig();
32 $styleDirectory = $config->get( MainConfigNames::StyleDirectory );
33 // Get all subdirectories which might contains skins
34 $possibleSkins = scandir( $styleDirectory );
35 $possibleSkins = array_filter( $possibleSkins, static function ( $maybeDir ) use ( $styleDirectory ) {
36 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
37 } );
38
39 // Filter out skins that aren't installed
40 $possibleSkins = array_filter( $possibleSkins, static function ( $skinDir ) use ( $styleDirectory ) {
41 return is_file( "$styleDirectory/$skinDir/skin.json" )
42 || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
43 } );
44
45 return $possibleSkins;
46 }
47
53 private function buildHelpfulInformationMessage() {
54 $config = $this->getConfig();
55 $defaultSkin = $config->get( MainConfigNames::DefaultSkin );
56 $installedSkins = $this->findInstalledSkins();
57 $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
58 $enabledSkins = $skinFactory->getInstalledSkins();
59 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
60
61 if ( $installedSkins ) {
62 $skinsInstalledText = [];
63 $skinsInstalledSnippet = [];
64
65 foreach ( $installedSkins as $skinKey ) {
66 $normalizedKey = strtolower( $skinKey );
67 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
68 if ( $isEnabled ) {
69 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
70 ->params( $normalizedKey, $skinKey )->plain();
71 } else {
72 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
73 ->params( $normalizedKey, $skinKey )->plain();
74 $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
75 }
76 }
77
78 return $this->msg( 'default-skin-not-found' )->params(
79 $defaultSkin,
80 implode( "\n", $skinsInstalledText ),
81 implode( "\n", $skinsInstalledSnippet ) )->numParams(
82 count( $skinsInstalledText ),
83 count( $skinsInstalledSnippet )
84 )->parseAsBlock();
85 } else {
86 return $this->msg( 'default-skin-not-found-no-skins' )->params(
87 $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}
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:93
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:55
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.