r60770 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60769‎ | r60770 | r60771 >
Date:07:07, 7 January 2010
Author:robla
Status:deferred (Comments)
Tags:
Comment:
New functions: getPreferredExtensionForType and getNormalizedExtensionFromName
Modified paths:
  • /branches/extensionless-files/includes/MimeMagic.php (modified) (history)
  • /branches/extensionless-files/includes/filerepo/File.php (modified) (history)

Diff [purge]

Index: branches/extensionless-files/includes/MimeMagic.php
@@ -313,6 +313,19 @@
314314 return $r;
315315 }
316316
 317+
 318+ /**
 319+ * returns the preferred file extension for a given mime type
 320+ */
 321+ function getPreferredExtensionForType( $mime ) {
 322+ $ext = explode( ' ', $this->getExtensionsForType( $mime ) );
 323+ // assume the first one listed is preferred, unless normalizeExtension
 324+ // decides otherwise
 325+ $ext = File::normalizeExtension( $ext[0] );
 326+
 327+ return $ext;
 328+ }
 329+
317330 /** returns a list of mime types for a given file extension
318331 * as a space separated string.
319332 */
Index: branches/extensionless-files/includes/filerepo/File.php
@@ -91,6 +91,19 @@
9292 }
9393
9494 /**
 95+ * Given a file name, normalize its extension extension to the common form,
 96+ * and ensure it's clean.
 97+ *
 98+ * @param $ext string (without the .)
 99+ * @return string
 100+ */
 101+ function getNormalizedExtensionFromName( $name ) {
 102+ $n = strrpos( $name, '.' );
 103+ return File::normalizeExtension( $n ? substr( $name, $n + 1 )
 104+ : '' );
 105+ }
 106+
 107+ /**
95108 * Checks if file extensions are compatible
96109 *
97110 * @param $old File Old file
@@ -98,9 +111,8 @@
99112 */
100113 static function checkExtensionCompatibility( File $old, $new ) {
101114 $oldMime = $old->getMimeType();
102 - $n = strrpos( $new, '.' );
103 - $newExt = self::normalizeExtension(
104 - $n ? substr( $new, $n + 1 ) : '' );
 115+ $newExt = self::getNormalizedExtensionFromName( $new );
 116+
105117 $mimeMagic = MimeMagic::singleton();
106118 return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
107119 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r60807followup to r60770: getNormalizedExtensionFromName documentation fixrobla20:52, 7 January 2010

Comments

#Comment by Bryan (talk | contribs)   14:47, 7 January 2010

Needs documentation fixage for the first @param of getNormalizedExtensionFromName

#Comment by RobLa (talk | contribs)   20:53, 7 January 2010

Thanks Bryan....I've fixed the documentation in r60807

Status & tagging log