[MediaWiki-commits] [Gerrit] edit-post action for Topic block - change (mediawiki...Flow)

2013-08-15 Thread EBernhardson (WMF) (Code Review)
EBernhardson (WMF) has submitted this change and it was merged.

Change subject: edit-post action for Topic block
..


edit-post action for Topic block

Includes some refactoring of Parsoid, and a few other unrelated changes.

Change-Id: Ie62ff67ae09ec131ae49acce3ffe779311203842
---
M Flow.i18n.php
M Flow.php
M includes/Block/Topic.php
M includes/Block/TopicList.php
M includes/Model/PostRevision.php
M includes/Model/UUID.php
M includes/Model/Workflow.php
A includes/ParsoidUtils.php
M includes/Templating.php
M includes/UrlGenerator.php
M includes/api/ApiQueryFlow.php
M modules/base/ext.flow.base.js
M modules/discussion/base.css
M modules/discussion/discussion.js
A templates/edit-post.html.php
M templates/post.html.php
M templates/topic.html.php
17 files changed, 502 insertions(+), 117 deletions(-)

Approvals:
  EBernhardson (WMF): Verified; Looks good to me, approved



diff --git a/Flow.i18n.php b/Flow.i18n.php
index 38844e0..2914ba7 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -29,7 +29,13 @@
'flow-reply-placeholder' = 'Click to reply to $1. Be nice!',
'flow-reply-submit' = 'Post Reply',
 
+   'flow-edit-post-submit' = 'Submit changes',
+
+   'flow-post-action-view' = 'Permalink',
+   'flow-post-action-post-history' = 'Post history',
'flow-post-action-delete-post' = 'Delete post',
+   'flow-post-action-edit-post' = 'Edit post',
+   'flow-post-action-edit' = 'Edit',
'flow-post-action-restore-post' = 'Restore post',
'flow-topic-action-edit-title' = 'Edit Title',
 
diff --git a/Flow.php b/Flow.php
index 2ba0fee..10508c5 100755
--- a/Flow.php
+++ b/Flow.php
@@ -40,7 +40,7 @@
'descriptionmsg' = 'flow-desc',
 );
 
-$dir = dirname( __FILE__ ) . '/';
+$dir = __DIR__ . '/';
 $wgExtensionMessagesFiles['Flow'] = $dir . 'Flow.i18n.php';
 
 // Classes fulfilling the mediawiki extension architecture
@@ -51,6 +51,7 @@
 $wgAutoloadClasses['Pimple'] = $dir . 'vendor/Pimple.php';
 $wgAutoloadClasses['Flow\Container'] = $dir . 'includes/Container.php';
 $wgAutoloadClasses['Flow\DbFactory'] = $dir . 'includes/DbFactory.php';
+$wgAutoloadClasses['Flow\ParsoidUtils'] = $dir . 'includes/ParsoidUtils.php';
 $wgAutoloadClasses['Flow\Templating'] = $dir . 'includes/Templating.php';
 $wgAutoloadClasses['Flow\UrlGenerator'] = $dir . 'includes/UrlGenerator.php';
 $wgAutoloadClasses['Flow\WorkflowLoader'] = $dir . 
'includes/WorkflowLoader.php';
@@ -158,6 +159,7 @@
'flow-error-external',
'flow-error-external-multi',
'flow-edit-title-submit',
+   'flow-edit-post-submit',
),
),
 );
@@ -190,6 +192,6 @@
 
 $wgFlowUseParsoid = false;
 $wgFlowParsoidURL = 'http://localhost:8000';
-$wgFlowParsoidPrefix = '_wikitext';
+$wgFlowParsoidPrefix = 'localhost';
 $wgFlowParsoidTimeout = 100;
 
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 59f5a9b..66ddb02 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -8,6 +8,7 @@
 use Flow\Data\ManagerGroup;
 use Flow\Data\RootPostLoader;
 use Flow\DbFactory;
+use Flow\ParsoidUtils;
 use Flow\Templating;
 use User;
 
@@ -17,8 +18,12 @@
protected $topicTitle;
protected $rootLoader;
protected $newRevision;
+   protected $requestedPost;
 
-   protected $supportedActions = array( 'edit-title', 'reply', 
'delete-topic', 'delete-post', 'restore-post' );
+   protected $supportedActions = array(
+   'edit-post', 'delete-post', 'restore-post',
+   'reply', 'delete-topic',
+   );
 
public function __construct( Workflow $workflow, ManagerGroup $storage, 
$root ) {
parent::__construct( $workflow, $storage );
@@ -56,6 +61,10 @@
$this-validateRestorePost();
break;
 
+   case 'edit-post':
+   $this-validateEditPost();
+   break;
+
default:
throw new \MWException( Unexpected action: 
{$this-action} );
}
@@ -80,7 +89,7 @@
if ( empty( $this-submitted['content'] ) ) {
$this-errors['content'] = wfMessage( 
'flow-error-missing-content' );
} else {
-   $this-parsedContent = $this-convertWikitextToHtml5( 
$this-submitted['content'] );
+   $this-parsedContent = 
ParsoidUtils::convertWikitextToHtml5( $this-submitted['content'], 
$this-workflow-getArticleTitle() );
if ( empty( $this-parsedContent ) ) {
$this-errors['content'] = wfMessage( 
'flow-error-parsoid-failure' );
}
@@ -153,45 +162,25 @@
}
}
 
