Matthias Mullie has uploaded a new change for review.

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


Change subject: Use page-less Parsoid API for Flow
......................................................................

Use page-less Parsoid API for Flow

Relevant Parsoid change at https://gerrit.wikimedia.org/r/#/c/91321/

Bug: 55682
Change-Id: I0cbb164f9ec7cb269b77f765bfdadee074b3770c
---
M includes/ParsoidUtils.php
1 file changed, 20 insertions(+), 26 deletions(-)


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

diff --git a/includes/ParsoidUtils.php b/includes/ParsoidUtils.php
index 280d272..820d71c 100644
--- a/includes/ParsoidUtils.php
+++ b/includes/ParsoidUtils.php
@@ -36,43 +36,37 @@
         * @return string
         */
        protected static function parsoid( $from, $to, $content ) {
-               if ( !class_exists( 'ApiVisualEditor' ) ) {
-                       throw new \MWException( 'VisualEditor is unavailable' );
-               }
+               global $wgVisualEditorParsoidURL, $wgVisualEditorParsoidPrefix, 
$wgVisualEditorParsoidTimeout;
 
-               if ( $to === 'html' ) {
-                       $action = 'parsefragment';
-               } elseif ( $to === 'wikitext' ) {
-                       $action = 'serialize';
+               if ( $from == 'html' ) {
+                       $from = 'html';
+               } elseif ( in_array( $from, array( 'wt', 'wikitext' ) ) ) {
+                       $from = 'wt';
                } else {
                        throw new \MWException( 'Unknown format: '. $to );
                }
 
-               global $wgRequest;
-               $params = new \DerivativeRequest(
-                       $wgRequest,
+               $response = \Http::post(
+                       $wgVisualEditorParsoidURL . '/' . 
$wgVisualEditorParsoidPrefix . '/',
                        array(
-                               'action' => 'visualeditor',
-                               'page' => \SpecialPage::getTitleFor( 'Flow' 
)->getPrefixedDBkey(),
-                               // 'basetimestamp' => ?,
-                               // 'starttimestamp' => ?,
-                               'paction' => $action,
-                               'oldid' => '',
-                               $from => $content,
-                       ),
-                       true // POST
+                               'postData' => array( $from => $content ),
+                               'timeout' => $wgVisualEditorParsoidTimeout
+                       )
                );
 
-               wfDebugLog( __CLASS__, __FUNCTION__ . ": Roundtripping parsoid 
for $from => $to" );
-               $api = new \ApiMain( $params, true );
-               $api->execute();
-               $result = $api->getResultData();
+               // Full HTML document is returned, we only want what's inside 
<body>
+               if ( $to == 'html' ) {
+                       $dom = new \DOMDocument();
+                       $dom->loadHTML( $response );
+                       $body = $dom->getElementsByTagName( 'body' )->item(0);
 
-               if ( !isset( $result['visualeditor']['content'] ) ) {
-                       throw new \MWException( 'Unable to parse content' );
+                       $response = '';
+                       foreach( $body->childNodes as $child ) {
+                               $response .= $child->ownerDocument->saveXML( 
$child );
+                       }
                }
 
-               return $result['visualeditor']['content'];
+               return $response;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0cbb164f9ec7cb269b77f765bfdadee074b3770c
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