jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: fetch usernames directly in RevisionFormatter
......................................................................


Hygiene: fetch usernames directly in RevisionFormatter

We have already checked the permissions of the revision at
this point and know the user can see the username, so just
fetch it directly instead of going through Templating.

Getting closer to being able to remove the templating class :)

Change-Id: I7a027f65c7d96e2467a266c798dc41f7efe66d39
---
M includes/Formatter/RevisionFormatter.php
M includes/Repository/UserNameBatch.php
M includes/Templating.php
3 files changed, 18 insertions(+), 94 deletions(-)

Approvals:
  Matthias Mullie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Formatter/RevisionFormatter.php 
b/includes/Formatter/RevisionFormatter.php
index 22cea4c..7d55a2f 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -796,13 +796,13 @@
                switch ( $param ) {
                case 'creator-text':
                        if ( $revision instanceof PostRevision ) {
-                               return $this->templating->getCreatorText( 
$revision );
+                               return $this->usernames->getFromTuple( 
$revision->getCreatorTuple() );
                        } else {
                                return '';
                        }
 
                case 'user-text':
-                       return $this->templating->getUserText( $revision );
+                       return $this->usernames->getFromTuple( 
$revision->getUserTuple() );
 
                case 'user-links':
                        return Message::rawParam( 
$this->templating->getUserLinks( $revision ) );
diff --git a/includes/Repository/UserNameBatch.php 
b/includes/Repository/UserNameBatch.php
index bb7d13c..72a0448 100644
--- a/includes/Repository/UserNameBatch.php
+++ b/includes/Repository/UserNameBatch.php
@@ -5,6 +5,7 @@
  */
 namespace Flow\Repository;
 
+use Flow\Model\UserTuple;
 use User;
 
 /**
@@ -52,6 +53,13 @@
        }
 
        /**
+        * @param UserTuple $tuple
+        */
+       public function addFromTuple( UserTuple $tuple ) {
+               $this->add( $tuple->wiki, $tuple->id, $tuple->ip );
+       }
+
+       /**
         * Get the displayable username
         *
         * @param string $wiki
@@ -74,6 +82,14 @@
        }
 
        /**
+        * @param UserTuple $tuple
+        * @return string|boolean false if username is not found or display is 
suppressed
+        */
+       public function getFromTuple( UserTuple $tuple ) {
+               return $this->get( $tuple->wiki, $tuple->id, $tuple->ip );
+       }
+
+       /**
         * Resolve all queued user ids to usernames for the given wiki
         *
         * @param string $wiki
diff --git a/includes/Templating.php b/includes/Templating.php
index 9c85032..bcdb7fe 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -75,58 +75,6 @@
                return $this->urlGenerator;
        }
 
-       public function userToolLinks( $userId, $userText ) {
-               static $cache = array();
-               if ( isset( $cache[$userId][$userText] ) ) {
-                       return $cache[$userId][$userText];
-               }
-
-               if ( $userText instanceof Message ) {
-                       // username was moderated away, we dont know who this is
-                       $res = '';
-               } else {
-                       $res = Linker::userLink( $userId, $userText ) . 
Linker::userToolLinks( $userId, $userText );
-               }
-               return $cache[$userId][$userText] = $res;
-       }
-
-       /**
-        * Formats a revision's usertext for displaying. Usually, the revision's
-        * usertext can just be displayed. In the event of moderation, however, 
that
-        * info should not be exposed.
-        *
-        * If a specific i18n message is available for a certain moderation 
level,
-        * that message will be returned (well, unless the user actually has the
-        * required permissions to view the full username). Otherwise, in normal
-        * cases, the full username will be returned.
-        *
-        * @param AbstractRevision $revision Revision to display usertext for
-        * @return string
-        */
-       public function getUserText( AbstractRevision $revision ) {
-               // if this specific revision is moderated, its usertext can 
always be
-               // displayed, since it will be the moderator user
-               if ( $revision->isModerated() || $this->permissions->isAllowed( 
$revision, 'view' ) ) {
-                       return $this->usernames->get( wfWikiId(), 
$revision->getUserId(), $revision->getUserIp() ) ?: '';
-               } else {
-                       $revision = $this->getModeratedRevision( $revision );
-                       $username = $this->usernames->get(
-                               wfWikiId(),
-                               $revision->getModeratedByUserId(),
-                               $revision->getModeratedByUserIp()
-                       );
-                       $state = $revision->getModerationState();
-                       // Messages: flow-hide-usertext, flow-delete-usertext, 
flow-suppress-usertext
-                       $message = wfMessage( "flow-$state-usertext", $username 
);
-                       if ( $message->exists() ) {
-                               return $message->text();
-                       } else {
-                               wfWarn( __METHOD__ . ': Failed to locate 
message for moderated content: ' . $message->getKey() );
-                               return wfMessage( 'flow-error-other' )->text();
-                       }
-               }
-       }
-
        /**
         * Returns pretty-printed user links + user tool links for history and
         * RecentChanges pages.
@@ -152,46 +100,6 @@
                }
                $username = $this->usernames->get( wfWikiId(), $userid, $userip 
);
                return $cache[$userid][$userip] = Linker::userLink( $userid, 
$username ) . Linker::userToolLinks( $userid, $username );
-       }
-
-       /**
-        * Formats a post's creator name for displaying. Usually, the post's 
creator
-        * name can just be displayed. In the event of moderation, however, that
-        * info should not be exposed.
-        *
-        * If a specific i18n message is available for a certain moderation 
level,
-        * that message will be returned (well, unless the user actually has the
-        * required permissions to view the full username). Otherwise, in normal
-        * cases, the full creator name will be returned.
-        *
-        * @param PostRevision $revision Revision to display creator name for
-        * @return string
-        */
-       public function getCreatorText( PostRevision $revision ) {
-               if ( $this->permissions->isAllowed( $revision, 'view' ) ) {
-                       return $this->usernames->get(
-                               wfWikiId(),
-                               $revision->getCreatorId(),
-                               $revision->getCreatorIp()
-                       ) ?: '';
-               } else {
-                       $revision = $this->getModeratedRevision( $revision );
-                       $state = $revision->getModerationState();
-                       $username = $this->usernames->get(
-                               wfWikiId(),
-                               $revision->getModeratedByUserId(),
-                               $revision->getModeratedByUserIp()
-                       );
-                       // Messages: flow-hide-usertext, flow-delete-usertext, 
flow-suppress-usertext
-                       $message = wfMessage( "flow-$state-usertext", $username 
);
-
-                       if ( $message->exists() ) {
-                               return $message->text();
-                       } else {
-                               wfWarn( __METHOD__ . ': Failed to locate 
message for moderated content: ' . $message->getKey() );
-                               return wfMessage( 'flow-error-other' )->text();
-                       }
-               }
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/190392
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7a027f65c7d96e2467a266c798dc41f7efe66d39
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: SG <shah...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to