Commit graph

301 commits

Author SHA1 Message Date
James D. Forrester
9203493606 Add namespace to remaining parts of Wikimedia\FileBackend
Bug: T353458
Change-Id: I49c843c9d8f6459c0fbf774afeea7a82fa564b59
2024-10-03 16:21:22 +00:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
Umherirrender
da63db52af libs: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I46f46f1855ca32c89a276b06f4e2051ff541886e
2024-09-13 17:24:12 +00:00
Func
0c889c7fdc StreamFile: Support streaming webp from thumb_handler.php
Bug: T366422
Change-Id: Ib3ba7dccc10f8308fc706500c74a2beca357efdf
2024-09-03 14:39:04 +08:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Ebrahim Byagowi
6e093bbe2d Add namespace and deprecation alias to MultiHttpClient
This patch introduces a namespace declaration for the
Wikimedia\Http to MultiHttpClient and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I4ebc1a3b496de08b2b430301da376578d13fcfe6
2024-05-20 00:32:45 +03:30
Ebrahim Byagowi
d21cc67450 Add namespace and deprecation alias to FileBackend
This patch introduces a namespace declaration for the
Wikimedia\FileBackend to FileBackend and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Id897687b1d679fd7d179e3a32e617aae10ebff33
2024-05-19 22:35:58 +03:30
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
jenkins-bot
af9b10ae24 Merge "Make HTTPFileStreamer testable" 2024-04-27 02:01:23 +00:00
daniel
9672a6e5e4 Make HTTPFileStreamer testable
This also improves ThumbnailEntryPointTest by allowing it
to assert which headers got sent.

Change-Id: I33911775bce1b3cc7a53a03c2be50d53a28fabd1
2024-04-26 13:22:55 +02:00
jenkins-bot
6a64cdca71 Merge "Allow to set .rlistings on a container" 2024-04-26 05:36:39 +00:00
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02:00
Paladox
369cacd244 Allow to set .rlistings on a container
Needed for if you use large objects and you access the url anonymously.

Change-Id: I9aa384f525b0747793bba0c0691cc36b6369ed9b
2024-04-17 21:16:15 +00:00
Aaron Schulz
eeabc10b6b filebackend: simplify "headless" parameter and STREAM_HEADLESS flag
In FileBackend::streamFile(), do not send "headers" in "headless" mode.

In HTTPFileStreamer::stream(), do not treat $headers as an exception.
Just use $headerFunc like with all the other headers.

Nothing relies on the old behavior, and the only things using "headless" are
integration tests anyway. The same holds true for STREAM_HEADLESS.

Change-Id: I75faf9195a713d6a8a8f1273cb9e747980f4d57f
2024-04-04 21:25:35 +00:00
Kunal Mehta
903544aabc Update Apache config syntax in .htaccess files
"Deny from all" is deprecated; the replacement syntax has been
available since Apache 2.4 (originally released in 2012).

See <https://httpd.apache.org/docs/2.4/howto/access.html>.

Bug: T360850
Change-Id: I825053ccefe34f6ca4e04af5ad2601f79e4d51a7
2024-03-23 23:36:31 -04:00
Tim Starling
d23c174390 filebackend: Retry Swift requests with new auth token on 401
Every Wednesday, we get hundreds of user-visible storage failures,
because there is only one global storage token and it has a lifetime of
one week. The code assumes that requesting a token regularly will avoid
expiry, but that is not the case.

So, when a request fails with a 401, refresh the auth token, then retry
the request. Factor out HTTP request handling to allow this.

Swift gives us the remaining lifetime of the token in seconds, so use
that as the server and process cache expiry time. There will be a
stampede when it expires, but my laptop can do 700 req/s single-
threaded, so it should be OK.

Add tests to cover the cases previously handled by checking the return
value of getAuthentication().

Bug: T358830
Change-Id: If9fe4dde4127592adae1b81e8eb925c4f59443d9
2024-03-15 21:34:36 +00:00
Tim Starling
01b2db9252 filebackend: Fix MemoryFileBackend move result
MemoryFileBackend, a class which is only used for testing, does not
correctly respect the ignoreMissingSource option to its move operation.
The copy succeeds due to the forwarded ignoreMissingSource option, so it
proceeds with the source deletion, which fails.

This was implemented in the base class method FileBackendStore
::doMoveInternal, but every other subclass was overriding it.

So, make it abstract, by analogy with doCopyInternal and
doDeleteInternal. Add an implementation specific to MemoryFileBackend
which handles ignoreMissingSource correctly.

Change-Id: Ib5733046d741b962c65db42b5364705b073c4b06
2024-03-13 12:22:54 +11:00
jenkins-bot
eea0849a01 Merge "filebackend: Fix Swift integration test failures" 2024-03-12 22:18:37 +00:00
Tim Starling
9a8300fd77 filebackend: Fix Swift integration test failures
It's possible to run FileBackendIntegrationTest against an actual Swift
server, but there were a few failures when I tried it:

