mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
ApiVisualEditor: Add option to return lint errors from Parsoid
Depends-On: I6bbe2fc5aea07c65eb99768f2c44ed42601792a3 Depends-On: I6bdf5635763ef8a44d44a031c64cd7f289261a32 Change-Id: I723ec766d1244d117f8d624440026fe5af0d3403
This commit is contained in:
parent
108131f4e1
commit
ae86f7290b
|
@ -36,6 +36,7 @@
|
|||
"apihelp-visualeditor-param-etag": "ETag to send.",
|
||||
"apihelp-visualeditor-param-format": "The format of the output.",
|
||||
"apihelp-visualeditor-param-html": "HTML to send to Parsoid to convert to wikitext.",
|
||||
"apihelp-visualeditor-param-lint": "Also return lint errors from Parsoid.",
|
||||
"apihelp-visualeditor-param-oldid": "The revision number to use (defaults to latest revision).",
|
||||
"apihelp-visualeditor-param-paction": "Action to perform.",
|
||||
"apihelp-visualeditor-param-page": "The page to perform actions on.",
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
"apihelp-visualeditor-param-etag": "{{doc-apihelp-param|visualeditor|etag}}",
|
||||
"apihelp-visualeditor-param-format": "{{doc-apihelp-param|visualeditor|format}}",
|
||||
"apihelp-visualeditor-param-html": "{{doc-apihelp-param|visualeditor|html}}",
|
||||
"apihelp-visualeditor-param-lint": "{{doc-apihelp-param|visualeditor|lint}}",
|
||||
"apihelp-visualeditor-param-oldid": "{{doc-apihelp-param|visualeditor|oldid}}",
|
||||
"apihelp-visualeditor-param-paction": "{{doc-apihelp-param|visualeditor|paction}}",
|
||||
"apihelp-visualeditor-param-page": "{{doc-apihelp-param|visualeditor|page}}",
|
||||
|
|
|
@ -109,12 +109,15 @@ class ApiVisualEditor extends ApiBase {
|
|||
$request['body'] = $params;
|
||||
}
|
||||
// Should be synchronised with modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js
|
||||
$reqheaders['Accept'] = 'text/html; charset=utf-8;' .
|
||||
' profile="https://www.mediawiki.org/wiki/Specs/HTML/2.0.0"';
|
||||
$reqheaders['Accept-Language'] = self::getPageLanguage( $title )->getCode();
|
||||
$reqheaders['User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
|
||||
$reqheaders['Api-User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
|
||||
$request['headers'] = $reqheaders;
|
||||
$defaultReqHeaders = [
|
||||
'Accept' =>
|
||||
'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/2.0.0"',
|
||||
'Accept-Language' => self::getPageLanguage( $title )->getCode(),
|
||||
'User-Agent' => 'VisualEditor-MediaWiki/' . $wgVersion,
|
||||
'Api-User-Agent' => 'VisualEditor-MediaWiki/' . $wgVersion,
|
||||
];
|
||||
// $reqheaders take precedence over $defaultReqHeaders
|
||||
$request['headers'] = $reqheaders + $defaultReqHeaders;
|
||||
$response = $this->serviceClient->run( $request );
|
||||
if ( $response['code'] === 200 && $response['error'] === "" ) {
|
||||
// If response was served directly from Varnish, use the response
|
||||
|
@ -376,6 +379,22 @@ class ApiVisualEditor extends ApiBase {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $params['lint'] ) {
|
||||
$lintResponse = $this->requestRestbase(
|
||||
$title,
|
||||
'GET',
|
||||
'page/lint/' . urlencode( $title->getPrefixedDBkey() ) . '/' . $oldid .
|
||||
'?redirect=false',
|
||||
[],
|
||||
[
|
||||
// page/lint/ API always returns a HTTP 406 Not Acceptable error if an 'Accept'
|
||||
// header is sent, so suppress it
|
||||
'Accept' => null,
|
||||
'Accept-Language' => null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
$content = '';
|
||||
Hooks::run( 'EditFormPreloadText', [ &$content, &$title ] );
|
||||
|
@ -673,6 +692,9 @@ class ApiVisualEditor extends ApiBase {
|
|||
$result['preloaded'] = $params['preload'];
|
||||
}
|
||||
}
|
||||
if ( $params['lint'] && isset( $lintResponse ) && $lintResponse['body'] ) {
|
||||
$result['lint'] = json_decode( $lintResponse['body'], true );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'templatesused':
|
||||
|
@ -818,6 +840,7 @@ class ApiVisualEditor extends ApiBase {
|
|||
'oldid' => null,
|
||||
'editintro' => null,
|
||||
'pst' => false,
|
||||
'lint' => false,
|
||||
'preload' => null,
|
||||
'preloadparams' => [
|
||||
ApiBase::PARAM_ISMULTI => true,
|
||||
|
|
|
@ -178,8 +178,9 @@
|
|||
* @param {string} [options.targetName] Optional target name for tracking
|
||||
* @param {boolean} [options.modified] The page was been modified before loading (e.g. in source mode)
|
||||
* @param {string} [options.wikitext] Wikitext to convert to HTML. The original document is fetched if undefined.
|
||||
* @param {string} [preload] Name of a page to use as preloaded content if pageName is empty
|
||||
* @param {Array} [preloadparams] Parameters to substitute into preload if it's used
|
||||
* @param {string} [options.preload] Name of a page to use as preloaded content if pageName is empty
|
||||
* @param {Array} [options.preloadparams] Parameters to substitute into preload if it's used
|
||||
* @param {boolean} [options.lint] Also return lint errors from Parsoid
|
||||
* @return {jQuery.Promise} Abortable promise resolved with a JSON object
|
||||
*/
|
||||
requestPageData: function ( mode, pageName, options ) {
|
||||
|
@ -280,6 +281,7 @@
|
|||
editintro: uri.query.editintro,
|
||||
preload: options.preload,
|
||||
preloadparams: options.preloadparams,
|
||||
lint: options.lint,
|
||||
formatversion: 2
|
||||
};
|
||||
|
||||
|
@ -477,6 +479,7 @@
|
|||
editintro: uri.query.editintro,
|
||||
preload: options.preload,
|
||||
preloadparams: options.preloadparams,
|
||||
lint: options.lint,
|
||||
formatversion: 2
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue