Add UserProfile::getGuestUserProfile()
authorMatthias Schmidt <gravatronics@live.com>
Sun, 27 Mar 2016 06:25:38 +0000 (08:25 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 27 Mar 2016 06:25:38 +0000 (08:25 +0200)
CHANGELOG.md
wcfsetup/install/files/lib/data/comment/StructuredComment.class.php
wcfsetup/install/files/lib/data/comment/ViewableComment.class.php
wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php
wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php
wcfsetup/install/files/lib/data/user/UserProfile.class.php
wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentResponseUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php

index ef86f01b0785c757e618c5bff478865b85c8b6ee..b05c294f9aedcaab6ae109b93913a1fe322ef769 100644 (file)
@@ -28,7 +28,8 @@
 * `wcf\system\event\listener\AbstractUserMergeListener` added.
 * Notice texts support `{$username}` and `{$email}` placeholders.
 * Notifications for comments in moderation.
-* Continuous numeration of edit history version in template.  
+* Continuous numeration of edit history version in template.
+* `\wcf\data\user\UserProfile::getGuestUserProfile()` added.
 
 #### New Traits
 
index 544b43a4a667e6e19b92b749225a434960edcd6d..a4fd6e32a04c8b67579efaf38f19aa35af66a7db 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\data\comment;
 use wcf\data\comment\response\StructuredCommentResponse;
-use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObjectDecorator;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
@@ -108,9 +107,7 @@ class StructuredComment extends DatabaseObjectDecorator implements \Countable, \
                                $this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
                        }
                        else {
-                               $this->userProfile = new UserProfile(new User(null, [
-                                       'username' => $this->username
-                               ]));
+                               $this->userProfile = UserProfile::getGuestUserProfile($this->username);
                        }
                }
                
index 34d749556be028ff854496018e0f50b18a3ab01b..6e611ed042f3ddf0f32b4d53135d405df4bc21fe 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\data\comment;
-use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObjectDecorator;
 use wcf\data\TLegacyUserPropertyAccess;
@@ -41,9 +40,7 @@ class ViewableComment extends DatabaseObjectDecorator {
                                $this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
                        }
                        else {
-                               $this->userProfile = new UserProfile(new User(null, [
-                                       'username' => $this->username
-                               ]));
+                               $this->userProfile = UserProfile::getGuestUserProfile($this->username);
                        }
                }
                
index b4eef2f3bbf4071ff287ff21649448de65ae03ca..dec2dccfcbb851169d728c554acaf0d08aad83a0 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\data\comment\response;
-use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObjectDecorator;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
@@ -59,9 +58,7 @@ class StructuredCommentResponse extends DatabaseObjectDecorator {
                                $this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
                        }
                        else {
-                               $this->userProfile = new UserProfile(new User(null, array(
-                                       'username' => $this->username
-                               )));
+                               $this->userProfile = UserProfile::getGuestUserProfile($this->username);
                        }
                }
                
index 507cabfaf30a26d88757ad7ddcbb9f9098bf9a98..18c4d34cccc27456a12b683166d9f98c0a61b142 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\data\comment\response;
-use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObjectDecorator;
 use wcf\data\TLegacyUserPropertyAccess;
@@ -41,9 +40,7 @@ class ViewableCommentResponse extends DatabaseObjectDecorator {
                                $this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
                        }
                        else {
-                               $this->userProfile = new UserProfile(new User(null, [
-                                       'username' => $this->username
-                               ]));
+                               $this->userProfile = UserProfile::getGuestUserProfile($this->username);
                        }
                }
                
index 68efae21489d5238ad8da30eaf79006f7822e1de..a0d07996e36475670c736b85f9133b60a89d7147 100644 (file)
@@ -791,4 +791,18 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider
                
                return '<a href="'.$link.'" class="userLink" data-user-id="'.$this->userID.'">'.StringUtil::encodeHtml($this->username).'</a>';
        }
+       
+       /**
+        * Returns an "empty" user profile object for a guest with the given username.
+        * 
+        * Such objects can also be used in situations where the relevant user has been deleted
+        * but their original username is still known.
+        * 
+        * @param       string          $username
+        * @return      UserProfile
+        * @since       2.2
+        */
+       public static function getGuestUserProfile($username) {
+               return new UserProfile(new User(null, ['username' => $username]));
+       }
 }
index 5c75ad2f44538e7fbe4852004eb4ba85e0c2e63b..eecac0d9c170accc70102b6267ea809fdc3d2855 100644 (file)
@@ -2,7 +2,6 @@
 namespace wcf\system\user\notification\event;
 use wcf\data\moderation\queue\ViewableModerationQueue;
 use wcf\data\object\type\ObjectTypeCache;
-use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\system\cache\runtime\CommentRuntimeCache;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
@@ -82,9 +81,7 @@ class ModerationQueueCommentResponseUserNotificationEvent extends AbstractShared
                        $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
                }
                else {
-                       $commentAuthor = new UserProfile(new User(null, [
-                               'username' => $comment->username
-                       ]));
+                       $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
                }
                
                return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [
@@ -134,9 +131,7 @@ class ModerationQueueCommentResponseUserNotificationEvent extends AbstractShared
                        $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
                }
                else {
-                       $commentAuthor = new UserProfile(new User(null, [
-                               'username' => $comment->username
-                       ]));
+                       $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
                }
                
                return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
index da1c68cfeeed6a852dc4383d5832886a7cdf952f..3d710690db6472d8487040e0ec92e86862359362 100644 (file)
@@ -56,9 +56,7 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare
                        $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
                }
                else {
-                       $commentAuthor = new UserProfile(new User(null, [
-                               'username' => $comment->username
-                       ]));
+                       $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
                }
                
                $authors = $this->getAuthors();