* In SwiftFileBackend::getDirListPageInternal(), fix a PHP warning due
  to strpos(null).
* In setUp(), fix exception "Backend domain ID not provided" due to
  missing domainId parameter.
* In doTestGetLocalCopyAndReference404(), getLocalCopy() on a sharded
  backend for a file that cannot exist, due to having no shard, returns
  null not false, which I think is fine. Use a path that can exist so
  that the assertion passes.
* In doTestGetFileList(), there is an assertion to confirm that
  getFileList() on a non-existent container will return null, but in
  Swift this is not known until iteration begins, so it returns an
  iterator. Fix the assertion.

Change-Id: If3fc47eb285b51366e7cfd8b6cf6e64bd0f8cd41
2024-03-12 09:43:06 +11:00
Tim Starling
c01e62a9fc filebackend: Clean up batch handling in doQuickOperationsInternal()
Remove $fileOpHandles since it was effectively no longer used. Rename
$curFileOpHandles to $batch and note its type. Remove unnecessary
comments and improve the comment about T230245 by explaining what was
going on with that bug.

Followup to I67f9f25b3bc68a389c49c39b7b6def2343bda34e.

Change-Id: I809afc7ce4f2f32018c975ec0073cd8a4af21763
2024-03-08 11:06:57 +11:00
Platonides
7fa80ae548 Respect $maxConcurrency when queuing async FileOps
Too many queued FileOps may end up causing 'Too many open files'
failures, and mysterious error messages claiming that existing
files were not found.

Bug: T230245
Change-Id: I67f9f25b3bc68a389c49c39b7b6def2343bda34e
2024-03-07 19:16:56 +11:00
jenkins-bot
8af7393edb Merge "filebackend: improve documentation of FileOp fields" 2024-03-04 06:38:24 +00:00
Aaron Schulz
fa066f3184 filebackend: improve documentation of FileOp fields
Add comments to the STATE_* constants and rename cancelled -> noOp.

Change-Id: I17fd8bd296e8845fcddd4e9676d100fbb82b5e6d
2024-02-21 14:24:08 -08:00
Aaron Schulz
7913713d88 filebackend: add FileStatePredicates helper class for file operations
This replaces the old pass-by-reference $predicates array and makes the
intent clearer. It also supports lazy-loading of predicated properties,
which useful for avoiding expensive computations like SHA-1 hashes when
they end up not being needed.

Pass FileOp::doPrecheck() a mutable "batch level" FileStatePredicates
instance along with an immutable "operation level" FileStatePredicates
instance. The later can be used in callbacks that need to recall the
predicated file states just before the start of the operation.

Make FileOp::precheckDestExistence() support lazy size/sha1 closures.

Bug: T348294
Change-Id: I709c1920d2bee4b76f69e38c1643a44a73d63265
2024-02-21 14:00:27 -08:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
jenkins-bot
6c07e2acf1 Merge "Use thousands separators in selected integer literals" 2023-12-12 02:15:04 +00:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
Paladox
f164c8f71f SwiftFileBackend: Fix "PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated"
Change-Id: Ie4023ba59653c749f717356a2b6d9d52537d8e35
2023-12-11 19:25:21 +00:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Brian Wolff
29b5fd433a filebackend: Allow uploading files up to 32 GB with FSFileBackend
The SwiftBackend theoretical max file size was increased to 5 GB

Sysadmins of MediaWiki are in a better position to judge what
is acceptable performance-wise for uploaded files than we are. The
answer presumably depends significantly on the hardware mediawiki
is running under. This increases the max limit to 32 GB (previously 4GB).
With files this big, operations such as copying and calculating SHA1
do become expensive. However everything still works, albeit with
some delay (I tested on a laptop with HDD, I imagine things are
significantly faster with an NVMe drive).

This changes the overall FileBackendStore limit which affects all
subclasses that haven't overriden the limit, including those from
extensions. Swift was set to 5GB as that backend has to change the
way it uses the Swift API for objects larger than 5GB.

This should not affect ordinary users as $wgMaxUploadSize is by
default only 100 MB in MediaWiki (4GB in Wikimedia).

Bug: T191805
Change-Id: Id091d51b620edbeea2d9df8c75422807bfc7aea0
2023-10-25 17:05:03 +00:00
jenkins-bot
33a5ba00d6 Merge "filebackend: Turn protected properties into actual constants" 2023-10-19 20:09:44 +00:00
jenkins-bot
449d23e23e Merge "filebackend: Fix incomplete callable|null type hints" 2023-10-19 20:03:29 +00:00
jenkins-bot
8260eadac4 Merge "filebackend: Fix and add missing @return documentation" 2023-10-18 18:20:31 +00:00
DannyS712
10f88b6c61 FSFileOpHandle: add missing @ in @var
Change-Id: I2771157a31aa6ee2b24fbd957c2c1ec0a0d9bdfc
2023-10-17 03:07:20 +00:00
thiemowmde
5542d943bd filebackend: Fix incomplete callable|null type hints
… and make a few generic array type hints more specific, where
possible.

