r55643 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55642‎ | r55643 | r55644 >
Date:22:09, 27 August 2009
Author:catrope
Status:ok
Tags:
Comment:
API: Add user-agent and method (GET/POST) to request logging, and only log the action= parameter for mustBePosted modules
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
@@ -123,7 +123,8 @@
124124
125125
126126 private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
127 - private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage;
 127+ private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
 128+ private $mInternalMode, $mSquidMaxage, $mModule;
128129
129130 /**
130131 * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
@@ -190,6 +191,13 @@
191192 public function getResult() {
192193 return $this->mResult;
193194 }
 195+
 196+ /**
 197+ * Get the API module object. Only works after executeAction()
 198+ */
 199+ public function getModule() {
 200+ return $this->mModule;
 201+ }
194202
195203 /**
196204 * Only kept for backwards compatibility
@@ -368,6 +376,7 @@
369377
370378 // Instantiate the module requested by the user
371379 $module = new $this->mModules[$this->mAction] ($this, $this->mAction);
 380+ $this->mModule = $module;
372381
373382 if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
374383 // Check for maxlag
Index: trunk/phase3/api.php
@@ -125,12 +125,19 @@
126126
127127 // Log the request
128128 if ( $wgAPIRequestLog ) {
129 - wfErrorLog( implode( ',', array(
 129+ $items = array(
130130 wfTimestamp( TS_MW ),
131131 $endtime - $starttime,
132132 wfGetIP(),
133 - wfArrayToCGI( $wgRequest->getValues() )
134 - ) ) . "\n", $wgAPIRequestLog );
 133+ $_SERVER['HTTP_USER_AGENT']
 134+ );
 135+ $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
 136+ if ( $processor->getModule()->mustBePosted() ) {
 137+ $items[] = "action=" . $wgRequest->getVal( 'action' );
 138+ } else {
 139+ $items[] = wfArrayToCGI( $wgRequest->getValues() );
 140+ }
 141+ wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog );
135142 wfDebug( "Logged API request to $wgAPIRequestLog\n" );
136143 }
137144

Status & tagging log