https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108109
Revision: 108109 Author: aaron Date: 2012-01-05 01:47:00 +0000 (Thu, 05 Jan 2012) Log Message: ----------- 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: trunk/phase3/includes/filerepo/file/FSFile.php =================================================================== --- trunk/phase3/includes/filerepo/file/FSFile.php 2012-01-05 01:39:49 UTC (rev 108108) +++ trunk/phase3/includes/filerepo/file/FSFile.php 2012-01-05 01:47:00 UTC (rev 108109) @@ -69,6 +69,15 @@ } /** + * Guess the MIME type from the file contents alone + * + * @return string + */ + public function getMimeType() { + return MimeMagic::singleton()->guessMimeType( $this->path, false ); + } + + /** * Get an associative array containing information about * a file with the given storage path. * @@ -89,12 +98,11 @@ # get the file extension if ( $ext === true ) { - $i = strrpos( $this->path, '.' ); - $ext = strtolower( $i ? substr( $this->path, $i + 1 ) : '' ); + $ext = self::extensionFromPath( $this->path ); } # mime type according to file contents - $info['file-mime'] = $magic->guessMimeType( $this->path, false ); + $info['file-mime'] = $this->getMimeType(); # logical mime type $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext ); @@ -143,6 +151,11 @@ return $info; } + /** + * Exract image size information + * + * @return Array + */ protected function extractImageSizeInfo( array $gis ) { $info = array(); # NOTE: $gis[2] contains a code for the image type. This is no longer used. @@ -180,6 +193,17 @@ } /** + * Get the final file extension from a file system path + * + * @param $path string + * @returns string + */ + public static function extensionFromPath( $path ) { + $i = strrpos( $path, '.' ); + return strtolower( $i ? substr( $path, $i + 1 ) : '' ); + } + + /** * Get an associative array containing information about a file in the local filesystem. * * @param $path String: absolute local filesystem path @@ -188,7 +212,7 @@ * * @return array */ - static function getPropsFromPath( $path, $ext = true ) { + public static function getPropsFromPath( $path, $ext = true ) { $fsFile = new self( $path ); return $fsFile->getProps( $ext ); } @@ -204,7 +228,7 @@ * * @return false|string False on failure */ - static function getSha1Base36FromPath( $path ) { + public static function getSha1Base36FromPath( $path ) { $fsFile = new self( $path ); return $fsFile->getSha1Base36(); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs