Commit graph

33 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
thiemowmde
06051e1256 Replace complex preg_replace_callback with strtr/preg_replace
The complexity is really not needed in these cases. strtr() does have
the behavior we want: It does all replacements at the same time instead
of sequentially.

We are also adding test cases for the previously uncovered
StringUtils::escapeRegexReplacement() we rely on in this patch.

Bug: T308395
Change-Id: I6741303775d6d54f3ad0d50635a986ff992ae8f4
2023-10-05 10:47:46 +02: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
Derk-Jan Hartman
8ed1cf88aa media: Remove unneeded complexity in BitmapHandler command replacement
Bug: T308394
Change-Id: I207b24473e761ac3fdd53d002ba8ce44f4d2dac3
2023-02-10 00:22:20 +00:00
Daimona Eaytoy
c5a01d4b2e Replace some usages of MWException
These exceptions are not documented with @throws and they're really not
meant to be caught.

Bug: T86704
Change-Id: I07f32e42c6fd4bc8785bac91547858f15a9fc2a8
2023-01-26 00:10:34 +00:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Daimona Eaytoy
947ff7c0f5 build: Update mediawiki/mediawiki-phan-config to 0.12.0
This patch only adds and removes suppressions, which must be done in the
same patch as the version bump.

Bug: T298571
Change-Id: I4044d4d9ce82b3dae7ba0af85bf04f22cb1dd347
2022-10-08 15:45:42 +02:00
Derk-Jan Hartman
d6b78f1e7d Guard CustomConvertCommand against placeholders within values
Because the str_replaces were done sequentially, it was possible that
the replacement values for the placeholders of the
CustomConvertCommand would insert placeholder values of their own.

Find all placeholders at once on the original value using
preg_replace_callback and make sure each is replaced only once.

Based on a suggestion by User:SacredSum

Bug: T308394
Change-Id: Id672996454445dd200e57cf207c56e3268a3fcc8
2022-06-08 22:49:04 +00:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Umherirrender
8d235dd805 media: Improve documentation on Handler functions
Add missing @return and use false instead of bool where possible

Change-Id: Ie85a40987422e32aa02c56969e103371ec2e5b5f
2022-03-29 17:50:17 +00:00
James D. Forrester
24e67e03b1 phan: Upgrade mediawiki-phan-config to 0.11.1 and set minimum_target_php_version
MediaWiki still supports PHP 7.2+, but we want to mainly test in newer versions
of PHP. Setting minimum_target_php_version to 7.2 this lets us run phan without
phan trying to get us to make PHP 7.2-incompatible changes to 'appease' PHP 8.0
or whatever later changes.

Some switches of generic 'resource' type-hinting to 'resource|object' to inform
phan to ignore this (triggering PHPCS at the time, ah well), rather than trying
to hint the specific novel PHP encapsulation classes to that have replaced them
from PHP 8.0 onwards but don't yet exist, and fixes from where we were checking
the results of implode and explode.

Bug: T293924
Change-Id: I629e3fb3adfad73beb3d424a07e643c2e079d9bb
2022-03-29 16:54:36 +00:00
jenkins-bot
8f86ffab04 Merge "media: Limit result array of explode() to minimum needed" 2022-03-18 13:55:33 +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
Umherirrender
89e5632737 media: Limit result array of explode() to minimum needed
Limit the array for the input to the expected size (or one bigger).
This avoids big arrays on bad input and allows to process with the
expected values in the array.

Change-Id: Iec1a85c29d928966c14cc0273b1a251dc0b6b738
2022-03-01 20:54:15 +01:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Umherirrender
98de078a4c Improve callable docs
Change-Id: I4cc9b2dbe285ad935a1dfd08effa673a39167483
2020-11-13 22:55:10 +01:00
Reedy
d7c5aacdfc media: Remove checks for ancient ImageMagick versions in BitmapHandler
Bug: T261258
Change-Id: I66d36a2e97d82dea704a51cc6e219fff8bc1d69b
2020-09-04 14:40:42 +00:00
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
aedc93fdb0 Mark remaining eligible classes as stable for subclassing
This classes were found by surveying concrete classes derved from base
classes in core.

Bug: T247862
Change-Id: I231752aaad26e2ab3f097301e449b31e723590f0
2020-07-10 15:02:27 +02: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
78e36ba527 Fix some Squiz.Scope.MethodScope.Missing
Change-Id: Id0351e44482885ee90e047c1ae3a439e484104c6
2020-05-16 22:42:24 +01:00
Umherirrender
6207fa9be1 Fix return type hints in media related classes
Change-Id: Id326fb2a54aac62cb27aa7045082924b5cd84940
2019-06-18 22:11:10 +02:00
Thiemo Kreuz
f0d5dceb2c Make some array type hints more specific
Change-Id: Ia9ed6fa851316baa47e73d9a5988a863d15f298c
2019-05-22 13:37:12 +02:00
Derick Alangi
84292b7728 Replace deprecated function wfEscapeShellArg with Shell::escape()
Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4
2019-04-07 20:17:39 +01:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00: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
Max Semenik
1e680456b4 Get rid of call_user_func(_array)(), part 3
Also cleaned up nearby code in a couple places.

Change-Id: Ibf44ee7c0ceb739d7e79406e4ff39303c316e285
2018-06-10 02:21:24 +00:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -07:00
Timo Tijhof
9bf3916322 media: Rename files to match the name of the class they define
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
2018-04-28 02:07:33 +01:00
Renamed from includes/media/Bitmap.php (Browse further)