Commit graph

758 commits

Author SHA1 Message Date
Bartosz Dziewoński
691767b387 UploadBase: makeWarningsSerializable() should accept MessageParam objects
Bug: T390001
Change-Id: Icc151fc2bf32df044d85bf8aa89e843b0c0bf25f
(cherry picked from commit 5e7a5f87183b4cbeee949dc1882db52ff281c72a)
2025-04-12 22:40:51 +00:00
Ammarpad
39386a5b7c upload: Suppress warnings from iconv()
iconv() can still emit notices even when '//IGNORE'
string flag is passed.

Bug: T387690
Change-Id: I16f1e99f7c25457aa0b35cb428391c42dec7b91d
(cherry picked from commit 357f2b61e815e071147583e07b388801189462bf)
2025-03-18 00:28:14 +00:00
Umherirrender
1b29f07440 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I73fb416573f5af600e529d224b5beb5d2e3d27d3
2024-10-21 20:41:20 +02:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
James D. Forrester
91a37f53b4 Switch over a bunch of class_alias uses to actuals
Change-Id: Id175a83e71cc910eaee5d5890a9106872a3ca3b8
2024-10-03 17:09:36 +00:00
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
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
jenkins-bot
f3356d631b Merge "upload: Remove declaration UploadFromUrl::$mTempPath" 2024-09-17 08:05:24 +00:00
Umherirrender
f8adf80c35 upload: Remove declaration UploadFromUrl::$mTempPath
There is already UploadBase::$mTempPath
Added in baf83f74b8 (r82507), but unneeded.

Also remove error check of $mTempPath
Since e4009c7367 (I8bafc3a6e6) the property $mTempPath can no longer
be false. Previously, the false was from tempnam().
Since f9c6af781c (Icd05956608) it fatals when no temp file can be
created, because TempFSFile::factory can return null and bind() is
called unconditionally.

Change-Id: Ia1302c9c0528691436a0411ca62b651471811c98
2024-09-17 07:06:15 +00:00
James D. Forrester
2b11d61577 Migrate all uses of deprecated URL global functions to use wfGetUrlUtils()
wfGetUrlUtils() is also deprecated, but less so, so we can do this first
and then properly replace the individual uses with dependency injection
in local pieces of work.

Also:
* Switching Parser::getExternalLinkRel to UrlUtils::matchesDomainList
  exposed a type error in media.txt where $wgNoFollowDomainExceptions
  was set to a string (which is invalid) instead of an array.

Bug: T319340
Change-Id: Icb512d7241954ee155b64c57f3782b86acfd9a4c
2024-09-10 16:50:02 -07:00
jenkins-bot
3ff7fbbdfa Merge "upload: Add missing documentation to class properties" 2024-09-05 07:03:13 +00:00
Umherirrender
bc1af02d62 upload: 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: I07ce1f37d1bfb18d6e73dd008a712b3ca60a80e9
2024-09-04 20:09:32 +00:00
Umherirrender
0ed4f6f889 upload: Use const for UploadBase::$safeXmlEncodings
Change-Id: I897106d15c9e43f75eb006c35a14ac49edeb3ecd
2024-09-01 20:22:51 +02:00
thiemowmde
983c157e6b upload: Use more compact ?? operators and such
This makes the code more compact and more readable while doing the
same as before.

One relevant note: I'm also removing a null check for a variable
that will be used as an array index. This is fine because of the ??
operator. What actually happens is an $maxUploadSize[''] array
access, which never exists and falls back to what comes after the ??.

Change-Id: I7fc82fd179c9594ce5755327523ceec4f502d14f
2024-08-08 16:04:05 +02:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02: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
Umherirrender
472891385d Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Id9f3e775e143d1a17b6b96812a8230cfba14d9d3
2024-06-16 20:23:55 +02:00
jenkins-bot
9f0144af08 Merge "Use StatusValue::getMessages() instead of deprecated methods" 2024-05-29 02:12:05 +00:00
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
Bartosz Dziewoński
cfcfe299e2 Use StatusValue::getMessages() instead of deprecated methods
This commit replaces some of the uses of getErrorsArray(),
getWarningsArray(), getErrorsByType(), and getErrors().
In many cases the code becomes shorter and clearer.
Follow-up to Ibc4ce11594cf36ce7b2495d2636ee080d3443b04.

Change-Id: Id0ebeac26ae62231edb48458dbd2e13ddcbd0a9e
2024-05-18 14:45:54 +00:00
Taavi Väänänen
e9181469e5
upload: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I72deba3df549779fbd5e81c13d228cb54217e45f
2024-04-21 23:06:07 +03:00
Umherirrender
e10441e555 IReadableDatabase::select cannot return false
Remove check for false from IDatabase::select as this is not possible
A DBQueryError is thrown (documented since efda8cd3 / I056b7148)

Use IResultWrapper::numRows to check for empty IResultWrapper

This ignores includes\libs\rdbms as QUERY_SILENCE_ERRORS is an internal
option to get false from this function

