http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100475

Revision: 100475
Author:   aaron
Date:     2011-10-21 23:20:52 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
Revision objects now always use the current name of users, loading it on demand 
if necessary (e.g. when given a $row with no user_name but rev_user is not 0)

Modified Paths:
--------------
    trunk/phase3/includes/Revision.php
    trunk/phase3/includes/User.php

Modified: trunk/phase3/includes/Revision.php
===================================================================
--- trunk/phase3/includes/Revision.php  2011-10-21 23:17:16 UTC (rev 100474)
+++ trunk/phase3/includes/Revision.php  2011-10-21 23:20:52 UTC (rev 100475)
@@ -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;
@@ -348,7 +364,7 @@
                        $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,13 +392,14 @@
                                $this->mTextRow = null;
                        }
 
-                       // Use user_name for users and rev_user_text for IPs.
-                       // Also fallback to rev_user_text if user_name not 
given.
-                       if ( isset( $row->user_name ) ) {
-                               $this->mUserText = $row->user_name; // 
logged-in user (ideally)
-                       } else {
-                               $this->mUserText = $row->rev_user_text; // IP 
user (ideally)
+                       // 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;
@@ -542,7 +559,7 @@
                } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( 
self::DELETED_USER, $user ) ) {
                        return '';
                } else {
-                       return $this->mUserText;
+                       return $this->getRawUserText();
                }
        }
 
@@ -552,6 +569,14 @@
         * @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;
        }
 

Modified: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php      2011-10-21 23:17:16 UTC (rev 100474)
+++ trunk/phase3/includes/User.php      2011-10-21 23:20:52 UTC (rev 100475)
@@ -448,9 +448,9 @@
        /**
         * Get the username corresponding to a given user ID
         * @param $id Int User ID
-        * @return String The corresponding username
+        * @return String|false The corresponding username
         */
-       static function whoIs( $id ) {
+       public static function whoIs( $id ) {
                $dbr = wfGetDB( DB_SLAVE );
                return $dbr->selectField( 'user', 'user_name', array( 'user_id' 
=> $id ), __METHOD__ );
        }
@@ -459,7 +459,7 @@
         * Get the real name of a user given their user ID
         *
         * @param $id Int User ID
-        * @return String The corresponding user's real name
+        * @return String|false The corresponding user's real name
         */
        public static function whoIsReal( $id ) {
                $dbr = wfGetDB( DB_SLAVE );


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to