MediaWiki REL1_35
SkinFallback.php
Go to the documentation of this file.
1<?php
9
14 public $skinname = 'fallback';
15
19 public function initPage( OutputPage $out ) {
20 parent::initPage( $out );
21 $out->enableClientCache( false );
22 }
23
27 private function findInstalledSkins() {
28 $config = $this->getConfig();
29 $styleDirectory = $config->get( 'StyleDirectory' );
30 // Get all subdirectories which might contains skins
31 $possibleSkins = scandir( $styleDirectory );
32 $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
33 return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
34 } );
35
36 // Filter out skins that aren't installed
37 $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
38 return is_file( "$styleDirectory/$skinDir/skin.json" )
39 || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
40 } );
41
42 return $possibleSkins;
43 }
44
50 private function buildHelpfulInformationMessage() {
51 $config = $this->getConfig();
52 $defaultSkin = $config->get( 'DefaultSkin' );
53 $installedSkins = $this->findInstalledSkins();
54 $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
55 $enabledSkins = $skinFactory->getSkinNames();
56 $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
57
58 if ( $installedSkins ) {
59 $skinsInstalledText = [];
60 $skinsInstalledSnippet = [];
61
62 foreach ( $installedSkins as $skinKey ) {
63 $normalizedKey = strtolower( $skinKey );
64 $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
65 if ( $isEnabled ) {
66 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-enabled' )
67 ->params( $normalizedKey, $skinKey )->plain();
68 } else {
69 $skinsInstalledText[] = $this->msg( 'default-skin-not-found-row-disabled' )
70 ->params( $normalizedKey, $skinKey )->plain();
71 $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skinKey );
72 }
73 }
74
75 return $this->msg( 'default-skin-not-found' )->params(
76 $defaultSkin,
77 implode( "\n", $skinsInstalledText ),
78 implode( "\n", $skinsInstalledSnippet ) )->numParams(
79 count( $skinsInstalledText ),
80 count( $skinsInstalledSnippet )
81 )->parseAsBlock();
82 } else {
83 return $this->msg( 'default-skin-not-found-no-skins' )->params(
84 $defaultSkin
85 )->parseAsBlock();
86 }
87 }
88
95 private static function getSnippetForSkin( $skin ) {
96 global $IP;
97 if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
98 return "wfLoadSkin( '$skin' );";
99 } else {
100 return "require_once \"\$IP/skins/$skin/$skin.php\";";
101 }
102 }
103
113 public function getTemplateData() {
114 $config = $this->getConfig();
115 $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
116 $data = parent::getTemplateData();
117 // If the default skin isn't configured correctly, append a warning to the
118 // subtitle to alert a sysadmin.
119 if ( !isset( $skinFactory->getSkinNames()[$config->get( 'DefaultSkin' )] ) ) {
120 $data['html-fallback-warning'] = Html::warningBox( $this->buildHelpfulInformationMessage() );
121 }
122 return $data;
123 }
124}
$IP
Definition WebStart.php:49
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
MediaWikiServices is the service locator for the application scope of MediaWiki.
This is one of the Core classes and should be read at least once by any new developers.
enableClientCache( $state)
Use enableClientCache(false) to force it to send nocache headers.
SkinTemplate class for the fallback skin.
buildHelpfulInformationMessage()
Inform the user why they are seeing this skin.
static getSnippetForSkin( $skin)
Get the appropriate LocalSettings.php snippet to enable the given 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.