Merge "installer: Fix display of UPGRADE by disabling InterwikiLookup"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 7 Jun 2018 16:49:40 +0000 (16:49 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 7 Jun 2018 16:49:40 +0000 (16:49 +0000)
autoload.php
includes/installer/Installer.php
includes/interwiki/NullInterwikiLookup.php [new file with mode: 0644]

index 7bbffc3..1adc5e4 100644 (file)
@@ -897,6 +897,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 f5fd3f2..05da0db 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 ) {
+       }
+}