Commit graph

13 commits

Author SHA1 Message Date
Func
0a23641e5f mediaHandler: Respect image scaler configs for Webp and XCF files
ImageMagick should not be used if it's not installed. When a custom
convert command is configured, it's the site admin's responsibility
to make sure it works with Webp and XCF files. The php-imagick
extension is just a wrapper for the ImageMagick library, and would
also work for Webp and XCF files.

Bug: T308386
Change-Id: I9fcf22b0c4b6d5d132e5a44530e3f255075f7fb4
2024-06-02 19:50:21 +00:00
Daimona Eaytoy
4be770a196 Deprecate and replace the wfUnpack global function
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
2024-01-17 21:17:24 +00:00
Derk-Jan Hartman
9556256bda media: code style improvements
- 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
2023-03-09 11:07:32 +00:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
Tim Starling
b4849e03b7 Use the unserialized form of image metadata internally
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
2021-06-08 17:04:01 +10:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
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
2020-06-03 12:01:16 +10:00
Reedy
161baa43dd Fix includes/media/ Squiz.Scope.MethodScope.Missing
Change-Id: I2bf5543b99dc2ae05f7de02940d120dee353adfe
2020-05-18 21:02:22 +00:00
Umherirrender
6207fa9be1 Fix return type hints in media related classes
Change-Id: Id326fb2a54aac62cb27aa7045082924b5cd84940
2019-06-18 22:11:10 +02:00
Umherirrender
1ba94a9e5b Allow int as return type of MediaHandler::isMetadataValid
MediaHandler::METADATA_COMPATIBLE is a int,
which is a possible return value here

Change-Id: Ia84139ee8e09839e1f46a6d34738612dfd365415
2019-06-04 21:33:37 +02:00
Fomafix
9cbb8f104d Use https://www.php.net/ instead of https://secure.php.net/
Change-Id: I0acca592c6909e91b28b904da49dcbd6a43cd2a5
2019-04-12 06:44:48 +02:00
Thiemo Kreuz
867ec07040 media: Mark public MediaHandler/ImageHandler methods as such
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
2019-02-25 10:16:30 +01:00
Kunal Mehta
951690c02e Rename tests/phpunit/includes/media files to match class names
The classes were renamed in 9bf39163, this updates the test cases to
match. Also take care of XCF while we're at it too.

Change-Id: Iaaeee93e496af6cdd610df5bc75302ecfe273f64
2019-01-29 23:21:13 -08:00
Renamed from includes/media/XCF.php (Browse further)