summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/UploadWizard/resources/mw.fileApi.js
blob: 86e1af0480bab376c764b1693ad5df9db325facd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* miscellaneous fileApi routines -- partially copied from mediawiki.special.upload.js, must refactor... */

( function ( mw, $ ) {

	mw.fileApi = {

		/**
		 * Check if this is a recognizable image type...
		 * Also excludes files over 10M to avoid going insane on memory usage.
		 *
		 * TODO is there a way we can ask the browser what's supported in <img>s?
		 * TODO put SVG back after working around Firefox 7 bug <https://bugzilla.wikimedia.org/show_bug.cgi?id=31643>
		 *
		 * @param {File} file
		 * @return {boolean}
		 */
		isPreviewableFile: function ( file ) {
			var	known = [ 'image/png', 'image/gif', 'image/jpeg' ],
				tooHuge = 10 * 1024 * 1024;
			return this.isPreviewableVideo( file ) || ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge;
		},

		/**
		 * Check if this is a recognizable video type...
		 *
		 * @param {File} file
		 * @return {boolean}
		 */
		isPreviewableVideo: function ( file ) {
			var video = document.createElement( 'video' );
			return video.canPlayType && video.canPlayType( file.type ).replace( 'no', '' ) !== '';
		}

	};
}( mediaWiki, jQuery ) );