Matthias Mullie has uploaded a new change for review.

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


Change subject: Editor
......................................................................

Editor

Change-Id: I6a5fb9b066daef4a74ab2e965e92b25131bce58f
---
M Flow.php
A includes/api/ApiQueryRevisionContentFlow.php
M modules/discussion/discussion.js
A modules/editor/ext.flow.editor.js
A modules/editor/ext.flow.none.js
A modules/editor/ext.flow.ve.js
M special/SpecialFlow.php
7 files changed, 220 insertions(+), 4 deletions(-)


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

diff --git a/Flow.php b/Flow.php
index 7ff4339..c3cd3ca 100755
--- a/Flow.php
+++ b/Flow.php
@@ -111,7 +111,9 @@
 
 // API modules
 $wgAutoloadClasses['ApiQueryFlow'] = "$dir/includes/api/ApiQueryFlow.php";
+$wgAutoloadClasses['ApiQueryRevisionContentFlow'] = 
"$dir/includes/api/ApiQueryRevisionContentFlow.php";
 $wgAutoloadClasses['ApiFlow'] = "$dir/includes/api/ApiFlow.php";
+$wgAPIListModules['flow-revision-content'] = 'ApiQueryRevisionContentFlow';
 $wgAPIListModules['flow'] = 'ApiQueryFlow';
 $wgAPIModules['flow'] = 'ApiFlow';
 
@@ -134,7 +136,6 @@
                // 'styles' => 'base/ext.flow.base.css',
                'scripts' => 'base/ext.flow.base.js',
                'dependencies' => array(
-                       'ext.visualEditor.standalone',
                        'mediawiki.api',
                        'jquery.json',
                ),
@@ -150,6 +151,7 @@
                'dependencies' => array(
                        'mediawiki.ui',
                        'ext.flow.base',
+                       'ext.flow.editor',
                ),
                'messages' => array(
                        'flow-newtopic-start-placeholder',
@@ -162,6 +164,23 @@
                        'flow-edit-title-submit',
                        'flow-edit-post-submit',
                ),
+       ),
+       'ext.flow.editor' => $flowResourceTemplate + array(
+               'scripts' => 'editor/ext.flow.editor.js',
+               'dependencies' => array(
+                       'ext.flow.ve',
+                       'ext.flow.none',
+               ),
+       ),
+       'ext.flow.ve' => $flowResourceTemplate + array(
+               'scripts' => 'editor/ext.flow.ve.js',
+               'dependencies' => array(
+                       'ext.visualEditor.standalone',
+                       'ext.visualEditor.core',
+               ),
+       ),
+       'ext.flow.none' => $flowResourceTemplate + array(
+               'scripts' => 'editor/ext.flow.none.js',
        ),
 );
 
@@ -191,7 +210,7 @@
 // use this workflow
 $wgFlowDefaultWorkflow = 'discussion';
 
-$wgFlowUseParsoid = false;
+$wgFlowUseParsoid = true;
 $wgFlowParsoidURL = 'http://localhost:8000';
 $wgFlowParsoidPrefix = 'localhost';
 $wgFlowParsoidTimeout = 100;
diff --git a/includes/api/ApiQueryRevisionContentFlow.php 
b/includes/api/ApiQueryRevisionContentFlow.php
new file mode 100644
index 0000000..1fa3b00
--- /dev/null
+++ b/includes/api/ApiQueryRevisionContentFlow.php
@@ -0,0 +1,65 @@
+<?php
+
+use Flow\Model\UUID;
+
+class ApiQueryRevisionContentFlow extends ApiQueryBase {
+       public function __construct( $query, $moduleName ) {
+               parent::__construct( $query, $moduleName, 'rev' );
+       }
+
+       public function execute() {
+               $params = $this->extractRequestParams();
+
+               $container = include __DIR__ . "/../../container.php";
+               if ( !isset( $container[$params['container']] ) ) {
+                       throw new \MWException( 'Unknown container: '. 
$params['container'] );
+               }
+
+               $post = $container[$params['container']]->find( array( 'rev_id' 
=> UUID::create( $params['id'] ) ) );
+               if ( !isset( $post[0] ) ) {
+                       throw new \MWException( 'Unknown post: '. $params['id'] 
);
+               }
+
+               $result = array(
+                       'html' => $post[0]->getContent(),
+                       'wikitext' => 
\Flow\ParsoidUtils::convertHtml5ToWikitext( $post[0]->getContent() ),
+               );
+               $this->getResult()->addValue( 'query', $this->getModuleName(), 
$result );
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'id' => array(
+                               ApiBase::PARAM_REQUIRED => true,
+                       ),
+                       'container' => array(
+                               ApiBase::PARAM_REQUIRED => true,
+                       ),
+               );
+       }
+
+       public function getParamDescription() {
+               return array(
+                       'id' => 'Hex-encoded rev_id',
+                       'container' => 'Revision storage container',
+               );
+       }
+
+       public function getDescription() {
+               return 'Gets parsed content for Revision objects';
+       }
+
+       public function getExamples() {
+               return array(
+                       
'api.php?action=query&list=flow-revision-content&revid=05021b0a3015fc3eb5dbb8f6b11bc701&revcontainer=storage.post',
+               );
+       }
+
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/Flow_Portal';
+       }
+
+       public function getVersion() {
+               return __CLASS__ . '-0.1';
+       }
+}
diff --git a/modules/discussion/discussion.js b/modules/discussion/discussion.js
index 42403eb..5219a83 100644
--- a/modules/discussion/discussion.js
+++ b/modules/discussion/discussion.js
@@ -152,6 +152,8 @@
                                $(this).closest( 'form' )
                                        .children( '.flow-post-form-extras' )
                                        .show();
