Set Api-User-Agent in requests to RESTBase/Parsoid

Bug: T149050
Change-Id: I7670450724f18865a7d9c7c7eb182449964f32b0
This commit is contained in:
James D. Forrester 2016-10-27 08:54:46 -07:00
parent cdb98fe3c9
commit 7eeb66f63e
2 changed files with 11 additions and 5 deletions

View file

@ -93,6 +93,7 @@ class ApiVisualEditor extends ApiBase {
// Should be synchronised with modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js
$reqheaders['Accept'] = 'text/html; charset=utf-8; profile="mediawiki.org/specs/html/1.2.0"';
$reqheaders['User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
$reqheaders['Api-User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
$request['headers'] = $reqheaders;
$response = $this->serviceClient->run( $request );
if ( $response['code'] === 200 && $response['error'] === "" ) {

View file

@ -122,7 +122,7 @@
},
requestParsoidData: function ( pageName, oldid, targetName, modified, wikitext ) {
var start, apiXhr, restbaseXhr, apiPromise, restbasePromise, dataPromise, pageHtmlUrl,
var start, apiXhr, restbaseXhr, apiPromise, restbasePromise, dataPromise, pageHtmlUrl, headers,
switched = false,
fromEditedState = false,
data = {
@ -157,6 +157,13 @@
if ( conf.fullRestbaseUrl || conf.restbaseUrl ) {
ve.track( 'trace.restbaseLoad.enter' );
// Should be synchronised with ApiVisualEditor.php
headers = {
Accept: 'text/html; charset=utf-8; profile="mediawiki.org/specs/html/1.2.0"',
'Api-User-Agent': 'VisualEditor-MediaWiki/' + mw.config.get( 'wgVersion' )
};
if (
conf.fullRestbaseUrl &&
( wikitext || ( wikitext = $( '#wpTextbox1' ).textSelection( 'getContents' ) ) ) &&
@ -177,8 +184,7 @@
wikitext: wikitext,
stash: 'true'
},
// Should be synchronised with ApiVisualEditor.php
headers: { Accept: 'text/html; charset=utf-8; profile="mediawiki.org/specs/html/1.2.0"' },
headers: headers,
dataType: 'text'
} );
} else {
@ -191,8 +197,7 @@
url: pageHtmlUrl + encodeURIComponent( pageName ) +
( oldid === undefined ? '' : '/' + oldid ) + '?redirect=false',
type: 'GET',
// Should be synchronised with ApiVisualEditor.php
headers: { Accept: 'text/html; charset=utf-8; profile="mediawiki.org/specs/html/1.2.0"' },
headers: headers,
dataType: 'text'
} );
}