Change-Id: I1d0a89a9f10f0438f3bdd21d4067b0de69881c56
2023-10-16 12:28:39 +02:00
thiemowmde
17ae460968 filebackend: Fix and add missing @return documentation
array[]|bool[]|null[] means: It's either an array of arrays, an array
that contains only bools, or an array where all values are null. But
this is not what's happening here, as far as I can tell.

This minor fixup is motivated by T348688, but doesn't solve it.
However, now it's more obvious that the values that trigger the
reported error are "null", i.e. some instance of self::$RES_ERROR.

Bug: T348688
Change-Id: Ia9debe97d21a3abff7bff75f16a94bec8be6ddc5
2023-10-16 11:47:57 +02:00
thiemowmde
5d9a3e6fb5 filebackend: Turn protected properties into actual constants
This is a direct follow up to Id0e4b0d from 2019 where these
"constants" have been introduced. I believe the reason for using
protected properties was that we still had to support PHP 7.0 back
then, but class constants can only be marked as protected since
PHP 7.1.

According to codesearch these are apparently meant to be internal
to the filebackend classes in core and not used anywhere else.

Change-Id: I55683e3540f8d76324370efecb98d08e07547c28
2023-10-16 10:20:54 +02:00
Umherirrender
3ad015537d filebackend: Log cache set failure in FileBackendStore
Similiar to what happen on cache delete failure

Change-Id: I9a29b73850ca99f3e333f7b733dcafedf7a2773b
2023-09-03 18:25:35 +00:00
jenkins-bot
cf0ffcdd6d Merge "filebackend: Include truncated http body for 502 on SwiftFileBackend" 2023-08-22 16:00:30 +00:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Umherirrender
f0895674d4 filebackend: Include truncated http body for 502 on SwiftFileBackend
Put 100 bytes of the body into the log message to possible see more
information about the gateway error message

See T328872#8757648

Bug: T328872
Change-Id: I8b2df6d318d8de912eb9b992051b209bab236f37
2023-08-01 00:09:47 +00:00
Aaron Schulz
ac472f18f4 filebackend: improve SwiftFileBackendList field names and nullity checks
Avoid calling next() or count() when the buffer is null.
This avoids the risk of type errors.

Also improve some comments.

Change-Id: Ida422f4b7f185ac8bffc479ab5c82711e5621c89
2023-06-23 10:53:23 +10:00
jenkins-bot
6f9ac8889b Merge "Replace substr with cleaner string methods" 2023-06-06 14:15:27 +00:00
Umherirrender
3f3e435777 filebackend: Remove unneeded array_filter
Since 208ebda there are never nulls in the array

Change-Id: I8299777689a6fb16c719ebf3c2bbc454255c0a37
2023-06-03 02:13:54 +02:00
Matěj Suchánek
676fcf4379 Replace substr with cleaner string methods
Use str_starts_with, str_ends_with or string offset where appropriate.

This fixes a bug in MimeAnalyzer where the "UTF-16LE" header could not
be identified because of wrong constant. This is the exact type of bug
that the new functions can avoid.

Change-Id: I9f30881e7e895f011db29cf5dcbe43bc4f341062
2023-05-20 15:40:21 +02:00
Umherirrender
423bff2b08 filebackend: Use SwiftFileBackend::$RES_ABSENT for self-documentation
Collapse conditions when other types of the return value already checked

Change-Id: Iff7273495a58c8505b5f3aaf132964bdde2a63bb
2023-05-11 22:41:52 +02:00
Umherirrender
03e3868a43 filebackend: Split missing file and error on getLocalReference/Copy
FileBackend::getLocalReference and FileBackend::getLocalCopy should
report failure and missing with different values to make error reporting
for the caller easier (FileBackendStore::doConcatenate in this case).

The existing subclass implementation for
FileBackendStore::doGetLocalCopyMulti already doing that.

Change-Id: Ie29aed48dc33bcd9fe1ed1e91685596044dfd988
2023-04-29 01:01:07 +02:00
Amir Sarabadani
6487841402 filebackend: Find thumbnails from all backends in FileBackendMultiWrite
When trying to purge thumbnails, currently it tries to purge from the
main backend only leading to unhappiness

Bug: T331138
Change-Id: I2b13912296df68b2833b8c7c0bfe17d4ba362fce
2023-04-17 10:55:56 +02:00
Tim Starling
7775a3f7b7 TempFSFile: Keep the WeakMap alive
If you store a WeakMap in the object, containing only circular
references in the values, then nothing is keeping the WeakMap alive and
it can be deleted along with its parent TempFSFile by the garbage
collector.

A WeakMap contains normal references to its values, so those normal
references can be marked by the GC like any other references.

Instead, store the WeakMap as a static property.

Bug: T332461
Bug: T332397
Change-Id: Idbaa1019c2bac3d1dd9b001753c2f4c0aaf66e98
2023-03-18 14:20:13 +11:00