aboutsummaryrefslogtreecommitdiffstats
path: root/includes/media/BmpHandler.php
Commit message (Collapse)AuthorAgeFilesLines
* Replace a number of uses of class aliases with the real thingsJames D. Forrester2025-03-261-0/+1
| | | | | | | Found via disabling phan's alias support for a run (and ignoring wgLang's hard-coded state of being a \Language, alas). Change-Id: I4753bcd84d72d6de111fc7ffc5841fa417bf7333
* Deprecate and replace the wfUnpack global functionDaimona Eaytoy2024-01-171-3/+5
| | | | | | | | | | | Move it to the StringUtils class, and make it throw a dedicated exception. Update code in media/ to use the new method. Those seemed to be the only usages across all known MW code [1], so hard-deprecate the method as well. [1] - https://codesearch.wmcloud.org/search/?q=wfUnpack&files=&excludeFiles=&repos= Change-Id: I82ce96b6373443cf57a48b98595ca05290f37349
* Try not to discard Excimer timeout exceptionsTim Starling2022-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Don't catch and discard exceptions from the RequestTimeout library, except when the exception is properly handled and the code seems to be trying to wrap things up. In most cases the exception is rethrown. Ideally it should instead be done by narrowing the catch, and this was feasible in a few cases. But sometimes the exception being caught is an instance of the base class (notably DateTime::__construct()). Often Exception is the root of the hierarchy of exceptions being thrown and so is the obvious catch-all. Notes on specific callers: * In the case of ResourceLoader::respond(), exceptions were caught for API correctness, but processing continued. I added an outer try block for timeout handling so that termination would be more prompt. * In LCStoreCDB the Exception being caught was Cdb\Exception not \Exception. I added an alias to avoid confusion. * In ImageGallery I added a special exception class. * In Message::__toString() the rationale for catching disappears in PHP 7.4.0+, so I added a PHP version check. * In PoolCounterRedis, let the shutdown function do its thing, but rethrow the exception for logging. Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
* Use the unserialized form of image metadata internallyTim Starling2021-06-081-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Image metadata is usually a serialized string representing an array. Passing the string around internally and having everything unserialize it is an awkward convention. Also, many image handlers were reading the file twice: once for getMetadata() and again for getImageSize(). Often getMetadata() would actually read the width and height and then throw it away. So, in filerepo: * Add File::getMetadataItem(), which promises to allow partial loading of metadata per my proposal on T275268 in a future commit. * Add File::getMetadataArray(), which returns the unserialized array. Some file handlers were returning non-serializable strings from getMetadata(), so I gave them a legacy array form ['_error' => ...] * Changed MWFileProps to return the array form of metadata. * Deprecate the weird File::getImageSize(). It was apparently not called by anything, but was overridden by UnregisteredLocalFile. * Wrap serialize/unserialize with File::getMetadataForDb() and File::loadMetadataFromDb() in preparation for T275268. In MediaHandler: * Merged MediaHandler::getImageSize() and MediaHandler::getMetadata() into getSizeAndMetadata(). Deprecated the old methods. * Instead of isMetadataValid() we now have isFileMetadataValid(), which only gets a File object, so it can decide what data it needs to load. * Simplified getPageDimensions() by having it return false for non-paged media. It was not called in that case, but was implemented anyway. In specific handlers: * Rename DjVuHandler::getUnserializedMetadata() and extractTreesFromMetadata() for clarity. "Metadata" in these function names meant an XML string. * Updated DjVuImage::getImageSize() to provide image sizes in the new style. * In ExifBitmapHandler, getRotationForExif() now takes just the Orientation tag, rather than a serialized string. Also renamed for clarity. * In GIFMetadataExtractor, return the width, height and bits per channel instead of throwing them away. There was some conflation in decodeBPP() which I picked apart. Refer to GIF89a section 18. * In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract bits per channel, width, height and components (channel count). This is essentially a port of PHP's getimagesize(), so should be bugwards compatible. * In PNGMetadataExtractor, return the width and height, which were previously assigned to unused local variables. I verified the implementation by referring to the specification. * In SvgHandler, retain the version validation from unpackMetadata(), but rename the function since it now takes an array as input. In tests: * In ExifBitmapTest, refactored some tests by using a provider. * In GIFHandlerTest and PNGHandlerTest, I removed the tests in which getMetadata() returns null, since it doesn't make sense when ported to getMetadataArray(). I added tests for empty arrays instead. * In tests, I retained serialization of input data since I figure it's useful to confirm that existing database rows will continue to be read correctly. I removed serialization of expected values, replacing them with plain data. * In tests, I replaced access to private class constants like BROKEN_FILE with string literals, since stability is essential. If the class constant changes, the test should fail. Elsewhere: * In maintenance/refreshImageMetadata.php, I removed the check for shrinking image metadata, since it's not easy to implement and is not future compatible. Image metadata is expected to shrink in future. Bug: T275268 Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
* Fix includes/media/ Squiz.Scope.MethodScope.MissingReedy2020-05-181-1/+1
| | | | Change-Id: I2bf5543b99dc2ae05f7de02940d120dee353adfe
* Fix return type hints in media related classesUmherirrender2019-06-181-1/+1
| | | | Change-Id: Id326fb2a54aac62cb27aa7045082924b5cd84940
* media: Fix $ext property name in BmpHandler::getThumbType()Thiemo Kreuz2019-05-281-2/+2
| | | | | | This is not "text", it's a file extension. Change-Id: I92e3b70805df974e74e8aaa9e780dcb55ff584b9
* media: Mark public MediaHandler/ImageHandler methods as suchThiemo Kreuz2019-02-251-1/+1
| | | | | | | | | | | | | Note I'm intentionally not touching the entire file, but only methods I'm absolutely sure are already called from outside, e.g. from MediaHandlerFactory, and must be public because of this. I'm intentionally not doing anything with private or protected in this patch, as such changes are much more fragile. This is a direct follow up for the changes proposed in Iaa4f60d. Change-Id: Ida817b289ddd5e9a8c162cc1fa3335c639a0bbe5
* Fix PhanTypeMismatchDeclaredParamUmherirrender2018-07-071-1/+1
| | | | | | Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
* media: Rename files to match the name of the class they defineTimo Tijhof2018-04-281-0/+80
This will make jumping from file to file much easier in text editors when file name lookups will autocomplete naturally when looking for a class by name. Change-Id: I4b2e55a2e72674b619d5a592866c8a019a2b0224