Bsitu has uploaded a new change for review.

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

Change subject: Add topic/post summary diff view
......................................................................

Add topic/post summary diff view

Do not review including i18n as this is very far from complete

Change-Id: I0bf26d798b1f5bebd391773fc3fd52a5ee95ecbd
---
M Flow.i18n.php
M Flow.php
M includes/Block/TopicSummary.php
M includes/View/Revision.php
A templates/postsummary.html.php
5 files changed, 237 insertions(+), 5 deletions(-)


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

diff --git a/Flow.i18n.php b/Flow.i18n.php
index 112f2cc..bce54f4 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -302,12 +302,16 @@
 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-revision-permalink-warning-postsummary-first' => 'This is a 
permanent link to the first version of this post summary.
+You can view later versions on the [$4 post history page].',
        'flow-revision-permalink-warning-header' => 'This is a permanent link 
to a single version of the header.
 This version is from $1.  You can see the [$3 differences from the previous 
version], or view other versions on the [$2 board history page].',
        'flow-revision-permalink-warning-header-first' => 'This is a permanent 
link to the first version of the header.
 You can view later versions on the [$2 board history page].',
        'flow-compare-revisions-revision-header' => 'Version by 
{{GENDER:$2|$2}} from $1',
        'flow-compare-revisions-header-post' => 'This page shows the 
{{GENDER:$3|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].',
+       'flow-compare-revisions-header-postsummary' => 'This page shows the 
{{GENDER:$3|changes}} between two versions of a post summary by $3 in the post 
"[$5 $2]" on [$4 $1].
 You can see other versions of this post at its [$6 history page].',
        'flow-compare-revisions-header-header' => 'This page shows the 
{{GENDER:$2|changes}} between two versions of the header on [$3 $1].
 You can see other versions of the header at its [$4 history page].',
@@ -1190,6 +1194,20 @@
 See also:
 * {{msg-mw|Flow-revision-permalink-warning-post}}
 * {{msg-mw|Flow-revision-permalink-warning-header-first}}',
+       'flow-revision-permalink-warning-postsummary-first' => 'Header 
displayed at the top of a page when somebody is viewing a single-revision 
permalink of a post summary.
+
+This message will only be shown for the first revision.
+
+Note that the "topic permalink warning" (see 
{{msg-mw|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 RFC2822 timestamp when hovered 
over.
+* $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
+See also:
+* {{msg-mw|Flow-revision-permalink-warning-post}}
+* {{msg-mw|Flow-revision-permalink-warning-header-first}}',
        'flow-revision-permalink-warning-header' => 'Header displayed at the 
top of a page when somebody is viewing a single-revision permalink of board 
header.
 
 This message will not appear for the first revision, which has its own message 
({{msg-mw|Flow-revision-permalink-warning-header-first}}).
@@ -1223,6 +1241,15 @@
 * $6 - URL to the history page for this post
 See also:
 * {{msg-mw|Flow-compare-revisions-header-header}}',
+       'flow-compare-revisions-header-postsummary' => 'Header for a page 
showing a "diff" between two revisions of a Flow post summary. 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
+* $6 - URL to the history page for this post
+See also:
+* {{msg-mw|Flow-compare-revisions-header-header}}',
        'flow-compare-revisions-header-header' => 'Header for a page showing a 
"diff" between two revisions of a Flow board header. Parameters:
 * $1 - the title of the Board on which this header sits. Example: User 
talk:Andrew
 * $2 - the username of the author of the header
diff --git a/Flow.php b/Flow.php
index 72805e4..24722ea 100755
--- a/Flow.php
+++ b/Flow.php
@@ -111,6 +111,7 @@
 $wgAutoloadClasses['Flow\View\RevisionView'] = 
"$dir/includes/View/Revision.php";
 $wgAutoloadClasses['Flow\View\PostRevisionView'] = 
"$dir/includes/View/Revision.php";
 $wgAutoloadClasses['Flow\View\HeaderRevisionView'] = 
"$dir/includes/View/Revision.php";
+$wgAutoloadClasses['Flow\View\PostSummaryRevisionView'] = 
"$dir/includes/View/Revision.php";
 
 // Classes that deal with database interaction between database and the models
 $wgAutoloadClasses['Flow\Repository\TreeRepository'] = $dir . 
'includes/Repository/TreeRepository.php';
diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php
index 442b055..26a3ab7 100644
--- a/includes/Block/TopicSummary.php
+++ b/includes/Block/TopicSummary.php
@@ -136,7 +136,7 @@
                }
        }
 
-       protected function findTopicTitle() {
+       public function findTopicTitle() {
                if ( $this->topicTitle ) {
                        return $this->topicTitle;
                }
@@ -179,11 +179,12 @@
                }
        }
 
-       /**
-        * @Todo - Add edit-topic-summary get action for no js support in UI 
patch
-        */
        public function render( Templating $templating, array $options ) {
-
+               switch( $this->action ) {
+                       case 'compare-postsummary-revision':
+                               
+                       break;
+               }
        }
 
        public function renderAPI( Templating $templating, array $options ) {
diff --git a/includes/View/Revision.php b/includes/View/Revision.php
index de73b2b..a47b837 100644
--- a/includes/View/Revision.php
+++ b/includes/View/Revision.php
@@ -5,12 +5,14 @@
 use Flow\Block\AbstractBlock;
 use Flow\Block\HeaderBlock;
 use Flow\Block\TopicBlock;
+use Flow\Block\TopicSummaryBlock;
 use Flow\Container;
 use Flow\Data\ManagerGroup;
 use Flow\Exception\InvalidInputException;
 use Flow\Model\AbstractRevision;
 use Flow\Model\Header;
 use Flow\Model\PostRevision;
+use Flow\Model\PostSummaryRevision;
 use Flow\Model\UUID;
 use Flow\Repository\TreeRepository;
 use Flow\Templating;
@@ -623,3 +625,201 @@
                return $message;
        }
 }
+
+/**
+ * PostSummary revision view
+ *
+ * @Todo - This is supposed to support post summary in general but assuming 
topic
+ * for now. When topicsummary block support a post summary, corresponding 
changes
+ * should be made in here as well
+ */
+class PostSummaryRevisionView extends RevisionView {
+
+       /**
+        * @var PostSummary
+        */
+       protected $revision;
+
+       /**
+        * The block the revision view being rendered in
+        *
+        * @var TopicSummaryBlock
+        */
+       protected $block;
+
+       /**
+        * @param Header $revision
+        * @param Templating $templating
+        * @param HeaderBlock $block
+        * @param User $user
+        */
+       public function __construct( TopicSummary $revision, Templating 
$templating, TopicSummaryBlock $block, User $user ) {
+               parent::__construct( $templating, $user );
+               $this->revision = $revision;
+               $this->block = $block;
+       }
+
+       /**
+        * Create a revision view instance from a revision id
+        *
+        * @param string|UUID $revId
+        * @param Templating $templating
+        * @param HeaderBlock $block
+        * @param User $user
+        * @return PostSummaryRevisionView|false
+        */
+       public static function newFromId( $revId, Templating $templating, 
TopicSummaryBlock $block, User $user ) {
+               $revision = self::createRevision( $revId, $block->getStorage() 
);
+
+               if ( $revision ) {
+                       return new self( $revision, $templating, $block, $user 
);
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * @param UUID|string $revId
+        * @param ManagerGroup $storage
+        * @return PostSummary|null
+        */
+       public static function createRevision( $revId, ManagerGroup $storage ) {
+               if ( !$revId instanceof UUID ) {
+                       $revId = UUID::create( $revId );
+               }
+
+               return $storage->get( 'PostSummary', $revId );
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getRevision() {
+               return $this->revision;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getBlock() {
+               return $this->block;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function renderSingleView( $return = false ) {
+               $prefix = $this->templating->render(
+                       'flow:revision-permalink-warning.html.php',
+                       array(
+                               'block' => $this->block,
+                               'revision' => $this->revision,
+                               'message' => $this->getSingleViewHeader()
+                       ),
+                       $return
+               );
+
+               return $prefix . $this->templating->renderHeader(
+                       $this->revision,
+                       $this->block,
+                       $this->user,
+                       'flow:postsummary.html.php',
+                       $return
+               );
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function isComparableTo( AbstractRevision $revision ) {
+               if ( $revision instanceof TopicSummary ) {
+                       return $this->revision->getSummaryTargetId()->equals( 
$revision->getSummaryTargetId() );
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * @param PostSummary $newRevision
+        * @param PostSummary $oldRevision
+        * @return Message
+        */
+       public function getDiffViewHeader( $newRevision, $oldRevision ) {
+               $postFragment = '#flow-post-' . 
$newRevision->getPostId()->getAlphadecimal();
+               $boardLinkTitle = clone 
$this->block->getWorkflow()->getArticleTitle();
+               $boardLinkTitle->setFragment( $postFragment );
+               $boardLink = $this->templating->getUrlGenerator()
+                       ->buildUrl(
+                               $boardLinkTitle,
+                               'view'
+                       );
+               /** @var Title $topicLinkTitle */
+               /** @var string $topicLinkQuery */
+               list( $topicLinkTitle, $topicLinkQuery ) = 
$this->templating->getUrlGenerator()
+                       ->generateUrlData(
+                               $this->block->getWorkflow(),
+                               'view',
+                               array(
+                                       $this->block->getName().'_postId' => 
$newRevision->getPostId()->getAlphadecimal()
+                               )
+                       );
+
+               $topicLinkTitle = clone $topicLinkTitle;
+               $topicLinkTitle->setFragment( $postFragment );
+
+               $historyLink = $this->templating->getUrlGenerator()
+                       ->generateUrl(
+                               $this->block->getWorkflow(),
+                               'history',
+                               array(
+                                       $this->block->getName().'_postId' => 
$newRevision->getPostId()->getAlphadecimal()
+                               )
+                       );
+               $headerMsg = wfMessage( 
'flow-compare-revisions-header-postsummary' )
+                       ->params(
+                               $this->block->getWorkflow()->getArticleTitle(),
+                               $this->templating->getContent( 
$this->block->findTopicTitle(), 'wikitext' ),
+                               $this->templating->getUsernames()->get( 
wfWikiId(), $newRevision->getCreatorId() ),
+                               $boardLink,
+                               $topicLinkTitle->getFullUrl( $topicLinkQuery ),
+                               $historyLink
+                       );
+               return $headerMsg;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getDiffType() {
+               return 'compare-postsummary-revisions';
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getSingleViewHeader() {
+               $historyLink = 
$this->templating->getUrlGenerator()->generateUrl(
+                       $this->block->getWorkflow(),
+                       'history',
+                       array(
+                               $this->block->getName().'_postId' => 
$this->revision->getSummaryTargetId()->getAlphadecimal(),
+                       )
+               );
+
+               $compareLink = $this->getDiffLinkAgainstPrevious();
+
+               $msgKey = $compareLink ? 'flow-revision-permalink-warning-post' 
: 'flow-revision-permalink-warning-postsummary-first';
+               $message = wfMessage( $msgKey )
+                       ->params( 
$this->revision->getRevisionId()->getTimestampObj()->getHumanTimestamp() )
+                       ->params(
+                               $this->block->getWorkflow()->getArticleTitle(),
+                               $this->templating->getContent( 
$this->block->findTopicTitle(), 'wikitext' ),
+                               $historyLink
+                       );
+
+               if ( $compareLink ) {
+                       $message->params( $compareLink );
+               }
+               return $message;
+       }
+}
diff --git a/templates/postsummary.html.php b/templates/postsummary.html.php
new file mode 100644
index 0000000..f251ea6
--- /dev/null
+++ b/templates/postsummary.html.php
@@ -0,0 +1,3 @@
+<div class="flow-post-summary">
+       Post summary single view
+</div>

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

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

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

Reply via email to