X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FRevision.php;h=e2ca4814d7d602cfd482ca85337b961ebda77eb8;hb=d3efb28185e84383ee21f77871f592fbe72f4846;hp=c8015e62b6431dec9e210ed34042bd0966ffce45;hpb=53ebdc8a18e1252525c41a4c45df12e875ef887f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Revision.php b/includes/Revision.php index c8015e62b6..e2ca4814d7 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -121,7 +121,7 @@ class Revision implements IDBAccessObject { if ( $id ) { // Use the specified ID $conds['rev_id'] = $id; - return self::newFromConds( $conds, (int)$flags ); + return self::newFromConds( $conds, $flags ); } else { // Use a join to get the latest revision $conds[] = 'rev_id=page_latest'; @@ -148,11 +148,13 @@ class Revision implements IDBAccessObject { $conds = array( 'page_id' => $pageId ); if ( $revId ) { $conds['rev_id'] = $revId; + return self::newFromConds( $conds, $flags ); } else { // Use a join to get the latest revision $conds[] = 'rev_id = page_latest'; + $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE ); + return self::loadFromConds( $db, $conds, $flags ); } - return self::newFromConds( $conds, (int)$flags ); } /** @@ -304,12 +306,6 @@ class Revision implements IDBAccessObject { private static function newFromConds( $conditions, $flags = 0 ) { $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE ); $rev = self::loadFromConds( $db, $conditions, $flags ); - if ( $rev === null && wfGetLB()->getServerCount() > 1 ) { - if ( !( $flags & self::READ_LATEST ) ) { - $dbw = wfGetDB( DB_MASTER ); - $rev = self::loadFromConds( $dbw, $conditions, $flags ); - } - } if ( $rev ) { $rev->mQueryFlags = $flags; } @@ -826,9 +822,11 @@ class Revision implements IDBAccessObject { * Fetch revision's user id without regard for the current user's permissions * * @return string + * @deprecated since 1.25, use getUser( Revision::RAW ) */ public function getRawUser() { - return $this->mUser; + wfDeprecated( __METHOD__, '1.25' ); + return $this->getUser( self::RAW ); } /** @@ -850,7 +848,15 @@ class Revision implements IDBAccessObject { } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) { return ''; } else { - return $this->getRawUserText(); + if ( $this->mUserText === null ) { + $this->mUserText = User::whoIs( $this->mUser ); // load on demand + if ( $this->mUserText === false ) { + # This shouldn't happen, but it can if the wiki was recovered + # via importing revs and there is no user table entry yet. + $this->mUserText = $this->mOrigUserText; + } + } + return $this->mUserText; } } @@ -858,17 +864,11 @@ class Revision implements IDBAccessObject { * Fetch revision's username without regard for view restrictions * * @return string + * @deprecated since 1.25, use getUserText( Revision::RAW ) */ public function getRawUserText() { - if ( $this->mUserText === null ) { - $this->mUserText = User::whoIs( $this->mUser ); // load on demand - if ( $this->mUserText === false ) { - # This shouldn't happen, but it can if the wiki was recovered - # via importing revs and there is no user table entry yet. - $this->mUserText = $this->mOrigUserText; - } - } - return $this->mUserText; + wfDeprecated( __METHOD__, '1.25' ); + return $this->getUserText( self::RAW ); } /** @@ -898,9 +898,11 @@ class Revision implements IDBAccessObject { * Fetch revision comment without regard for the current user's permissions * * @return string + * @deprecated since 1.25, use getComment( Revision::RAW ) */ public function getRawComment() { - return $this->mComment; + wfDeprecated( __METHOD__, '1.25' ); + return $this->getComment( self::RAW ); } /** @@ -936,7 +938,7 @@ class Revision implements IDBAccessObject { $dbr = wfGetDB( DB_SLAVE ); return RecentChange::newFromConds( array( - 'rc_user_text' => $this->getRawUserText(), + 'rc_user_text' => $this->getUserText( Revision::RAW ), 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ), 'rc_this_oldid' => $this->getId() ), @@ -1672,23 +1674,21 @@ class Revision implements IDBAccessObject { * * @param Title $title * @param int $id - * @return string + * @return string|bool False if not found */ - static function getTimestampFromId( $title, $id ) { - $dbr = wfGetDB( DB_SLAVE ); + static function getTimestampFromId( $title, $id, $flags = 0 ) { + $db = ( $flags & self::READ_LATEST ) + ? wfGetDB( DB_MASTER ) + : wfGetDB( DB_SLAVE ); // Casting fix for databases that can't take '' for rev_id if ( $id == '' ) { $id = 0; } $conds = array( 'rev_id' => $id ); $conds['rev_page'] = $title->getArticleID(); - $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ ); - if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) { - # Not in slave, try master - $dbw = wfGetDB( DB_MASTER ); - $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ ); - } - return wfTimestamp( TS_MW, $timestamp ); + $timestamp = $db->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ ); + + return ( $timestamp !== false ) ? wfTimestamp( TS_MW, $timestamp ) : false; } /**