aboutsummaryrefslogtreecommitdiffstats
path: root/includes/media/PNGHandler.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
* Use namespaced classes (2)Umherirrender2024-06-161-0/+1
| | | | | | | Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: Id9f3e775e143d1a17b6b96812a8230cfba14d9d3
* media: code style improvementsDerk-Jan Hartman2023-03-091-8/+4
| | | | | | | | | | | | | - Avoid unnecesary else branching - Static vs non-static fixes - string, int and float casting instead of strval, intval, floatval (faster and more readable) - Strict comparisons (but not for all '' and 0 as might have implicit falsey behavior) - Few spelling mistakes - Remove TimestampException handling, caught by parent function Change-Id: I08725c8e391965529a2766dfaf5d8f6cf8a86db8
* media: Make the file metadata "_error" check looserAmir Sarabadani2021-06-241-5/+1
| | | | | | | | Follows-up I039785d5b6 and I0ccb9971c7b6d99. It basically cancelled out when the value of error is 0, which is falsy. Bug: T285431 Change-Id: I79a3c021973e43cf8012a783c24e40bbd33d8652
* Check for _error in getting metadata array in PNGHandlerAmir Sarabadani2021-06-231-1/+5
| | | | | | | | | Before I039785d5b6, it would just suppress errors and return empty value in which shorten out. Now, it returns [ '_error' => some value ] which is not empty value but doesn't have anything this method wants either. Bug: T285431 Change-Id: Ia2bc0982ffaeda0575af1481f9b84faad7d784ad
* Use the unserialized form of image metadata internallyTim Starling2021-06-081-31/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* media: Fix mismatching/incomplete PHPDocs related to metadataThiemo Kreuz2020-10-301-3/+3
| | | | | | | | | | | | | | * Use false instead of bool in PHPDocs, because that's the only bool value that's allowed. * This patch also fixes DjVuHandler::getPageText() not returning strings, but XML objects. This kind of "worked" because all consuming code magically casts these to strings. But this is an actual violation of the contract of the method. This is also why the test was doing this weird (string) cast, instead of actually testing the type of the return value. Change-Id: I00db6b910f1de6d37a80543b8a5dd5ea3bab3c76
* Fix incomplete type hint for File::formatMetadataThiemo Kreuz2020-10-281-1/+1
| | | | Change-Id: I4e4d779230b8151500ed828c5a9554274c739811
* Remove terminating line breaks from debug messagesTim Starling2020-06-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | A terminating line break has not been required in wfDebug() since 2014, however no migration was done. Some of these line breaks found their way into LoggerInterface::debug() calls, where they mess up the formatting of the debug log. So, remove terminating line breaks from wfDebug() and LoggerInterface::debug() calls. Also: * Fix the stripping of leading line breaks from the log header emitted by Setup.php. This feature, accidentally broken in 2014, allows requests to be distinguished in the log file. * Avoid using the global variable $self. * Move the logging of the client IP back to Setup.php. It was moved to WebRequest in the hopes that it would not always be needed, however $wgRequest->getIP() is now called unconditionally a few lines up in Setup.php. This means that it is put in its proper place after the "start request" message. * Wrap the log header code in a closure so that variables like $name do not leak into global scope. * In Linker.php, remove a few instances of an unnecessary second parameter to wfDebug(). Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
* Fix includes/media/ Squiz.Scope.MethodScope.MissingReedy2020-05-181-3/+3
| | | | Change-Id: I2bf5543b99dc2ae05f7de02940d120dee353adfe
* Add const visibility to includes/mediaMax Semenik2020-04-261-1/+1
| | | | Change-Id: I80ec7aa44b1ea5e7b7d6193732b7da03d7f11960
* media: Mark public MediaHandler/ImageHandler methods as suchThiemo Kreuz2019-02-251-4/+4
| | | | | | | | | | | | | 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
* media: Rename files to match the name of the class they defineTimo Tijhof2018-04-281-0/+203
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