Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/196720
Change subject: [WIP] Send requests to RESTbase directly when so configured ...................................................................... [WIP] Send requests to RESTbase directly when so configured Requires a few things done by the API to be done client-side instead based on information in the <head> of the Parsoid HTML. Bug: T90374 Change-Id: I71edbc0f8dc15a6f8d3672c10ca3c641cc172be7 --- M ApiVisualEditor.php M VisualEditor.hooks.php M VisualEditor.php M extension.json M modules/ve-mw/init/ve.init.mw.TargetLoader.js 5 files changed, 69 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/20/196720/1 diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php index 2ec1dae..ea5c71c 100644 --- a/ApiVisualEditor.php +++ b/ApiVisualEditor.php @@ -152,6 +152,7 @@ return array( 'result' => array( 'content' => $content, + // TODO handle these things client-side (get from Parsoid HTML) 'basetimestamp' => $timestamp, 'starttimestamp' => wfTimestampNow(), 'oldid' => $oldid, @@ -374,6 +375,11 @@ switch ( $params['paction'] ) { case 'parse': $parsed = $this->getHTML( $page, $parserParams ); + if ( $parsed === false ) { + $this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' ); + } + + case 'metadata': // Dirty hack to provide the correct context for edit notices global $wgTitle; // FIXME NOOOOOOOOES $wgTitle = $page; @@ -389,6 +395,7 @@ )->parseAsBlock(); } if ( $parsed && $parsed['restoring'] ) { + // TODO move this client-side $notices[] = $this->msg( 'editingold' )->parseAsBlock(); } @@ -539,20 +546,16 @@ // On parser cache miss, just don't bother populating red link data - if ( $parsed === false ) { - $this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' ); - } else { - $result = array_merge( - array( - 'result' => 'success', - 'notices' => $notices, - 'checkboxes' => $checkboxes, - 'links' => $links, - 'protectedClasses' => implode( ' ', $protectedClasses ), - 'watched' => $user->isWatched( $page ) - ), - $parsed['result'] - ); + $result = array( + 'result' => 'success', + 'notices' => $notices, + 'checkboxes' => $checkboxes, + 'links' => $links, + 'protectedClasses' => implode( ' ', $protectedClasses ), + 'watched' => $user->isWatched( $page ) + ); + if ( $params['paction'] === 'parse' ) { + $result = array_merge( $result, $parsed['result'] ); } break; @@ -669,6 +672,7 @@ ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_TYPE => array( 'parse', + 'metadata', 'parsefragment', 'serialize', 'serializeforcache', diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 2346f12..2bf7fcc 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -414,6 +414,7 @@ 'enableTocWidget' => $veConfig->get( 'VisualEditorEnableTocWidget' ), 'svgMaxSize' => $coreConfig->get( 'SVGMaxSize' ), 'namespacesWithSubpages' => $coreConfig->get( 'NamespacesWithSubpages' ), + 'restbaseUrl' => $coreConfig->get( 'VisualEditorRestbaseURL' ), ); return true; diff --git a/VisualEditor.php b/VisualEditor.php index 15e6d17..6c777ae 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -1590,6 +1590,15 @@ // Serialization cache timeout, in seconds $wgVisualEditorSerializationCacheTimeout = 3600; +// URL to RESTbase. The page name will be appended directly to this value, so this needs to be set +// to something like 'https://rest.wikimedia.org/en.wikpedia.org/v1/page/html/' including the +// trailing slash. +// +// If this is set, the page HTML will be requested from RESTbase. If this is not set, the page HTML +// will be requested from the API, which will send an HTTP request to Parsoid or to RESTbase +// if available. +$wgVisualEditorRestbaseURL = false; + // Namespaces to enable VisualEditor in $wgVisualEditorNamespaces = array_merge( $wgContentNamespaces, array( NS_USER ) ); diff --git a/extension.json b/extension.json index 4751164..f7c16ce 100644 --- a/extension.json +++ b/extension.json @@ -94,6 +94,7 @@ }, "VisualEditorTabPosition": "before", "VisualEditorParsoidURL": "http://localhost:8000", + "VisualEditorRestbaseURL": false, "VisualEditorEnableTocWidget": false, "VisualEditorNamespaces": [], "VisualEditorParsoidTimeout": 100 diff --git a/modules/ve-mw/init/ve.init.mw.TargetLoader.js b/modules/ve-mw/init/ve.init.mw.TargetLoader.js index 450b893..9c86d28 100644 --- a/modules/ve-mw/init/ve.init.mw.TargetLoader.js +++ b/modules/ve-mw/init/ve.init.mw.TargetLoader.js @@ -94,10 +94,10 @@ * @return {jQuery.Promise} Abortable promise resolved with a JSON object */ requestPageData: function ( pageName, oldid ) { - var start, xhr, + var start, apiXhr, restbaseXhr, apiPromise, restbasePromise, dataPromise, data = { action: 'visualeditor', - paction: 'parse', + paction: conf.restbaseUrl ? 'metadata' : 'parse', page: pageName, uselang: mw.config.get( 'wgUserLanguage' ) }; @@ -111,19 +111,51 @@ } // Load DOM start = ve.now(); - ve.track( 'trace.domLoad.enter' ); + ve.track( 'trace.apiLoad.enter' ); - xhr = new mw.Api().get( data ); - return xhr.then( function ( data, jqxhr ) { - ve.track( 'mwtiming.performance.system.domLoad', { + apiXhr = new mw.Api().get( data ); + apiPromise = apiXhr.then( function ( data, jqxhr ) { + ve.track( 'trace.apiLoad.exit' ); + ve.track( 'mwtiming.performance.system.apiLoad', { bytes: $.byteLength( jqxhr.responseText ), duration: ve.now() - start, cacheHit: /hit/i.test( jqxhr.getResponseHeader( 'X-Cache' ) ), parsoid: jqxhr.getResponseHeader( 'X-Parsoid-Performance' ) } ); - ve.track( 'trace.domLoad.exit' ); return data; - } ).promise( { abort: xhr.abort } ); + } ); + + if ( conf.restbaseUrl ) { + ve.track( 'trace.restbaseLoad.enter' ); + restbaseXhr = $.ajax( { + url: conf.restbaseUrl + encodeURIComponent( pageName ) + + ( oldid === undefined ? '' : '/' + oldid ), + type: 'GET', + dataType: 'text' + } ); + restbasePromise = restbaseXhr.then( function ( data, status, jqxhr ) { + ve.track( 'trace.restbaseLoad.exit' ); + ve.track( 'mwtiming.performance.system.restbaseLoad', { + bytes: $.byteLength( jqxhr.responseText ), + duration: ve.now() - start + } ); + return data; + } ); + + dataPromise = $.when( apiPromise, restbasePromise ) + .then( function ( apiData, restbaseHtml ) { + apiData.content = restbaseHtml; + return apiData; + } ) + .promise( { abort: function () { + apiXhr.abort(); + restbaseXhr.abort(); + } } ); + } else { + dataPromise = apiPromise.promise( { abort: apiXhr.abort } ); + } + + return dataPromise; } }; }() ); -- To view, visit https://gerrit.wikimedia.org/r/196720 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I71edbc0f8dc15a6f8d3672c10ca3c641cc172be7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Catrope <roan.katt...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits