X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=blobdiff_plain;f=api.php;h=554c2726bc188772192c25b1824f7ec46da193a0;hb=e0e58939694c085c04518816d03b98b03407e6ce;hp=51bb2ad31a21441580bc0485ab0f28c01a4de7c4;hpb=8eab930bc2483a06ced563a1376be41aff5ed5b0;p=lhc%2Fweb%2Fwiklou.git diff --git a/api.php b/api.php index 51bb2ad31a..554c2726bc 100644 --- a/api.php +++ b/api.php @@ -70,10 +70,25 @@ $wgTitle = Title::makeTitle( NS_MAIN, 'API' ); $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI ); // Last chance hook before executing the API -wfRunHooks( 'ApiBeforeMain', array( &$processor ) ); +try { + wfRunHooks( 'ApiBeforeMain', array( &$processor ) ); + if ( !$processor instanceof ApiMain ) { + throw new MWException( 'ApiBeforMain hook set $processor to a non-ApiMain class' ); + } +} catch ( Exception $e ) { + // Crap. Try to report the exception in API format to be friendly to clients. + ApiMain::handleApiBeforeMainException( $e ); + $processor = false; +} // Process data & print results -$processor->execute(); +if ( $processor ) { + $processor->execute(); +} + +if ( function_exists( 'fastcgi_finish_request' ) ) { + fastcgi_finish_request(); +} // Execute any deferred updates DeferredUpdates::doUpdates(); @@ -81,6 +96,7 @@ DeferredUpdates::doUpdates(); // Log what the user did, for book-keeping purposes. $endtime = microtime( true ); wfProfileOut( 'api.php' ); + wfLogProfilingData(); // Log the request @@ -92,11 +108,15 @@ if ( $wgAPIRequestLog ) { $_SERVER['HTTP_USER_AGENT'] ); $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; - $module = $processor->getModule(); - if ( $module->mustBePosted() ) { - $items[] = "action=" . $wgRequest->getVal( 'action' ); + if ( $processor ) { + $module = $processor->getModule(); + if ( $module->mustBePosted() ) { + $items[] = "action=" . $wgRequest->getVal( 'action' ); + } else { + $items[] = wfArrayToCgi( $wgRequest->getValues() ); + } } else { - $items[] = wfArrayToCgi( $wgRequest->getValues() ); + $items[] = "failed in ApiBeforeMain"; } wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog ); wfDebug( "Logged API request to $wgAPIRequestLog\n" );