http://www.mediawiki.org/wiki/Special:Code/MediaWiki/74034
Revision: 74034
Author: demon
Date: 2010-09-30 19:13:25 +0000 (Thu, 30 Sep 2010)
Log Message:
-----------
Refactor GAID_FOR_UPDATE into Title::GAID_FOR_UPDATE. Yay less file-scope code
(extensions will follow)
Modified Paths:
--------------
trunk/phase3/includes/Article.php
trunk/phase3/includes/EditPage.php
trunk/phase3/includes/FileDeleteForm.php
trunk/phase3/includes/Title.php
trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
Modified: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php 2010-09-30 18:42:21 UTC (rev 74033)
+++ trunk/phase3/includes/Article.php 2010-09-30 19:13:25 UTC (rev 74034)
@@ -3111,7 +3111,7 @@
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 @@
$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;
Modified: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php 2010-09-30 18:42:21 UTC (rev 74033)
+++ trunk/phase3/includes/EditPage.php 2010-09-30 19:13:25 UTC (rev 74034)
@@ -869,7 +869,7 @@
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' ) ) {
Modified: trunk/phase3/includes/FileDeleteForm.php
===================================================================
--- trunk/phase3/includes/FileDeleteForm.php 2010-09-30 18:42:21 UTC (rev
74033)
+++ trunk/phase3/includes/FileDeleteForm.php 2010-09-30 19:13:25 UTC (rev
74034)
@@ -116,7 +116,7 @@
$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 );
Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php 2010-09-30 18:42:21 UTC (rev 74033)
+++ trunk/phase3/includes/Title.php 2010-09-30 19:13:25 UTC (rev 74034)
@@ -13,8 +13,6 @@
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,7 +34,13 @@
*/
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
* Please use the accessor functions instead.
@@ -193,11 +197,11 @@
* 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 @@
* 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 @@
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 @@
* 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 @@
* 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 @@
/**
* 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 @@
* 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 @@
* 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 @@
/**
* 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;
Modified: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
2010-09-30 18:42:21 UTC (rev 74033)
+++ trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
2010-09-30 19:13:25 UTC (rev 74034)
@@ -235,7 +235,7 @@
$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 @@
$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' );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs