r25854 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r25853 | r25854 (on ViewVC) | r25855 >
Date:15:29, 14 September 2007
Author:brion
Status:ok
Tags:
Comment:* 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 <nowiki>s for non-linked standalone use.
Added File::getFullURL() function for cleaner calls; using full path to ensure consistency here.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/ExternalEdit.php
===================================================================
--- trunk/phase3/includes/ExternalEdit.php	(revision 25853)
+++ trunk/phase3/includes/ExternalEdit.php	(revision 25854)
@@ -47,12 +47,7 @@
 		} 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: trunk/phase3/includes/Parser.php
===================================================================
--- trunk/phase3/includes/Parser.php	(revision 25853)
+++ trunk/phase3/includes/Parser.php	(revision 25854)
@@ -174,6 +174,7 @@
 		$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: trunk/phase3/includes/filerepo/File.php
===================================================================
--- trunk/phase3/includes/filerepo/File.php	(revision 25853)
+++ trunk/phase3/includes/filerepo/File.php	(revision 25854)
@@ -149,6 +149,21 @@
 		}
 		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: trunk/phase3/includes/CoreParserFunctions.php
===================================================================
--- trunk/phase3/includes/CoreParserFunctions.php	(revision 25853)
+++ trunk/phase3/includes/CoreParserFunctions.php	(revision 25854)
@@ -197,5 +197,18 @@
 			$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: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 25853)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 25854)
@@ -340,6 +340,7 @@
 	'padright'               => array( 0,    'PADRIGHT'               ),
 	'special'                => array( 0,    'special',               ),
 	'defaultsort'            => array( 1,    'DEFAULTSORT:', 'DEFAULTSORTKEY:', 'DEFAULTCATEGORYSORT:' ),
+	'filepath'               => array( 0,    'FILEPATH:'              ),
 );
 
 /**
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 25853)
+++ trunk/phase3/RELEASE-NOTES	(revision 25854)
@@ -22,7 +22,10 @@
 
 === 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 ===
 
 * Subpages are now indexed for searching properly when using PostgreSQL

Follow-up revisions

RevisionCommit summaryAuthorDate
r25861Merged revisions 25849-25860 via svnmerge fromdavid20:03, 14 September 2007
Views
Toolbox