Bsitu has uploaded a new change for review.

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


Change subject: Add diff view of changes to board header
......................................................................

Add diff view of changes to board header

Change-Id: I363b6bd9e972467953b0e64cd437309ce08446b7
---
M Flow.i18n.php
M Flow.php
M Hooks.php
M container.php
A includes/Block/BoardHistory.php
M includes/Block/Header.php
M includes/Block/TopicList.php
M includes/Templating.php
M includes/UrlGenerator.php
M includes/WorkflowLoader.php
M templates/compare-revisions.html.php
M templates/revision-permalink-warning.html.php
12 files changed, 400 insertions(+), 139 deletions(-)


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

diff --git a/Flow.i18n.php b/Flow.i18n.php
index f83cf8d..3e79810 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -261,10 +261,15 @@
 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-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-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].',
 
        // Topic collapse states
        'flow-topic-collapsed-one-line' => 'Small view',
@@ -1054,6 +1059,25 @@
 * $4 - URL to the history page
 See also:
 * {{msg-mw|Flow-revision-permalink-warning-post}}',
+       '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}}).
+
+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 - URL to the history page
+* $3 - URL to the diff from the previous revision to this one
+See also:
+* {{msg-mw|Flow-revision-permalink-warning-header-first}}',
+       'flow-revision-permalink-warning-header-first' => 'Header displayed at 
the top of a page when somebody is viewing a single-revision permalink of board 
header.
+
+This message will only be shown for the first revision.
+
+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 - URL to the history page
+See also:
+* {{msg-mw|Flow-revision-permalink-warning-header}}',
        '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.
 * $2 - user who made this revision',
@@ -1064,6 +1088,11 @@
 * $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.',
+       '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.
+* $3: URL to the Board, with the fragment set to the post in question.
+* $4: URL to the history page for this post.',
        'flow-topic-collapsed-one-line' => 'Used as title for the icon which is 
used to show small view of topics.
 
 "Small view" is also called "Collapsed one line view".',
diff --git a/Flow.php b/Flow.php
index d323341..c797b35 100755
--- a/Flow.php
+++ b/Flow.php
@@ -146,6 +146,7 @@
 $wgAutoloadClasses['Flow\Data\HeaderRevisionStorage'] = $dir . 
'includes/Data/RevisionStorage.php';
 
 // The individual workflow pieces
+$wgAutoloadClasses['Flow\Block\BoardHistoryBlock'] = $dir . 
'includes/Block/BoardHistory.php';
 $wgAutoloadClasses['Flow\Block\Block'] = $dir . 'includes/Block/Block.php';
 $wgAutoloadClasses['Flow\Block\AbstractBlock'] = $dir . 
'includes/Block/Block.php';
 $wgAutoloadClasses['Flow\Block\BlockView'] = $dir . 'includes/Block/Block.php';
@@ -336,3 +337,30 @@
 
 // Actions that must pass through to mediawiki on flow enabled pages
 $wgFlowCoreActionWhitelist = array( 'protect', 'unprotect' );
+
+// Flow definitions
+$wgFlowDefinitions = array(
+       'discussion' => array(
+               'blocks' => array(
+                       '\Flow\Block\HeaderBlock',
+                       '\Flow\Block\TopicListBlock',
+               ),
+               'custom' => array (
+                       'board-history' => array(
+                               'blocks' => array(
+                                       '\Flow\Block\BoardHistoryBlock',
+                               ),
+                       ),
+                       'header-view' => array(
+                               'blocks' => array(
+                                       '\Flow\Block\HeaderBlock',
+                               ),
+                       ),
+               ),
+       ),
+       'topic' => array(
+               'blocks' => array(
+                       '\Flow\Block\TopicBlock',
+               ),
+       ),
+);
diff --git a/Hooks.php b/Hooks.php
index 31eb345..54857af 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -200,7 +200,7 @@
                        $links['views'] = array( array(
                                'class' => $selected ? 'selected' : '',
                                'text' => wfMessageFallback( 
"$skname-view-history", "history_short" )->text(),
-                               'href' => $title->getLocalURL( 
'action=board-history' ),
+                               'href' => $title->getLocalURL( 
'definition=board-history' ),
                        ) );
 
                        // hide all ?action= links unless whitelisted
