Merge "Clean up $wgSQLiteDataDir handling and removed standalone sqlite class"
[lhc/web/wiklou.git] / includes / Revision.php
index 6ec7eaf..e2ca481 100644 (file)
@@ -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()
                        ),
@@ -1325,7 +1327,6 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
-
                $this->checkContentModel();
 
                $data = $this->mText;
@@ -1536,7 +1537,6 @@ class Revision implements IDBAccessObject {
                        $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
                }
 
-
                return $text;
        }
 
@@ -1558,7 +1558,6 @@ class Revision implements IDBAccessObject {
        public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
                global $wgContentHandlerUseDB;
 
-
                $fields = array( 'page_latest', 'page_namespace', 'page_title',
                                                'rev_text_id', 'rev_len', 'rev_sha1' );
 
@@ -1675,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;
        }
 
        /**