MediaWiki  1.34.0
SkinFallbackTemplate.php
Go to the documentation of this file.
1 <?php
2 
13 
21  private function findInstalledSkins() {
22  $styleDirectory = $this->config->get( 'StyleDirectory' );
23  // Get all subdirectories which might contains skins
24  $possibleSkins = scandir( $styleDirectory );
25  $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
26  return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
27  } );
28 
29  // Filter out skins that aren't installed
30  $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
31  return is_file( "$styleDirectory/$skinDir/skin.json" )
32  || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
33  } );
34 
35  return $possibleSkins;
36  }
37 
43  private function buildHelpfulInformationMessage() {
44  $defaultSkin = $this->config->get( 'DefaultSkin' );
45  $installedSkins = $this->findInstalledSkins();
46  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
47  $enabledSkins = $skinFactory->getSkinNames();
48  $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
49 
50  if ( $installedSkins ) {
51  $skinsInstalledText = [];
52  $skinsInstalledSnippet = [];
53 
54  foreach ( $installedSkins as $skin ) {
55  $normalizedKey = strtolower( $skin );
56  $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
57  if ( $isEnabled ) {
58  $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
59  ->params( $normalizedKey, $skin )->plain();
60  } else {
61  $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
62  ->params( $normalizedKey, $skin )->plain();
63  $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skin );
64  }
65  }
66 
67  return $this->getMsg( 'default-skin-not-found' )->params(
68  $defaultSkin,
69  implode( "\n", $skinsInstalledText ),
70  implode( "\n", $skinsInstalledSnippet ) )->numParams(
71  count( $skinsInstalledText ),
72  count( $skinsInstalledSnippet )
73  )->parseAsBlock();
74  } else {
75  return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
76  $defaultSkin
77  )->parseAsBlock();
78  }
79  }
80 
87  private function getSnippetForSkin( $skin ) {
88  global $IP;
89  if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
90  return "wfLoadSkin( '$skin' );";
91  } else {
92  return "require_once \"\$IP/skins/$skin/$skin.php\";";
93  }
94  }
95 
100  public function execute() {
101  $this->html( 'headelement' );
102  echo Html::warningBox( $this->buildHelpfulInformationMessage() );
103  ?>
104  <form action="<?php $this->text( 'wgScript' ) ?>">
105  <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
106  <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
107  <?php echo $this->makeSearchInput( [ "id" => "searchInput" ] ) ?>
108  <?php echo $this->makeSearchButton( 'go' ) ?>
109  </form>
110 
111  <div class="mw-body" role="main">
112  <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
113 
114  <div class="mw-body-content">
115  <?php $this->html( 'bodytext' ) ?>
116  <?php $this->html( 'catlinks' ) ?>
117  </div>
118  </div>
119 
120  <?php $this->printTrail() ?>
121  </body></html>
122 
123  <?php
124  }
125 }
BaseTemplate\msg
msg( $str)
Definition: BaseTemplate.php:42
SkinFallbackTemplate
BaseTemplate class for the fallback skin.
Definition: SkinFallbackTemplate.php:17
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
BaseTemplate\makeSearchButton
makeSearchButton( $mode, $attrs=[])
Definition: BaseTemplate.php:531
SkinFallbackTemplate\execute
execute()
Outputs the entire contents of the page.
Definition: SkinFallbackTemplate.php:100
SkinFallbackTemplate\getSnippetForSkin
getSnippetForSkin( $skin)
Get the appropriate LocalSettings.php snippet to enable the given skin.
Definition: SkinFallbackTemplate.php:87
SkinFallbackTemplate\buildHelpfulInformationMessage
buildHelpfulInformationMessage()
Inform the user why they are seeing this skin.
Definition: SkinFallbackTemplate.php:43
value
if( $inline) $status value
Definition: SyntaxHighlight.php:346
$IP
$IP
Definition: update.php:3
BaseTemplate\printTrail
printTrail()
Output getTrail.
Definition: BaseTemplate.php:744
SkinFallbackTemplate\findInstalledSkins
findInstalledSkins()
Definition: SkinFallbackTemplate.php:21
BaseTemplate\makeSearchInput
makeSearchInput( $attrs=[])
Definition: BaseTemplate.php:521
QuickTemplate\html
html( $str)
Definition: QuickTemplate.php:116
BaseTemplate\getMsg
getMsg( $name,... $params)
Get a Message object with its context set.
Definition: BaseTemplate.php:38
BaseTemplate
New base template for a skin's template extended from QuickTemplate this class features helper method...
Definition: BaseTemplate.php:29