SkinFallbackTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Skin template for the fallback skin.
  4. *
  5. * The structure is copied from the example skin (mediawiki/skins/Example).
  6. *
  7. * @since 1.24
  8. * @file
  9. */
  10. /**
  11. * BaseTemplate class for the fallback skin
  12. */
  13. class SkinFallbackTemplate extends BaseTemplate {
  14. /**
  15. * @return array
  16. */
  17. private function findInstalledSkins() {
  18. $styleDirectory = $this->config->get( 'StyleDirectory' );
  19. // Get all subdirectories which might contains skins
  20. $possibleSkins = scandir( $styleDirectory );
  21. $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) use ( $styleDirectory ) {
  22. return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$styleDirectory/$maybeDir" );
  23. } );
  24. // Filter out skins that aren't installed
  25. $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) use ( $styleDirectory ) {
  26. return is_file( "$styleDirectory/$skinDir/skin.json" )
  27. || is_file( "$styleDirectory/$skinDir/$skinDir.php" );
  28. } );
  29. return $possibleSkins;
  30. }
  31. /**
  32. * Inform the user why they are seeing this skin.
  33. *
  34. * @return string
  35. */
  36. private function buildHelpfulInformationMessage() {
  37. $defaultSkin = $this->config->get( 'DefaultSkin' );
  38. $installedSkins = $this->findInstalledSkins();
  39. $enabledSkins = SkinFactory::getDefaultInstance()->getSkinNames();
  40. $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
  41. if ( $installedSkins ) {
  42. $skinsInstalledText = [];
  43. $skinsInstalledSnippet = [];
  44. foreach ( $installedSkins as $skin ) {
  45. $normalizedKey = strtolower( $skin );
  46. $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
  47. if ( $isEnabled ) {
  48. $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
  49. ->params( $normalizedKey, $skin )->plain();
  50. } else {
  51. $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
  52. ->params( $normalizedKey, $skin )->plain();
  53. $skinsInstalledSnippet[] = $this->getSnippetForSkin( $skin );
  54. }
  55. }
  56. return $this->getMsg( 'default-skin-not-found' )->params(
  57. $defaultSkin,
  58. implode( "\n", $skinsInstalledText ),
  59. implode( "\n", $skinsInstalledSnippet ) )->numParams(
  60. count( $skinsInstalledText ),
  61. count( $skinsInstalledSnippet )
  62. )->parseAsBlock();
  63. } else {
  64. return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
  65. $defaultSkin
  66. )->parseAsBlock();
  67. }
  68. }
  69. /**
  70. * Get the appropriate LocalSettings.php snippet to enable the given skin
  71. *
  72. * @param string $skin
  73. * @return string
  74. */
  75. private function getSnippetForSkin( $skin ) {
  76. global $IP;
  77. if ( file_exists( "$IP/skins/$skin/skin.json" ) ) {
  78. return "wfLoadSkin( '$skin' );";
  79. } else {
  80. return "require_once \"\$IP/skins/$skin/$skin.php\";";
  81. }
  82. }
  83. /**
  84. * Outputs the entire contents of the page. No navigation (other than search box), just the big
  85. * warning message and page content.
  86. */
  87. public function execute() {
  88. $this->html( 'headelement' );
  89. echo Html::warningBox( $this->buildHelpfulInformationMessage() );
  90. ?>
  91. <form action="<?php $this->text( 'wgScript' ) ?>">
  92. <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
  93. <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
  94. <?php echo $this->makeSearchInput( [ "id" => "searchInput" ] ) ?>
  95. <?php echo $this->makeSearchButton( 'go' ) ?>
  96. </form>
  97. <div class="mw-body" role="main">
  98. <h1 class="firstHeading"><?php $this->html( 'title' ) ?></h1>
  99. <div class="mw-body-content">
  100. <?php $this->html( 'bodytext' ) ?>
  101. <?php $this->html( 'catlinks' ) ?>
  102. </div>
  103. </div>
  104. <?php $this->printTrail() ?>
  105. </body></html>
  106. <?php
  107. }
  108. }