Update Postgres with missing uploadstash tables
[lhc/web/wiklou.git] / includes / Revision.php
index 065d7f9..ec0508c 100644 (file)
@@ -4,6 +4,22 @@
  * @todo document
  */
 class Revision {
+       protected $mId;
+       protected $mPage;
+       protected $mUserText;
+       protected $mOrigUserText;
+       protected $mUser;
+       protected $mMinorEdit;
+       protected $mTimestamp;
+       protected $mDeleted;
+       protected $mSize;
+       protected $mParentId;
+       protected $mComment;
+       protected $mText;
+       protected $mTextRow;
+       protected $mTitle;
+       protected $mCurrent;
+
        const DELETED_TEXT = 1;
        const DELETED_COMMENT = 2;
        const DELETED_USER = 4;
@@ -305,7 +321,7 @@ class Revision {
         * Return the list of text fields that should be selected to read the
         * revision text
         */
-       static function selectTextFields() {
+       public static function selectTextFields() {
                return array(
                        'old_text',
                        'old_flags'
@@ -315,7 +331,7 @@ class Revision {
        /**
         * Return the list of page fields that should be selected from page table
         */
-       static function selectPageFields() {
+       public static function selectPageFields() {
                return array(
                        'page_namespace',
                        'page_title',
@@ -326,8 +342,8 @@ class Revision {
        /**
         * Return the list of user fields that should be selected from user table
         */
-       static function selectUserFields() {
-               return array( 'COALESCE(user_name,rev_user_text) AS rev_user_name' );
+       public static function selectUserFields() {
+               return array( 'user_name' );
        }
 
        /**
@@ -348,7 +364,7 @@ class Revision {
                        $this->mDeleted   = intval( $row->rev_deleted );
 
                        if( !isset( $row->rev_parent_id ) ) {
-                               $this->mParentId = is_null($row->rev_parent_id) ? null : 0;
+                               $this->mParentId = is_null( $row->rev_parent_id ) ? null : 0;
                        } else {
                                $this->mParentId  = intval( $row->rev_parent_id );
                        }
@@ -376,11 +392,14 @@ class Revision {
                                $this->mTextRow = null;
                        }
 
-                       if ( isset( $row->rev_user_name ) ) {
-                               $this->mUserText = $row->rev_user_name; // current user name
-                       } else { // fallback to rev_user_text
-                               $this->mUserText = $row->rev_user_text; // de-normalized
+                       // Use user_name for users and rev_user_text for IPs...
+                       $this->mUserText = null; // lazy load if left null
+                       if ( $this->mUser == 0 ) {
+                               $this->mUserText = $row->rev_user_text; // IP user
+                       } elseif ( isset( $row->user_name ) ) {
+                               $this->mUserText = $row->user_name; // logged-in user
                        }
+                       $this->mOrigUserText = $row->rev_user_text;
                } elseif( is_array( $row ) ) {
                        // Build a new revision to be saved...
                        global $wgUser;
@@ -540,7 +559,7 @@ class Revision {
                } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) {
                        return '';
                } else {
-                       return $this->mUserText;
+                       return $this->getRawUserText();
                }
        }
 
@@ -550,6 +569,14 @@ class Revision {
         * @return String
         */
        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;
        }