Bsitu has submitted this change and it was merged.

Change subject: Display post creator
......................................................................


Display post creator

Display the user who origionally created a post in the post title.  On hover
of the username add links to their user page, talk page and contributions.

Change-Id: Id5af3e9b206fa81c22ebab51d36d7fa6c7ffa786
---
M includes/Model/AbstractRevision.php
M includes/Model/PostRevision.php
M includes/Model/UUID.php
M includes/Model/Workflow.php
M includes/ParsoidUtils.php
M includes/Templating.php
M modules/discussion/ui.js
M templates/post.html.php
M templates/topic.html.php
9 files changed, 70 insertions(+), 24 deletions(-)

Approvals:
  Bsitu: Verified; Looks good to me, approved



diff --git a/includes/Model/AbstractRevision.php 
b/includes/Model/AbstractRevision.php
index 92f1afa..7cfbd09 100644
--- a/includes/Model/AbstractRevision.php
+++ b/includes/Model/AbstractRevision.php
@@ -13,7 +13,7 @@
 
        const MODERATED_CENSORED = 'censor';
 
-       static private $perms = array(
+       static protected $perms = array(
                self::MODERATED_NONE => array(
                        'perm' => null,
                        'usertext' => null,
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index bd06b87..d450452 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -3,6 +3,7 @@
 namespace Flow\Model;
 
 use User;
+use MWTimestamp;
 
 class PostRevision extends AbstractRevision {
        protected $postId;
@@ -83,7 +84,21 @@
                return $this->origUserId;
        }
 
-       public function getCreatorName() {
+       public function getCreatorName( $user = null ) {
+               if ( $this->isAllowed( $user ) ) {
+                       return $this->getCreatorNameRaw();
+               } else {
+                       $moderatedAt = new MWTimestamp( 
$this->moderationTimestamp );
+
+                       return wfMessage(
+                               self::$perms[$this->moderationState]['content'],
+                               $this->moderatedByUserText,
+                               $moderatedAt->getHumanTimestamp()
+                       );
+               }
+       }
+
+       public function getCreatorNameRaw() {
                return $this->origUserText;
        }
 
diff --git a/includes/Model/UUID.php b/includes/Model/UUID.php
index 8a2d5b0..04f7ffe 100644
--- a/includes/Model/UUID.php
+++ b/includes/Model/UUID.php
@@ -78,6 +78,14 @@
                return $ts ? $ts->getTimestamp( TS_MW ) : false;
        }
 
+       public function getHumanTimestamp( $relativeTo = null, User $user = 
null, Language $lang = null ) {
+               if ( $relativeTo instanceof UUID ) {
+                       $relativeTo = $relativeTo->getTimestampObj() ?: null;
+               }
+               $ts = $this->getTimestampObj();
+               return $ts ? $ts->getHumanTimestamp( $relativeTo, $user, $lang 
) : false;
+       }
+
        public static function convertUUIDs( $array ) {
                foreach( ObjectManager::makeArray( $array ) as $key => $value ) 
{
                        if ( is_a( $value, 'Flow\Model\UUID' ) ) {
diff --git a/includes/Model/Workflow.php b/includes/Model/Workflow.php
index e6e9a9c..bc7194f 100644
--- a/includes/Model/Workflow.php
+++ b/includes/Model/Workflow.php
@@ -2,6 +2,7 @@
 
 namespace Flow\Model;
 
+use MWTimestamp;
 use SpecialPage;
 use Title;
 use User;
@@ -104,6 +105,7 @@
        public function getUserId() { return $this->userId; }
        public function getUserText() { return $this->userText; }
        public function getLastModified() { return $this->lastModified; }
+       public function getLastModifiedObj() { return new MWTimestamp( 
$this->lastModified ); }
 
        public function updateLastModified() {
                $this->lastModified = wfTimestampNow();
diff --git a/includes/ParsoidUtils.php b/includes/ParsoidUtils.php
index 2cca5fa..c507bb7 100644
--- a/includes/ParsoidUtils.php
+++ b/includes/ParsoidUtils.php
@@ -57,6 +57,7 @@
                                // 'basetimestamp' => ?,
                                // 'starttimestamp' => ?,
                                'paction' => $action,
+                               'oldid' => '',
                                $from => $content,
                        ),
                        true // POST
diff --git a/includes/Templating.php b/includes/Templating.php
index 5fedb9e..87943f8 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -9,8 +9,13 @@
 use Flow\Model\Workflow;
 use OutputPage;
 // These dont really belong here
-use RequestContext;
+use Html;
+use Linker;
 use MWTimestamp;
+use RequestContext;
+use SpecialPage;
+use Title;
+use User;
 
 class Templating {
        protected $namespaces;
@@ -72,6 +77,11 @@
        }
 
        // Helper methods for the view
+       //
+       // Everything below here *DOES* *NOT*  belong in this class.  Its also 
pointless for us to invent a properly
+       // abstracted templating implementation so these can be elsewhere.  
Figure out if we can transition to an
+       // industry standard templating solution and stop the NIH.
+
        public function generateUrl( $workflow, $action = 'view', array $query 
= array() ) {
                return $this->urlGenerator->generateUrl( $workflow, $action, 
$query );
        }
@@ -130,13 +140,14 @@
                return $output;
        }
 
-       public function timeAgo( $timestamp ) {
-               if ( $timestamp instanceof UUID ) {
-                       $timestamp = $timestamp->getTimestamp();
+       public function userToolLinks( $userId, $userText ) {
+               global $wgLang;
+
+               if ( $userText instanceof MWMessage ) {
+                       // username was moderated away, we dont know who this is
+                       return '';
                }
-               $now = new MWTimestamp;
-               $then = new MWTimestamp( $timestamp );
-               return $then->getHumanTimestamp( $now );
+
+               return Linker::userLink( $userId, $userText ) . 
Linker::userToolLinks( $userId, $userText );
        }
 }
-
diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js
index 000a50b..b67672d 100644
--- a/modules/discussion/ui.js
+++ b/modules/discussion/ui.js
@@ -17,9 +17,16 @@
 
                // Set up timestamp on-hover
                $container.find( '.flow-topic-datestamp, .flow-datestamp' )
-                       .hover( function () {
-                               $( this ).children( '.flow-agotime' ).toggle();
-                               $( this ).children( '.flow-utctime' ).toggle();
+                       .hover(function() {
+                               $(this).children( '.flow-agotime' ).toggle();
+                               $(this).children( '.flow-utctime' ).toggle();
+                       } );
+
+               // Set up post creator on-hover
+               $container.find( '.flow-creator' )
+                       .hover( function() {
+                               $(this).children( '.flow-creator-simple' 
).toggle();
+                               $(this).children( '.flow-creator-full' 
).toggle();
                        } );
 
                // Set up reply form
diff --git a/templates/post.html.php b/templates/post.html.php
index bbb1229..751fa8d 100644
--- a/templates/post.html.php
+++ b/templates/post.html.php
@@ -48,7 +48,7 @@
        );
 };
 
-$createReplyForm = function() use( $self, $block, $post, $editToken ) {
+$createReplyForm = function() use( $self, $block, $post, $editToken, $user ) {
        $replyForm = Html::openElement( 'form', array(
                        'method' => 'POST',
                        // root post id is same as topic workflow id
@@ -70,7 +70,7 @@
                ) ) .
                Html::textarea( $block->getName() . '[content]', '', array(
                        'placeholder' => wfMessage( 'flow-reply-placeholder',
-                               $post->getUserText() )->text(),
+                               $post->getCreatorName( $user ) )->text(),
                        'class' => 'flow-reply-content flow-input',
                ) ) .
                Html::openElement( 'div', array( 'class' => 
'flow-post-form-extras' ) ) .
@@ -89,11 +89,6 @@
 };
 
 $class = $post->isModerated() ? 'flow-post-moderated' : 'flow-post';
-$content = $post->getContent( $user, 'html' );
-$userText = $post->getUserText();
-if ( !$userText instanceof \Message ) {
-       $userText = Html::element( 'span', null, $userText );
-}
 $actions = array();
 $replyForm = '';
 
@@ -159,10 +154,17 @@
        ) ); ?>
                <div class="flow-post-title">
                        <div class="flow-post-authorline">
-                               <?php echo $userText; ?>
+                               <span class="flow-creator">
+                                       <span class="flow-creator-simple" 
style="display: inline">
+                                               <?php echo 
$post->getCreatorName( $user ); ?>
+                                       </span>
+                                       <span class="flow-creator-full" 
style="display: none">
+                                               <?php echo 
$this->userToolLinks( $post->getCreatorId(), $post->getCreatorName() ); ?>
+                                       </span>
+                               </span>
                                <span class="flow-datestamp">
                                        <span class="flow-agotime" 
style="display: inline">
-                                               <?php echo $self->timeAgo( 
$post->getPostId() ); ?>
+                                               <?php echo 
$post->getPostId()->getHumanTimestamp(); ?>
                                        </span>
                                        <span class="flow-utctime" 
style="display: none">
                                                <?php echo 
$post->getPostId()->getTimestampObj()->getTimestamp( TS_RFC2822 ); ?>
@@ -171,7 +173,7 @@
                        </div>
                </div>
                <div class="flow-post-content">
-                       <?php echo $content ?>
+                       <?php echo $post->getContent( $user, 'html' ); ?>
                </div>
                <div class="flow-post-controls">
                        <div class="flow-post-actions">
diff --git a/templates/topic.html.php b/templates/topic.html.php
index 38ff59a..5d8fcdb 100644
--- a/templates/topic.html.php
+++ b/templates/topic.html.php
@@ -54,7 +54,7 @@
        <span class="flow-topic-datestamp">
                <span class="flow-agotime" style="display: inline">
                        <?php echo wfMessage( 'flow-last-modified' )->rawParams(
-                               $this->timeAgo( $topic->getLastModified() )
+                               
$topic->getLastModifiedObj()->getHumanTimestamp()
                        ); ?>
                </span>
                <span class="flow-utctime" style="display: none">

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id5af3e9b206fa81c22ebab51d36d7fa6c7ffa786
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson (WMF) <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: EBernhardson (WMF) <ebernhard...@wikimedia.org>

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

Reply via email to