From ef1545f14af8c1b26dd3a90bdb9a85e602a56a88 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 14 Sep 2007 15:29:52 +0000 Subject: [PATCH] * Add {{filepath:}} parser function to get full path to an uploaded file, complementing {{fullurl:}} for pages. Giving this a |nowiki option to wrap the returned path in s for non-linked standalone use. Added File::getFullURL() function for cleaner calls; using full path to ensure consistency here. --- RELEASE-NOTES | 3 +++ includes/CoreParserFunctions.php | 13 +++++++++++++ includes/ExternalEdit.php | 7 +------ includes/Parser.php | 1 + includes/filerepo/File.php | 15 +++++++++++++++ languages/messages/MessagesEn.php | 1 + 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6cf3e93d7f..171e8a59ed 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -22,6 +22,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN === New features in 1.12 === * Add a warning for non-descriptive filenames at Special:Upload +* Add {{filepath:}} parser function to get full path to an uploaded file, + complementing {{fullurl:}} for pages. + === Bug fixes in 1.12 === diff --git a/includes/CoreParserFunctions.php b/includes/CoreParserFunctions.php index a5f45016d1..af4458adf9 100644 --- a/includes/CoreParserFunctions.php +++ b/includes/CoreParserFunctions.php @@ -197,5 +197,18 @@ class CoreParserFunctions { $parser->setDefaultSort( $text ); return ''; } + + public static function filepath( $parser, $name='', $option='' ) { + $file = wfFindFile( $name ); + if( $file ) { + $url = $file->getFullUrl(); + if( $option == 'nowiki' ) { + return "$url"; + } + return $url; + } else { + return ''; + } + } } diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php index f3fc22e3bc..f592d3c229 100644 --- a/includes/ExternalEdit.php +++ b/includes/ExternalEdit.php @@ -47,12 +47,7 @@ class ExternalEdit { } elseif($this->mMode=="file") { $type="Edit file"; $image = wfLocalFile( $this->mTitle ); - $img_url = $image->getURL(); - if(strpos($img_url,"://")) { - $url = $img_url; - } else { - $url = $wgServer . $img_url; - } + $url = $image->getFullURL(); $extension=substr($name, $pos); } $special=$wgLang->getNsText(NS_SPECIAL); diff --git a/includes/Parser.php b/includes/Parser.php index 1afe47dc4e..6a73d297fc 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -174,6 +174,7 @@ class Parser $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH ); $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) ); $this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH ); + $this->setFunctionHook( 'filepath', array( 'CoreParserFunctions', 'filepath' ), SFH_NO_HASH ); if ( $wgAllowDisplayTitle ) { $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH ); diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 21b7a86547..fbf4d25135 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -149,6 +149,21 @@ abstract class File { } return $this->url; } + + /** + * Return a fully-qualified URL to the file. + * Upload URL paths _may or may not_ be fully qualified, so + * we check. Local paths are assumed to belong on $wgServer. + * @return string + */ + public function getFullUrl() { + $url = $this->getUrl(); + if( substr( $url, 0, 1 ) == '/' ) { + global $wgServer; + return $wgServer . $url; + } + return $url; + } function getViewURL() { if( $this->mustRender()) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 2ef21ae260..9317ee2743 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -340,6 +340,7 @@ $magicWords = array( 'padright' => array( 0, 'PADRIGHT' ), 'special' => array( 0, 'special', ), 'defaultsort' => array( 1, 'DEFAULTSORT:', 'DEFAULTSORTKEY:', 'DEFAULTCATEGORYSORT:' ), + 'filepath' => array( 0, 'FILEPATH:' ), ); /** -- 2.20.1