jenkins-bot has submitted this change and it was merged.
Change subject: Edit topic summary
......................................................................
Edit topic summary
Change-Id: I3b13a4333b5860857ec168502d227d028b8c2f6d
---
M Flow.php
M FlowActions.php
M container.php
M handlebars/Makefile
A handlebars/flow_block_topicsummary_edit.html.handlebars
A handlebars/flow_block_topicsummary_edit.html.handlebars.php
M includes/Block/TopicSummary.php
A includes/Formatter/PostSummaryQuery.php
M includes/Formatter/RevisionFormatter.php
M includes/TemplateHelper.php
10 files changed, 180 insertions(+), 85 deletions(-)
Approvals:
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Flow.php b/Flow.php
index 00ac9b1..84cf6bd 100755
--- a/Flow.php
+++ b/Flow.php
@@ -177,6 +177,7 @@
$wgAutoloadClasses['Flow\Formatter\RecentChangesQuery'] = $dir .
'includes/Formatter/RecentChangesQuery.php';
$wgAutoloadClasses['Flow\Formatter\RecentChangesRow'] = $dir .
'includes/Formatter/RecentChangesQuery.php';
$wgAutoloadClasses['Flow\Formatter\SinglePostQuery'] = $dir .
'includes/Formatter/SinglePostQuery.php';
+$wgAutoloadClasses['Flow\Formatter\PostSummaryQuery'] = $dir .
'includes/Formatter/PostSummaryQuery.php';
$wgAutoloadClasses['Flow\Formatter\TopicListQuery'] = $dir .
'includes/Formatter/TopicListQuery.php';
$wgAutoloadClasses['Flow\Formatter\TopicHistoryQuery'] = $dir .
'includes/Formatter/TopicHistoryQuery.php';
$wgAutoloadClasses['Flow\Formatter\TopicRow'] = $dir .
'includes/Formatter/TopicRow.php';
diff --git a/FlowActions.php b/FlowActions.php
index e2b2a6d..9278d98 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -83,6 +83,7 @@
),
'button-method' => 'GET',
'links' => array( 'topic', 'topic-history' ),
+ 'actions' => array( 'edit-topic-summary' ),
'history' => array(
'i18n-message' =>
'flow-rev-message-create-topic-summary',
'i18n-params' => array(
@@ -107,6 +108,7 @@
),
'button-method' => 'GET',
'links' => array( 'topic', 'topic-history', 'diff-post-summary'
),
+ 'actions' => array( 'edit-topic-summary' ),
'history' => array(
'i18n-message' => 'flow-rev-message-edit-topic-summary',
'i18n-params' => array(
diff --git a/container.php b/container.php
index fe80c15..c4648f7 100644
--- a/container.php
+++ b/container.php
@@ -638,6 +638,13 @@
$c['flow_actions']
);
} );
+$c['query.postsummary'] = $c->share( function( $c ) {
+ return new Flow\Formatter\PostSummaryQuery(
+ $c['storage'],
+ $c['repository.tree'],
+ $c['flow_actions']
+ );
+} );
$c['formatter.recentchanges'] = $c->share( function( $c ) {
return new Flow\Formatter\RecentChanges(
$c['permissions'],
diff --git a/handlebars/Makefile b/handlebars/Makefile
index 32e970e..f8ebe94 100644
--- a/handlebars/Makefile
+++ b/handlebars/Makefile
@@ -9,6 +9,7 @@
flow_block_topiclist.html.handlebars.php \
flow_block_topic.html.handlebars.php \
flow_block_board-history.html.handlebars.php \
+ flow_block_topicsummary_edit.html.handlebars.php \
flow_board.html.handlebars.php \
flow_post.html.handlebars.php \
timestamp.html.handlebars.php
@@ -16,6 +17,9 @@
flow_block_header.html.handlebars.php: flow_block_header.html.handlebars
$(COMPILE) flow_block_header
+flow_block_topicsummary_edit.html.handlebars.php:
flow_block_topicsummary_edit.html.handlebars
+ $(COMPILE) flow_block_topicsummary_edit
+
flow_board_collapsers_subcomponent.html.handlebars.php:
flow_board_collapsers_subcomponent.html.handlebars
$(COMPILE) flow_board_collapsers_subcomponent
diff --git a/handlebars/flow_block_topicsummary_edit.html.handlebars
b/handlebars/flow_block_topicsummary_edit.html.handlebars
new file mode 100644
index 0000000..0babf0d
--- /dev/null
+++ b/handlebars/flow_block_topicsummary_edit.html.handlebars
@@ -0,0 +1,30 @@
+<div class="flow-board-header">
+ {{#if errors}}
+ <ul>
+ {{#each errors}}
+ <li>{{message}}</li>
+ {{/each}}
+ </ul>
+ {{/if}}
+ <form class="flow-edit-form" data-flow-initial-state="collapsed"
method="POST" action="{{revision.actions.edit.url}}">
+ <input type="hidden" name="wpEditToken" value="{{editToken}}" />
+ {{#if revision.previousRevisionId}}
+ <input type="hidden" name="{{type}}_prev_revision"
value="{{revision.previousRevisionId}}" />
+ {{/if}}
+ <textarea name="{{type}}_summary" data-flow-expandable="true"
class="mw-ui-input" type="text">
+ {{~#if submitted && submitted.content~}}
+ {{~submitted.content~}}
+ {{~else~}}
+ {{~#if revision.revisionId~}}
+ {{~revision.content~}}
+ {{~/if~}}
+ {{~/if~}}
+ </textarea>
+ <div class="flow-form-actions flow-form-collapsible">
+ <button data-role="submit" class="flow-ui-button
flow-ui-constructive">{{l10n "Summarize"}}</button>
+ <button data-role="action" class="flow-ui-button
flow-ui-progressive flow-ui-quiet">{{l10n "Preview"}}</button>
+ <button data-flow-interactive-handler="cancelForm"
data-role="cancel" class="flow-ui-button flow-ui-destructive
flow-ui-quiet">{{l10n "Cancel"}}</button>
+ <small class="flow-terms-of-use plainlinks">{{l10n
"summarize_TOU"}}</small>
+ </div>
+ </form>
+</div>
diff --git a/handlebars/flow_block_topicsummary_edit.html.handlebars.php
b/handlebars/flow_block_topicsummary_edit.html.handlebars.php
new file mode 100644
index 0000000..ad95f80
--- /dev/null
+++ b/handlebars/flow_block_topicsummary_edit.html.handlebars.php
@@ -0,0 +1,40 @@
+<?php return function ($in) {
+ $cx = Array(
+ 'flags' => Array(
+ 'jstrue' => false,
+ 'jsobj' => false,
+ 'spvar' => true,
+ ),
+ 'helpers' => Array( 'l10n' => 'Flow\TemplateHelper::l10n',
+),
+ 'blockhelpers' => Array(),
+ 'scopes' => Array($in),
+ 'sp_vars' => Array(),
+ 'path' => Array(),
+
+ );
+ return '<div class="flow-board-header">
+ '.((LCRun2::ifvar(((is_array($in) && isset($in['errors'])) ?
$in['errors'] : null))) ? '
+ <ul>
+ '.LCRun2::sec(((is_array($in) && isset($in['errors']))
? $in['errors'] : null), $cx, $in, true, function($cx, $in) {return '
+ <li>'.htmlentities(((is_array($in) &&
isset($in['message'])) ? $in['message'] : null), ENT_QUOTES, 'UTF-8').'</li>
+ ';}).'
+ </ul>
+ ' : '').'
+ <form class="flow-edit-form" data-flow-initial-state="collapsed"
method="POST"
action="'.htmlentities(((is_array($in['revision']['actions']['edit']) &&
isset($in['revision']['actions']['edit']['url'])) ?
$in['revision']['actions']['edit']['url'] : null), ENT_QUOTES, 'UTF-8').'">
+ <input type="hidden" name="wpEditToken"
value="'.htmlentities(((is_array($in) && isset($in['editToken'])) ?
$in['editToken'] : null), ENT_QUOTES, 'UTF-8').'" />
+ '.((LCRun2::ifvar(((is_array($in['revision']) &&
isset($in['revision']['previousRevisionId'])) ?
$in['revision']['previousRevisionId'] : null))) ? '
+ <input type="hidden"
name="'.htmlentities(((is_array($in) && isset($in['type'])) ? $in['type'] :
null), ENT_QUOTES, 'UTF-8').'_prev_revision"
value="'.htmlentities(((is_array($in['revision']) &&
isset($in['revision']['previousRevisionId'])) ?
$in['revision']['previousRevisionId'] : null), ENT_QUOTES, 'UTF-8').'" />
+ ' : '').'
+ <textarea name="'.htmlentities(((is_array($in) &&
isset($in['type'])) ? $in['type'] : null), ENT_QUOTES, 'UTF-8').'_summary"
data-flow-expandable="true" class="mw-ui-input"
type="text">'.((LCRun2::ifvar(((is_array($in) && isset($in['submitted'])) ?
$in['submitted'] : null))) ? ''.htmlentities(((is_array($in['submitted']) &&
isset($in['submitted']['content'])) ? $in['submitted']['content'] : null),
ENT_QUOTES, 'UTF-8').'' : ''.((LCRun2::ifvar(((is_array($in['revision']) &&
isset($in['revision']['revisionId'])) ? $in['revision']['revisionId'] : null)))
? ''.htmlentities(((is_array($in['revision']) &&
isset($in['revision']['content'])) ? $in['revision']['content'] : null),
ENT_QUOTES, 'UTF-8').'' : '').'').'</textarea>
+ <div class="flow-form-actions flow-form-collapsible">
+ <button data-role="submit" class="flow-ui-button
flow-ui-constructive">'.LCRun2::ch('l10n', Array('Summarize'), 'enc',
$cx).'</button>
+ <button data-role="action" class="flow-ui-button
flow-ui-progressive flow-ui-quiet">'.LCRun2::ch('l10n', Array('Preview'),
'enc', $cx).'</button>
+ <button data-flow-interactive-handler="cancelForm"
data-role="cancel" class="flow-ui-button flow-ui-destructive
flow-ui-quiet">'.LCRun2::ch('l10n', Array('Cancel'), 'enc', $cx).'</button>
+ <small class="flow-terms-of-use
plainlinks">'.LCRun2::ch('l10n', Array('summarize_TOU'), 'enc', $cx).'</small>
+ </div>
+ </form>
+</div>
+';
+}
+?>
\ No newline at end of file
diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php
index 134bca6..a80a412 100644
--- a/includes/Block/TopicSummary.php
+++ b/includes/Block/TopicSummary.php
@@ -7,6 +7,7 @@
use Flow\Exception\InvalidActionException;
use Flow\Exception\InvalidDataException;
use Flow\Exception\InvalidInputException;
+use Flow\Formatter\FormatterRow;
use Flow\Model\AbstractRevision;
use Flow\Model\PostRevision;
use Flow\Model\PostSummary;
@@ -20,6 +21,11 @@
* @var PostSummary|null
*/
protected $topicSummary;
+
+ /**
+ * @var FormatterRow
+ */
+ protected $formatterRow;
/**
* Allows or denies actions to be performed
@@ -48,11 +54,16 @@
*/
protected $supportedGetActions = array( 'topic-summary-view',
'compare-postsummary-revisions', 'edit-topic-summary' );
+ /**
+ * @var string[]
+ */
+ protected $requiresWikitext = array( 'edit-topic-summary' );
+
// @Todo - fill in the template names
protected $templates = array(
'topic-summary-view' => '',
'compare-postsummary-revisions' => '',
- 'edit-topic-summary' => '',
+ 'edit-topic-summary' => 'edit',
);
/**
@@ -64,13 +75,9 @@
$this->permissions = new RevisionActionPermissions(
Container::get( 'flow_actions' ), $user );
if ( !$this->workflow->isNew() ) {
- $found = $this->storage->find(
- 'PostSummary',
- array( 'rev_type_id' =>
$this->workflow->getId() ),
- array( 'sort' => 'rev_id', 'order' => 'DESC',
'limit' => 1 )
- );
- if ( $found ) {
- $this->topicSummary = reset( $found );
+ $this->formatterRow = Container::get(
'query.postsummary' )->getResult( $this->workflow->getId() );
+ if ( $this->formatterRow ) {
+ $this->topicSummary =
$this->formatterRow->revision;
}
}
}
@@ -238,67 +245,10 @@
* Render for an action
* @param Templating
* @param array
- * @throws InvalidActionException
+ * @throws InvalidInputException
*/
public function render( Templating $templating, array $options, $return
= false ) {
- $output = $templating->getOutput();
- $output->addModuleStyles( array( 'ext.flow.discussion.styles',
'ext.flow.moderation' ) );
- $output->addModules( array( 'ext.flow.discussion' ) );
- $title = $templating->getContent( $this->findTopicTitle(),
'wikitext' );
- $output->setHtmlTitle( $title );
- $output->setPageTitle( $title );
-
- $prefix = $templating->render(
- 'flow:topic-permalink-warning.html.php',
- array(
- 'block' => $this,
- ),
- $return
- );
-
- switch( $this->action ) {
- case 'compare-postsummary-revisions':
- if ( !isset( $options['newRevision'] ) ) {
- throw new InvalidInputException( 'A
revision must be provided for comparison', 'revision-comparison' );
- }
- $revisionView =
PostSummaryRevisionView::newFromId( $options['newRevision'], $templating,
$this, $this->user );
- if ( !$revisionView ) {
- throw new InvalidInputException( 'An
invalid revision was provided for comparison', 'revision-comparison' );
- }
-
- if ( isset( $options['oldRevision'] ) ) {
- return $prefix .
$revisionView->renderDiffViewAgainst( $options['oldRevision'], $return );
- } else {
- return $prefix .
$revisionView->renderDiffViewAgainstPrevious( $return );
- }
- break;
-
- case 'topic-summary-view':
- $revisionView = null;
- if ( isset( $options['revId'] ) ) {
- $revisionView =
PostSummaryRevisionView::newFromId( $options['revId'], $templating, $this,
$this->user );
- }
- if ( !$revisionView ) {
- throw new InvalidInputException( 'The
requested revision could not be found', 'missing-revision' );
- } else if ( !$this->permissions->isAllowed(
$revisionView->getRevision(), 'view' ) ) {
- $this->addError( 'moderation',
wfMessage( 'flow-error-not-allowed' ) );
- return null;
- }
- return $prefix .
$revisionView->renderSingleView( $return );
- break;
-
- case 'edit-topic-summary':
- return $templating->render(
'flow:edit-topic-summary.html.php', array(
- 'block' => $this,
- 'workflow' => $this->getWorkflow(),
- 'topicSummary' => $this->topicSummary,
- 'user' => $this->user,
- ), $return );
- break;
-
- default:
- throw new InvalidActionException( "Unexpected
action: {$this->action}", 'invalid-action' );
- }
+ throw new InvalidInputException( 'deprecated' );
}
/**
@@ -309,27 +259,41 @@
* @return array
*/
public function renderAPI( Templating $templating, array $options ) {
- $output = array( 'type' => 'topicsummary' );
+ $output = array( 'type' => $this->getName() );
- if ( $this->topicSummary !== null ) {
- if ( isset( $options['contentFormat'] ) ) {
- $contentFormat = $options['contentFormat'];
- } else {
- $contentFormat =
$this->topicSummary->getContentFormat();
- }
-
- $output['format'] = $contentFormat;
- $output['*'] = $templating->getContent(
$this->topicSummary, $contentFormat );
- $output['topicsummary-id'] =
$this->topicSummary->getRevisionId()->getAlphadecimal();
- } else {
- $output['*'] = '';
- $output['topicsummary-id'] = '';
+ if ( $this->wasSubmitted() ) {
+ $output += array(
+ 'submitted' => $this->submitted,
+ 'errors' => $this->errors,
+ );
}
- return array(
- '_element' => 'topicsummary',
- 0 => $output,
- );
+ $formatter = Container::get( 'formatter.revision' );
+ if ( in_array( $this->action, $this->requiresWikitext ) ) {
+ $formatter->setContentFormat( 'wikitext' );
+ }
+ switch ( $this->action ) {
+ case 'topic-summary-view':
+ case 'edit-topic-summary':
+ if ( $this->formatterRow ) {
+ $output['revision'] =
$formatter->formatApi(
+ $this->formatterRow,
\RequestContext::getMain()
+ );
+ } else {
+
$output['revision']['actions']['edit']['url'] = Container::get( 'url_generator'
)->buildUrl(
+
$this->workflow->getArticleTitle(),
+ 'edit-topic-summary',
+ array(
+ 'workflow' =>
$this->workflow->getId(),
+ )
+ );
+ }
+ break;
+
+ default:
+ throw new InvalidActionException( "Unexpected
action: {$this->action}", 'invalid-action' );
+ }
+ return $output;
}
public function getName() {
diff --git a/includes/Formatter/PostSummaryQuery.php
b/includes/Formatter/PostSummaryQuery.php
new file mode 100644
index 0000000..f926d7e
--- /dev/null
+++ b/includes/Formatter/PostSummaryQuery.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Flow\Formatter;
+
+use Flow\Exception\InvalidDataException;
+use Flow\Model\UUID;
+
+class PostSummaryQuery extends AbstractQuery {
+ /**
+ * @param UUID[] $postIds
+ * @return FormatterRow
+ */
+ public function getResult( UUID $postId ) {
+ $section = new \ProfileSection( __METHOD__ );
+ $found = $this->storage->find(
+ 'PostSummary',
+ array( 'rev_type_id' => $postId ),
+ array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit'
=> 1 )
+ );
+ if ( !$found ) {
+ return null;
+ }
+ $this->loadMetadataBatch( $found );
+
+ return $this->buildResult( reset( $found ), null );
+ }
+}
diff --git a/includes/Formatter/RevisionFormatter.php
b/includes/Formatter/RevisionFormatter.php
index 12efb44..6d1f3fb 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -292,6 +292,18 @@
);
break;
+ case 'edit-topic-summary':
+ $links['edit'] = array(
+ 'url' => $this->urlGenerator->buildUrl(
+ $title,
+ 'edit-topic-summary',
+ array(
+ 'workflow' =>
$workflowId,
+ )
+ ),
+ 'title' => $this->msg(
'flow-summarize-topic-submit' )
+ );
+ break;
case 'edit-header':
$links['edit'] = array(
'url' => $this->urlGenerator->buildUrl(
diff --git a/includes/TemplateHelper.php b/includes/TemplateHelper.php
index 382e932..d2d19aa 100644
--- a/includes/TemplateHelper.php
+++ b/includes/TemplateHelper.php
@@ -168,6 +168,10 @@
$str = 'flow-load-more';
break;
+ case 'Summarize':
+ $str = 'flow-summarize-topic-submit';
+ break;
+
case 'block':
$str = 'blocklink';
break;
@@ -253,6 +257,10 @@
$str = 'flow-terms-of-use-reply';
break;
+ case 'summarize_TOU':
+ $str = 'flow-terms-of-use-summarize';
+ break;
+
case '_time':
break;
--
To view, visit https://gerrit.wikimedia.org/r/130548
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3b13a4333b5860857ec168502d227d028b8c2f6d
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: frontend-rewrite
Gerrit-Owner: Bsitu <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits