r108109 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108108‎ | r108109 | r108110 >
Date:01:47, 5 January 2012
Author:aaron
Status:ok
Tags:
Comment:
In FSFile:
* Added getMimeType() and extensionFromPath() functions.
* A few other minor code and comment cleanups.
Modified paths:
  • /trunk/phase3/includes/filerepo/file/FSFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/file/FSFile.php
@@ -69,6 +69,15 @@
7070 }
7171
7272 /**
 73+ * Guess the MIME type from the file contents alone
 74+ *
 75+ * @return string
 76+ */
 77+ public function getMimeType() {
 78+ return MimeMagic::singleton()->guessMimeType( $this->path, false );
 79+ }
 80+
 81+ /**
7382 * Get an associative array containing information about
7483 * a file with the given storage path.
7584 *
@@ -89,12 +98,11 @@
9099
91100 # get the file extension
92101 if ( $ext === true ) {
93 - $i = strrpos( $this->path, '.' );
94 - $ext = strtolower( $i ? substr( $this->path, $i + 1 ) : '' );
 102+ $ext = self::extensionFromPath( $this->path );
95103 }
96104
97105 # mime type according to file contents
98 - $info['file-mime'] = $magic->guessMimeType( $this->path, false );
 106+ $info['file-mime'] = $this->getMimeType();
99107 # logical mime type
100108 $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext );
101109
@@ -143,6 +151,11 @@
144152 return $info;
145153 }
146154
 155+ /**
 156+ * Exract image size information
 157+ *
 158+ * @return Array
 159+ */
147160 protected function extractImageSizeInfo( array $gis ) {
148161 $info = array();
149162 # NOTE: $gis[2] contains a code for the image type. This is no longer used.
@@ -180,6 +193,17 @@
181194 }
182195
183196 /**
 197+ * Get the final file extension from a file system path
 198+ *
 199+ * @param $path string
 200+ * @returns string
 201+ */
 202+ public static function extensionFromPath( $path ) {
 203+ $i = strrpos( $path, '.' );
 204+ return strtolower( $i ? substr( $path, $i + 1 ) : '' );
 205+ }
 206+
 207+ /**
184208 * Get an associative array containing information about a file in the local filesystem.
185209 *
186210 * @param $path String: absolute local filesystem path
@@ -188,7 +212,7 @@
189213 *
190214 * @return array
191215 */
192 - static function getPropsFromPath( $path, $ext = true ) {
 216+ public static function getPropsFromPath( $path, $ext = true ) {
193217 $fsFile = new self( $path );
194218 return $fsFile->getProps( $ext );
195219 }
@@ -204,7 +228,7 @@
205229 *
206230 * @return false|string False on failure
207231 */
208 - static function getSha1Base36FromPath( $path ) {
 232+ public static function getSha1Base36FromPath( $path ) {
209233 $fsFile = new self( $path );
210234 return $fsFile->getSha1Base36();
211235 }

Status & tagging log