Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mimetypes.list.php to config/mimetypemapping.dist.json #17481

Merged
merged 3 commits into from
Jul 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions config/mimetypemapping.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"_comment" : "Array mapping file extensions to mimetypes (in alphabetical order]",
"_comment2": "The first index in the mime type array is the assumed correct mimetype",
"_comment3": "and the second (if present] is a secure alternative",

"_comment4": "Any changes you make here will be overwritten on an update of ownCloud",
"_comment5": "Put any custom mappings in a new file mimetypemapping.json in this directory",


"3gp": ["video/3gpp"],
"7z": ["application/x-7z-compressed"],
"accdb": ["application/msaccess"],
"ai": ["application/illustrator"],
"apk": ["application/vnd.android.package-archive"],
"arw": ["image/x-dcraw"],
"avi": ["video/x-msvideo"],
"bash": ["text/x-shellscript"],
"blend": ["application/x-blender"],
"bin": ["application/x-bin"],
"bmp": ["image/bmp"],
"bpg": ["image/bpg"],
"cb7": ["application/x-cbr"],
"cba": ["application/x-cbr"],
"cbr": ["application/x-cbr"],
"cbt": ["application/x-cbr"],
"cbtc": ["application/x-cbr"],
"cbz": ["application/x-cbr"],
"cc": ["text/x-c"],
"cdr": ["application/coreldraw"],
"cnf": ["text/plain"],
"conf": ["text/plain"],
"cpp": ["text/x-c++src"],
"cr2": ["image/x-dcraw"],
"css": ["text/css"],
"csv": ["text/csv"],
"cvbdl": ["application/x-cbr"],
"c": ["text/x-c"],
"c++": ["text/x-c++src"],
"dcr": ["image/x-dcraw"],
"deb": ["application/x-deb"],
"dng": ["image/x-dcraw"],
"doc": ["application/msword"],
"docm": ["application/vnd.ms-word.document.macroEnabled.12"],
"docx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
"dot": ["application/msword"],
"dotx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"],
"dv": ["video/dv"],
"eot": ["application/vnd.ms-fontobject"],
"epub": ["application/epub+zip"],
"eps": ["application/postscript"],
"erf": ["image/x-dcraw"],
"exe": ["application/x-ms-dos-executable"],
"flac": ["audio/flac"],
"flv": ["video/x-flv"],
"gif": ["image/gif"],
"gz": ["application/x-gzip"],
"gzip": ["application/x-gzip"],
"h": ["text/x-h"],
"hh": ["text/x-h"],
"html": ["text/html", "text/plain"],
"htm": ["text/html", "text/plain"],
"ical": ["text/calendar"],
"ics": ["text/calendar"],
"iiq": ["image/x-dcraw"],
"impress": ["text/impress"],
"jpeg": ["image/jpeg"],
"jpg": ["image/jpeg"],
"jps": ["image/jpeg"],
"js": ["application/javascript", "text/plain"],
"json": ["application/json", "text/plain"],
"k25": ["image/x-dcraw"],
"kdc": ["image/x-dcraw"],
"key": ["application/x-iwork-keynote-sffkey"],
"keynote": ["application/x-iwork-keynote-sffkey"],
"kra": ["application/x-krita"],
"m2t": ["video/mp2t"],
"m4v": ["video/mp4"],
"markdown": ["text/markdown"],
"mdown": ["text/markdown"],
"md": ["text/markdown"],
"mdb": ["application/msaccess"],
"mdwn": ["text/markdown"],
"mkd": ["text/markdown"],
"mef": ["image/x-dcraw"],
"mkv": ["video/x-matroska"],
"mobi": ["application/x-mobipocket-ebook"],
"mov": ["video/quicktime"],
"mp3": ["audio/mpeg"],
"mp4": ["video/mp4"],
"mpeg": ["video/mpeg"],
"mpg": ["video/mpeg"],
"mpo": ["image/jpeg"],
"msi": ["application/x-msi"],
"mts": ["video/MP2T"],
"mt2s": ["video/MP2T"],
"nef": ["image/x-dcraw"],
"numbers": ["application/x-iwork-numbers-sffnumbers"],
"odf": ["application/vnd.oasis.opendocument.formula"],
"odg": ["application/vnd.oasis.opendocument.graphics"],
"odp": ["application/vnd.oasis.opendocument.presentation"],
"ods": ["application/vnd.oasis.opendocument.spreadsheet"],
"odt": ["application/vnd.oasis.opendocument.text"],
"oga": ["audio/ogg"],
"ogg": ["audio/ogg"],
"ogv": ["video/ogg"],
"opus": ["audio/ogg"],
"orf": ["image/x-dcraw"],
"otf": ["application/font-sfnt"],
"pages": ["application/x-iwork-pages-sffpages"],
"pdf": ["application/pdf"],
"pfb": ["application/x-font"],
"pef": ["image/x-dcraw"],
"php": ["application/x-php"],
"pl": ["application/x-perl"],
"png": ["image/png"],
"pot": ["application/vnd.ms-powerpoint"],
"potm": ["application/vnd.ms-powerpoint.template.macroEnabled.12"],
"potx": ["application/vnd.openxmlformats-officedocument.presentationml.template"],
"ppa": ["application/vnd.ms-powerpoint"],
"ppam": ["application/vnd.ms-powerpoint.addin.macroEnabled.12"],
"pps": ["application/vnd.ms-powerpoint"],
"ppsm": ["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"],
"ppsx": ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"],
"ppt": ["application/vnd.ms-powerpoint"],
"pptm": ["application/vnd.ms-powerpoint.presentation.macroEnabled.12"],
"pptx": ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
"ps": ["application/postscript"],
"psd": ["application/x-photoshop"],
"py": ["text/x-python"],
"raf": ["image/x-dcraw"],
"rar": ["application/x-rar-compressed"],
"reveal": ["text/reveal"],
"rw2": ["image/x-dcraw"],
"sgf": ["application/sgf"],
"sh-lib": ["text/x-shellscript"],
"sh": ["text/x-shellscript"],
"srf": ["image/x-dcraw"],
"sr2": ["image/x-dcraw"],
"svg": ["image/svg+xml", "text/plain"],
"swf": ["application/x-shockwave-flash", "application/octet-stream"],
"tar": ["application/x-tar"],
"tar.gz": ["application/x-compressed"],
"tex": ["application/x-tex"],
"tgz": ["application/x-compressed"],
"tiff": ["image/tiff"],
"tif": ["image/tiff"],
"ttf": ["application/font-sfnt"],
"txt": ["text/plain"],
"vcard": ["text/vcard"],
"vcf": ["text/vcard"],
"vob": ["video/dvd"],
"wav": ["audio/wav"],
"webm": ["video/webm"],
"woff": ["application/font-woff"],
"wmv": ["video/x-ms-wmv"],
"xcf": ["application/x-gimp"],
"xla": ["application/vnd.ms-excel"],
"xlam": ["application/vnd.ms-excel.addin.macroEnabled.12"],
"xls": ["application/vnd.ms-excel"],
"xlsb": ["application/vnd.ms-excel.sheet.binary.macroEnabled.12"],
"xlsm": ["application/vnd.ms-excel.sheet.macroEnabled.12"],
"xlsx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
"xlt": ["application/vnd.ms-excel"],
"xltm": ["application/vnd.ms-excel.template.macroEnabled.12"],
"xltx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"],
"xml": ["application/xml", "text/plain"],
"xrf": ["image/x-dcraw"],
"yaml": ["application/yaml", "text/plain"],
"yml": ["application/yaml", "text/plain"],
"zip": ["application/zip"]
}
2 changes: 1 addition & 1 deletion lib/private/files/type/detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function registerTypeArray($types) {

// Update the alternative mimetypes to avoid having to look them up each time.
foreach ($this->mimetypes as $mimeType) {
$this->secureMimeTypes[$mimeType[0]] = $mimeType[1] ?: $mimeType[0];
$this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0];
}
}

Expand Down
12 changes: 11 additions & 1 deletion lib/private/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,18 @@ static function rmdirr($dir, $deleteSelf = true) {
*/
static public function getMimetypeDetector() {
if (!self::$mimetypeDetector) {
$dist = file_get_contents(OC::$configDir . '/mimetypemapping.dist.json');
$mimetypemapping = get_object_vars(json_decode($dist));

//Check if need to load custom mappings
if (file_exists(OC::$configDir . '/mimetypemapping.json')) {
$custom = file_get_contents(OC::$configDir . '/mimetypemapping.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, TBH I think the code looks better with those slashes there. PHP ignores multiple slashes (as does any UNIX utility), so we have no bug concerns, and it also means less effort if $configDir at some point loses the trailing slash.

TL;DR: leave the slashes, they're good 😄

$custom_mapping = get_object_vars(json_decode($custom));
$mimetypemapping = array_merge($mimetypemapping, $custom_mapping);
}

self::$mimetypeDetector = new \OC\Files\Type\Detection();
self::$mimetypeDetector->registerTypeArray(include 'mimetypes.list.php');
self::$mimetypeDetector->registerTypeArray($mimetypemapping);
}
return self::$mimetypeDetector;
}
Expand Down
Loading