Localisation updates for core messages from translatewiki.net (2009-08-18 23:54 UTC)
[lhc/web/wiklou.git] / api.php
diff --git a/api.php b/api.php
index 2f1d1a3..16657ca 100644 (file)
--- a/api.php
+++ b/api.php
@@ -49,16 +49,10 @@ wfProfileIn('api.php');
 // which will end up triggering HTML detection and execution, hence
 // XSS injection and all that entails.
 //
-// Ensure that all access is through the canonical entry point...
-//
-if( isset( $_SERVER['SCRIPT_NAME'] ) ) {
-       $url = $_SERVER['SCRIPT_NAME'];
-} else {
-       $url = $_SERVER['URL'];
-}
-if( strcmp( "$wgScriptPath/api$wgScriptExtension", $url ) ) {
+if( $wgRequest->isPathInfoBad() ) {
        wfHttpError( 403, 'Forbidden',
-               'API must be accessed through the primary script entry point.' );
+               'Invalid file extension found in PATH_INFO. ' . 
+               'The API must be accessed through the primary script entry point.' );
        return;
 }
 
@@ -69,8 +63,27 @@ if (!$wgEnableAPI) {
        die(1);
 }
 
+// Selectively allow cross-site AJAX
+if ( $wgCrossSiteAJAXdomains && isset($_SERVER['HTTP_ORIGIN']) ) {
+       if ( $wgCrossSiteAJAXdomains == '*' ) {
+               header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
+               header( 'Access-Control-Allow-Credentials: true' );
+       } elseif ( $wgCrossSiteAJAXdomainsRegex ) {
+               foreach ( $wgCrossSiteAJAXdomains as $regex ) {
+                       if ( preg_match( $regex, $_SERVER['HTTP_ORIGIN'] ) ) {
+                               header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
+                               header( 'Access-Control-Allow-Credentials: true' );
+                               break;
+                       }
+               }
+       } elseif ( in_array( $_SERVER['HTTP_ORIGIN'], $wgCrossSiteAJAXdomains ) ) {
+               header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
+               header( 'Access-Control-Allow-Credentials: true' );
+       }
+}
+
 // So extensions can check whether they're running in API mode
-define('API', true);
+define('MW_API', true);
 
 // Set a dummy $wgTitle, because $wgTitle == null breaks various things
 // In a perfect world this wouldn't be necessary