From 0ea9e36c3cbeb8c4d1c6583483c049f8ce80d7ed Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 15 May 2008 18:33:12 +0000 Subject: [PATCH] Force output of a full URL in Special:Filepath and ApiQueryImageInfo in case the wiki images are not configured to full urls. --- includes/HttpFunctions.php | 16 ++++++++++++++++ includes/SpecialFilepath.php | 3 ++- includes/api/ApiQueryImageInfo.php | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 555a79b733..98e397a5e9 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -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; + } } diff --git a/includes/SpecialFilepath.php b/includes/SpecialFilepath.php index 84412ab616..30fa9623aa 100644 --- a/includes/SpecialFilepath.php +++ b/includes/SpecialFilepath.php @@ -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 ); diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index fdb389f81c..7f4fb76979 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -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(); -- 2.20.1