X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderWikiModule.php;h=6eddfc0923517ef9a529d2a22b61e642bf05e0ea;hb=0b53a14377fcf275ad3e5a0f7ad9f7d5bcd85cab;hp=f6f14b37d48795a3244205da628a65c2cd47899a;hpb=1d3fee7c596245ce78ea71c7204c3b92581ad909;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index f6f14b37d4..6eddfc0923 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -22,6 +22,9 @@ * @author Roan Kattouw */ +use Wikimedia\Rdbms\Database; +use Wikimedia\Rdbms\IDatabase; + /** * Abstraction for ResourceLoader modules which pull from wiki pages * @@ -146,7 +149,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { protected function getContent( $titleText ) { $title = Title::newFromText( $titleText ); if ( !$title ) { - return null; + return null; // Bad title } // If the page is a redirect, follow the redirect. @@ -154,7 +157,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { $content = $this->getContentObj( $title ); $title = $content ? $content->getUltimateRedirectTarget() : null; if ( !$title ) { - return null; + return null; // Dead redirect } } @@ -164,12 +167,12 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { } elseif ( $handler->isSupportedFormat( CONTENT_FORMAT_JAVASCRIPT ) ) { $format = CONTENT_FORMAT_JAVASCRIPT; } else { - return null; + return null; // Bad content model } $content = $this->getContentObj( $title ); if ( !$content ) { - return null; + return null; // No content found } return $content->serialize( $format ); @@ -180,12 +183,10 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { * @return Content|null */ protected function getContentObj( Title $title ) { - $revision = Revision::newKnownCurrent( wfGetDB( DB_REPLICA ), $title->getArticleID(), - $title->getLatestRevID() ); + $revision = Revision::newKnownCurrent( wfGetDB( DB_REPLICA ), $title ); if ( !$revision ) { return null; } - $revision->setTitle( $title ); $content = $revision->getContent( Revision::RAW ); if ( !$content ) { wfDebugLog( 'resourceloader', __METHOD__ . ': failed to load content of JS/CSS page!' ); @@ -196,7 +197,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { /** * @param ResourceLoaderContext $context - * @return string + * @return string JavaScript code */ public function getScript( ResourceLoaderContext $context ) { $scripts = ''; @@ -370,7 +371,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { if ( $module instanceof self ) { $mDB = $module->getDB(); // Subclasses may disable getDB and implement getTitleInfo differently - if ( $mDB && $mDB->getWikiID() === $db->getWikiID() ) { + if ( $mDB && $mDB->getDomainID() === $db->getDomainID() ) { $wikiModules[] = $module; $allPages += $module->getPages( $context ); } @@ -392,14 +393,17 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { $cache = ObjectCache::getMainWANInstance(); $allInfo = $cache->getWithSetCallback( - $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID(), $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 ); return call_user_func( $func, $db, $pageNames, $fname ); }, - [ 'checkKeys' => [ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID() ) ] ] + [ + 'checkKeys' => [ + $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID() ) ] + ] ); foreach ( $wikiModules as $wikiModule ) {