-   // @todo: I assume not only topic reply, but also TopicListBlock  
SummaryBlock's content need to 

[MediaWiki-commits] [Gerrit] edit-post action for Topic block - change (mediawiki...Flow)

2013-08-12 Thread EBernhardson (WMF) (Code Review)
EBernhardson (WMF) has uploaded a new change for review.

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


Change subject: edit-post action for Topic block
..

edit-post action for Topic block

Change-Id: Ie62ff67ae09ec131ae49acce3ffe779311203842
---
M Flow.php
M container.php
M includes/Block/Topic.php
A templates/edit-post.html.php
M templates/topic.html.php
5 files changed, 142 insertions(+), 27 deletions(-)


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

diff --git a/Flow.php b/Flow.php
index 6df3ccb..f5be5aa 100755
--- a/Flow.php
+++ b/Flow.php
@@ -40,7 +40,7 @@
'descriptionmsg' = 'flow-desc',
 );
 
-$dir = dirname( __FILE__ ) . '/';
+$dir = __DIR__ . '/';
 $wgExtensionMessagesFiles['Flow'] = $dir . 'Flow.i18n.php';
 
 // Classes fulfilling the mediawiki extension architecture
diff --git a/container.php b/container.php
index d2665cc..401f24f 100644
--- a/container.php
+++ b/container.php
@@ -33,7 +33,11 @@
 $c['templating.namespaces'] = array(
'flow' = __DIR__ . '/templates',
 );
-$c['templating.global_variables'] = array();
+$c['templating.global_variables'] = $c-share( function( $c ) {
+   return array(
+   'user' = $c['user'],
+   );
+} );
 $c['templating'] = $c-share( function( $c ) {
return new Flow\Templating(
$c['url_generator'],
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 1266d03..32d0f3b 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -16,8 +16,12 @@
protected $root;
protected $rootLoader;
protected $newRevision;
+   protected $requestedPost;
 
-   protected $supportedActions = array( 'reply', 'delete-topic', 
'delete-post', 'restore-post' );
+   protected $supportedActions = array(
+   'delete-post', 'restore-post', 'edit-post',
+   'reply', 'delete-topic',
+   );
 
public function __construct( Workflow $workflow, ManagerGroup $storage, 
$root ) {
parent::__construct( $workflow, $storage );
@@ -49,6 +53,10 @@
 
case 'restore-post':
$this-validateRestorePost();
+   break;
+
+   case 'edit-post':
+   $this-validateEditPost();
break;
 
default:
@@ -133,6 +141,28 @@
}
}
 
+   protected function validateEditPost() {
+   if ( empty( $this-submitted['postId'] ) ) {
+   $this-errors['edit-post'] = wfMessage( 
'flow-no-post-provided' );
+   return;
+   }
+   if ( empty( $this-submitted['content'] ) ) {
+   $this-errors['content'] = wfMessage( 
'flow-missing-post-content' );
+   } else {
+   $this-parsedContent = $this-convertWikitextToHtml5( 
$this-submitted['content'] );
+   if ( empty( $this-parsedContent ) ) {
+   $this-errors['content'] = wfMessage( 
'flow-empty-parsoid-result' );
+   return;
+   }
+   }
+   $post = $this-loadRequestedPost( $this-submitted['postId'] );
+   if ( $post ) {
+   $this-newRevision = $post-newNextRevision( 
$this-user, $this-parsedContent );
+   } else {
+   $this-errors['edit-post'] = wfMessage( 
'flow-post-not-found' );
+   }
+   }
+
// @todo: I assume not only topic reply, but also TopicListBlock  
SummaryBlock's content need to be converted?
protected function convertWikitextToHtml5( $wikitext ) {
global $wgFlowUseParsoid;
@@ -180,6 +210,7 @@
case 'reply':
case 'delete-post':
case 'restore-post':
+   case 'edit-post':
if ( $this-newRevision === null ) {
throw new \MWException( 'Attempt to save null 
revision' );
}
@@ -196,24 +227,47 @@
}
 
public function render( Templating $templating, array $options, $return 
= false ) {
-   if ( $this-action === 'post-history' ) {
-   if ( empty( $options['postId'] ) ) {
-   var_dump( $this-getName() );
-   var_dump( $options );
-   throw new \Exception( 'No postId specified' );
-   $history = array();
-   } else {
-   $history = $this-getHistory( 
$options['postId'] );
-   }
-   return $templating-render( 
flow:post-history.html.php, array(
-   'block' = $this,
-   'topic' =