From 509b3db9ba10d7bd6bdf21d1b890ad8414787ddc Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 18 Apr 2014 13:19:54 -0700 Subject: [PATCH] Use Parsoid API for action=parsefragment Bug: 48524 Change-Id: I8a61d2fab87d2a2e88ec2f3bbdef9ede1c7ad773 --- ApiVisualEditor.php | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php index 0536e14528..154ae4cd99 100644 --- a/ApiVisualEditor.php +++ b/ApiVisualEditor.php @@ -161,6 +161,15 @@ class ApiVisualEditor extends ApiBase { ); } + protected function parseWikitextFragment( $title, $wikitext ) { + return $this->requestParsoid( 'POST', $title, + array( + 'wt' => $wikitext, + 'body' => 1, + ) + ); + } + protected function parseWikitext( $title ) { $apiParams = array( 'action' => 'parse', @@ -197,29 +206,6 @@ class ApiVisualEditor extends ApiBase { ); } - protected function parseWikitextFragment( $wikitext, $title = null ) { - $apiParams = array( - 'action' => 'parse', - 'title' => $title, - 'prop' => 'text', - 'disablepp' => true, - 'pst' => true, - 'text' => $wikitext - ); - $api = new ApiMain( - new DerivativeRequest( - $this->getRequest(), - $apiParams, - false // was posted? - ), - true // enable write? - ); - - $api->execute(); - $result = $api->getResultData(); - return isset( $result['parse']['text']['*'] ) ? $result['parse']['text']['*'] : false; - } - protected function diffWikitext( $title, $wikitext ) { $apiParams = array( 'action' => 'query', @@ -426,9 +412,9 @@ class ApiVisualEditor extends ApiBase { break; case 'parsefragment': - $content = $this->parseWikitextFragment( $params['wikitext'], $page->getText() ); + $content = $this->parseWikitextFragment( $page, $params['wikitext'] ); if ( $content === false ) { - $this->dieUsage( 'Error querying MediaWiki API', 'parsoidserver' ); + $this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' ); } else { $result = array( 'result' => 'success',