Change-Id: I4b2fc26ca0e68612f6beadc01e68097a74962c84
2024-04-18 22:48:25 +02:00
Giuseppe Lavagetto
cfa7ed13b1 Switch Special:Upload to use async upload-by-url
With this change, when async uploads are enabled, upload-by-url
will spawn a job and a form with a button to check the status of the
process is shown to the user.

In the process, add processing of warnings in the remote jobs spawned by
the API or the Special page. This is done by adding checks to
UploadJobTrait::verifyUpload. In order to manage warnings serialized in
the job status, a method to unserialize the result of
UploadBase::makeWarningsSerializable.

Things that we might want to fix:
* The form's UI is abysmal, we should probably use Codex
* While it's not a huge deal, I'd like to figure out why I need to
purge the page cache if I want the file to show up. And more
interestingly, why this doesn't happen when uploading via the API

Bug: T295007
Bug: T118887
Change-Id: I49181d93901f064815808380285fc4abae755341
2024-03-28 11:01:46 +01:00
Giuseppe Lavagetto
b5ed16c1e7 Allow async upload by url via the Api
To this end if 'async' is passed with 'url' to the api:
* Avoid downloading the file synchronously, but verify early
  if the upload is allowed by adding a canFetchFile to UploadBase
  overridden in UploadFromUrl
* Spawn an UploadFromUrlJob
* When checking for the status of the job, do it fetching the data in
  the main stash.

Bug: T295007
Change-Id: If95ccf376cfa9fbe9b3cd058e8e334a6bdd2eb44
2024-03-23 11:23:07 +01:00
jenkins-bot
10abc5335d Merge "Make verifyPartialFile reuse SHA1 hash if we already know" 2024-03-12 23:14:45 +00:00
Brian Wolff
15c3fb401a Make verifyPartialFile reuse SHA1 hash if we already know
During a stashed upload, the SHA1 has already been calculated and
is populated based on data saved in DB. Reuse that value in
verifyPartialFile() instead of recalculating as SHA1 can take a
long time to calculate for large files.

This should improve the speed of PublishStashedFile jobs.

Bug: T200820
Change-Id: Ie2967c636b2f942921a125ef62d1a466c6035ca0
2024-03-02 00:56:39 -08:00
Giuseppe Lavagetto
8039e062c2 Add getCacheKey static method to UploadFromUrl
This will be useful in making the upload async and allow us
to retrieve the status of an upload remotely.

Change-Id: I7279185b3c5ece5f4177c0550ca0852810c8f052
2024-02-28 16:15:39 +01:00
jenkins-bot
f4d1a6f010 Merge "Make chunked upload delete chunks in deferred update" 2024-02-27 00:45:41 +00:00
Brian Wolff
befd8fcd93 Optimize AssembleUploadChunks to reuse SHA1 hash instead of recalc
AssembleUploadChunks was calculating the SHA1 hash of the same
file 5 times in a row. Calculating SHA1 hashes can be somewhat
expensive for multi-GB files, making the job slow, possibly to
the point of a timeout. This change ensures that the SHA1 value
is kept and reused when applicable so that the job will only
calculate it once.

Bug: T200820
Change-Id: I842814c7a2b7dc6e427e040c8dd4d43e7c7cabb4
2024-02-25 23:54:33 -08:00
Brian Wolff
d119c166b7 Make chunked upload delete chunks in deferred update
I believe deleting chunks of large uploads may have been taking
a fair bit of time, potentially triggering a timeout causing the
whole job to fail (Which is unfortunate as they will just be
deleted by a cron job later). Putting them in a deferred job
after transactions commit should ensure that the upload will
still go through.

Additionally, this ties it to AutoCommitUpdate which should cause
the deletes to be cancelled if something causes the transaction
to abort, which is a step towards making the Assemble job be retriable
on failure.

Bug: T200820
Change-Id: I49b8eb23adcd8960783f4f90707faa21760ce078
2024-02-23 11:58:48 +00:00
Brian Wolff
30585aef79 Improve chunked upload jobs and abort assemble job if already in progress
One possible theory for why chunked upload is unreliable is that
there are multiple jobs racing each other. Add some logging warnings
that should detect such a situation, and abort job if it appears the
job is already in progress

Bug: T200820
Change-Id: Ifaf217bc288dfaa1f7f4ca7e58f8210df232db1b
2024-02-21 15:52:31 -08:00
Brian Wolff
bb0209d56e Add additional debug logging for chunked upload
Users often complain that chunked upload is unreliable. However
it is often difficult to see what happened when it failed. Add
additional debug logging so we can better determine how often
chunked upload fails, and hopefully have a better idea what the
causes are.

This only adds logging and should not change any behaviour

Change-Id: I45b710fa57c7d05bb27a7b00a3303e78f5d2ff2a
2024-02-16 15:55:39 -08:00
Brian Wolff
ea84b992ef Change $wgSVGMetadataCutoff default to 5 MiB (previously 512KiB).
This is used to (among other things) detect lang tags in multilingual
SVGs. Users have complained that lang tags are often missed in large
SVG files.

