* Add {{filepath:}} parser function to get full path to an uploaded file, complementi...
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 14 Sep 2007 15:29:52 +0000 (15:29 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 14 Sep 2007 15:29:52 +0000 (15:29 +0000)
Giving this a |nowiki option to wrap the returned path in <nowiki>s for non-linked standalone use.
Added File::getFullURL() function for cleaner calls; using full path to ensure consistency here.

RELEASE-NOTES
includes/CoreParserFunctions.php
includes/ExternalEdit.php
includes/Parser.php
includes/filerepo/File.php
languages/messages/MessagesEn.php

index 6cf3e93..171e8a5 100644 (file)
@@ -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 ===
 
index a5f4501..af4458a 100644 (file)
@@ -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 "<nowiki>$url</nowiki>";
+                       }
+                       return $url;
+               } else {
+                       return '';
+               }
+       }
 }
 
index f3fc22e..f592d3c 100644 (file)
@@ -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);
index 1afe47d..6a73d29 100644 (file)
@@ -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 );
index 21b7a86..fbf4d25 100644 (file)
@@ -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()) {
index 2ef21ae..9317ee2 100644 (file)
@@ -340,6 +340,7 @@ $magicWords = array(
        'padright'               => array( 0,    'PADRIGHT'               ),
        'special'                => array( 0,    'special',               ),
        'defaultsort'            => array( 1,    'DEFAULTSORT:', 'DEFAULTSORTKEY:', 'DEFAULTCATEGORYSORT:' ),
+       'filepath'               => array( 0,    'FILEPATH:'              ),
 );
 
 /**