diff --git a/container.php b/container.php
index e48626b..55672bc 100644
--- a/container.php
+++ b/container.php
@@ -12,7 +12,7 @@
        $c['memcache'] = new \HashBagOStuff;
 }
 $c['cache.version'] = $GLOBALS['wgFlowCacheVersion'];
-
+$c['definitions'] = $GLOBALS['wgFlowDefinitions'];
 
 // Flow config
 $c['flow_actions'] = $c->share( function( $c ) {
diff --git a/includes/Block/BoardHistory.php b/includes/Block/BoardHistory.php
new file mode 100644
index 0000000..83e91c3
--- /dev/null
+++ b/includes/Block/BoardHistory.php
@@ -0,0 +1,143 @@
+<?php
+
+namespace Flow\Block;
+
+use Flow\RevisionActionPermissions;
+use Flow\View\History\History;
+use Flow\View\History\HistoryRenderer;
+use Flow\Container;
+use Flow\Model\Workflow;
+use Flow\Templating;
+use User;
+use Flow\Exception\InvalidDataException;
+
+class BoardHistoryBlock extends AbstractBlock {
+
+       /**
+        * @var RevisionActionPermissions $permissions Allows or denies actions 
to be performed
+        */
+       protected $permissions;
+
+       public function init( $action, $user ) {
+               parent::init( $action, $user );
+               $this->permissions = new RevisionActionPermissions( 
Container::get( 'flow_actions' ), $user );
+       }
+
+       /**
+        * Nothing to validate
+        */
+       public function validate() {
+
+       }
+
+       /**
+        * Nothing to commit
+        */
+       public function commit() {
+
+       }
+
+       public function render( Templating $templating, array $options ) {
+               $templating->getOutput()->addModuleStyles( array( 
'ext.flow.history' ) );
+               $templating->getOutput()->addModules( array( 'ext.flow.history' 
) );
+               $tplVars = array(
+                       'title' => wfMessage( 'flow-board-history', 
$this->workflow->getArticleTitle() )->escaped(),
+                       'historyExists' => false,
+               );
+
+               $history = $this->filterBoardHistory( $this->loadBoardHistory() 
);
+
+               if ( $history ) {
+                       $tplVars['historyExists'] = true;
+                       $tplVars['history'] = new History( $history );
+                       $tplVars['historyRenderer'] = new HistoryRenderer( 
$templating, $this );
+               }
+
+               $templating->render( "flow:board-history.html.php", $tplVars );
+       }
+
+       protected function filterBoardHistory( array $history ) {
+               // get rid of history entries user doesn't have sufficient 
permissions for
+               $query = $needed = array();
+               foreach ( $history as $i => $revision ) {
+                       switch( $revision->getRevisionType() ) {
+                               case 'header':
+                                       // headers can't be moderated
+                                       break;
+                               case 'post':
+                                       if ( $revision->isTopicTitle() ) {
+                                               
$needed[$revision->getPostId()->getHex()] = $i;
+                                               $query[] = array( 
'tree_rev_descendant_id' => $revision->getPostId() );
+                                       } else {
+                                               // comments should not be in 
board history
+                                               unset( $history[$i] );
+                                       }
+                                       break;
+                       }
+               }
+
+               if ( !$needed ) {
+                       return $history;
+               }
+
+               // check permissions against most recent revision
+               $found = $this->storage->findMulti(
+                       'PostRevision',
+                       $query,
+                       array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' 
=> 1 )
+               );
+               foreach ( $found as $newest ) {
+                       $newest = reset( $newest );
+                       $id = $newest->getPostId()->getHex();
+
+                       if ( isset( $needed[$id] ) ) {
+                               $i = $needed[$id];
+                               unset( $needed[$id] );
+
+                               if ( !$this->permissions->isAllowed( $newest, 
'board-history' ) ) {
+                                       unset( $history[$i] );
+                               }
+                       }
+               }
+
+               // not found
+               foreach ( $needed as $i ) {
+                       unset( $history[$i] );
+               }
+
+               return $history;
+       }
+
+       public function renderAPI( Templating $templating, array $options ) {
+               $output = array(
+                       'type' => 'board-history',
+                       '*' =>  $this->filterBoardHistory( 
$this->loadBoardHistory() ),
+               );
+
+               $output = array(
+                       '_element' => 'board-history',
+                       0 => $output,
+               );
+
+               return $output;
+       }
+
+       protected function loadBoardHistory() {
+               $found = $this->storage->find(
+                       'BoardHistoryEntry',
+                       array( 'topic_list_id' => $this->workflow->getId() ),
+                       array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' 
=> 300 )
+               );
+
+               if ( $found === false ) {
+                       throw new InvalidDataException( 'Unable to load topic 
list history for ' . $this->workflow->getId()->getHex(), 'fail-load-history' );
+               }
+
+               return $found;
+       }
+
+       public function getName() {
+               return 'board-history';
+       }
+
+}
diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index 3786b07..e844416 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -13,8 +13,10 @@
 use Flow\Repository\HeaderRepository;
 use Flow\Templating;
 use User;
+use Flow\Model\UUID;
 use Flow\Exception\InvalidActionException;
 use Flow\Exception\InvalidDataException;
+use Flow\Exception\InvalidInputException;
 
 class HeaderBlock extends AbstractBlock {
 
@@ -149,89 +151,107 @@
                }
        }
 
