Api request log: improve module retrieval
authorSergio Santoro <santoro.srg@gmail.com>
Tue, 22 Jul 2014 13:18:15 +0000 (15:18 +0200)
committerSergio Santoro <santoro.srg@gmail.com>
Wed, 23 Jul 2014 18:44:10 +0000 (20:44 +0200)
The execution of an API request can throw an exception.
In those cases $processor->getModule() could return NULL.
Use the module manager directly to try to retrieve the
module instance.

Change-Id: Ie49762681ef797388216ab40d99b8e7458a837f6

api.php

diff --git a/api.php b/api.php
index e8a911e..6b5a0a0 100644 (file)
--- a/api.php
+++ b/api.php
@@ -108,8 +108,13 @@ if ( $wgAPIRequestLog ) {
        );
        $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
        if ( $processor ) {
-               $module = $processor->getModule();
-               if ( $module->mustBePosted() ) {
+               try {
+                       $manager = $processor->getModuleManager();
+                       $module = $manager->getModule( $wgRequest->getVal( 'action' ), 'action' );
+               } catch ( Exception $ex ) {
+                       $module = null;
+               }
+               if ( !$module || $module->mustBePosted() ) {
                        $items[] = "action=" . $wgRequest->getVal( 'action' );
                } else {
                        $items[] = wfArrayToCgi( $wgRequest->getValues() );