+
+                               mw.flow.editor.load( $( this ) );
                        } );
 
                $container.find( '.flow-post-form-extras' )
@@ -174,6 +176,8 @@
                                                        .find( '.flow-error' )
                                                                .remove();
                                        });
+
+                               mw.flow.editor.unload( $( this ) );
                        } )
                        .insertBefore( $container.find('.flow-reply-form 
input[type=submit]') );
 
@@ -279,7 +283,7 @@
                                        .closest( '.flow-post-container' )
                                        .data( 'post-id' );
 
-                               var content = $form.find( '.flow-reply-content' 
).val();
+                               var content = mw.flow.editor.getContent( 
$form.find( '.flow-reply-content' ) );
 
                                return [ workflowId, replyToId, content ];
                        },
diff --git a/modules/editor/ext.flow.editor.js 
b/modules/editor/ext.flow.editor.js
new file mode 100644
index 0000000..be6c8ee
--- /dev/null
+++ b/modules/editor/ext.flow.editor.js
@@ -0,0 +1,60 @@
+( function( $, mw ) {
+mw.flow.editor = {
+       editor: mw.flow.none, // @todo: only VE if enabled, other editor 
otherwise
+
+       init: function() {
+
+       },
+
+       /**
+        * @param jQuery $node
+        * @param string[optional] id 32-char rev_id, to load existing content
+        * @param string[optional] container, to load existing content
+        */
+       load: function( $node, id, container ) {
+               // @todo: check if editor not already loaded
+
+               if ( id && container ) {
+                       new mw.Api()
+                               .get( {
+                                       action: 'query',
+                                       list: 'flow-revision-content',
+                                       revid: id, // 
'05021b0a3015fc3eb5dbb8f6b11bc701'
+                                       revcontainer: container // 
'storage.post'
+                               } )
+                               .done( function( response ) {
+                                       mw.flow.editor.editor.load(
+                                               $node,
+                                               
response.query['flow-revision-content'][mw.flow.editor.editor.contentType]
+                                       );
+                               } )
+                               .fail( function() {
+                                       // @todo: proper error handling
+                                       alert( 'Could not fetch content' );
+                               } );
+               } else {
+                       mw.flow.editor.editor.load(
+                               $node,
+                               ''
+                       );
+               }
+       },
+
+       /**
+        * @param jQuery $node
+        */
+       unload: function( $node ) {
+               mw.flow.editor.editor.unload( $node );
+       },
+
+       /**
+        * @param jQuery $node
+        * @return string
+        */
+       getContent: function( $node ) {
+               return mw.flow.editor.editor.getContent( $node );
+       }
+};
+
+$( mw.flow.editor.init );
+} )( jQuery, mediaWiki );
diff --git a/modules/editor/ext.flow.none.js b/modules/editor/ext.flow.none.js
new file mode 100644
index 0000000..ac0db25
--- /dev/null
+++ b/modules/editor/ext.flow.none.js
@@ -0,0 +1,33 @@
+( function( $, mw ) {
+mw.flow.none = {
+       /**
+        * Type of content to use (html or wikitext)
+        *
+        * @var string
+        */
+       contentType: 'wikitext',
+
+       /**
+        * @param jQuery $node
+        * @param string content
+        */
+       load: function( $node, content ) {
+               $node.val( content );
+       },
+
+       /**
+        * @param jQuery $node
+        */
+       unload: function( $node ) {
+
+       },
+
+       /**
+        * @param jQuery $node
+        * @return string
+        */
+       getContent: function( $node ) {
+               return $node.val();
+       }
+};
+} )( jQuery, mediaWiki );
diff --git a/modules/editor/ext.flow.ve.js b/modules/editor/ext.flow.ve.js
new file mode 100644
index 0000000..db7cbf2
--- /dev/null
+++ b/modules/editor/ext.flow.ve.js
@@ -0,0 +1,35 @@
+( function( $, mw ) {
+mw.flow.ve = {
+       /**
+        * Type of content to use (html or wikitext)
+        *
+        * @var string
+        */
+       contentType: 'html',
+
+       /**
+        * @param jQuery $node
+        * @param string content
+        */
+       load: function( $node, content ) {
+               // ve does not "convert" a textarea
+               $node = $( '<div>' ).insertAfter( $node.hide() );
+               new ve.init.sa.Target( $node, ve.createDocumentFromHtml( 
content ) );
+       },
+
+       /**
+        * @param jQuery $node
+        */
+       unload: function( $node ) {
+               // @todo
+       },
+
+       /**
+        * @param jQuery $node
+        * @return string
+        */
+       getContent: function( $node ) {
+               // @todo
+       }
+};
+} )( jQuery, mediaWiki );
diff --git a/special/SpecialFlow.php b/special/SpecialFlow.php
index cd14148..61c2265 100644
--- a/special/SpecialFlow.php
+++ b/special/SpecialFlow.php
@@ -24,7 +24,7 @@
 
        public function execute( $subPage ) {
                $this->setHeaders();
-               $this->getOutput()->addModules( array('ext.flow.base') );
+               $this->getOutput()->addModules( array( 'ext.flow.base', 
'ext.flow.editor' ) );
                
                if ( empty( $subPage ) ) {
                        // If no specific article was requested, render the 
users flow

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

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

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

Reply via email to