From ba03c0139a0e67c87fb635e1a9f09b060e69cc8b Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 30 Apr 2015 14:55:23 -0400 Subject: [PATCH] Support Title::GAID_FOR_UPDATE for Title->exists Without this, you have to call: getArticleID( Title::GAID_FOR_UPDATE ) then either use that directly (bypassing the TitleExists hook) or call exists afterwards. Change-Id: Ieec5579e4de2a289795364e7001028932535e435 --- includes/Title.php | 6 ++++-- tests/phpunit/includes/TitleTest.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index fe989b5f55..509fc27d69 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4235,10 +4235,12 @@ class Title { * If you want to know if a title can be meaningfully viewed, you should * probably call the isKnown() method instead. * + * @param int $flags An optional bit field; may be Title::GAID_FOR_UPDATE to check + * from master/for update * @return bool */ - public function exists() { - $exists = $this->getArticleID() != 0; + public function exists( $flags = 0 ) { + $exists = $this->getArticleID( $flags ) != 0; Hooks::run( 'TitleExists', array( $this, &$exists ) ); return $exists; } diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 74a741ad40..a8cffd1083 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -638,4 +638,26 @@ class TitleTest extends MediaWikiTestCase { $title = Title::makeTitle( NS_MAIN, 'Interwiki link', '', 'externalwiki' ); $this->assertTrue( $title->isAlwaysKnown() ); } + + /** + * @covers Title::exists + */ + public function testExists() { + $title = Title::makeTitle( NS_PROJECT, 'New page' ); + $linkCache = LinkCache::singleton(); + + $article = new Article( $title ); + $page = $article->getPage(); + $page->doEditContent( new WikitextContent( 'Some [[link]]' ), 'summary' ); + + // Tell Title it doesn't know whether it exists + $title->mArticleID = -1; + + // Tell the link cache it doesn't exists when it really does + $linkCache->clearLink( $title ); + $linkCache->addBadLinkObj( $title ); + + $this->assertEquals( false, $title->exists(), 'exists() should rely on link cache unless GAID_FOR_UPDATE is used' ); + $this->assertEquals( true, $title->exists( Title::GAID_FOR_UPDATE ), 'exists() should re-query database when GAID_FOR_UPDATE is used' ); + } } -- 2.20.1