(bug 5167) Add {{SUBPAGENAME}} variable
[lhc/web/wiklou.git] / includes / HttpFunctions.php
index f4d00e5..2c2fd4c 100644 (file)
@@ -5,24 +5,36 @@
 
 /**
  * Get the contents of a file by HTTP
- * 
+ *
  * if $timeout is 'default', $wgHTTPTimeout is used
  */
 function wfGetHTTP( $url, $timeout = 'default' ) {
-       global $wgHTTPTimeout, $wgHTTPProxy;
+       global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle, $wgCommandLineMode;
 
        # Use curl if available
        if ( function_exists( 'curl_init' ) ) {
                $c = curl_init( $url );
                if ( wfIsLocalURL( $url ) ) {
                        curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
-               } else if ($wgHTTPProxy)
+               } else if ($wgHTTPProxy) {
                        curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy);
+               }
 
                if ( $timeout == 'default' ) {
                        $timeout = $wgHTTPTimeout;
                }
                curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
+               curl_setopt( $c, CURLOPT_USERAGENT, "MediaWiki/$wgVersion" );
+
+               # Set the referer to $wgTitle, even in command-line mode
+               # This is useful for interwiki transclusion, where the foreign
+               # server wants to know what the referring page is.
+               # $_SERVER['REQUEST_URI'] gives a less reliable indication of the 
+               # referring page.
+               if ( is_object( $wgTitle ) ) {
+                       curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() );
+               }
+
                ob_start();
                curl_exec( $c );
                $text = ob_get_contents();