Merge "CologneBlue rewrite: kill mWatchLinkNum, watchThisPage() is only called once...
[lhc/web/wiklou.git] / includes / MimeMagic.php
index 248c1e3..1873e7b 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Module defining helper functions for detecting and dealing with mime types.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  */
 
@@ -29,6 +44,7 @@ application/ogg ogx ogg ogm ogv oga spx
 application/pdf pdf
 application/vnd.oasis.opendocument.chart odc
 application/vnd.oasis.opendocument.chart-template otc
+application/vnd.oasis.opendocument.database odb
 application/vnd.oasis.opendocument.formula odf
 application/vnd.oasis.opendocument.formula-template otf
 application/vnd.oasis.opendocument.graphics odg
@@ -40,8 +56,8 @@ application/vnd.oasis.opendocument.presentation-template otp
 application/vnd.oasis.opendocument.spreadsheet ods
 application/vnd.oasis.opendocument.spreadsheet-template ots
 application/vnd.oasis.opendocument.text odt
-application/vnd.oasis.opendocument.text-template ott
 application/vnd.oasis.opendocument.text-master otm
+application/vnd.oasis.opendocument.text-template ott
 application/vnd.oasis.opendocument.text-web oth
 application/x-javascript js
 application/x-shockwave-flash swf
@@ -79,6 +95,7 @@ define('MM_WELL_KNOWN_MIME_INFO', <<<END_STRING
 application/pdf [OFFICE]
 application/vnd.oasis.opendocument.chart [OFFICE]
 application/vnd.oasis.opendocument.chart-template [OFFICE]
+application/vnd.oasis.opendocument.database [OFFICE]
 application/vnd.oasis.opendocument.formula [OFFICE]
 application/vnd.oasis.opendocument.formula-template [OFFICE]
 application/vnd.oasis.opendocument.graphics [OFFICE]
@@ -121,7 +138,7 @@ END_STRING
  * Implements functions related to mime types such as detection and mapping to
  * file extension.
  *
- * Instances of this class are stateles, there only needs to be one global instance
+ * Instances of this class are stateless, there only needs to be one global instance
  * of MimeMagic. Please use MimeMagic::singleton() to get that instance.
  */
 class MimeMagic {
@@ -157,11 +174,11 @@ class MimeMagic {
        private static $extensionLoaded = false;
 
        /** Initializes the MimeMagic object. This is called by MimeMagic::singleton().
-       *
-       * This constructor parses the mime.types and mime.info files and build internal mappings.
-       */
+        *
+        * This constructor parses the mime.types and mime.info files and build internal mappings.
+        */
        function __construct() {
-               /*
+               /**
                *   --- load mime.types ---
                */
 
@@ -213,8 +230,6 @@ class MimeMagic {
                                continue;
                        }
 
-                       #print "processing MIME line $s<br>";
-
                        $mime = substr( $s, 0, $i );
                        $ext = trim( substr($s, $i+1 ) );
 
@@ -244,9 +259,9 @@ class MimeMagic {
                        }
                }
 
-               /*
-               *   --- load mime.info ---
-               */
+               /**
+                *   --- load mime.info ---
+                */
 
                global $wgMimeInfoFile;
                if ( $wgMimeInfoFile == 'includes/mime.info' ) {
@@ -424,6 +439,10 @@ class MimeMagic {
        /** 
         * Returns true if the mime type is known to represent an image format 
         * supported by the PHP GD library.
+        *
+        * @param $mime string
+        * 
+        * @return bool
         */
        public function isPHPImageType( $mime ) {
                // As defined by imagegetsize and image_type_to_mime
@@ -560,11 +579,13 @@ class MimeMagic {
         *
         * @param string $file
         * @param mixed $ext
+        * @return bool|string
         */
        private function doGuessMimeType( $file, $ext ) { // TODO: remove $ext param
                // Read a chunk of the file
                wfSuppressWarnings();
-               $f = fopen( $file, 'rt' ); // FIXME: Shouldn't this be rb?
+               // @todo FIXME: Shouldn't this be rb?
+               $f = fopen( $file, 'rt' );
                wfRestoreWarnings();
                
                if( !$f ) {
@@ -627,12 +648,12 @@ class MimeMagic {
                        return "image/webp";
                }
 
-               /*
+               /**
                 * Look for PHP.  Check for this before HTML/XML...  Warning: this is a
                 * heuristic, and won't match a file with a lot of non-PHP before.  It
                 * will also match text files which could be PHP. :)
                 *
-                * FIXME: For this reason, the check is probably useless -- an attacker
+                * @todo FIXME: For this reason, the check is probably useless -- an attacker
                 * could almost certainly just pad the file with a lot of nonsense to
                 * circumvent the check in any case where it would be a security
                 * problem.  On the other hand, it causes harmful false positives (bug
@@ -651,7 +672,7 @@ class MimeMagic {
                        return 'application/x-php';
                }
 
-               /*
+               /**
                 * look for XML formats (XHTML and SVG)
                 */
                $xml = new XmlTypeCheck( $file );
@@ -664,7 +685,7 @@ class MimeMagic {
                        }
                }
 
-               /*
+               /**
                 * look for shell scripts
                 */
                $script_type = null;
@@ -856,7 +877,7 @@ class MimeMagic {
 
                $m = null;
                if ( $wgMimeDetectorCommand ) {
-                       // FIXME: Use wfShellExec
+                       // @todo FIXME: Use wfShellExec
                        $fn = wfEscapeShellArg( $file );
                        $m = `$wgMimeDetectorCommand $fn`;
                } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) {
@@ -1023,6 +1044,7 @@ class MimeMagic {
         *
         * This funktion relies on the mapping defined by $this->mMediaTypes
         * @access private
+        * @return int|string
         */
        function findMediaType( $extMime ) {
                if ( strpos( $extMime, '.' ) === 0 ) { 
@@ -1060,6 +1082,7 @@ class MimeMagic {
         * @param $fileName String: the file name (unused at present)
         * @param $chunk String: the first 256 bytes of the file
         * @param $proposed String: the MIME type proposed by the server
+        * @return Array
         */
        public function getIEMimeTypes( $fileName, $chunk, $proposed ) {
                $ca = $this->getIEContentAnalyzer();