installer: Fix display of UPGRADE by disabling InterwikiLookup
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 7 Jun 2018 08:01:13 +0000 (01:01 -0700)
committerLegoktm <legoktm@member.fsf.org>
Thu, 7 Jun 2018 17:39:37 +0000 (17:39 +0000)
Since 129067c907ea65f62, parsing section titles has looked up interwiki
prefixes with InterwikiLookup. In the web upgrader, this triggers
database access, and since that service is disabled, it throws
exceptions, causing parsing to fail.

Work around that by using a dummy InterwikiLookup service that knows
about no interwiki prefixes. Maybe one could be written to just read
from the stock `interwiki.list`, but that's a project for another time.

Bug: T196607
Change-Id: I13485a9af79297b552a1128240cb8597c2ef83d8
(cherry picked from commit a498abf272c7aff376c5225a6f593349e3cc3eaa)

autoload.php
includes/installer/Installer.php
includes/interwiki/NullInterwikiLookup.php [new file with mode: 0644]

index 0e1b30f..b306bf5 100644 (file)
@@ -893,6 +893,7 @@ $wgAutoloadLocalClasses = [
        'MediaWiki\\Interwiki\\ClassicInterwikiLookup' => __DIR__ . '/includes/interwiki/ClassicInterwikiLookup.php',
        'MediaWiki\\Interwiki\\InterwikiLookup' => __DIR__ . '/includes/interwiki/InterwikiLookup.php',
        'MediaWiki\\Interwiki\\InterwikiLookupAdapter' => __DIR__ . '/includes/interwiki/InterwikiLookupAdapter.php',
+       'MediaWiki\\Interwiki\\NullInterwikiLookup' => __DIR__ . '/includes/interwiki/NullInterwikiLookup.php',
        'MediaWiki\\Languages\\Data\\CrhExceptions' => __DIR__ . '/languages/data/CrhExceptions.php',
        'MediaWiki\\Languages\\Data\\Names' => __DIR__ . '/languages/data/Names.php',
        'MediaWiki\\Languages\\Data\\ZhConversion' => __DIR__ . '/languages/data/ZhConversion.php',
index 4b6e8cc..abf4de4 100644 (file)
@@ -23,6 +23,8 @@
  * @file
  * @ingroup Deployment
  */
+
+use MediaWiki\Interwiki\NullInterwikiLookup;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Shell\Shell;
 
@@ -404,7 +406,7 @@ abstract class Installer {
                $installerConfig = self::getInstallerConfig( $defaultConfig );
 
                // Reset all services and inject config overrides
-               MediaWiki\MediaWikiServices::resetGlobalInstance( $installerConfig );
+               MediaWikiServices::resetGlobalInstance( $installerConfig );
 
                // Don't attempt to load user language options (T126177)
                // This will be overridden in the web installer with the user-specified language
@@ -415,13 +417,19 @@ abstract class Installer {
                Language::getLocalisationCache()->disableBackend();
 
                // Disable all global services, since we don't have any configuration yet!
-               MediaWiki\MediaWikiServices::disableStorageBackend();
+               MediaWikiServices::disableStorageBackend();
 
+               $mwServices = MediaWikiServices::getInstance();
                // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
                // SqlBagOStuff will then throw since we just disabled wfGetDB)
-               $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get( 'ObjectCaches' );
+               $wgObjectCaches = $mwServices->getMainConfig()->get( 'ObjectCaches' );
                $wgMemc = ObjectCache::getInstance( CACHE_NONE );
 
+               // Disable interwiki lookup, to avoid database access during parses
+               $mwServices->redefineService( 'InterwikiLookup', function () {
+                       return new NullInterwikiLookup();
+               } );
+
                // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
                $wgUser = User::newFromId( 0 );
                RequestContext::getMain()->setUser( $wgUser );
diff --git a/includes/interwiki/NullInterwikiLookup.php b/includes/interwiki/NullInterwikiLookup.php
new file mode 100644 (file)
index 0000000..09fa1ec
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Copyright (C) 2018 Kunal Mehta <legoktm@member.fsf.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+namespace MediaWiki\Interwiki;
+
+/**
+ * An interwiki lookup that has no data, intended
+ * for use in the installer.
+ *
+ * @since 1.31
+ */
+class NullInterwikiLookup implements InterwikiLookup {
+
+       /**
+        * @inheritDoc
+        */
+       public function isValidInterwiki( $prefix ) {
+               return false;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function fetch( $prefix ) {
+               return false;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function getAllPrefixes( $local = null ) {
+               return [];
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function invalidateCache( $prefix ) {
+       }
+}