00001 <?php
00002
00037
00038 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
00039
00040 wfProfileIn( 'api.php' );
00041 $starttime = microtime( true );
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 if ( $wgRequest->isPathInfoBad() ) {
00054 wfHttpError( 403, 'Forbidden',
00055 'Invalid file extension found in PATH_INFO or QUERY_STRING.' );
00056 return;
00057 }
00058
00059
00060 if ( !$wgEnableAPI ) {
00061 echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
00062 echo '<pre><b>$wgEnableAPI=true;</b></pre>';
00063 die( 1 );
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 function convertWildcard( $search ) {
00075 $search = preg_quote( $search, '/' );
00076 $search = str_replace(
00077 array( '\*', '\?' ),
00078 array( '.*?', '.' ),
00079 $search
00080 );
00081 return "/$search/";
00082 }
00083
00084 if ( $wgCrossSiteAJAXdomains && isset( $_SERVER['HTTP_ORIGIN'] ) ) {
00085 $exceptions = array_map( 'convertWildcard', $wgCrossSiteAJAXdomainExceptions );
00086 $regexes = array_map( 'convertWildcard', $wgCrossSiteAJAXdomains );
00087 foreach ( $regexes as $regex ) {
00088 if ( preg_match( $regex, $_SERVER['HTTP_ORIGIN'] ) ) {
00089 foreach ( $exceptions as $exc ) {
00090 if ( preg_match( $exc, $_SERVER['HTTP_ORIGIN'] ) ) {
00091 break 2;
00092 }
00093 }
00094 header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
00095 header( 'Access-Control-Allow-Credentials: true' );
00096 break;
00097 }
00098 }
00099 }
00100
00101
00102 define( 'MW_API', true );
00103
00104
00105
00106 $wgTitle = Title::makeTitle( NS_MAIN, 'API' );
00107
00108
00109
00110
00111
00112 $processor = new ApiMain( $wgRequest, $wgEnableWriteAPI );
00113
00114
00115 $processor->execute();
00116
00117
00118 wfDoUpdates();
00119
00120
00121 $endtime = microtime( true );
00122 wfProfileOut( 'api.php' );
00123 wfLogProfilingData();
00124
00125
00126 if ( $wgAPIRequestLog ) {
00127 $items = array(
00128 wfTimestamp( TS_MW ),
00129 $endtime - $starttime,
00130 wfGetIP(),
00131 $_SERVER['HTTP_USER_AGENT']
00132 );
00133 $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
00134 if ( $processor->getModule()->mustBePosted() ) {
00135 $items[] = "action=" . $wgRequest->getVal( 'action' );
00136 } else {
00137 $items[] = wfArrayToCGI( $wgRequest->getValues() );
00138 }
00139 wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog );
00140 wfDebug( "Logged API request to $wgAPIRequestLog\n" );
00141 }
00142
00143
00144 wfGetLBFactory()->shutdown();
00145