From 49aa4d3f9c48bced2e7293925786479a99b56b33 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 7 Jun 2018 01:01:13 -0700 Subject: [PATCH] installer: Fix display of UPGRADE by disabling InterwikiLookup 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 | 1 + includes/installer/Installer.php | 14 ++++-- includes/interwiki/NullInterwikiLookup.php | 57 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 includes/interwiki/NullInterwikiLookup.php diff --git a/autoload.php b/autoload.php index 0e1b30fe0f..b306bf5aac 100644 --- a/autoload.php +++ b/autoload.php @@ -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', diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 4b6e8ccd48..abf4de4f69 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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 index 0000000000..09fa1ecd22 --- /dev/null +++ b/includes/interwiki/NullInterwikiLookup.php @@ -0,0 +1,57 @@ + + * + * 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 ) { + } +} -- 2.20.1