MediaWiki
REL1_20
|
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 if ( isset( $_SERVER['MW_COMPILED'] ) ) { 00045 require ( 'core/includes/WebStart.php' ); 00046 } else { 00047 require ( __DIR__ . '/includes/WebStart.php' ); 00048 } 00049 00050 wfProfileIn( 'api.php' ); 00051 $starttime = microtime( true ); 00052 00053 // URL safety checks 00054 if ( !$wgRequest->checkUrlExtension() ) { 00055 return; 00056 } 00057 00058 // Verify that the API has not been disabled 00059 if ( !$wgEnableAPI ) { 00060 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 ); 00061 echo( 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php' 00062 . '<pre><b>$wgEnableAPI=true;</b></pre>' ); 00063 die(1); 00064 } 00065 00066 // Set a dummy $wgTitle, because $wgTitle == null breaks various things 00067 // In a perfect world this wouldn't be necessary 00068 $wgTitle = Title::makeTitle( NS_MAIN, 'API' ); 00069 00070 /* Construct an ApiMain with the arguments passed via the URL. What we get back 00071 * is some form of an ApiMain, possibly even one that produces an error message, 00072 * but we don't care here, as that is handled by the ctor. 00073 */ 00074 $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI ); 00075 00076 // Process data & print results 00077 $processor->execute(); 00078 00079 // Execute any deferred updates 00080 DeferredUpdates::doUpdates(); 00081 00082 // Log what the user did, for book-keeping purposes. 00083 $endtime = microtime( true ); 00084 wfProfileOut( 'api.php' ); 00085 wfLogProfilingData(); 00086 00087 // Log the request 00088 if ( $wgAPIRequestLog ) { 00089 $items = array( 00090 wfTimestamp( TS_MW ), 00091 $endtime - $starttime, 00092 $wgRequest->getIP(), 00093 $_SERVER['HTTP_USER_AGENT'] 00094 ); 00095 $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; 00096 $module = $processor->getModule(); 00097 if ( $module->mustBePosted() ) { 00098 $items[] = "action=" . $wgRequest->getVal( 'action' ); 00099 } else { 00100 $items[] = wfArrayToCGI( $wgRequest->getValues() ); 00101 } 00102 wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog ); 00103 wfDebug( "Logged API request to $wgAPIRequestLog\n" ); 00104 } 00105 00106 // Shut down the database. foo()->bar() syntax is not supported in PHP4: we won't ever actually 00107 // get here to worry about whether this should be = or =&, but the file has to parse properly. 00108 $lb = wfGetLBFactory(); 00109 $lb->shutdown(); 00110