API: Add user-agent and method (GET/POST) to request logging, and only log the action= parameter for mustBePosted modules
This commit is contained in:
parent
3ac3ccaaf0
commit
d7f593a312
2 changed files with 20 additions and 4 deletions
13
api.php
13
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" );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue