MediaWiki  REL1_22
api.php
Go to the documentation of this file.
00001 <?php
00033 // So extensions (and other code) can check whether they're running in API mode
00034 define( 'MW_API', true );
00035 
00036 // Bail if PHP is too low
00037 if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.3.2' ) < 0 ) {
00038     // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+
00039     require dirname( __FILE__ ) . '/includes/PHPVersionError.php';
00040     wfPHPVersionError( 'api.php' );
00041 }
00042 
00043 // Initialise common code.
00044 require __DIR__ . '/includes/WebStart.php';
00045 
00046 wfProfileIn( 'api.php' );
00047 $starttime = microtime( true );
00048 
00049 // URL safety checks
00050 if ( !$wgRequest->checkUrlExtension() ) {
00051     return;
00052 }
00053 
00054 // Verify that the API has not been disabled
00055 if ( !$wgEnableAPI ) {
00056     header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
00057     echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'
00058         . '<pre><b>$wgEnableAPI=true;</b></pre>';
00059     die( 1 );
00060 }
00061 
00062 // Set a dummy $wgTitle, because $wgTitle == null breaks various things
00063 // In a perfect world this wouldn't be necessary
00064 $wgTitle = Title::makeTitle( NS_MAIN, 'API' );
00065 
00066 /* Construct an ApiMain with the arguments passed via the URL. What we get back
00067  * is some form of an ApiMain, possibly even one that produces an error message,
00068  * but we don't care here, as that is handled by the ctor.
00069  */
00070 $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI );
00071 
00072 // Process data & print results
00073 $processor->execute();
00074 
00075 // Execute any deferred updates
00076 DeferredUpdates::doUpdates();
00077 
00078 // Log what the user did, for book-keeping purposes.
00079 $endtime = microtime( true );
00080 wfProfileOut( 'api.php' );
00081 wfLogProfilingData();
00082 
00083 // Log the request
00084 if ( $wgAPIRequestLog ) {
00085     $items = array(
00086         wfTimestamp( TS_MW ),
00087         $endtime - $starttime,
00088         $wgRequest->getIP(),
00089         $_SERVER['HTTP_USER_AGENT']
00090     );
00091     $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
00092     $module = $processor->getModule();
00093     if ( $module->mustBePosted() ) {
00094         $items[] = "action=" . $wgRequest->getVal( 'action' );
00095     } else {
00096         $items[] = wfArrayToCgi( $wgRequest->getValues() );
00097     }
00098     wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog );
00099     wfDebug( "Logged API request to $wgAPIRequestLog\n" );
00100 }
00101 
00102 // Shut down the database.  foo()->bar() syntax is not supported in PHP4: we won't ever actually
00103 // get here to worry about whether this should be = or =&, but the file has to parse properly.
00104 $lb = wfGetLBFactory();
00105 $lb->shutdown();