Werdna has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/94102


Change subject: Add access to historical revisions.
......................................................................

Add access to historical revisions.

* Includes a refactoring of timestamp display (I could not get to it in
  post.html.php because it is abstracted away)
* Still needs API module, access to header revisions.
* Copy is not final.

Change-Id: I4255fb669f4884d984307ec7e8197dd0bb1b7bbe
---
M Flow.i18n.php
M Resources.php
M includes/Block/Topic.php
M includes/View/History/HistoryRenderer.php
M modules/base/styles/various.less
M modules/discussion/styles/post.less
M modules/discussion/styles/topic.less
A modules/history/styles/diff.less
A templates/compare-revisions.html.php
M templates/history-line.html.php
A templates/revision-permalink-warning.html.php
A templates/timestamp.html.php
M templates/topic.html.php
13 files changed, 351 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/02/94102/1

diff --git a/Flow.i18n.php b/Flow.i18n.php
index 9b6220a..2a70204 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -179,6 +179,15 @@
        // Permalink related stuff
        'flow-topic-permalink-warning' => 'This topic was started on [$2 $1]',
        'flow-topic-permalink-warning-user-board' => 'This topic was started on 
[$2 {{GENDER:$1|$1}}\'s board]',
+       'flow-revision-permalink-warning-post' => 'This is a permanent link to 
a single version of this post.
+This version is from $1.
+You can see the [$5 differences from the previous version], or view other 
versions on the [$4 post history page].',
+       'flow-revision-permalink-warning-post-first' => 'This is a permanent 
link to the first version of this post.
+You can view later versions on the [$4 post history page].',
+
+       'flow-compare-revisions-revision-header' => 'Version by 
{{GENDER:$2|$2}} from $1',
+       'flow-compare-revisions-header-post' => 'This page shows the changes 
between two versions of a post by $3 in the topic "[$5 $2]" on [$4 $1].
+You can see other versions of this post at its [$6 history page].',
 );
 
 /** Message documentation (Message documentation)
@@ -667,6 +676,37 @@
 * $2 - URL for a link to the board that the topic comes from
 See also:
 * {{msg-mw|Flow-topic-permalink-warning}}",
+
+       'flow-revision-permalink-warning-post' => 'Header displayed at the top 
of a page when somebody is viewing a single-revision permalink of a post.
+This message will not appear for the first revision, which has its own message 
(flow-revision-permalink-warning-post-first).
+Note that the "topic permalink warning" (see flow-topic-permalink-warning) 
will also be displayed.
+
+Parameters:
+* $1: Date and timestamp, formatted as most are in Flow. That is, a 
human-readable timestamp that changes into an RFC-2822 timestamp when hovered 
over. I hope that doesn\'t cause too much translation trouble.
+* $2: Title of the Flow Board that the post appears on. Example: User 
talk:Andrew
+* $3: Title of the topic that this post appears in.
+* $4: URL to the history page.
+* $5: URL to the diff from the previous revision to this one.',
+       'flow-revision-permalink-warning-post-first' => 'Header displayed at 
the top of a page when somebody is viewing a single-revision permalink of a 
post.
+This message will only be shown for the first revision.
+Note that the "topic permalink warning" (see flow-topic-permalink-warning) 
will also be displayed.
+
+Parameters:
+* $1: Date and timestamp, formatted as most are in Flow. That is, a 
human-readable timestamp that changes into an RFC-2822 timestamp when hovered 
over. I hope that doesn\'t cause too much translation trouble.
+* $2: Title of the Flow Board that the post appears on. Example: User 
talk:Andrew
+* $3: Title of the topic that this post appears in.
+* $4: URL to the history page.',
+
+       'flow-compare-revisions-revision-header' => 'Diff column header for a 
revision. Parameters:
+* $1: Date and timestamp, formatted as most are in Flow. That is, a 
human-readable timestamp that changes into an RFC-2822 timestamp when hovered 
over. I hope that doesn\'t cause too much translation trouble.
+* $2: User who made this revision.',
+       'flow-compare-revisions-header-post' => 'Header for a page showing a 
"diff" between two revisions of a Flow post. Parameters:
+* $1: The title of the Board on which this post sits. Example: User 
talk:Andrew.
+* $2: The subject of the Topic in which this post sits.
+* $3: The username of the author of the post.
+* $4: URL to the Board, with the fragment set to the post in question.
+* $5: URL to the Topic, with the fragment set to the post in question.
+* $5: URL to the history page for this post.',
 );
 
 /** Arabic (العربية)
diff --git a/Resources.php b/Resources.php
index 2212417..864114d 100644
--- a/Resources.php
+++ b/Resources.php
@@ -79,7 +79,10 @@
                'position' => 'top',
        ),
        'ext.flow.history' => $flowResourceTemplate + array(
-               'styles' => 'history/styles/history.less',
+               'styles' => array(
+                       'history/styles/history.less',
+                       'history/styles/diff.less',
+               ),
                'scripts' => 'history/history.js',
        ),
        'ext.flow.moderation' => $flowResourceTemplate + array(
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 1fcd240..6606493 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -357,6 +357,31 @@
                                'topicTitle' => $this->loadTopicTitle(),
                        ), $return );
 
+               case 'compare-revisions':
+                       if ( ! isset( $options['oldRevision'] ) || ! isset( 
$options['newRevision'] ) ) {
+                               throw new \MWException( "Two revisions must be 
specified to compare them" );
+                       }
+
+                       $oldRev = $this->storage->get( 'PostRevision', 
UUID::create( $options['oldRevision'] ) );
+                       $newRev = $this->storage->get( 'PostRevision', 
UUID::create( $options['newRevision'] ) );
+
+                       if ( ! $oldRev->getPostId()->equals( 
$newRev->getPostId() ) ) {
+                               throw new \MWException( "Attempt to compare 
revisions of different posts" );
+                       }
+
+                       $templating->getOutput()->addModules( 
'ext.flow.history' );
+
+                       return $prefix . $templating->render(
+                               'flow:compare-revisions.html.php',
+                               array(
+                                       'block' => $this,
+                                       'user' => $this->user,
+                                       'oldRevision' => $oldRev,
+                                       'newRevision' => $newRev,
+                               ), $return
+                       );
+                       break;
+
                default:
                        $root = $this->loadRootPost();
 
@@ -385,6 +410,36 @@
                                        $this,
                                        $return
                                );
+                       } elseif ( isset( $options['revId'] ) ) {
+                               $postRevision = $this->storage->get(
+                                       'PostRevision',
+                                       UUID::create( $options['revId'] )
+                               );
+
+                               if ( ! $postRevision ) {
+                                       throw new \MWException( "The requested 
revision could not be found" );
+                               }
+
+                               $templating->getOutput()->addModules( 
'ext.flow.history' );
+
+                               // Set children as empty, otherwise it's just 
confusing
+                               // @todo Do we perhaps want to show children at 
the time of editing?
+                               $postRevision->setChildren( array() );
+
+                               $prefix = $templating->render(
+                                       
'flow:revision-permalink-warning.html.php',
+                                       array(
+                                               'block' => $this,
+                                               'revision' => $postRevision,
+                                       ),
+                                       $return
+                               );
+
+                               return $prefix . $templating->renderPost(
+                                       $postRevision,
+                                       $this,
+                                       $return
+                               );
                        } else {
                                return $prefix . $templating->renderTopic(
                                        $root,
diff --git a/includes/View/History/HistoryRenderer.php 
b/includes/View/History/HistoryRenderer.php
index c1b11c4..47987c9 100644
--- a/includes/View/History/HistoryRenderer.php
+++ b/includes/View/History/HistoryRenderer.php
@@ -139,6 +139,15 @@
                                $historyRecord = new HistoryRecord( $revision );
                                $children .= $this->renderLine( $historyRecord 
);
                        }
+                       $historicalLink = null;
+               } else {
+                       $historicalLink = $this->templating->getUrlGenerator()
+                               ->generateUrl( $this->block->getWorkflowId(),
+                                       'view',
+                                       array(
+                                               
$this->block->getName().'[revId]' => 
$record->getRevision()->getRevisionId()->getHex(),
+                                       )
+                               );
                }
 
                return $this->templating->render( 'flow:history-line.html.php', 
array(
@@ -151,7 +160,8 @@
                                $this->block
                        ),
                        'timestamp' => $record->getTimestamp(),
-                       'children' => $children
+                       'children' => $children,
+                       'historicalLink' => $historicalLink,
                ), true );
        }
 }
diff --git a/modules/base/styles/various.less b/modules/base/styles/various.less
index 773c6c4..fa3db99 100644
--- a/modules/base/styles/various.less
+++ b/modules/base/styles/various.less
@@ -13,3 +13,7 @@
 .flow-datestamp {
        color: #aaa;
 }
+
+span.flow-datestamp {
+       color: inherit !important;
+}
diff --git a/modules/discussion/styles/post.less 
b/modules/discussion/styles/post.less
index ce4379f..09b6730 100644
--- a/modules/discussion/styles/post.less
+++ b/modules/discussion/styles/post.less
@@ -78,7 +78,7 @@
                // similar trick.
                margin-right: -40px;
 
-               a.flow-action-history-link {
+               a {
                        color: inherit;
                }
        }
diff --git a/modules/discussion/styles/topic.less 
b/modules/discussion/styles/topic.less
index 59d252b..5ae8f9a 100644
--- a/modules/discussion/styles/topic.less
+++ b/modules/discussion/styles/topic.less
@@ -98,7 +98,7 @@
                        right: 22px;
                        bottom: 22px;
 
-                       a.flow-action-history-link {
+                       a {
                                color: inherit;
                        }
                }
@@ -223,7 +223,9 @@
        }
 }
 
-.flow-topic-permalink-warning {
+.flow-topic-permalink-warning,
+.flow-revision-permalink-warning,
+.flow-compare-revisions-header {
        color: #898989;
        border-bottom: 1px solid #ccc;
        padding-bottom: 0.5em;
diff --git a/modules/history/styles/diff.less b/modules/history/styles/diff.less
new file mode 100644
index 0000000..cc3eff4
--- /dev/null
+++ b/modules/history/styles/diff.less
@@ -0,0 +1,11 @@
+.flow-compare-revisions {
+       .diff-otitle,
+       .diff-ntitle {
+               color: #898989;
+
+               a {
+                       color: inherit;
+                       font-weight: bold;
+               }
+       }
+}
\ No newline at end of file
diff --git a/templates/compare-revisions.html.php 
b/templates/compare-revisions.html.php
new file mode 100644
index 0000000..4a5af74
--- /dev/null
+++ b/templates/compare-revisions.html.php
@@ -0,0 +1,119 @@
+<?php
+
+// Make sure that the order is always correct
+if ( $oldRevision->getRevisionId()->getTimestamp() > 
$newRevision->getRevisionId()->getTimestamp() ) {
+       $temp = $oldRevision;
+       $oldRevision = $newRevision;
+       $newRevision = $temp;
+}
+
+$oldContent = $oldRevision->getContent( $user, 'wikitext' );
+$newContent = $newRevision->getContent( $user, 'wikitext' );
+
+$differenceEngine = new DifferenceEngine();
+$templating = $this;
+
+$differenceEngine->setContent(
+       new TextContent( $oldContent ),
+       new TextContent( $newContent )
+);
+
+$differenceEngine->showDiffStyle();
+
+$getRevisionHeader = function( $revision ) use ( $templating, $block ) {
+       $timestamp = $templating->render(
+               'flow:timestamp.html.php',
+               array(
+                       'timestamp' => 
$revision->getRevisionId()->getTimestampObj(),
+                       'tag' => 'span',
+               ),
+               true /* return */
+       );
+       $message = wfMessage( 'flow-compare-revisions-revision-header' )
+               ->rawParams( $timestamp )
+               ->params(
+                       $revision->getUserText()
+               );
+
+       $permalinkUrl = $templating->getUrlGenerator()
+               ->generateUrl(
+                       $block->getWorkflow(),
+                       'view',
+                       array(
+                               $block->getName().'[revId]' => 
$revision->getRevisionId()->getHex(),
+                       )
+               );
+
+       $link = Html::rawElement( 'a',
+               array(
+                       'class' => 'flow-diff-revision-link',
+                       'href' => $permalinkUrl,
+               ),
+               $message->parse()
+       );
+
+       return $link;
+};
+
+$headerMsg = null;
+
+switch( $newRevision->getRevisionType() ) {
+       case 'post':
+               $postFragment = '#flow-post-' . 
$newRevision->getPostId()->getHex();
+               $boardLinkTitle = clone 
$block->getWorkflow()->getArticleTitle();
+               $boardLinkTitle->setFragment( $postFragment );
+               $boardLink = $templating->getUrlGenerator()
+                       ->buildUrl(
+                               $boardLinkTitle,
+                               'view'
+                       );
+               list( $topicLinkTitle, $topicLinkQuery ) = 
$templating->getUrlGenerator()
+                       ->generateUrlData(
+                               $block->getWorkflow(),
+                               'view',
+                               array(
+                                       $block->getName().'[postId]' => 
$newRevision->getPostId()->getHex()
+                               )
+                       );
+
+               $topicLinkTitle = clone $topicLinkTitle;
+               $topicLinkTitle->setFragment( $postFragment );
+
+               $historyLink = $templating->getUrlGenerator()
+                       ->generateUrl(
+                               $block->getWorkflow(),
+                               'post-history',
+                               array(
+                                       $block->getName().'[postId]' => 
$newRevision->getPostId()->getHex()
+                               )
+                       );
+               $headerMsg = wfMessage( 'flow-compare-revisions-header-post' )
+                       ->params(
+                               $block->getWorkflow()->getArticleTitle(),
+                               $block->getTitleText(),
+                               $newRevision->getCreator()->getName(),
+                               $boardLink,
+                               $topicLinkTitle->getFullUrl( $topicLinkQuery ),
+                               $historyLink
+                       );
+               break;
+       case 'header':
+               // @todo later
+       default:
+               throw new MWException( "Unsupported revision type 
".$newRevision->getRevisionType() );
+}
+
+if ( $headerMsg ) {
+       echo Html::rawElement(
+               'div',
+               array(
+                       'class' => 'flow-compare-revisions-header plainlinks',
+               ),
+               $headerMsg->parse()
+       );
+}
+
+?>
+<div class="flow-compare-revisions">
+<?php echo $differenceEngine->getDiff( $getRevisionHeader( $oldRevision ), 
$getRevisionHeader( $newRevision ) ); ?>
+</div>
\ No newline at end of file
diff --git a/templates/history-line.html.php b/templates/history-line.html.php
index 019f369..bdbc1a6 100644
--- a/templates/history-line.html.php
+++ b/templates/history-line.html.php
@@ -1,10 +1,10 @@
 <li class="<?php echo $class; ?>">
        <p><span class="plainlinks"><?php echo $message->parse(); ?></span></p>
-       <p class="flow-datestamp">
-               <a href="<?php echo '#'; /* @todo: link to historical revision 
*/ ?>">
-                       <span class="flow-agotime" style="display: 
inline"><?php echo htmlspecialchars( $timestamp->getHumanTimestamp() ); 
?></span>
-                       <span class="flow-utctime" style="display: none"><?php 
echo htmlspecialchars( $timestamp->getTimestamp( TS_RFC2822 ) ); ?></span>
-               </a>
-       </p>
+<?php
+echo $this->render( 'flow:timestamp.html.php', array(
+       'timestamp' => $timestamp,
+       'historicalLink' => $historicalLink,
+), true );
+?>
        <?php echo $children ? '<ul>' . $children . '</ul>' : ''; ?>
 </li>
diff --git a/templates/revision-permalink-warning.html.php 
b/templates/revision-permalink-warning.html.php
new file mode 100644
index 0000000..2703f1c
--- /dev/null
+++ b/templates/revision-permalink-warning.html.php
@@ -0,0 +1,65 @@
+<?php
+
+$type = $revision->getRevisionType();
+if ( $type == 'post' && $revision->isTopicTitle() ) {
+       $type = 'title';
+}
+
+$timestamp = $revision->getRevisionId()->getTimestampObj();
+$formattedTimestamp = $this->render( 'flow:timestamp.html.php', array(
+       'timestamp' => $timestamp,
+       'tag' => 'span',
+), true );
+
+$urlGenerator = $this->getUrlGenerator();
+
+if ( $revision->getPrevRevisionId() ) {
+       $compareLink = $urlGenerator->generateUrl(
+               $block->getWorkflow(),
+               'compare-revisions',
+               array(
+                       $block->getName().'[newRevision]' => 
$revision->getRevisionId()->getHex(),
+                       $block->getName().'[oldRevision]' => 
$revision->getPrevRevisionId()->getHex()
+               )
+       );
+} else {
+       $compareLink = false;
+}
+
+switch( $revision->getRevisionType() ) {
+       case 'post':
+               $historyLink = $urlGenerator->generateUrl(
+                       $block->getWorkflow(),
+                       'post-history',
+                       array(
+                               $block->getName().'[postId]' => 
$revision->getPostId()->getHex(),
+                       )
+               );
+
+               $msgKey = $compareLink ? 'flow-revision-permalink-warning-post' 
: 'flow-revision-permalink-warning-post-first';
+               $message = wfMessage( $msgKey )
+                       ->rawParams( $formattedTimestamp )
+                       ->params(
+                               $block->getWorkflow()->getArticleTitle(),
+                               $block->getTitleText(),
+                               $historyLink
+                       );
+
+               if ( $compareLink ) {
+                       $message->params( $compareLink );
+               }
+               break;
+       case 'header':
+               // @todo Implement
+               break;
+       default:
+               throw new \MWException( "Unknown revision type: " . 
$revision->getRevisionType() );
+}
+
+echo Html::rawElement(
+       'div',
+       array(
+               'class' => 'flow-revision-permalink-warning plainlinks',
+       ),
+       $message->parse()
+);
diff --git a/templates/timestamp.html.php b/templates/timestamp.html.php
new file mode 100644
index 0000000..1759b9c
--- /dev/null
+++ b/templates/timestamp.html.php
@@ -0,0 +1,9 @@
+<?php echo Html::openElement( isset( $tag ) ? $tag : 'p', array( 'class' => 
'flow-datestamp' ) ); ?>
+       <?php if ( isset( $historicalLink ) && $historicalLink !== null ) {?>
+       <a href="<?php echo $historicalLink; ?>">
+       <?php } ?>
+               <span class="flow-agotime" style="display: inline"><?php echo 
htmlspecialchars( $timestamp->getHumanTimestamp() ); ?></span>
+               <span class="flow-utctime" style="display: none"><?php echo 
htmlspecialchars( $timestamp->getTimestamp( TS_RFC2822 ) ); ?></span>
+       </a>
+       <?php if ( isset( $historicalLink ) && $historicalLink !== null ) { 
echo '</a>'; } ?>
+<?php echo Html::closeElement( isset( $tag ) ? $tag : 'p' ); ?>
\ No newline at end of file
diff --git a/templates/topic.html.php b/templates/topic.html.php
index aa807e9..9c9c7c3 100644
--- a/templates/topic.html.php
+++ b/templates/topic.html.php
@@ -48,40 +48,31 @@
                        </div>
                </div>
 
-               <p class="flow-datestamp">
-                       <?php
-                               // timestamp html
-                               $content = '
-                                       <span class="flow-agotime" 
style="display: inline">' . htmlspecialchars( 
$topic->getLastModifiedObj()->getHumanTimestamp() ) . '</span>
-                                       <span class="flow-utctime" 
style="display: none">' . htmlspecialchars( 
$topic->getLastModifiedObj()->getTimestamp( TS_RFC2822 ) ) . '</span>';
+               <?php
+                       $children = $root->getChildren();
 
