Commit graph

73 commits

Author SHA1 Message Date
Alexandre Emsenhuber
a682b7335a Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I0db3461139284edcb6ac02923eb83d54e6756ffb
2012-05-12 22:33:51 +02:00
Max Semenik
aacbb6bea7 Fix typo in comments, rm debugging code
Change-Id: I1ae2e59048fbeaf1a1f279dd5bd38bd19b5a8498
2012-05-10 21:01:50 +04:00
Sam Reed
2ec09c5165 More return documentation 2012-02-09 21:35:05 +00:00
Antoine Musso
b634f915c2 application/vnd.oasis.opendocument.database [OFFICE] 2012-01-04 16:24:41 +00:00
Sam Reed
527e85fa9f More documentation in various files 2011-05-29 14:01:47 +00:00
Sam Reed
e514478ba5 Fix function level comments that start with /* not /** 2011-05-21 19:35:16 +00:00
Siebrand Mazeland
75c6696aa8 Use consistent notation for "@todo FIXME". Should update http://svn.wikimedia.org/doc/todo.html nicely. 2011-05-17 22:03:20 +00:00
Tim Starling
7bb50c630a The beginnings of HipHop compiled mode support. It works now for parser cache hits.
* Work around HipHop issue 314 (volatile broken) and issue 308 (no compilation detection) by adding some large and ugly compilation detection code to WebStart.php and doMaintenance.php.
* Provide an MW_COMPILED constant which can be used to detect compiled mode throughout the codebase.
* Introduced wfIsHipHop(), which detects either compiled or interpreted mode. Used this to work around unusual eval() return value in eval.php.
* Work around lack of ini_get() in Maintenance.php, by duplicating wfIsHipHop(). 
* In Maintenance::shouldExecute(), accept "include" as an inclusion function name, since all kinds of inclusion give this string in HipHop.
* Introduced new class MWInit, which provides some static functions in the pre-autoloader environment.
* Introduced MWInit::compiledPath(), which provides a relative path for invoking a compiled file, and MWInit::interpretedPath(), which provides an absolute path for interpreting a PHP file. Used these new functions in the appropriate places.
* When we are running compiled code, don't include files which would generate duplicate class, function or constant definitions. Documented the new requirements on the contents of Defines.php and UtfNormalDefines.php.
* In HipHop compiled mode, it's not possible to have executable code in the same file as a class definition. 
  ** Moved MimeMagic initialisation to the constructor.
  ** Moved Namespace.php global variable initialisation to Setup.php.
  ** Moved MemcachedSessions.php initialisation to the caller in GlobalFunctions.php.
  ** Moved Sanitizer.php constants and global variables to static class members. Introduced an accessor function for the attribs regex, as a new place to put code formerly at file level. 
  ** Moved Language.php initialisation of $wgLanguageNames to Language::getLanguageNames(). Removed the global variable, marked "private" since forever.

* In two places: don't use error_log() with type=3 to append to a file, HipHop doesn't support it. Use file_put_contents() with FILE_APPEND instead.
* Work around the terrible breakage of class_exists() by using MWInit::classExists() instead in various places. In WebInstaller::getPageByName(), the class_exists() was marked with a fixme comment already, so I replaced it with an autoloader solution.
2011-04-04 12:59:55 +00:00
Sam Reed
8771ed7d10 Some braces, and also return type documentation 2011-03-13 22:26:56 +00:00
Bryan Tong Minh
9b35539f7e Cleanup MimeMagic: Add public identifier to functions; kill error operator; Cleanup function documentation; Manual stylize 2011-02-06 22:47:10 +00:00
Sam Reed
9ecca4db51 Couple more return hints
Swap and for &&
2011-02-02 11:38:50 +00:00
Bryan Tong Minh
347dbed5a4 Document how the mime<->extension map is supposed to work, to my best understanding from reading the code. Fixed the built-in mini-mime.types according to this specification. Should fix bug 26367. 2011-01-07 19:41:38 +00:00
Antoine Musso
6fe29c9c30 revert r76464
* mixed style changes and variable removing
* logic changes
* useful comments removed
2010-11-25 20:01:34 +00:00
Sam Reed
10ecfeb03b Various unused variables, add some braces
Explicitally define some variables used in hook type calls
2010-11-10 19:49:04 +00:00
Derk-Jan Hartman
0e81f31105 Add support to upload WebP files. Disabled by default and no thumbnailing support.
Relates to bug 25397
2010-10-20 14:50:30 +00:00
Sam Reed
6b3b915353 Big attack on unused variables... 2010-10-14 20:53:04 +00:00
Tim Starling
bb3deb3701 Fixed some overly-long lines, mostly from r72023. 2010-09-13 03:10:28 +00:00
Daniel Kinzler
1917b3b1bd Follow-up to r71944: Interoducing MimeMagic::improveTypeFromExtension() for two reasons:
a) avoid redundant inspection of file contents when validating uploads, caused by multiple calls to guessMimeType
b) deprecated obscure use of the file extension when guessing mime types, using an explicit call to improveTypeFromExtension() instead

Note that File::getPropsFromPath() will now return an additional field: $props['file-mime'] contains the mime type as determined solely from the file's content, $props['mime'] contains the type that was derived considering the file extension too.
2010-08-31 13:47:24 +00:00
Alexandre Emsenhuber
5be509b0c1 * Standardised file description headers
* Added some descriptions
* Added @file where needed
2010-08-08 14:23:14 +00:00
Derk-Jan Hartman
bcd3dd1943 Recognize webm and matroska files. See also Bug 23888
Currently all webm files are stored as video/webm. It is not possible to detect 
wether this file is an audio file without using a full parser. This is why We should 
really move mime and mediatype accessors to the MediaHandlers.

Using video/x-matroska for MKV files. There is no official mime for MKV (though the 
webm isn't official either, but everyone is already using it apparently).
2010-07-28 19:24:00 +00:00
Derk-Jan Hartman
2b9139e9eb (bug 24073) Recognize MS Office 2003 style files that have been saved by MS 2007.
These files have OPC trailers with 2007 specific information.
2010-07-02 12:11:39 +00:00
Derk-Jan Hartman
08c96166ee Bug 23642. Best effort mime detection for OpenXML files
OpenXML files are Open Package Convention files. Internally, we use the custom mime application/x-opc+zip for these files. In the database, we store the 'proper' mime, which we gu
ess from the file extension, or if not supported, application/zip. All OPC files are blacklisted by $wgMimeTypeBlacklist by default, just as other zip files.
2010-06-19 18:47:34 +00:00
Chad Horohoe
94a69f24fc Cleanup most of the DIY extension detection/dl() code into nice clean wfDl() 2010-06-14 18:09:19 +00:00
Alexandre Emsenhuber
547c76203f Fixed some doxygen warnings 2010-05-17 20:07:50 +00:00
Bryan Tong Minh
0a9762dd06 (bug 23375) Added ogv, oga, spx as extensions for ogg files. Patch by Derk-Jan Hartman. 2010-05-02 19:40:33 +00:00
Chad Horohoe
cadc248105 (bug 22935) image/x-ms-bmp mime type added for BMP files 2010-04-01 23:27:49 +00:00
Chad Horohoe
a4e5e935b6 Mass convert NULL -> null. Left strings and comments alone, obviously. 2009-12-11 21:07:27 +00:00
Aryeh Gregor
777386da76 Reduce false positives for PHP in MimeMagic
(bug 16583) This was detecting PHP if any of a few three-byte strings
occurred anywhere in the first 1024 bytes of the file.  This is too
paranoid -- it creates a significant number of false positives for
binary files, reportedly on the order of about one every 4096 uploads.

It's hard to see what security advantage this check every conveyed,
because it only looks in the first 1024 bytes anyway.  For the purposes
of upload it could surely be removed entirely, but I didn't check all
callers, so maybe some caller wants to guess whether the file is PHP for
some purpose other than banning it.  So for now I only removed the
checks for the shortest strings, which were most likely to get hit.
2009-11-06 21:03:19 +00:00
Brion Vibber
5bb6e71e38 Fix ordering of OpenDocument type detection so template files can actually be uploaded.
Previously, the shorter types like 'text' matched before the longer ones like 'text-template', causing an .ott file to be misdetected as an .odt... and thus rejected for being the wrong type.
2009-01-22 00:15:16 +00:00
Tim Starling
ea471f0d79 Moved the IE content type checks to their own class. Disassembled IE 5 and 6 and added the results to the class. The entry points now return an array giving MIME types for all versions. The most important version difference is the introduction of an early check for PNG headers in IE 7. Added application/x-msdownload to disallowed types, haven't been able to reproduce any vulnerability, but it's better to be on the safe side. 2008-12-12 15:06:35 +00:00
Tim Starling
c6362060b0 New file upload content type checks using a simulation of IE's content type detection algorithm. 2008-12-05 05:35:22 +00:00
Brion Vibber
a14508de09 * Improved upload file type detection for OpenDocument formats
Added a check for the magic value header in OpenDocument zip archives which specifies which subtype it is. Such files will get detected with the appropriate mime type and matching extension, so ODT etc uploads will work again where enabled.

(Previously the general ZIP check and blacklist would disable them.)
2008-09-25 18:43:33 +00:00
Chad Horohoe
b042f2c835 Add accessor to $rootElement, rather than accessing it directly. 2008-09-19 13:39:30 +00:00
Tim Starling
1347fc05a6 By default, reject file uploads that look like ZIP files, to avoid the so-called GIFAR vulnerability. 2008-08-12 03:10:07 +00:00
Chad Horohoe
53914531b8 Trying this again. Define XML mimetypes in new global called $wgXMLMimeTypes. Used for MimeMagic detection of svg, etc. Now with less code and more documentation. :) 2008-07-02 23:25:20 +00:00
Brion Vibber
f041d796db Revert r36816 for the moment (Add $wgAdditionalXMLTypes, an array of XML mimetypes we can check for with MimeMagic.)
I very much like the idea of making this extensible, but the current implementation has a couple problems. I'd recommend addresses the following:
* The format of the array isn't documented; it has neither examples nor a description of the content format in its comment. If I wanted to add something to it, I wouldn't know what the result should look like without looking up the code.
* Rather than "additional" types, it might be best to simply list *all* the types we recognize in the default array -- then it can be modified and extended in local configuration. This would have the following benefits:
** Allows modifying existing types
** Defaults are an example of format, making the structure self-documenting
** Avoids code duplication -- we only have to check one array, not two, and don't have to worry about their formats getting out of sync.
2008-07-02 23:07:39 +00:00
Chad Horohoe
a946cdda2d Add $wgAdditionalXMLTypes, an array of XML mimetypes we can check for with MimeMagic. 2008-06-30 14:46:19 +00:00
Brion Vibber
2d38ed8aa4 Add 'ogv' as recognized alias to 'ogg', allowing uploads of .ogv files to proceed if allowed 2008-06-06 19:58:06 +00:00
Leon Weber
5677670d27 * * Added 'application/x-dia-diagram' to XML MIME types. Patch by dpy 2008-04-27 13:28:55 +00:00
Siebrand Mazeland
79d5225c0e * remove end of line whitespace
* remove empty lines at end of file
* remove "?>" where still present
2008-04-14 07:45:50 +00:00
River Tarnell
2ae9780ec4 the correct magic for PDF is "%PDF" 2008-02-09 23:59:26 +00:00
Brion Vibber
fee0f038b8 More file type checks...
* Switch XML type detection/validity check from dipping for XML processing instructions, doctypes, or subtags to just trying to parse it and checking the root element's name and namespace. This lets us properly handle SVG files which specify a namespace but no doctype, as well as rejecting files that aren't well-formed. (See http://meta.wikimedia.org/wiki/SVG_validity_checks for some samples of bad files I encountered.) Non-XML files will abort parsing pretty quickly, so this shouldn't be a big burden on other types that didn't hit a magic check.
* Fix Unicode unix script checks (er.... is that even right? :D), remove the iconv dependency
2008-02-06 01:23:12 +00:00
Brion Vibber
d3ddd6efdb While we're in there, let's remove a dependency on iconv(). Do the UTF-16 to ASCII merging in the XML checks manually. 2008-02-05 23:13:17 +00:00
Brion Vibber
aa3fc2541e More SVG detection fixes based on tests on files downloaded from commons...
* Make the autodetection work for UTF-16LE and UTF-16BE XML, which never worked before due to using the wrong string compare length
* Allow doctype strings to break over newlines
* Detect XML if there's a doctype even if there's no XML header (the xml header isn't required for UTF-8 files)
2008-02-05 22:50:21 +00:00
Brion Vibber
839871e486 Fix for XML type checks... don't look for the closing angle-brace on the root tag, as it may not be in the header chunk we read. Some SVGs have a lot of attributes on the root element! 2008-02-05 22:35:28 +00:00
Brion Vibber
d2722f9351 Make an initial stab at refactoring the mime type detection.
Adds magic header checks for the following types:
* MIDI
* Ogg
* PDF
* XCF
* DOS/Windows, Mach-O, and ELF executables

Locks down detection to prevent uploading different file types for the following extensions:
* mid, ogg, pdf, svg, wmf, xcf

This should now cover all the file types we have uploadable at Wikimedia public sites. (I've disabled the old StarOffice formats.)

Changed priority so our own checks happen in favor of the external checks, since we don't trust that stuff. Would like to see much further work here to replace it all.

Hopefully I haven't broken SVG files; I'm not 100% certain the built-in checks are correct.
2008-02-05 22:11:36 +00:00
Roan Kattouw
2e5d1b0c59 Reverting r29798 on the committer's request, part 1 of 2 2008-01-15 16:04:50 +00:00
ThomasV
764238cca2 fix for IE 2008-01-15 15:53:09 +00:00
Brion Vibber
adb89e7f3b * Compatibility with incorrectly detected old-style DJVU mime types 2007-10-01 20:23:14 +00:00
Tim Starling
164bb322f2 Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.

Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00