Page MenuHomePhabricator

RevisionStore::getRevisionByTitle can fail for foreign wikis when called with TitleValue
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:
Use RevisionStore::getRevisionByTitle to attempt to obtain a RevisionRecord for a foreign wiki, for a title that exists both on the local and the foreign wiki, like so:

$revisionStoreFactory = MediaWiki\MediaWikiServices::getInstance()->getRevisionStoreFactory();
$foreignRevisionStore = $revisionStoreFactory->getRevisionStore( 'some_foreign_db_name' );

$title = new TitleValue( NS_MAIN, 'Main_Page' );
$revision = $foreignRevisionStore->getRevisionByTitle( $title );

Actual Results:
InvalidArgumentException with message: "The given Title (Main Page) does not belong to page ID XXX but actually belongs to YYY.", where XXX is the page ID of the title on the local wiki and YYY is the page ID of the title on the foreign wiki.

Expected Results:
A revision instance should be correctly returned for the foreign wiki.

Event Timeline

This looks to be caused by rMWaed6be4, which changed RevisionStore::getRevisionByTitle to convert the passed LinkTarget to a Title using Title::newFromLinkTarget, to resolve T206498. Unfortunately, this breaks when the given RevisionStore is operating in the context of a foreign wiki. In this scenario, when RevisionStoreRecord::__construct calls Title::getArticleID on the Title instance to perform a sanity check of the page ID against the page ID reference stored in the revision table for the given revision record, then Title::getArticleID will lazily fetch the page ID on the local, rather than the foreign wiki. This results in the aforementioned InvalidArgumentException being thrown.

The easiest fix I see would be to change RevisionStore::getRevisionByTitle such that it would only create a Title object when operating in the context of the local wiki, similar to how RevisionStore::getTitle and friends do it already. For foreign wikis, we can just pass null downstream and a Title object will be fetched from the foreign wiki DB for us. This still isn't optimal, given how dependent Title is on global state, but it should get rid of the exception.

Change 584158 had a related patch set uploaded (by TK-999; owner: TK-999):
[mediawiki/core@master] Ensure RevisionStore::getRevisionByTitle works for foreign wikis

https://gerrit.wikimedia.org/r/584158

Change 584158 merged by jenkins-bot:
[mediawiki/core@master] Revision: Ensure getRevisionByTitle() works for foreign wikis

https://gerrit.wikimedia.org/r/584158

CCicalese_WMF subscribed.

Untagging, since there is nothing to review right now. Feel free to re-tag if there's a new patch.

TK-999 claimed this task.

This should be resolved now, thanks!