X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderWikiModule.php;h=d37c31b1f54eb7c2c19755210d5316ffebe957b1;hb=b950c0e8eaaa35ce4bf9f1dc0f73964e469f80b1;hp=a91537fb321b6380fe06316143782e44275add61;hpb=e9a27a78e455de664144d0c3cfc789bcc411fab2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index a91537fb32..d37c31b1f5 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -82,7 +82,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { * getPages. */ public function __construct( array $options = null ) { - if ( is_null( $options ) ) { + if ( $options === null ) { return; } @@ -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 ); @@ -433,7 +432,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { // Avoid including ids or timestamps of revision/page tables so // that versions are not wasted $title = new TitleValue( (int)$row->page_namespace, $row->page_title ); - $titleInfo[ self::makeTitleKey( $title ) ] = [ + $titleInfo[self::makeTitleKey( $title )] = [ 'page_len' => $row->page_len, 'page_latest' => $row->page_latest, 'page_touched' => $row->page_touched, @@ -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 ); } @@ -485,7 +484,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $allInfo = $cache->getWithSetCallback( - $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID(), $hash ), + $cache->makeGlobalKey( 'resourceloader-titleinfo', $db->getDomainID(), $hash ), $cache::TTL_HOUR, function ( $curVal, &$ttl, array &$setOpts ) use ( $func, $pageNames, $db, $fname ) { $setOpts += Database::getCacheSetOptions( $db ); @@ -494,7 +493,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { }, [ 'checkKeys' => [ - $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID() ) ] + $cache->makeGlobalKey( 'resourceloader-titleinfo', $db->getDomainID() ) ] ] ); @@ -551,7 +550,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { if ( $purge ) { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); - $key = $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $domain ); + $key = $cache->makeGlobalKey( 'resourceloader-titleinfo', $domain ); $cache->touchCheckKey( $key ); } }