Merge "Clean up $wgSQLiteDataDir handling and removed standalone sqlite class"
[lhc/web/wiklou.git] / includes / Revision.php
index 28a825d..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;
                }
@@ -515,7 +511,6 @@ class Revision implements IDBAccessObject {
                if ( !$revIds ) {
                        return $revLens; // empty
                }
-               wfProfileIn( __METHOD__ );
                $res = $db->select( 'revision',
                        array( 'rev_id', 'rev_len' ),
                        array( 'rev_id' => $revIds ),
@@ -523,7 +518,6 @@ class Revision implements IDBAccessObject {
                foreach ( $res as $row ) {
                        $revLens[$row->rev_id] = $row->rev_len;
                }
-               wfProfileOut( __METHOD__ );
                return $revLens;
        }
 
@@ -678,13 +672,8 @@ class Revision implements IDBAccessObject {
                        $this->mCurrent = false;
 
                        // If we still have no length, see it we have the text to figure it out
-                       if ( !$this->mSize ) {
-                               if ( $this->mContent !== null ) {
-                                       $this->mSize = $this->mContent->getSize();
-                               } else {
-                                       #NOTE: this should never happen if we have either text or content object!
-                                       $this->mSize = null;
-                               }
+                       if ( !$this->mSize && $this->mContent !== null ) {
+                               $this->mSize = $this->mContent->getSize();
                        }
 
                        // Same for sha1
@@ -833,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 );
        }
 
        /**
@@ -857,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;
                }
        }
 
@@ -865,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 );
        }
 
        /**
@@ -905,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 );
        }
 
        /**
@@ -943,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()
                        ),
@@ -1065,8 +1060,6 @@ class Revision implements IDBAccessObject {
                                $format = $this->getContentFormat();
 
                                $this->mContent = $handler->unserializeContent( $this->mText, $format );
-                       } else {
-                               $this->mContent = false; // negative caching!
                        }
                }
 
@@ -1220,7 +1213,6 @@ class Revision implements IDBAccessObject {
         * @return string Text the text requested or false on failure
         */
        public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
-               wfProfileIn( __METHOD__ );
 
                # Get data
                $textField = $prefix . 'text';
@@ -1235,7 +1227,6 @@ class Revision implements IDBAccessObject {
                if ( isset( $row->$textField ) ) {
                        $text = $row->$textField;
                } else {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -1244,7 +1235,6 @@ class Revision implements IDBAccessObject {
                        $url = $text;
                        $parts = explode( '://', $url, 2 );
                        if ( count( $parts ) == 1 || $parts[1] == '' ) {
-                               wfProfileOut( __METHOD__ );
                                return false;
                        }
                        $text = ExternalStore::fetchFromURL( $url, array( 'wiki' => $wiki ) );
@@ -1254,7 +1244,6 @@ class Revision implements IDBAccessObject {
                if ( $text !== false ) {
                        $text = self::decompressRevisionText( $text, $flags );
                }
-               wfProfileOut( __METHOD__ );
                return $text;
        }
 
@@ -1338,8 +1327,6 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
-               wfProfileIn( __METHOD__ );
-
                $this->checkContentModel();
 
                $data = $this->mText;
@@ -1350,7 +1337,6 @@ class Revision implements IDBAccessObject {
                        // Store and get the URL
                        $data = ExternalStore::insertToDefault( $data );
                        if ( !$data ) {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Unable to store text to external storage" );
                        }
                        if ( $flags ) {
@@ -1410,7 +1396,6 @@ class Revision implements IDBAccessObject {
                        $title = $this->getTitle();
 
                        if ( $title === null ) {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Insufficient information to determine the title of the "
                                        . "revision's page!" );
                        }
@@ -1426,9 +1411,8 @@ class Revision implements IDBAccessObject {
 
                $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
 
-               wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
+               Hooks::run( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
 
-               wfProfileOut( __METHOD__ );
                return $this->mId;
        }
 
@@ -1497,7 +1481,6 @@ class Revision implements IDBAccessObject {
         * @return string|bool The revision's text, or false on failure
         */
        protected function loadText() {
-               wfProfileIn( __METHOD__ );
 
                // Caching may be beneficial for massive use of external storage
                global $wgRevisionCacheExpiry, $wgMemc;
@@ -1507,7 +1490,6 @@ class Revision implements IDBAccessObject {
                        $text = $wgMemc->get( $key );
                        if ( is_string( $text ) ) {
                                wfDebug( __METHOD__ . ": got id $textId from cache\n" );
-                               wfProfileOut( __METHOD__ );
                                return $text;
                        }
                }
@@ -1555,8 +1537,6 @@ class Revision implements IDBAccessObject {
                        $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $text;
        }
 
@@ -1578,8 +1558,6 @@ class Revision implements IDBAccessObject {
        public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
                global $wgContentHandlerUseDB;
 
-               wfProfileIn( __METHOD__ );
-
                $fields = array( 'page_latest', 'page_namespace', 'page_title',
                                                'rev_text_id', 'rev_len', 'rev_sha1' );
 
@@ -1626,7 +1604,6 @@ class Revision implements IDBAccessObject {
                        $revision = null;
                }
 
-               wfProfileOut( __METHOD__ );
                return $revision;
        }
 
@@ -1697,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;
        }
 
        /**