Remove use of Revision::newFromTitle

Bug: T249183
Change-Id: Ibfcb8d7e56f559f3fb5179bac4dfeade8da22533
This commit is contained in:
DannyS712 2020-04-02 00:38:28 +00:00
parent f7e1b0e282
commit 3f00fbb5aa
2 changed files with 22 additions and 7 deletions

View file

@ -2,6 +2,8 @@
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionLookup;
use MediaWiki\Revision\SlotRecord;
use Wikimedia\Rdbms\Database;
/**
@ -21,8 +23,15 @@ class GadgetDefinitionNamespaceRepo extends GadgetRepo {
*/
private $wanCache;
/**
* @var RevisionLookup
*/
private $revLookup;
public function __construct() {
$this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$services = MediaWikiServices::getInstance();
$this->wanCache = $services->getMainWANObjectCache();
$this->revLookup = $services->getRevisionLookup();
}
/**
@ -109,13 +118,13 @@ class GadgetDefinitionNamespaceRepo extends GadgetRepo {
return null;
}
$rev = Revision::newFromTitle( $title );
if ( !$rev ) {
$revRecord = $this->revLookup->getRevisionByTitle( $title );
if ( !$revRecord ) {
$ttl = WANObjectCache::TTL_UNCACHEABLE;
return null;
}
$content = $rev->getContent();
$content = $revRecord->getContent( SlotRecord::MAIN );
if ( !$content instanceof GadgetDefinitionContent ) {
// Uhm...
$ttl = WANObjectCache::TTL_UNCACHEABLE;

View file

@ -2,6 +2,7 @@
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\SlotRecord;
use Wikimedia\Rdbms\Database;
/**
@ -136,12 +137,17 @@ class MediaWikiGadgetsDefinitionRepo extends GadgetRepo {
if ( $forceNewText === null ) {
// T157210: avoid using wfMessage() to avoid staleness due to cache layering
$title = Title::makeTitle( NS_MEDIAWIKI, 'Gadgets-definition' );
$rev = Revision::newFromTitle( $title );
if ( !$rev || !$rev->getContent() || $rev->getContent()->isEmpty() ) {
$revRecord = MediaWikiServices::getInstance()
->getRevisionLookup()
->getRevisionByTitle( $title );
if ( !$revRecord
|| !$revRecord->getContent( SlotRecord::MAIN )
|| $revRecord->getContent( SlotRecord::MAIN )->isEmpty()
) {
return false; // don't cache
}
$g = $rev->getContent()->getNativeData();
$g = $revRecord->getContent( SlotRecord::MAIN )->getNativeData();
} else {
$g = $forceNewText;
}