-                               $children = $root->getChildren();
+                       // Timestamp should be turned into a link to history if:
+                       $history = false;
+                       // topic title has changed
+                       $history |= !$root->isFirstRevision();
+                       // topic has more than 1 comment
+                       $history |= count( $children ) > 1;
+                       // first comment was submitted separately from topic 
title
+                       $history |= isset( $children[0] ) && 
$children[0]->getRevisionId()->getTimestamp() !== 
$root->getRevisionId()->getTimestamp();
+                       // original topic comment has replies
+                       $history |= isset( $children[0] ) && count( 
$children[0]->getChildren() ) > 0;
 
-                               // Timestamp should be turned into a link to 
history if:
-                               $history = false;
-                               // topic title has changed
-                               $history |= !$root->isFirstRevision();
-                               // topic has more than 1 comment
-                               $history |= count( $children ) > 1;
-                               // first comment was submitted separately from 
topic title
-                               $history |= isset( $children[0] ) && 
$children[0]->getRevisionId()->getTimestamp() !== 
$root->getRevisionId()->getTimestamp();
-                               // original topic comment has replies
-                               $history |= isset( $children[0] ) && count( 
$children[0]->getChildren() ) > 0;
+                       if ( $history ) {
+                               $historicalLink = $this->generateUrl( 
$root->getPostId(), 'topic-history' );
+                       } else {
+                               $historicalLink = null;
+                       }
 
-                               if ( $history ) {
-                                       // build history button with timestamp 
html as content
-                                       echo Html::rawElement( 'a',
-                                               array(
-                                                       'class' => 
'flow-action-history-link',
-                                                       'href' => 
$this->generateUrl( $root->getPostId(), 'topic-history' ),
-                                               ),
-                                               $content
-                                       );
-                               } else {
-                                       echo $content;
-                               }
-                       ?>
-               </p>
+                       echo $this->render( 'flow:timestamp.html.php', array(
+                               'historicalLink' => $historicalLink,
+                               'timestamp' => $topic->getLastModifiedObj(),
+                       ), true );
+               ?>
 
                <?php
                        echo Html::element(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4255fb669f4884d984307ec7e8197dd0bb1b7bbe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Werdna <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to