EBernhardson (WMF) has submitted this change and it was merged. Change subject: Last modified timestamps with hover swap to full ts ......................................................................
Last modified timestamps with hover swap to full ts Change-Id: I74cb43a9bf04aa17bde57fa3cd8831f30c302668 --- M Flow.i18n.php M includes/Block/Topic.php M includes/Model/UUID.php M includes/Model/Workflow.php M includes/Templating.php M modules/discussion/ui.js M templates/post.html.php M templates/topic.html.php 8 files changed, 91 insertions(+), 17 deletions(-) Approvals: EBernhardson (WMF): Verified; Looks good to me, approved diff --git a/Flow.i18n.php b/Flow.i18n.php index 3e256db..b88058f 100644 --- a/Flow.i18n.php +++ b/Flow.i18n.php @@ -70,6 +70,10 @@ 'flow-paging-rev' => 'More recent topics', 'flow-paging-fwd' => 'Older topics', + 'flow-last-modified' => 'Last modified about $1', + 'flow-days-ago' => '$1 {{PLURAL:$1|day|days}} ago', + 'flow-monthss-ago' => '$1 {{PLURAL:$1|months|monthss}} ago', + 'flow-years-ago' => '$1 {{PLURAL:$1|year|years}} ago', ); /** Message documentation (Message documentation) diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php index 82edc2f..baee11f 100644 --- a/includes/Block/Topic.php +++ b/includes/Block/Topic.php @@ -187,6 +187,8 @@ } public function commit() { + $this->workflow->updateLastModified(); + switch( $this->action ) { case 'reply': case 'delete-post': @@ -197,6 +199,7 @@ throw new \MWException( 'Attempt to save null revision' ); } $this->storage->put( $this->newRevision ); + $this->storage->put( $this->workflow ); $self = $this; $newRevision = $this->newRevision; $rootPost = $this->loadRootPost(); @@ -220,12 +223,11 @@ ); return $output; - break; + case 'delete-topic': $this->storage->put( $this->workflow ); return 'success'; - break; default: throw new \MWException( "Unknown commit action: {$this->action}" ); diff --git a/includes/Model/UUID.php b/includes/Model/UUID.php index fa60fa7..8a2d5b0 100644 --- a/includes/Model/UUID.php +++ b/includes/Model/UUID.php @@ -57,13 +57,25 @@ return wfBaseConvert( $this->getHex(), 16, 10 ); } - public function getTimestamp() { + public function getTimestampObj() { // First 6 bytes === 48 bits - $timePortion = substr( $this->getHex(), 0, 12 ); + $hex = $this->getHex(); + $timePortion = substr( $hex, 0, 12 ); $bits_48 = wfBaseConvert( $timePortion, 16, 2, 48 ); $bits_46 = substr( $bits_48, 0, 46 ); $msTimestamp = wfBaseConvert( $bits_46, 2, 10 ); - return wfTimestamp( TS_MW, intval( $msTimestamp / 1000 ) ); + + try { + return new \MWTimestamp( intval( $msTimestamp / 1000 ) ); + } catch ( \TimestampException $e ) { + wfDebugLog( __CLASS__, __FUNCTION__ . ": bogus time value: UUID=$hex; VALUE=$msTimestamp" ); + return false; + } + } + + public function getTimestamp() { + $ts = $this->getTimestampObj(); + return $ts ? $ts->getTimestamp( TS_MW ) : false; } public static function convertUUIDs( $array ) { diff --git a/includes/Model/Workflow.php b/includes/Model/Workflow.php index 3f79665..e6e9a9c 100644 --- a/includes/Model/Workflow.php +++ b/includes/Model/Workflow.php @@ -20,6 +20,7 @@ // is the active state. protected $lockState; protected $definitionId; + protected $lastModified; static public function fromStorageRow( array $row, $obj = null ) { if ( $obj === null ) { @@ -37,6 +38,7 @@ $obj->userText = $row['workflow_user_text']; $obj->lockState = $row['workflow_lock_state']; $obj->definitionId = UUID::create( $row['workflow_definition_id'] ); + $obj->lastModified = $row['workflow_last_update_timestamp']; return $obj; } @@ -51,6 +53,7 @@ 'workflow_user_text' => $obj->userText, 'workflow_lock_state' => $obj->lockState, 'workflow_definition_id' => $obj->definitionId->getBinary(), + 'workflow_last_update_timestamp' => $obj->lastModified, ); } @@ -77,6 +80,7 @@ $obj->userText = $user->getName(); $obj->lockState = 0; $obj->definitionId = $definition->getId(); + $obj->updateLastModified(); return $obj; } @@ -99,6 +103,11 @@ public function getDefinitionId() { return $this->definitionId; } public function getUserId() { return $this->userId; } public function getUserText() { return $this->userText; } + public function getLastModified() { return $this->lastModified; } + + public function updateLastModified() { + $this->lastModified = wfTimestampNow(); + } public function getNamespaceName() { global $wgContLang; diff --git a/includes/Templating.php b/includes/Templating.php index 6da848c..ba13cf9 100644 --- a/includes/Templating.php +++ b/includes/Templating.php @@ -5,8 +5,12 @@ use Flow\Block\Block; use Flow\Block\TopicBlock; use Flow\Model\PostRevision; +use Flow\Model\UUID; use Flow\Model\Workflow; use OutputPage; +// These dont really belong here +use RequestContext; +use MWTimestamp; class Templating { protected $namespaces; @@ -125,5 +129,32 @@ return $output; } + + public function timeAgo( $timestamp ) { + if ( $timestamp instanceof UUID ) { + $timestamp = $timestamp->getTimestamp(); + } + return self::getApproxHumanTimestamp( new MWTimestamp( $timestamp ), new MWTimestamp ); + } + + static public function getApproxHumanTimestamp( MWTimestamp $ts, MWTimestamp $relativeTo ) { + $diff = $ts->diff( $relativeTo ); + $lang = RequestContext::getMain()->getLanguage(); + if ( $diff->y ) { + return wfMessage( 'flow-years-ago' )->inLanguage( $lang )->numParams( $diff->y )->text(); + } elseif ( $diff->m ) { + return wfMessage( 'flow-months-ago' )->inLanguage( $lang )->numParams( $diff->m )->text(); + } elseif ( $diff->d ) { + return wfMessage( 'flow-days-ago' )->inLanguage( $lang )->numParams( $diff->d )->text(); + } elseif ( $diff->h ) { + return wfMessage( 'hours-ago' )->inLanguage( $lang )->numParams( $diff->h )->text(); + } elseif ( $diff->i ) { + return wfMessage( 'minutes-ago' )->inLanguage( $lang )->numParams( $diff->i )->text(); + } elseif ( $diff->s >= 30 ) { + return wfMessage( 'seconds-ago' )->inLanguage( $lang )->numParams( $diff->s )->text(); + } else { + return wfMessage( 'just-now' )->text(); + } + } } diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js index 68c5932..ea2978a 100644 --- a/modules/discussion/ui.js +++ b/modules/discussion/ui.js @@ -14,6 +14,13 @@ .fadeOut(); } ); + // Set up timestamp on-hover + $container.find( '.flow-topic-datestamp, .flow-datestamp' ) + .hover(function() { + $(this).children( '.flow-agotime' ).toggle() + $(this).children( '.flow-utctime' ).toggle() + } ); + // Set up reply form $container.find( '.flow-reply-form textarea' ) .addClass( 'flow-reply-box-closed' ) @@ -114,4 +121,4 @@ .fadeOut( 'fast' ); } } ); -} )( jQuery, mediaWiki ); \ No newline at end of file +} )( jQuery, mediaWiki ); diff --git a/templates/post.html.php b/templates/post.html.php index 332e18e..3dfcb56 100644 --- a/templates/post.html.php +++ b/templates/post.html.php @@ -130,20 +130,20 @@ ?> <div class="flow-post-title"> <div class="flow-post-authorline"> -<?php -echo $user; -?> + <?php echo $user; ?> <span class="flow-datestamp"> - <span class="flow-agotime" style="display: inline"><timestamp></span> - <span class="flow-utctime" style="display: none"><timestamp></span> + <span class="flow-agotime" style="display: inline"> + <?php echo $self->timeAgo( $post->getPostId() ); ?> + </span> + <span class="flow-utctime" style="display: none"> + <?php echo $post->getPostId()->getTimestampObj()->getTimestamp( TS_RFC2822 ); ?> + </span> </span> </div> </div> <div class="flow-post-content"> -<?php -echo $content -?> +<?php echo $content ?> </div> <div class="flow-post-controls"> <div class="flow-post-actions"> @@ -174,4 +174,4 @@ } echo '</div>'; -echo '</div>'; \ No newline at end of file +echo '</div>'; diff --git a/templates/topic.html.php b/templates/topic.html.php index ee9a4db..4ba444d 100644 --- a/templates/topic.html.php +++ b/templates/topic.html.php @@ -51,8 +51,17 @@ </div> </div> <span class="flow-topic-datestamp"> - <span class="flow-agotime" style="display: inline"><timestamp></span> - <span class="flow-utctime" style="display: none"><timestamp></span> + <span class="flow-agotime" style="display: inline"> + <?php echo wfMessage( 'flow-last-modified' )->rawParams( + $this->timeAgo( $topic->getLastModified() ) + ); ?> + </span> + <span class="flow-utctime" style="display: none"> + <?php + $ts = new MWTimestamp( $topic->getLastModified() ); + echo $ts->getTimestamp( TS_RFC2822 ); + ?> + </span> </span> </div> -- To view, visit https://gerrit.wikimedia.org/r/81018 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I74cb43a9bf04aa17bde57fa3cd8831f30c302668 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson (WMF) <ebernhard...@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