From cc6a650bf8d89f4ea823b504642466700e18d951 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 30 Sep 2010 19:13:25 +0000 Subject: [PATCH] Refactor GAID_FOR_UPDATE into Title::GAID_FOR_UPDATE. Yay less file-scope code (extensions will follow) --- includes/Article.php | 4 +-- includes/EditPage.php | 2 +- includes/FileDeleteForm.php | 2 +- includes/Title.php | 34 +++++++++++-------- .../phpunit/includes/UploadFromUrlTest.php | 4 +-- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 3c8f98734c..0fe0dc98de 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -3111,7 +3111,7 @@ class Article { public function doDelete( $reason, $suppress = false ) { global $wgOut, $wgUser; - $id = $this->mTitle->getArticleID( GAID_FOR_UPDATE ); + $id = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE ); $error = ''; if ( wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) { @@ -3171,7 +3171,7 @@ class Article { $dbw = wfGetDB( DB_MASTER ); $t = $this->mTitle->getDBkey(); - $id = $id ? $id : $this->mTitle->getArticleID( GAID_FOR_UPDATE ); + $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE ); if ( $t === '' || $id == 0 ) { return false; diff --git a/includes/EditPage.php b/includes/EditPage.php index 07fd9ad465..fac405f09e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -869,7 +869,7 @@ class EditPage { wfProfileOut( __METHOD__ . '-checks' ); # If article is new, insert it. - $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE ); + $aid = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE ); if ( 0 == $aid ) { // Late check for create permission, just in case *PARANOIA* if ( !$this->mTitle->userCan( 'create' ) ) { diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 0f25d04bdf..2dc8d0d00b 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -116,7 +116,7 @@ class FileDeleteForm { $log->addEntry( 'delete', $title, $logComment ); } } else { - $id = $title->getArticleID( GAID_FOR_UPDATE ); + $id = $title->getArticleID( Title::GAID_FOR_UPDATE ); $article = new Article( $title ); $error = ''; $dbw = wfGetDB( DB_MASTER ); diff --git a/includes/Title.php b/includes/Title.php index a3b471811b..4ba12d5fb9 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -13,8 +13,6 @@ if ( !class_exists( 'UtfNormal' ) ) { require_once( dirname( __FILE__ ) . '/normal/UtfNormal.php' ); } -define ( 'GAID_FOR_UPDATE', 1 ); - /** * Represents a title within MediaWiki. * Optionally may contain an interwiki designation or namespace. @@ -36,6 +34,12 @@ class Title { */ const CACHE_MAX = 1000; + /** + * Used to be GAID_FOR_UPDATE define. Used with getArticleId() and friends + * to use the master DB + */ + const GAID_FOR_UPDATE = 1; + /** * @name Private member variables @@ -193,11 +197,11 @@ class Title { * Create a new Title from an article ID * * @param $id \type{\int} the page_id corresponding to the Title to create - * @param $flags \type{\int} use GAID_FOR_UPDATE to use master + * @param $flags \type{\int} use Title::GAID_FOR_UPDATE to use master * @return \type{Title} the new object, or NULL on an error */ public static function newFromID( $id, $flags = 0 ) { - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ ); if ( $row !== false ) { $title = Title::newFromRow( $row ); @@ -2326,7 +2330,7 @@ class Title { * Get the article ID for this Title from the link cache, * adding it if necessary * - * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select + * @param $flags \type{\int} a bit field; may be Title::GAID_FOR_UPDATE to select * for update * @return \type{\int} the ID */ @@ -2335,7 +2339,7 @@ class Title { return $this->mArticleID = 0; } $linkCache = LinkCache::singleton(); - if ( $flags & GAID_FOR_UPDATE ) { + if ( $flags & self::GAID_FOR_UPDATE ) { $oldUpdate = $linkCache->forUpdate( true ); $linkCache->clearLink( $this ); $this->mArticleID = $linkCache->addLinkObj( $this ); @@ -2352,7 +2356,7 @@ class Title { * Is this an article that is a redirect page? * Uses link cache, adding it if necessary * - * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update + * @param $flags \type{\int} a bit field; may be Title::GAID_FOR_UPDATE to select for update * @return \type{\bool} */ public function isRedirect( $flags = 0 ) { @@ -2373,7 +2377,7 @@ class Title { * What is the length of this page? * Uses link cache, adding it if necessary * - * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update + * @param $flags \type{\int} a bit field; may be Title::GAID_FOR_UPDATE to select for update * @return \type{\bool} */ public function getLength( $flags = 0 ) { @@ -2393,7 +2397,7 @@ class Title { /** * What is the page_latest field for this page? * - * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update + * @param $flags \type{\int} a bit field; may be Title::GAID_FOR_UPDATE to select for update * @return \type{\int} or 0 if the page doesn't exist */ public function getLatestRevID( $flags = 0 ) { @@ -3610,11 +3614,11 @@ class Title { * Get the revision ID of the previous revision * * @param $revId \type{\int} Revision ID. Get the revision that was before this one. - * @param $flags \type{\int} GAID_FOR_UPDATE + * @param $flags \type{\int} Title::GAID_FOR_UPDATE * @return \twotypes{\int,\bool} Old revision ID, or FALSE if none exists */ public function getPreviousRevisionID( $revId, $flags = 0 ) { - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); return $db->selectField( 'revision', 'rev_id', array( 'rev_page' => $this->getArticleId( $flags ), @@ -3629,11 +3633,11 @@ class Title { * Get the revision ID of the next revision * * @param $revId \type{\int} Revision ID. Get the revision that was after this one. - * @param $flags \type{\int} GAID_FOR_UPDATE + * @param $flags \type{\int} Title::GAID_FOR_UPDATE * @return \twotypes{\int,\bool} Next revision ID, or FALSE if none exists */ public function getNextRevisionID( $revId, $flags = 0 ) { - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); return $db->selectField( 'revision', 'rev_id', array( 'rev_page' => $this->getArticleId( $flags ), @@ -3647,11 +3651,11 @@ class Title { /** * Get the first revision of the page * - * @param $flags \type{\int} GAID_FOR_UPDATE + * @param $flags \type{\int} Title::GAID_FOR_UPDATE * @return Revision (or NULL if page doesn't exist) */ public function getFirstRevision( $flags = 0 ) { - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); $pageId = $this->getArticleId( $flags ); if ( !$pageId ) { return null; diff --git a/maintenance/tests/phpunit/includes/UploadFromUrlTest.php b/maintenance/tests/phpunit/includes/UploadFromUrlTest.php index c636010345..bf99f38aa4 100644 --- a/maintenance/tests/phpunit/includes/UploadFromUrlTest.php +++ b/maintenance/tests/phpunit/includes/UploadFromUrlTest.php @@ -235,7 +235,7 @@ class UploadFromUrlTest extends ApiTestSetup { $a->doDeleteArticle( '' ); } - $this->assertFalse( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk does not exist' ); + $this->assertFalse( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk does not exist' ); $data = $this->doApiRequest( array( 'action' => 'upload', @@ -252,7 +252,7 @@ class UploadFromUrlTest extends ApiTestSetup { $job->run(); $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ); - $this->assertTrue( (bool)$talk->getArticleId( GAID_FOR_UPDATE ), 'User talk exists' ); + $this->assertTrue( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk exists' ); $this->deleteFile( 'UploadFromUrlTest.png' ); -- 2.20.1