From 0b0d8d6266a5c76fc17de79217481e635505479a Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 14 Sep 2017 15:01:32 +0100 Subject: [PATCH] ApiVisualEditorEdit: Make tryDeflate public and static So other extensions can use it, e.g. ContentTranslation. Eventually we could upstream some of these document editing APIs. Change-Id: I1e4925c7302fbe90ab4f9380c5efb83c9c379609 --- ApiVisualEditorEdit.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php index b48c24e8a5..5ab517d000 100644 --- a/ApiVisualEditorEdit.php +++ b/ApiVisualEditorEdit.php @@ -118,14 +118,19 @@ class ApiVisualEditorEdit extends ApiVisualEditor { ]; } - protected function tryDeflate( $content ) { + public static function tryDeflate( $content ) { if ( substr( $content, 0, 11 ) === 'rawdeflate,' ) { $deflated = base64_decode( substr( $content, 11 ) ); MediaWiki\suppressWarnings(); $inflated = gzinflate( $deflated ); MediaWiki\restoreWarnings(); if ( $deflated === $inflated || $inflated === false ) { - $this->dieWithError( 'apierror-visualeditor-invaliddeflate', 'invaliddeflate' ); + // Static equivalent of $this->dieWithError + throw ApiUsageException::newWithMessage( + null, + 'apierror-visualeditor-invaliddeflate', + 'invaliddeflate' + ); } return $inflated; } @@ -147,7 +152,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor { protected function getWikitextNoCache( $title, $params, $parserParams ) { $this->requireOnlyOneParameter( $params, 'html' ); $wikitext = $this->postHTML( - $title, $this->tryDeflate( $params['html'] ), $parserParams, $params['etag'] + $title, self::tryDeflate( $params['html'] ), $parserParams, $params['etag'] ); if ( $wikitext === false ) { $this->dieWithError( 'apierror-visualeditor-docserver', 'docserver' );