Use a special fallback skin when selected skin is unavailable
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 22 Jul 2014 21:27:32 +0000 (23:27 +0200)
committerJdlrobson <jrobson@wikimedia.org>
Wed, 6 Aug 2014 16:41:36 +0000 (16:41 +0000)
It just displays a helpful message that explains why and how to
install and enable skins. There is no navigation nor other basic page
elements (like the logo or site notice), since this is not intended to
be a fully functional skin.

Bug: 68332
Change-Id: Id14fbb8733cd8fbb912a724ac658f5e7244364b5

includes/AutoLoader.php
includes/DefaultSettings.php
includes/Setup.php
includes/SkinFallback.php [new file with mode: 0644]
languages/i18n/en.json
languages/i18n/qqq.json

index 9fa0c13..083a596 100644 (file)
@@ -158,6 +158,8 @@ $wgAutoloadLocalClasses = array(
        'SiteStatsInit' => 'includes/SiteStats.php',
        'Skin' => 'includes/Skin.php',
        'SkinTemplate' => 'includes/SkinTemplate.php',
+       'SkinFallback' => 'includes/SkinFallback.php',
+       'SkinFallbackTemplate' => 'includes/SkinFallback.php',
        'SquidPurgeClient' => 'includes/SquidPurgeClient.php',
        'SquidPurgeClientPool' => 'includes/SquidPurgeClient.php',
        'StatCounter' => 'includes/StatCounter.php',
index 2fc2a9a..030f5d2 100644 (file)
@@ -2968,7 +2968,7 @@ $wgDefaultSkin = 'vector';
  *
  * @since 1.24
  */
-$wgFallbackSkin = 'vector';
+$wgFallbackSkin = 'fallback';
 
 /**
  * Specify the names of skins that should not be presented in the list of
index 03c529e..1eb04c3 100644 (file)
@@ -271,6 +271,10 @@ if ( $wgSkipSkin ) {
        $wgSkipSkins[] = $wgSkipSkin;
 }
 
+// Register a hidden "fallback" skin
+$wgValidSkinNames['fallback'] = 'Fallback'; // SkinFallback
+$wgSkipSkins[] = 'fallback';
+
 if ( $wgLocalInterwiki ) {
        array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
 }
diff --git a/includes/SkinFallback.php b/includes/SkinFallback.php
new file mode 100644 (file)
index 0000000..ab72a38
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/**
+ * Skin file for the fallback skin.
+ *
+ * The structure is copied from the example skin (mediawiki/skins/Example).
+ *
+ * @since 1.24
+ * @file
+ */
+
+/**
+ * SkinTemplate class for the fallback skin
+ */
+class SkinFallback extends SkinTemplate {
+       var $skinname = 'fallback', $template = 'SkinFallbackTemplate';
+
+       /**
+        * Add CSS via ResourceLoader
+        *
+        * @param $out OutputPage
+        */
+       function setupSkinUserCss( OutputPage $out ) {
+               parent::setupSkinUserCss( $out );
+               $out->addModuleStyles( 'mediawiki.skinning.interface' );
+       }
+}
+
+/**
+ * BaseTemplate class for the fallback skin
+ */
+class SkinFallbackTemplate extends BaseTemplate {
+       /**
+        * @return array
+        */
+       private function findInstalledSkins() {
+               global $wgStyleDirectory;
+
+               // Get all subdirectories which might contains skins
+               $possibleSkins = scandir( $wgStyleDirectory );
+               $possibleSkins = array_filter( $possibleSkins, function ( $maybeDir ) {
+                       global $wgStyleDirectory;
+                       return $maybeDir !== '.' && $maybeDir !== '..' && is_dir( "$wgStyleDirectory/$maybeDir" );
+               } );
+
+               // Only keep the ones that contain a .php file with the same name inside
+               $possibleSkins = array_filter( $possibleSkins, function ( $skinDir ) {
+                       global $wgStyleDirectory;
+                       return is_file( "$wgStyleDirectory/$skinDir/$skinDir.php" );
+               } );
+
+               return $possibleSkins;
+       }
+
+       /**
+        * Inform the user why they are seeing this skin.
+        *
+        * @return string
+        */
+       private function buildHelpfulInformationMessage() {
+               global $wgDefaultSkin, $wgValidSkinNames;
+
+               $installedSkins = $this->findInstalledSkins();
+               $enabledSkins = $wgValidSkinNames;
+               $enabledSkins = array_change_key_case( $enabledSkins, CASE_LOWER );
+
+               if ( $installedSkins ) {
+                       $skinsInstalledText = array();
+                       $skinsInstalledSnippet = array();
+
+                       foreach ( $installedSkins as $skin ) {
+                               $normalizedKey = strtolower( $skin );
+                               $isEnabled = array_key_exists( $normalizedKey, $enabledSkins );
+                               if ( $isEnabled ) {
+                                       $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-enabled' )
+                                               ->params( $normalizedKey, $skin )->plain();
+                               } else {
+                                       $skinsInstalledText[] = $this->getMsg( 'default-skin-not-found-row-disabled' )
+                                               ->params( $normalizedKey, $skin )->plain();
+                                       $skinsInstalledSnippet[] = "require_once \"\$IP/skins/$skin/$skin.php\";";
+                               }
+                       }
+
+                       return $this->getMsg( 'default-skin-not-found' )->params(
+                               $wgDefaultSkin,
+                               implode( "\n", $skinsInstalledText ),
+                               implode( "\n", $skinsInstalledSnippet )
+                       )->parseAsBlock();
+               } else {
+                       return $this->getMsg( 'default-skin-not-found-no-skins' )->params(
+                               $wgDefaultSkin
+                       )->parseAsBlock();
+               }
+       }
+
+       /**
+        * Outputs the entire contents of the page. No navigation (other than search box), just the big
+        * warning message and page content.
+        */
+       public function execute() {
+               $this->html( 'headelement' ) ?>
+
+               <div class="warningbox">
+                       <?php echo $this->buildHelpfulInformationMessage() ?>
+               </div>
+
+               <form action="<?php $this->text( 'wgScript' ) ?>">
+                       <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
+                       <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
+                       <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ) ?>
+                       <?php echo $this->makeSearchButton( 'go' ) ?>
+               </form>
+
+               <div class="mw-body" role="main">
+                       <h1 class="firstHeading">
+                               <span dir="auto"><?php $this->html( 'title' ) ?></span>
+                       </h1>
+
+                       <div class="mw-body-content">
+                               <?php $this->html( 'bodytext' ) ?>
+                               <?php $this->html( 'catlinks' ) ?>
+                       </div>
+               </div>
+
+               <?php $this->printTrail() ?>
+               </body></html>
+
+               <?php
+       }
+}
index 11c6c60..00159a4 100644 (file)
        "action-pagelang": "change the page language",
        "log-name-pagelang": "Change language log",
        "log-description-pagelang": "This is a log of changes in page languages.",
