From: Roan Kattouw Date: Thu, 27 Aug 2009 22:09:28 +0000 (+0000) Subject: API: Add user-agent and method (GET/POST) to request logging, and only log the action... X-Git-Tag: 1.31.0-rc.0~40022 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=d7f593a312539c06475d8733065a8f9e088a9c4c;p=lhc%2Fweb%2Fwiklou.git API: Add user-agent and method (GET/POST) to request logging, and only log the action= parameter for mustBePosted modules --- diff --git a/api.php b/api.php index cf56858383..ae40c6bb9f 100644 --- a/api.php +++ b/api.php @@ -125,12 +125,19 @@ wfLogProfilingData(); // Log the request if ( $wgAPIRequestLog ) { - wfErrorLog( implode( ',', array( + $items = array( wfTimestamp( TS_MW ), $endtime - $starttime, wfGetIP(), - wfArrayToCGI( $wgRequest->getValues() ) - ) ) . "\n", $wgAPIRequestLog ); + $_SERVER['HTTP_USER_AGENT'] + ); + $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; + if ( $processor->getModule()->mustBePosted() ) { + $items[] = "action=" . $wgRequest->getVal( 'action' ); + } else { + $items[] = wfArrayToCGI( $wgRequest->getValues() ); + } + wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog ); wfDebug( "Logged API request to $wgAPIRequestLog\n" ); } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 14e720964f..d338365477 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -123,7 +123,8 @@ class ApiMain extends ApiBase { private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames; - private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage; + private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest; + private $mInternalMode, $mSquidMaxage, $mModule; /** * Constructs an instance of ApiMain that utilizes the module and format specified by $request. @@ -190,6 +191,13 @@ class ApiMain extends ApiBase { public function getResult() { return $this->mResult; } + + /** + * Get the API module object. Only works after executeAction() + */ + public function getModule() { + return $this->mModule; + } /** * Only kept for backwards compatibility @@ -368,6 +376,7 @@ class ApiMain extends ApiBase { // Instantiate the module requested by the user $module = new $this->mModules[$this->mAction] ($this, $this->mAction); + $this->mModule = $module; if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) { // Check for maxlag