Force output of a full URL in Special:Filepath and ApiQueryImageInfo in case the...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 15 May 2008 18:33:12 +0000 (18:33 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 15 May 2008 18:33:12 +0000 (18:33 +0000)
includes/HttpFunctions.php
includes/SpecialFilepath.php
includes/api/ApiQueryImageInfo.php

index 555a79b..98e397a 100644 (file)
@@ -117,4 +117,20 @@ class Http {
                }
                return false;
        }
+       
+       /*
+        * Return the full url of something relative to $wgScriptPath or root
+        */
+       static function makeFullURL( $url ) {
+               global $wgServer, $wgScriptPath;
+               
+               // This is a full url
+               if ( strpos( $url, '://' ) !== false ) return $url;
+               
+               // This is a relative path
+               if ( substr( $url, 0, 1 ) != '/' )
+                       $url = $wgScriptPath.'/'.$url;          
+               
+               return $wgServer.$url;
+       }
 }
index 84412ab..30fa962 100644 (file)
@@ -13,7 +13,8 @@ function wfSpecialFilepath( $par ) {
        } else {
                $file = wfFindFile( $title );
                if ( $file && $file->exists() ) {
-                       $wgOut->redirect( $file->getURL() );
+                       // Force a real 30x so the real url is always exposed           
+                       $wgOut->redirect( Http::makeFullURL( $file->getURL() ) );
                } else {
                        $wgOut->setStatusCode( 404 );
                        $cform = new FilepathForm( $title );
index fdb389f..7f4fb76 100644 (file)
@@ -129,12 +129,12 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                $thumb = $f->getThumbnail($this->urlwidth, $this->urlheight);
                                if($thumb)
                                {
-                                       $vals['thumburl'] = $thumb->getURL();
+                                       $vals['thumburl'] = Http::makeFullUrl( $thumb->getURL() );
                                        $vals['thumbwidth'] = $thumb->getWidth();
                                        $vals['thumbheight'] = $thumb->getHeight();
                                }
                        }
-                       $vals['url'] = $f->getURL();
+                       $vals['url'] = Http::makeFullUrl( $f->getURL() );
                }
                if($this->fld_comment)
                        $vals['comment'] = $f->getDescription();