Esanders has uploaded a new change for review.

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

Change subject: Factor out API deflation and change storeInSerializationCache 
API
......................................................................

Factor out API deflation and change storeInSerializationCache API

Change-Id: I7e2e15a8ba5088e6c370cb035c71f7af18c13b61
---
M ApiVisualEditor.php
M ApiVisualEditorEdit.php
2 files changed, 14 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/32/303932/1

diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index 896b87b..2650a57 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -123,24 +123,22 @@
                return $response['body'];
        }
 
-       protected function storeInSerializationCache( $title, $oldid, $html, 
$etag ) {
+       protected function storeInSerializationCache( $title, $wikitext ) {
                global $wgMemc;
 
-               // Convert the VE HTML to wikitext
-               $text = $this->postHTML( $title, $html, [ 'oldid' => $oldid ], 
$etag );
-               if ( $text === false ) {
+               if ( $wikitext === false ) {
                        return false;
                }
 
                // Store the corresponding wikitext, referenceable by a new key
-               $hash = md5( $text );
+               $hash = md5( $wikitext );
                $key = wfMemcKey( 'visualeditor', 'serialization', $hash );
-               $wgMemc->set( $key, $text,
+               $wgMemc->set( $key, $wikitext,
                        $this->veConfig->get( 
'VisualEditorSerializationCacheTimeout' ) );
 
                // Also parse and prepare the edit in case it might be saved 
later
                $page = WikiPage::factory( $title );
-               $content = ContentHandler::makeContent( $text, $title, 
CONTENT_MODEL_WIKITEXT );
+               $content = ContentHandler::makeContent( $wikitext, $title, 
CONTENT_MODEL_WIKITEXT );
 
                $status = ApiStashEdit::parseAndStash( $page, $content, 
$this->getUser(), '' );
                if ( $status === ApiStashEdit::ERROR_NONE ) {
@@ -167,7 +165,7 @@
                        $path .= '/' . $parserParams['oldid'];
                }
                if ( !is_string( $etag ) || $etag === '' ) {
-                       wfDebugLog( 'AdHocDebug', 'VisualEditr T135171 - bad 
etag: ' . var_export( $etag, true ) );
+                       wfDebugLog( 'AdHocDebug', 'VisualEditor T135171 - bad 
etag: ' . var_export( $etag, true ) );
                }
                return $this->requestRestbase(
                        'POST',
@@ -303,17 +301,6 @@
                $parserParams = [];
                if ( isset( $params['oldid'] ) ) {
                        $parserParams['oldid'] = $params['oldid'];
-               }
-
-               $html = $params['html'];
-               if ( substr( $html, 0, 11 ) === 'rawdeflate,' ) {
-                       $deflated = base64_decode( substr( $html, 11 ) );
-                       wfSuppressWarnings();
-                       $html = gzinflate( $deflated );
-                       wfRestoreWarnings();
-                       if ( $deflated === $html || $html === false ) {
-                               $this->dieUsage( "HTML provided is not properly 
deflated", 'invaliddeflate' );
-                       }
                }
 
                wfDebugLog( 'visualeditor', "called on '$title' with paction: 
'{$params['paction']}'" );
@@ -582,7 +569,7 @@
                                        if ( $params['html'] === null ) {
                                                $this->dieUsageMsg( 
'missingparam', 'html' );
                                        }
-                                       $content = $this->postHTML( $title, 
$html, $parserParams, $params['etag'] );
+                                       $content = $this->postHTML( $title, 
$this->tryDeflate( $params['html'] ), $parserParams, $params['etag'] );
                                        if ( $content === false ) {
                                                $this->dieUsage( 'Error 
contacting the document server', 'docserver' );
                                        }
@@ -597,7 +584,7 @@
                                                $this->dieUsage( 'No cached 
serialization found with that key', 'badcachekey' );
                                        }
                                } else {
-                                       $wikitext = $this->postHTML( $title, 
$html, $parserParams, $params['etag'] );
+                                       $wikitext = $this->postHTML( $title, 
$this->tryDeflate( $params['html'] ), $parserParams, $params['etag'] );
                                        if ( $wikitext === false ) {
                                                $this->dieUsage( 'Error 
contacting the document server', 'docserver' );
                                        }
@@ -615,11 +602,13 @@
                                if ( !isset( $parserParams['oldid'] ) ) {
                                        $parserParams['oldid'] = 
Revision::newFromTitle( $title )->getId();
                                }
+                               if ( $params['html'] === null ) {
+                                       $this->dieUsageMsg( 'missingparam', 
'html' );
+                               }
+                               $wikitext = $this->postHTML( $title, 
$this->tryDeflate( $params['html'] ), $parserParams, $params['etag'] );
                                $key = $this->storeInSerializationCache(
                                        $title,
-                                       $parserParams['oldid'],
-                                       $html,
-                                       $params['etag']
+                                       $wikitext
                                );
                                $result = [ 'result' => 'success', 'cachekey' 
=> $key ];
                                break;
diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php
index 32e2b1f..2076e18 100644
--- a/ApiVisualEditorEdit.php
+++ b/ApiVisualEditorEdit.php
@@ -134,18 +134,13 @@
                        $parserParams['oldid'] = $params['oldid'];
                }
 
-               $html = $params['html'];
-               if ( substr( $html, 0, 11 ) === 'rawdeflate,' ) {
-                       $html = gzinflate( base64_decode( substr( $html, 11 ) ) 
);
-               }
-
                if ( $params['cachekey'] !== null ) {
                        $wikitext = $this->trySerializationCache( 
$params['cachekey'] );
                        if ( !is_string( $wikitext ) ) {
                                $this->dieUsage( 'No cached serialization found 
with that key', 'badcachekey' );
                        }
                } else {
-                       $wikitext = $this->postHTML( $title, $html, 
$parserParams, $params['etag'] );
+                       $wikitext = $this->postHTML( $title, $this->tryDeflate( 
$params['html'] ), $parserParams, $params['etag'] );
                        if ( $wikitext === false ) {
                                $this->dieUsage( 'Error contacting the 
Parsoid/RESTbase server', 'docserver' );
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e2e15a8ba5088e6c370cb035c71f7af18c13b61
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

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

Reply via email to