The cut-off is used for two things during upload:
* Run some (simple) regexes to detect <?xml header
* Use XMLReader (with entity substitution enabled!) to look for specific tags.

The first check doesn't make sense to use a configurable cut off. Change
it to look at the first 4096 bytes only. The <?xml header is required to be
the first thing in the file other than BOM, so this should be more than
sufficient. XML parsers give a fatal error if there is whitespace before
the <?xml declaration.

It seems unlikely to be problematic to use XMLReader on up to 5MB of the file,
since that is a "pull" XML parser, and won't load the entire file at once.
The code that cuts off the SVG at the 5MB mark likely uses more memory
than parsing the file does. In fact, we separately use XMLReader to do
security checks with no such cut-off, so potentially it could even make sense
to remove the cut-off entirely, since clearly parsing the full file is not
causing problems.

Bug: T270889
Change-Id: I7350918647d92c40934a7c86e906b6bfb8a40ada
2024-02-09 19:20:34 -08:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
thiemowmde
ab1e3a66e7 Make use of the [ ... ] operator instead of array_merge
The array spread operator is documented to behave identical to
array_merge. The syntax is just much shorter and easier to read in
situations like this, in my opinion.

Change-Id: I3b016e896e552af53d87d5e72436dc4e29070ce1
2024-01-31 15:47:44 +01:00
Umherirrender
b7e9611d4d upload: Distinct logs in UploadFromChunks as mention in comment
Use the unused variable for that

Follow-Up: I3f03b93de835f6f5497f4b5904b37d62d40eb9f2
Change-Id: Id46783bd8d8fd155471fe842d209a7680f2436ea
2024-01-30 22:01:34 +01:00
jenkins-bot
51ef54982f Merge "upload: Remove a duplicate strpos call in UploadBase" 2024-01-25 17:20:13 +00:00
thiemowmde
69d17d7659 upload: Remove a duplicate strpos call in UploadBase
Just use the result from one call in both places.

I'm also re-arranging the code for readability. This is quite
critical here. A file name like ".htaccess" where the very first
character is a dot but no other dot follows must be considered a
filename without an extension. I hope this is more visible with
the `> 0`.

Change-Id: I24179de62c3f4443effe8a4ebd089a3f77fd84e3
2024-01-25 12:26:06 +01:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
Bartosz Dziewoński
2b0edb46ac Remove unused UploadChunkZeroLengthFileException
Added in 0095c08ed2 / r104687 (2011),
it has never been used (not even in that commit).

Change-Id: I7cfcbc6a6d3ce20aa4052904116ef72bec7faf6e
2024-01-17 04:32:35 +01:00
Bartosz Dziewoński
dba4096276 Reparent trivial subclasses of MWException
Bug: T328220
Change-Id: If10bdd89859a273817ab471458ca787319c77f7b
2024-01-17 04:32:33 +01:00
Dogu
c5097a6167 Replace MWException with Exception in UploadChunkFileException
MediaWiki's MWException class is deprecated since version 1.40.
Accordingly, this patch replaces the MWException base class with
PHP's built-in Exception class in UploadChunkFileException to
conform to current standards.

Change-Id: Iaf18520576a237d909e02c3238eb75070bcd5a6e
2024-01-05 09:13:34 +00:00
daniel
2cb8d6fbde layering: UploadBase should not depend on API modules.
API modules are high level request handler, lower level code should not
depend on them.

This patch solves the problem only partially, since it leaves references
to ApiUpload in AssembleUploadChunksJob and PublishStashedFileJob. These
jobs were already accessing ApiMain, so while this does not fully resolve
the problem, it reduces it.

Change-Id: I39c9e30cfb2860c573eed8a791f1a292a83cbd76
2023-12-16 01:29:45 +00:00
Bartosz Dziewoński
d0becf9651 UploadStashException: Remove redundant doc comments
Change-Id: I819de8dfc40526544f9bf129495424625fc0cdc9
2023-12-14 13:29:11 +00:00
daniel
d5cc98f9ff Deprecate UploadBase::isThrottled
This method is now redundant since rate limit checks are implicit in
permission checks. verifyPermissions() calls authorizeWrite( 'upload' ),
which will enforce any limits on the upload action.

Change-Id: I2ab3c646b8246411df501b548f652eaf11d0bc8e
2023-10-23 08:43:14 +00:00
Umherirrender
94589db301 upload: Log all filebackend errors in UploadFromChunks
Log all the errors from a status object and not only the first one in
the exception. This assumes errors or warnings from the FileBackend
always indicate a infrastructure error and never a user-input-related
error (which should not be logged).

FileRepo::quickImportBatch merge in status of init operations and the
real operations, show all failures in the log.
Seeing only backend-fail-internal is not helpful.

Bug: T228292
Change-Id: I3f03b93de835f6f5497f4b5904b37d62d40eb9f2
2023-10-01 18:44:23 +00:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00