-       public function render( Templating $templating, array $options ) {
-               // Render board history view in header block, topiclist block 
will not be renderred
-               // when action = 'board-history'
-               if ( $this->action === 'board-history' ) {
-                       $templating->getOutput()->addModuleStyles( array( 
'ext.flow.history' ) );
-                       $templating->getOutput()->addModules( array( 
'ext.flow.history' ) );
-                       $tplVars = array(
-                               'title' => wfMessage( 'flow-board-history', 
$this->workflow->getArticleTitle() )->escaped(),
-                               'historyExists' => false,
-                       );
+       public function render( Templating $templating, array $options, $return 
= false ) {
+               $templating->getOutput()->addModuleStyles( array( 
'ext.flow.header' ) );
+               $templating->getOutput()->addModules( array( 'ext.flow.header' 
) );
 
-                       $history = $this->filterBoardHistory( 
$this->loadBoardHistory() );
+               switch ( $this->action ) {
+                       // @Todo - Most of the header single revision view and 
revision diff code duplicates
+                       // the post revision, need to consolidate them
+                       case 'compare-revisions':
+                               if ( ! isset( $options['oldRevision'] ) || ! 
isset( $options['newRevision'] ) ) {
+                                       throw new InvalidInputException( 'Two 
revisions must be specified to compare them', 'revision-comparison' );
+                               }
+       
+                               $oldRevId = UUID::create( 
$options['oldRevision'] );
+                               $newRevId = UUID::create( 
$options['newRevision'] );
 
-                       if ( $history ) {
-                               $tplVars['historyExists'] = true;
-                               $tplVars['history'] = new History( $history );
-                               $tplVars['historyRenderer'] = new 
HistoryRenderer( $templating, $this );
-                       }
+                               list( $oldRev, $newRev ) = 
$this->storage->getMulti(
+                                       'Header',
+                                       array(
+                                               $oldRevId,
+                                               $newRevId
+                                       )
+                               );
 
-                       $templating->render( "flow:board-history.html.php", 
$tplVars );
-               } else {
-                       $templating->getOutput()->addModuleStyles( array( 
'ext.flow.header' ) );
-                       $templating->getOutput()->addModules( array( 
'ext.flow.header' ) );
-                       $templateName = ( $this->action == 'edit-header' ) ? 
'edit-header' : 'header';
-                       $templating->render( "flow:$templateName.html.php", 
array(
-                               'block' => $this,
-                               'workflow' => $this->workflow,
-                               'header' => $this->header,
-                               'user' => $this->user,
-                       ) );
+                               // In theory the backend will return things in 
increasing PK order
+                               // (i.e. earlier revision first), but let's be 
sure.
+                               if (
+                                       
$oldRev->getRevisionId()->getTimestamp() >
+                                       $newRev->getRevisionId()->getTimestamp()
+                               ) {
+                                       $temp = $oldRev;
+                                       $oldRev = $newRev;
+                                       $newRev = $temp;
+                               }
+
+                               if ( !$oldRev->getWorkflowId()->equals( 
$newRev->getWorkflowId() ) ) {
+                                       throw new InvalidInputException( 
'Attempt to compare revisions of different headers', 'revision-comparison' );
+                               }
+
+                               return $templating->render(
+                                       'flow:compare-revisions.html.php',
+                                       array(
+                                               'block' => $this,
+                                               'user' => $this->user,
+                                               'oldRevision' => $oldRev,
+                                               'newRevision' => $newRev,
+                                               'header' => $this->header,
+                                       ), $return
+                               );
+                       break;
+
+                       default:
+                               if ( isset( $options['revId'] ) ) {
+                                       return $this->renderRevision( 
$templating, $options, $return );
+                               }
+                               // Single view of latest revision
+                               $templateName = ( $this->action == 
'edit-header' ) ? 'edit-header' : 'header';
+                               return $templating->renderHeader( 
$this->header, $this, $this->user, 'flow:' . $templateName . '.html.php' );
+                       break;
                }
        }
 
-       protected function filterBoardHistory( array $history ) {
-               // get rid of history entries user doesn't have sufficient 
permissions for
-               $query = $needed = array();
-               foreach ( $history as $i => $revision ) {
-                       switch( $revision->getRevisionType() ) {
-                               case 'header':
-                                       // headers can't be moderated
-                                       break;
-                               case 'post':
-                                       if ( $revision->isTopicTitle() ) {
-                                               
$needed[$revision->getPostId()->getHex()] = $i;
-                                               $query[] = array( 
'tree_rev_descendant_id' => $revision->getPostId() );
-                                       } else {
-                                               // comments should not be in 
board history
-                                               unset( $history[$i] );
-                                       }
-                                       break;
-                       }
+       protected function renderRevision( Templating $templating, array 
$options, $return = false ) {
+               $postRevision = $this->loadRequestedRevision( $options['revId'] 
);
+
+               if ( !$postRevision ) {
+                       return;
                }
 
-               if ( !$needed ) {
-                       return $history;
-               }
-
-               // check permissions against most recent revision
-               $found = $this->storage->findMulti(
-                       'PostRevision',
-                       $query,
-                       array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' 
=> 1 )
+               $prefix = $templating->render(
+                       'flow:revision-permalink-warning.html.php',
+                       array(
+                               'block' => $this,
+                               'revision' => $postRevision,
+                       ),
+                       $return
                );
-               foreach ( $found as $newest ) {
-                       $newest = reset( $newest );
-                       $id = $newest->getPostId()->getHex();
 
-                       if ( isset( $needed[$id] ) ) {
-                               $i = $needed[$id];
-                               unset( $needed[$id] );
+               return $prefix . $templating->renderHeader(
+                       $postRevision,
+                       $this,
+                       $this->user,
+                       'flow:header.html.php',
+                       $return
+               );
+       }
 
-                               if ( !$this->permissions->isAllowed( $newest, 
'board-history' ) ) {
-                                       unset( $history[$i] );
-                               }
-                       }
+       protected function loadRequestedRevision( $revisionId ) {
+               if ( !$revisionId instanceof UUID ) {
+                       $revisionId = UUID::create( $revisionId );
                }
 
-               // not found
-               foreach ( $needed as $i ) {
-                       unset( $history[$i] );
+               $found = $this->storage->get( 'Header', $revisionId );
+
+               if ( !$found ) {
+                       throw new InvalidInputException( 'The requested 
revision could not be found', 'missing-revision' );
+               } else if ( !$this->permissions->isAllowed( $found, 'view' ) ) {
+                       $this->addError( 'moderation', wfMessage( 
'flow-error-not-allowed' ) );
+                       return null;
                }
 
-               return $history;
+               return $found;
        }
 
        public function renderAPI( Templating $templating, array $options ) {
@@ -258,20 +278,6 @@
                );
 
                return $output;
-       }
-
-       protected function loadBoardHistory() {
-               $found = $this->storage->find(
-                       'BoardHistoryEntry',
-                       array( 'topic_list_id' => $this->workflow->getId() ),
-                       array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit' 
=> 300 )
-               );
-
-               if ( $found === false ) {
-                       throw new InvalidDataException( 'Unable to load topic 
list history for ' . $this->workflow->getId()->getHex(), 'fail-load-history' );
-               }
-
-               return $found;
        }
 
        public function getName() {
diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index 346e30c..9a0add8 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -23,7 +23,6 @@
 
        protected $treeRepo;
        protected $supportedActions = array( 'new-topic' );
-       protected $suppressedActions = array( 'board-history' );
        protected $topicWorkflow;
        protected $topicListEntry;
        protected $topicPost;
@@ -172,31 +171,28 @@
        }
 
        public function render( Templating $templating, array $options ) {
-               // Don't render the topcilist block for some actions, eg: 
board-history
-               if ( !in_array( $this->action, $this->suppressedActions, true ) 
) {
-                       $templating->getOutput()->addModuleStyles( array( 
'ext.flow.discussion', 'ext.flow.moderation' ) );
-                       $templating->getOutput()->addModules( array( 
'ext.flow.discussion' ) );
-                       if ( $this->workflow->isNew() ) {
-                               $templating->render( "flow:topiclist.html.php", 
array(
-                                       'block' => $this,
-                                       'topics' => array(),
-                                       'user' => $this->user,
-                                       'page' => false,
-                                       'permissions' => $this->permissions,
-                               ) );
-                       } else {
-                               $findOptions = $this->getFindOptions( $options 
);
-                               $page = $this->getPage( $findOptions );
-                               $topics = $this->getTopics( $page );
+               $templating->getOutput()->addModuleStyles( array( 
'ext.flow.discussion', 'ext.flow.moderation' ) );
+               $templating->getOutput()->addModules( array( 
'ext.flow.discussion' ) );
+               if ( $this->workflow->isNew() ) {
+                       $templating->render( "flow:topiclist.html.php", array(
+                               'block' => $this,
+                               'topics' => array(),
+                               'user' => $this->user,
+                               'page' => false,
+                               'permissions' => $this->permissions,
+                       ) );
+               } else {
+                       $findOptions = $this->getFindOptions( $options );
+                       $page = $this->getPage( $findOptions );
+                       $topics = $this->getTopics( $page );
 
-                               $templating->render( "flow:topiclist.html.php", 
array(
-                                       'block' => $this,
-                                       'topics' => $topics,
-                                       'user' => $this->user,
-                                       'page' => $page,
-                                       'permissions' => $this->permissions,
-                               ) );
-                       }
+                       $templating->render( "flow:topiclist.html.php", array(
+                               'block' => $this,
+                               'topics' => $topics,
+                               'user' => $this->user,
+                               'page' => $page,
+                               'permissions' => $this->permissions,
+                       ) );
                }
        }
 
diff --git a/includes/Templating.php b/includes/Templating.php
index e2af64d..70099ee 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -4,9 +4,11 @@
 
 use Flow\Block\Block;
 use Flow\Block\TopicBlock;
+use Flow\Block\HeaderBlock;
 use Flow\Data\UserNameBatch;
 use Flow\Model\AbstractRevision;
 use Flow\Model\PostRevision;
+use Flow\Model\Header;
 use Flow\View\PostActionMenu;
 use OutputPage;
 // These dont really belong here
@@ -196,6 +198,18 @@
                ), $return );
        }
 
+       public function renderHeader( Header $header, HeaderBlock $block, User 
$user, $template = '', $return = true ) {
+               if ( !$template ) {
+                       $template = 'flow:header.html.php';
+               }
+               return $this->render( $template, array(
+                       'block' => $block,
+                       'workflow' => $block->getWorkflow(),
+                       'header' => $header,
+                       'user' => $user,
+               ) );
+       }
+
        // An ideal world may pull this from the container, but for now this is 
fine.  This templating
        // class has too many responsibilities to keep receiving all required 
objects in the constructor.
        protected function createActionMenu( PostRevision $post, Block $block ) 
{
diff --git a/includes/UrlGenerator.php b/includes/UrlGenerator.php
index 91ce957..923fb2a 100644
--- a/includes/UrlGenerator.php
+++ b/includes/UrlGenerator.php
@@ -107,6 +107,12 @@
                                        $data['topic[revId]'] = 
$revision->getRevisionId()->getHex();
                                }
                        break;
+                       case 'header':
+                               if ( $specificRevision ) {
+                                       $data['header[revId]'] = 
$revision->getRevisionId()->getHex();
+                               }
+                               $data['definition'] = 'header-view';
+                       break;
                }
                return $this->generateUrl( $workflow, 'view', $data );
        }
diff --git a/includes/WorkflowLoader.php b/includes/WorkflowLoader.php
index 3d1e5d4..f56bc93 100644
--- a/includes/WorkflowLoader.php
+++ b/includes/WorkflowLoader.php
@@ -136,35 +136,32 @@
                return $definition;
        }
 
-       public function createBlocks( ) {
-               switch( $this->definition->getType() ) {
-               case 'discussion':
-                       $blocks = array(
-                               new HeaderBlock( $this->workflow, 
$this->storage, $this->notificationController ),
-                               new TopicListBlock( $this->workflow, 
$this->storage, $this->notificationController, $this->rootPostLoader ),
-                       );
-                       break;
+       public function createBlocks() {
+               $definitions = Container::get( 'definitions' );
 
-               case 'topic':
-                       $blocks = array(
-                               new TopicBlock( $this->workflow, 
$this->storage, $this->notificationController, $this->rootPostLoader ),
-                       );
-                       break;
-
-               default:
-                       throw new InvalidInputException( 'Not Implemented', 
'invalid-definition' );
+               if ( !isset( $definitions[$this->definition->getType()] ) ) {
+                       throw new InvalidInputException( 'Definition ' . 
$definition . ' is not implemented', 'invalid-definition' );
+               }
+               // Flow database definition
+               $def = $definitions[$this->definition->getType()];
+               
+               // Check if a valid custom definition is requested
+               $customDefinition = Container::get( 'request' )->getVal( 
'definition', '' );
+               if ( isset( $def['custom'][$customDefinition] ) ) {
+                       $def = $def['custom'][$customDefinition];
                }
 
-               $return = array();
-               foreach ( $blocks as $block ) {
-                       if ( !isset( $return[$block->getName()] ) ) {
-                               $return[$block->getName()] = $block;
-                       } else {
+               $blocks = array();
+               foreach ( $def['blocks'] as $blockName ) {
+                       $block = new $blockName( $this->workflow, 
$this->storage, $this->notificationController, $this->rootPostLoader );
+                       if ( isset( $blocks[$block->getName()] ) ) {
                                throw new InvalidDataException( 'Multiple 
blocks with same name is not yet supported', 'fail-load-data' );
+                       } else {
+                               $blocks[$block->getName()] = $block;    
                        }
                }
 
-               return $return;
+               return $blocks;
        }
 
        public function handleSubmit( $action, array $blocks, $user, 
\WebRequest $request ) {
diff --git a/templates/compare-revisions.html.php 
b/templates/compare-revisions.html.php
index 7b93911..9219b18 100644
--- a/templates/compare-revisions.html.php
+++ b/templates/compare-revisions.html.php
@@ -94,7 +94,28 @@
                        );
                break;
        case 'header':
-               // @todo later
+               $boardLinkTitle = $block->getWorkflow()->getArticleTitle();
+               $boardLink = $templating->getUrlGenerator()
+                       ->buildUrl(
+                               $boardLinkTitle,
+                               'view'
+                       );
+               $historyLink = $templating->getUrlGenerator()
+                       ->generateUrl(
+                               $block->getWorkflow(),
+                               'view',
+                               array(
+                                       'defintion' => 'board-history'
+                               )
+                       );
+               $headerMsg = wfMessage( 'flow-compare-revisions-header-header' )
+                       ->params(
+                               $block->getWorkflow()->getArticleTitle(),
+                               $this->usernames->get( wfWikiId(), 
$newRevision->getUserId() ),
+                               $boardLink,
+                               $historyLink
+                       );
+               break;
        default:
                throw new \Flow\Exception\InvalidDataException( "Unsupported 
revision type ".$newRevision->getRevisionType(), 'fail-load-data' );
 }
diff --git a/templates/revision-permalink-warning.html.php 
b/templates/revision-permalink-warning.html.php
index 5d27b2e..b4144d5 100644
--- a/templates/revision-permalink-warning.html.php
+++ b/templates/revision-permalink-warning.html.php
@@ -13,14 +13,18 @@
 
 $urlGenerator = $this->getUrlGenerator();
 
-if ( $revision->getLastContentEditId() ) {
+if ( $revision->getPrevRevisionId() ) {
+       $params = array(
+               $block->getName().'[newRevision]' => 
$revision->getRevisionId()->getHex(),
+               $block->getName().'[oldRevision]' => 
$revision->getPrevRevisionId()->getHex()
+       );
+       if ( $revision->getRevisionType() === 'header' ) {
+               $params['definition'] = 'header-view';
+       }
        $compareLink = $urlGenerator->generateUrl(
                $block->getWorkflow(),
                'compare-revisions',
-               array(
-                       $block->getName().'[newRevision]' => 
$revision->getRevisionId()->getHex(),
-                       $block->getName().'[oldRevision]' => 
$revision->getLastContentEditId()->getHex()
-               )
+               $params
        );
 } else {
        $compareLink = false;
@@ -50,7 +54,24 @@
                }
                break;
        case 'header':
-               // @todo Implement
+               $historyLink = $urlGenerator->generateUrl(
+                       $block->getWorkflow(),
+                       'view',
+                       array(
+                               'definition' => 'board-history'
+                       )
+               );
+
+               $msgKey = $compareLink ? 
'flow-revision-permalink-warning-header' : 
'flow-revision-permalink-warning-header-first';
+               $message = wfMessage( $msgKey )
+                       ->rawParams( $formattedTimestamp )
+                       ->params(
+                               $historyLink
+                       );
+
+               if ( $compareLink ) {
+                       $message->params( $compareLink );
+               }
                break;
        default:
                throw new \Flow\Exception\InvalidDataException( "Unknown 
revision type: " . $revision->getRevisionType(), 'fail-load-data' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I363b6bd9e972467953b0e64cd437309ce08446b7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Bsitu <bs...@wikimedia.org>

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

Reply via email to