From: Brad Jorsch Date: Tue, 18 Nov 2014 19:33:09 +0000 (-0500) Subject: API: Recognize an "Api-User-Agent" header X-Git-Tag: 1.31.0-rc.0~13187^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=28e75cfb710be11c18a7e9b8611679df556eba8d;p=lhc%2Fweb%2Fwiklou.git API: Recognize an "Api-User-Agent" header XMLHttpRequest does not allow overriding the "User-Agent" header. To allow such clients to make effective use of the api-feature-usage log, let's give them a different header they can use. Change-Id: Ia1e4f52f35f8d9a8e9f5590a00854d14c11f7cc9 --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 3f84f2a786..99c0fb4a5d 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -2277,7 +2277,7 @@ abstract class ApiBase extends ContextSource { ' "' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . '"' . ' "' . $request->getIP() . '"' . ' "' . addslashes( $request->getHeader( 'Referer' ) ) . '"' . - ' "' . addslashes( $request->getHeader( 'User-agent' ) ) . '"'; + ' "' . addslashes( $this->getMain()->getUserAgent() ) . '"'; wfDebugLog( 'api-feature-usage', $s, 'private' ); } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 10a99c9fb0..004bfae94c 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1242,6 +1242,21 @@ class ApiMain extends ApiBase { return $this->mModuleMgr; } + /** + * Fetches the user agent used for this request + * + * The value will be the combination of the 'Api-User-Agent' header (if + * any) and the standard User-Agent header (if any). + * + * @return string + */ + public function getUserAgent() { + return trim( + $this->getRequest()->getHeader( 'Api-user-agent' ) . ' ' . + $this->getRequest()->getHeader( 'User-agent' ) + ); + } + /************************************************************************//** * @name Deprecated * @{