Merge "Don't use isset() to check for null"
[lhc/web/wiklou.git] / includes / Revision.php
index 7b30540..de69827 100644 (file)
@@ -41,6 +41,11 @@ class Revision implements IDBAccessObject {
        protected $mParentId;
        protected $mComment;
        protected $mText;
+       protected $mTextId;
+
+       /**
+        * @var stdClass|null
+        */
        protected $mTextRow;
 
        /**
@@ -134,8 +139,8 @@ class Revision implements IDBAccessObject {
         *      Revision::READ_LATEST  : Select the data from the master (since 1.20)
         *      Revision::READ_LOCKING : Select & lock the data from the master
         *
-        * @param int $revId
-        * @param int $pageId (optional)
+        * @param int $pageId
+        * @param int $revId (optional)
         * @param int $flags Bitfield (optional)
         * @return Revision|null
         */
@@ -299,7 +304,7 @@ 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 ( is_null( $rev ) && wfGetLB()->getServerCount() > 1 ) {
+               if ( $rev === null && wfGetLB()->getServerCount() > 1 ) {
                        if ( !( $flags & self::READ_LATEST ) ) {
                                $dbw = wfGetDB( DB_MASTER );
                                $rev = self::loadFromConds( $dbw, $conditions, $flags );
@@ -444,6 +449,7 @@ class Revision implements IDBAccessObject {
                        'ar_id',
                        'ar_page_id',
                        'ar_rev_id',
+                       'ar_text',
                        'ar_text_id',
                        'ar_timestamp',
                        'ar_comment',
@@ -524,7 +530,7 @@ class Revision implements IDBAccessObject {
        /**
         * Constructor
         *
-        * @param object $row Either a database row or an array
+        * @param object|array $row Either a database row or an array
         * @throws MWException
         * @access private
         */
@@ -565,13 +571,13 @@ class Revision implements IDBAccessObject {
                                $this->mTitle = null;
                        }
 
-                       if ( !isset( $row->rev_content_model ) || is_null( $row->rev_content_model ) ) {
+                       if ( !isset( $row->rev_content_model ) ) {
                                $this->mContentModel = null; # determine on demand if needed
                        } else {
                                $this->mContentModel = strval( $row->rev_content_model );
                        }
 
-                       if ( !isset( $row->rev_content_format ) || is_null( $row->rev_content_format ) ) {
+                       if ( !isset( $row->rev_content_format ) ) {
                                $this->mContentFormat = null; # determine on demand if needed
                        } else {
                                $this->mContentFormat = strval( $row->rev_content_format );
@@ -651,7 +657,7 @@ class Revision implements IDBAccessObject {
                                $this->mContentHandler = null;
 
                                $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() );
-                       } elseif ( !is_null( $this->mText ) ) {
+                       } elseif ( $this->mText !== null ) {
                                $handler = $this->getContentHandler();
                                $this->mContent = $handler->unserializeContent( $this->mText );
                        }
@@ -673,7 +679,7 @@ class Revision implements IDBAccessObject {
 
                        // If we still have no length, see it we have the text to figure it out
                        if ( !$this->mSize ) {
-                               if ( !is_null( $this->mContent ) ) {
+                               if ( $this->mContent !== null ) {
                                        $this->mSize = $this->mContent->getSize();
                                } else {
                                        #NOTE: this should never happen if we have either text or content object!
@@ -683,7 +689,7 @@ class Revision implements IDBAccessObject {
 
                        // Same for sha1
                        if ( $this->mSha1 === null ) {
-                               $this->mSha1 = is_null( $this->mText ) ? null : self::base36Sha1( $this->mText );
+                               $this->mSha1 = $this->mText === null ? null : self::base36Sha1( $this->mText );
                        }
 
                        // force lazy init
@@ -758,11 +764,11 @@ class Revision implements IDBAccessObject {
         * @return Title|null
         */
        public function getTitle() {
-               if ( isset( $this->mTitle ) ) {
+               if ( $this->mTitle !== null ) {
                        return $this->mTitle;
                }
                //rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
-               if ( !is_null( $this->mId ) ) {
+               if ( $this->mId !== null ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        $row = $dbr->selectRow(
                                array( 'page', 'revision' ),
@@ -775,7 +781,7 @@ class Revision implements IDBAccessObject {
                        }
                }
 
-               if ( !$this->mTitle && !is_null( $this->mPage ) && $this->mPage > 0 ) {
+               if ( !$this->mTitle && $this->mPage !== null && $this->mPage > 0 ) {
                        $this->mTitle = Title::newFromID( $this->mPage );
                }
 
@@ -1030,7 +1036,7 @@ class Revision implements IDBAccessObject {
         * @return string
         */
        public function getSerializedData() {
-               if ( is_null( $this->mText ) ) {
+               if ( $this->mText === null ) {
                        $this->mText = $this->loadText();
                }
 
@@ -1047,9 +1053,9 @@ class Revision implements IDBAccessObject {
         * @return Content|null The Revision's content, or null on failure.
         */
        protected function getContentInternal() {
-               if ( is_null( $this->mContent ) ) {
+               if ( $this->mContent === null ) {
                        // Revision is immutable. Load on demand:
-                       if ( is_null( $this->mText ) ) {
+                       if ( $this->mText === null ) {
                                $this->mText = $this->loadText();
                        }
 
@@ -1183,7 +1189,7 @@ class Revision implements IDBAccessObject {
         * @return int
         */
        private function getPreviousRevisionId( $db ) {
-               if ( is_null( $this->mPage ) ) {
+               if ( $this->mPage === null ) {
                        return 0;
                }
                # Use page_latest if ID is not given
@@ -1201,18 +1207,18 @@ class Revision implements IDBAccessObject {
        }
 
        /**
-         * Get revision text associated with an old or archive row
-         * $row is usually an object from wfFetchRow(), both the flags and the text
-         * field must be included.
-         *
-         * @param stdClass $row The text data
-         * @param string $prefix Table prefix (default 'old_')
-         * @param string|bool $wiki The name of the wiki to load the revision text from
-         *   (same as the the wiki $row was loaded from) or false to indicate the local
-         *   wiki (this is the default). Otherwise, it must be a symbolic wiki database
-         *   identifier as understood by the LoadBalancer class.
-         * @return string Text the text requested or false on failure
-         */
+        * Get revision text associated with an old or archive row
+        * $row is usually an object from wfFetchRow(), both the flags and the text
+        * field must be included.
+        *
+        * @param stdClass $row The text data
+        * @param string $prefix Table prefix (default 'old_')
+        * @param string|bool $wiki The name of the wiki to load the revision text from
+        *   (same as the the wiki $row was loaded from) or false to indicate the local
+        *   wiki (this is the default). Otherwise, it must be a symbolic wiki database
+        *   identifier as understood by the LoadBalancer class.
+        * @return string Text the text requested or false on failure
+        */
        public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
                wfProfileIn( __METHOD__ );
 
@@ -1354,7 +1360,7 @@ class Revision implements IDBAccessObject {
                }
 
                # Record the text (or external storage URL) to the text table
-               if ( !isset( $this->mTextId ) ) {
+               if ( $this->mTextId === null ) {
                        $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
                        $dbw->insert( 'text',
                                array(
@@ -1371,7 +1377,7 @@ class Revision implements IDBAccessObject {
                }
 
                # Record the edit in revisions
-               $rev_id = isset( $this->mId )
+               $rev_id = $this->mId !== null
                        ? $this->mId
                        : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
                $row = array(
@@ -1385,10 +1391,10 @@ class Revision implements IDBAccessObject {
                        'rev_timestamp'  => $dbw->timestamp( $this->mTimestamp ),
                        'rev_deleted'    => $this->mDeleted,
                        'rev_len'        => $this->mSize,
-                       'rev_parent_id'  => is_null( $this->mParentId )
+                       'rev_parent_id'  => $this->mParentId === null
                                ? $this->getPreviousRevisionId( $dbw )
                                : $this->mParentId,
-                       'rev_sha1'       => is_null( $this->mSha1 )
+                       'rev_sha1'       => $this->mSha1 === null
                                ? Revision::base36Sha1( $this->mText )
                                : $this->mSha1,
                );
@@ -1418,7 +1424,7 @@ class Revision implements IDBAccessObject {
 
                $dbw->insert( 'revision', $row, __METHOD__ );
 
-               $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId();
+               $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
 
                wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
 
@@ -1507,7 +1513,7 @@ class Revision implements IDBAccessObject {
                }
 
                // If we kept data for lazy extraction, use it now...
-               if ( isset( $this->mTextRow ) ) {
+               if ( $this->mTextRow !== null ) {
                        $row = $this->mTextRow;
                        $this->mTextRow = null;
                } else {
@@ -1566,9 +1572,10 @@ class Revision implements IDBAccessObject {
         * @param int $pageId: ID number of the page to read from
         * @param string $summary Revision's summary
         * @param bool $minor Whether the revision should be considered as minor
+        * @param User|null $user User object to use or null for $wgUser
         * @return Revision|null Revision or null on error
         */
-       public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
+       public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
                global $wgContentHandlerUseDB;
 
                wfProfileIn( __METHOD__ );
@@ -1591,8 +1598,15 @@ class Revision implements IDBAccessObject {
                        __METHOD__ );
 
                if ( $current ) {
+                       if ( !$user ) {
+                               global $wgUser;
+                               $user = $wgUser;
+                       }
+
                        $row = array(
                                'page'       => $pageId,
+                               'user_text'  => $user->getName(),
+                               'user'       => $user->getId(),
                                'comment'    => $summary,
                                'minor_edit' => $minor,
                                'text_id'    => $current->rev_text_id,
@@ -1723,6 +1737,7 @@ class Revision implements IDBAccessObject {
         * 50 revisions for the sake of performance.
         *
         * @since 1.20
+        * @deprecated since 1.24
         *
         * @param DatabaseBase|int $db The Database to perform the check on. May be given as a
         *        Database object or a database identifier usable with wfGetDB.