jenkins-bot has submitted this change and it was merged.

Change subject: Factor out getWikitext in ApiVisualEditorEdit
......................................................................


Factor out getWikitext in ApiVisualEditorEdit

Change-Id: I0f6709f170034263acc94daa41603bcc77897d31
---
M ApiVisualEditorEdit.php
1 file changed, 36 insertions(+), 32 deletions(-)

Approvals:
  Alex Monk: Looks good to me, approved
  jenkins-bot: Verified

Objections:
  Jforrester: There's a problem with this change, please improve



diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php
index 1211bdc..22a4766 100644
--- a/ApiVisualEditorEdit.php
+++ b/ApiVisualEditorEdit.php
@@ -127,6 +127,29 @@
                return $content;
        }
 
+       protected function getWikitext( $title, $params, $parserParams ) {
+               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->getWikitextNoCache( $title, $params, 
$parserParams );
+               }
+               return $wikitext;
+       }
+
+       protected function getWikitextNoCache( $title, $params, $parserParams ) 
{
+               $this->requireOnlyOneParameter( $params, 'html' );
+               $wikitext = $this->postHTML(
+                       $title, $this->tryDeflate( $params['html'] ), 
$parserParams, $params['etag']
+               );
+               if ( $wikitext === false ) {
+                       $this->dieUsage( 'Error contacting the document 
server', 'docserver' );
+               }
+               return $wikitext;
+       }
+
        protected function storeInSerializationCache( $title, $wikitext ) {
                global $wgMemc;
 
@@ -160,22 +183,24 @@
                return $wgMemc->get( $key );
        }
 
-       protected function postHTML( $title, $html, $parserParams, $etag ) {
+       protected function postData( $path, $title, $data, $parserParams, $etag 
) {
                if ( $parserParams['oldid'] === 0 ) {
                        $parserParams['oldid'] = '';
                }
-               $path = 'transform/html/to/wikitext/' . urlencode( 
$title->getPrefixedDBkey() );
+               $path .= urlencode( $title->getPrefixedDBkey() );
                if ( $parserParams['oldid'] ) {
                        $path .= '/' . $parserParams['oldid'];
                }
                return $this->requestRestbase(
-                       'POST',
-                       $path,
-                       [
-                               'html' => $html,
-                               'scrub_wikitext' => 1,
-                       ],
+                       'POST', $path, $data,
                        [ 'If-Match' => $etag ]
+               );
+       }
+
+       protected function postHTML( $title, $html, $parserParams, $etag ) {
+               return $this->postData(
+                       'transform/html/to/wikitext/', $title,
+                       [ 'html' => $html, 'scrub_wikitext' => 1 ], 
$parserParams, $etag
                );
        }
 
@@ -236,30 +261,9 @@
                        $parserParams['oldid'] = $params['oldid'];
                }
 
-               if (
-                       $params['paction'] !== 'serialize' &&
-                       $params['paction'] !== 'serializeforcache' &&
-                       $params['wikitext'] !== null
-               ) {
-                       // Get wikitext from param
-                       $wikitext = $params['wikitext'];
-               } elseif ( $params['paction'] !== 'serializeforcache' && 
$params['cachekey'] !== null ) {
-                       // Get wikitext from cachekey
-                       $wikitext = $this->trySerializationCache( 
$params['cachekey'] );
-                       if ( !is_string( $wikitext ) ) {
-                               $this->dieUsage( 'No cached serialization found 
with that key', 'badcachekey' );
-                       }
-               } else {
-                       // Get wikitext by parsing HTML
-                       if ( $params['html'] === null ) {
-                               $this->dieUsageMsg( 'missingparam', 'html' );
-                       }
-                       $wikitext = $this->postHTML(
-                               $title, $this->tryDeflate( $params['html'] ), 
$parserParams, $params['etag']
-                       );
-                       if ( $wikitext === false ) {
-                               $this->dieUsage( 'Error contacting the 
Parsoid/RESTbase server', 'docserver' );
-                       }
+               $wikitext = $params['wikitext'];
+               if ( !$wikitext ) {
+                       $wikitext = $this->getWikitext( $title, $params, 
$parserParams );
                }
 
                if ( $params['paction'] === 'serialize' ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0f6709f170034263acc94daa41603bcc77897d31
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Alex Monk <a...@wikimedia.org>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to