-       "logentry-pagelang-pagelang": "$1 {{GENDER:$2|changed}} page language for $3 from $4 to $5."
+       "logentry-pagelang-pagelang": "$1 {{GENDER:$2|changed}} page language for $3 from $4 to $5.",
+       "default-skin-not-found": "Whoops! The default skin for your wiki (<code>$wgDefaultSkin</code>), <code>$1</code>, is not available.\n\nYour installation seems to include the following skins. See [https://www.mediawiki.org/wiki/Manual:Skin_configuration Manual: Skin configuration] for information how to enable them and choose the default.\n\n$2\n\n; If you have just installed MediaWiki:\n: You probably installed from git, or directly from the source code using some other method. This is expected.\n:* Try installing some skins from [https://www.mediawiki.org/wiki/Category:All_skins mediawiki.org's skin directory].\n:* Download the [https://www.mediawiki.org/wiki/Download tarball installer], which comes with several skins and extensions. You can copy and paste the <code>skins/</code> directory from it.\n: Doing this should not interfere with your git repository if you're a MediaWiki developer.\n\n; If you have just upgraded MediaWiki:\n: MediaWiki 1.24 and newer no longer automatically enables installed skins (see [https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery Manual: Skin autodiscovery]). You can paste the following lines into <code>LocalSettings.php</code> to enable all currently installed skins:\n\n<pre>$3</pre>\n\n; If you have just modified <code>LocalSettings.php</code>:\n: Double-check the skin names for typos.",
+       "default-skin-not-found-no-skins": "Whoops! The default skin for your wiki (<code>$wgDefaultSkin</code>), <code>$1</code>, is not available.\n\nYou have no installed skins.\n\n; If you have just installed MediaWiki:\n: You probably installed from git, or directly from the source code using some other method. This is expected.\n:* Try installing some skins from [https://www.mediawiki.org/wiki/Category:All_skins mediawiki.org's skin directory].\n:* Download the [https://www.mediawiki.org/wiki/Download tarball installer], which comes with several skins and extensions. You can copy and paste the <code>skins/</code> directory from it.\n: Doing this should not interfere with your git repository if you're a MediaWiki developer. See [https://www.mediawiki.org/wiki/Manual:Skin_configuration Manual: Skin configuration] for information how to enable skins and choose the default.\n",
+       "default-skin-not-found-row-enabled": "* <code>$1</code> / $2 (enabled)",
+       "default-skin-not-found-row-disabled": "* <code>$1</code> / $2 ('''disabled''')"
 }
index ed4e1b6..fa8abf5 100644 (file)
        "action-pagelang": "{{Doc-action|pagelang}}",
        "log-name-pagelang": "Display entry for log name for changes in page language in Special:Log.",
        "log-description-pagelang": "Display description for log name for changes in page language in Special:Log.",
-       "logentry-pagelang-pagelang": "{{Logentry}}\nAdditional parameters:\n* $4 - old language code, or \"[def]\" (hard-coded)\n* $5 - new language code, or \"[def]\" (hard-coded)"
+       "logentry-pagelang-pagelang": "{{Logentry}}\nAdditional parameters:\n* $4 - old language code, or \"[def]\" (hard-coded)\n* $5 - new language code, or \"[def]\" (hard-coded)",
+       "default-skin-not-found": "Message shown when the default skin for this MediaWiki installation can not be found.\n\nParameters:\n* $1: skin identifier for the default skin\n* $2: list of installed skins, composed using {{msg-mw|default-skin-not-found-row-enabled}} and {{msg-mw|default-skin-not-found-row-disabled}}\n* $3: code snippet to use to enable installed skins",
+       "default-skin-not-found-no-skins": "Message shown when the default skin for this MediaWiki installation can not be found and the installation has no skins at all.\n\nParameters:\n* $1: name of the default skin",
+       "default-skin-not-found-row-enabled": "One row of the list of installed skins shown as a part of {{msg-mw|default-skin-not-found}}, for an enabled skin.\n\nParameters:\n* $1: skin identifier\n$2: human-readable skin name",
+       "default-skin-not-found-row-disabled": "One row of the list of installed skins shown as a part of {{msg-mw|default-skin-not-found}}, for a disabled skin.\n\nParameters:\n* $1: skin identifier\n$2: human-readable skin name"
 }