From 472d3f4cb40edf4a7e743315aa2e59fa121f6016 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 17 Apr 2019 16:23:43 +0100 Subject: [PATCH] resourceloader: Remove unused logic for WikiModule::getDB() as null This was intended at some point for GlobalCssJs but ended up being implemented differently once we realised that not having any information about the remote wiki was unacceptable. The local placeholder that points to metawiki (in case of GlobalCssJs) must still at the very least be able to query version information so that it gets a new version hash after changes etc. to ensure cache rolls over. This is being removed in preparation for refactoring where compatibility with this broken model is no longer kept. Change-Id: I4f1a06ace881daf1a5f202bdba0075460804de57 --- .../ResourceLoaderWikiModule.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index 276d9a1fd8..4c11fce0b1 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -144,15 +144,18 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { } /** - * Get the Database object used in getTitleInfo(). + * Get the Database handle used for computing the module version. * - * Defaults to the local replica DB. Subclasses may want to override this to return a foreign - * database object, or null if getTitleInfo() shouldn't access the database. + * Subclasses may override this to return a foreign database, which would + * allow them to register a module on wiki A that fetches wiki pages from + * wiki B. * - * NOTE: This ONLY works for getTitleInfo() and isKnownEmpty(), NOT FOR ANYTHING ELSE. - * In particular, it doesn't work for getContent() or getScript() etc. + * The way this works is that the local module is a placeholder that can + * only computer a module version hash. The 'source' of the module must + * be set to the foreign wiki directly. Methods getScript() and getContent() + * will not use this handle and are not valid on the local wiki. * - * @return IDatabase|null + * @return IDatabase */ protected function getDB() { return wfGetDB( DB_REPLICA ); @@ -379,10 +382,6 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { */ protected function getTitleInfo( ResourceLoaderContext $context ) { $dbr = $this->getDB(); - if ( !$dbr ) { - // We're dealing with a subclass that doesn't have a DB - return []; - } $pageNames = array_keys( $this->getPages( $context ) ); sort( $pageNames ); @@ -462,8 +461,8 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { $module = $rl->getModule( $name ); if ( $module instanceof self ) { $mDB = $module->getDB(); - // Subclasses may disable getDB and implement getTitleInfo differently - if ( $mDB && $mDB->getDomainID() === $db->getDomainID() ) { + // Subclasses may implement getDB differently + if ( $mDB->getDomainID() === $db->getDomainID() ) { $wikiModules[] = $module; $allPages += $module->getPages( $context ); } -- 2.20.1