API: Add user-agent and method (GET/POST) to request logging, and only log the action...
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 27 Aug 2009 22:09:28 +0000 (22:09 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 27 Aug 2009 22:09:28 +0000 (22:09 +0000)
api.php
includes/api/ApiMain.php

diff --git a/api.php b/api.php
index cf56858..ae40c6b 100644 (file)
--- 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" );
 }
 
index 14e7209..d338365 100644 (file)
@@ -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