$title: name of the page changed.
$text: new contents of the page.
+'MimeMagicInit': Before processing the list mapping MIME types to media types
+and the list mapping MIME types to file extensions.
+As an extension author, you are encouraged to submit patches to MediaWiki's
+core to add new MIME types to mime.types.
+$mimeMagic: Instance of MimeMagic.
+ Use $mimeMagic->addExtraInfo( $stringOfInfo );
+ for adding new MIME info to the list.
+ Use $mimeMagic->addExtraTypes( $stringOfTypes );
+ for adding new MIME types to the list.
+
+'MimeMagicImproveFromExtension': Allows MW extensions to further improve the
+MIME type detected by considering the file extension.
+$mimeMagic: Instance of MimeMagic.
+$ext: File extension.
+&$mime: MIME type (in/out).
+
+'MimeMagicGuessFromContent': Allows MW extensions guess the MIME by content.
+$mimeMagic: Instance of MimeMagic.
+&$head: First 1024 bytes of the file in a string (in - Do not alter!).
+&$tail: More or equal than last 65558 bytes of the file in a string
+ (in - Do not alter!).
+$file: File path.
+&$mime: MIME type (out).
+
'ModifyExportQuery': Modify the query used by the exporter.
$db: The database object to be queried.
&$tables: Tables in the query.
*/
protected $mIEAnalyzer;
+ /** @var string Extra MIME types, set for example by media handling extensions
+ */
+ private $mExtraTypes = '';
+
+ /** @var string Extra MIME info, set for example by media handling extensions
+ */
+ private $mExtraInfo = '';
+
/** @var MimeMagic The singleton instance
*/
private static $instance = null;
global $wgMimeTypeFile, $IP;
+ # Allow media handling extensions adding MIME-types and MIME-info
+ wfRunHooks( 'MimeMagicInit', array( $this ) );
+
$types = MM_WELL_KNOWN_MIME_TYPES;
if ( $wgMimeTypeFile == 'includes/mime.types' ) {
wfDebug( __METHOD__ . ": no mime types file defined, using build-ins only.\n" );
}
+ $types .= "\n" . $this->mExtraTypes;
+
$types = str_replace( array( "\r\n", "\n\r", "\n\n", "\r\r", "\r" ), "\n", $types );
$types = str_replace( "\t", " ", $types );
$this->mMimeToExt = array();
- $this->mToMime = array();
+ $this->mExtToMime = array();
$lines = explode( "\n", $types );
foreach ( $lines as $s ) {
wfDebug( __METHOD__ . ": no mime info file defined, using build-ins only.\n" );
}
+ $info .= "\n" . $this->mExtraInfo;
+
$info = str_replace( array( "\r\n", "\n\r", "\n\n", "\r\r", "\r" ), "\n", $info );
$info = str_replace( "\t", " ", $info );
return self::$instance;
}
+ /**
+ * Adds to the list mapping MIME to file extensions.
+ * As an extension author, you are encouraged to submit patches to
+ * MediaWiki's core to add new MIME types to mime.types.
+ * @param string $types
+ */
+ public function addExtraTypes( $types ) {
+ $this->mExtraTypes .= "\n" . $types;
+ }
+
+ /**
+ * Adds to the list mapping MIME to media type.
+ * As an extension author, you are encouraged to submit patches to
+ * MediaWiki's core to add new MIME info to mime.info.
+ * @param string $info
+ */
+ public function addExtraInfo( $info ) {
+ $this->mExtraInfo .= "\n" . $info;
+ }
+
/**
* Returns a list of file extensions for a given mime type as a space
* separated string or null if the mime type was unrecognized. Resolves
$mime = $this->guessTypesForExtension( $ext );
}
+ # Media handling extensions can improve the MIME detected
+ wfRunHooks( 'MimeMagicImproveFromExtension', array( $this, $ext, &$mime ) );
+
if ( isset( $this->mMimeTypeAliases[$mime] ) ) {
$mime = $this->mMimeTypeAliases[$mime];
}
return 'image/vnd.djvu';
}
- return false;
+ # Media handling extensions can guess the MIME by content
+ # It's intentionally here so that if core is wrong about a type (false positive),
+ # people will hopefully nag and submit patches :)
+ $mime = false;
+ # Some strings by reference for performance - assuming well-behaved hooks
+ wfRunHooks(
+ 'MimeMagicGuessFromContent',
+ array( $this, &$head, &$tail, $file, &$mime )
+ );
+
+ return $mime;
}
/**