Commit graph

312 commits

Author SHA1 Message Date
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
Fomafix
1ba8a15a88 Remove superfluous spaces
Change-Id: I6ef0953be7b9a0baac5fb96df4d254a463fb7298
2024-07-03 04:24:59 +00:00
Umherirrender
7ba9818e07 api: Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Icc5b59f9ef6319d1fb785fcda17f43c94f94cc38
2024-06-14 21:38:40 +00:00
WMDE-Fisch
f089276e0f Replace deprecated status->getErrors calls in API classes
Change-Id: I770a98e7cc3e2bc78e363dd73439ab8b8599e0da
2024-06-13 13:27:01 +02:00
Michael Große
135315d2b2 Document more ApiBase methods that accept MessageSpecifier, not just Message
The documentation for ApiErrorFormatter::addError() was updated in
I1323d18baf17a8a27cc9bed31860c4cc89e61a22

Otherwise, phan complains about handing a MessageSpecifier to that
method.

Change-Id: If421729d58cd7e3e7dd7b866c671915ea8f47154
2024-05-31 10:07:02 +02:00
Umherirrender
28078f7081 api: Reduce use of WebRequest in action=upload
$this->mParams['file'] and $this->mParams['chunk'] are set to instance
of \Wikimedia\ParamValidator\Util\UploadedFile in the validation step.
Use ApiMain::getUpload

Fix ApiUploadTestCase to set error key to OK,
the null gets converted to UPLOAD_ERR_NO_FILE in
\Wikimedia\ParamValidator\Util\UploadedFile::getError
and breaking the test.

Change-Id: If57307a3f8278fd3fa25732231595bf148935679
2024-03-29 21:04:59 +00: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
74157f863b Merge "Use transactional time limit on api Upload (except checkstatus)" 2024-03-11 15:44:12 +00:00
jenkins-bot
e78541e80f Merge "upload: switch AssembleUploadChunksJob to GenericParameterJob" 2024-03-03 09:30:51 +00:00
Aaron Schulz
9c14663be9 upload: switch AssembleUploadChunksJob to GenericParameterJob
Change-Id: I75e401c047828abf4b42d519509a1e717509ba2f
2024-03-03 00:02:52 +00:00
Brian Wolff
de2e653583 Fix typo in log message
Change-Id: Ic688cca85b42bed2706d9579022429ea94fb1818
2024-03-02 00:34:29 -08:00
Brian Wolff
46cfc70b69 Use transactional time limit on api Upload (except checkstatus)
Uploads can be a long operation that we would prefer not to get
cut off. The API upload module supports a variety of upload types.
This calls useTransactionalTimeLimit() for all of them (except
checkstatus which is not a write operations) however it is more
applicable to some methods than other methods such as "async" where
the real work happens in the job queue.

Change-Id: I6795f6d38693306f22091afa77123f2f0721ef5b
2024-03-01 14:38:39 -08:00
Brian Wolff
10a7d46ac4 Use ->push not lazyPush for PublishStashedFile job
Follow up 4db0b0cb44

Change-Id: I1941372dd9a498ea286db75f16be52b549c6bb20
2024-02-27 08:29:43 -08:00
Brian Wolff
4db0b0cb44 Prevent race condition between AssembleUploadChunksJob and transaction
The ChunkedUpload feature stores information about in progress uploads
in the uploadstash table. The AssembleUploadChunksJob reads this data
from the primary DB to prevent race conditions. However the job is
inserted into the job queue before the current transaction commits,
so the race is still present. The job sees the old version, and as
a result drops the final chunk, corrupting the file (Often noticable
by files that have a size which are a multiple of 5mb).

This changes the job push from ->push to ->lazyPush which will make
the job insert happen in a DeferredUpdate after the primary transaction
has commited. Additionally, pass the expected size to the job queue
and assert that UploadStash class has the same filesize as expected.
This will ensure that if this issue happens again, the upload will
abort and it will show up in the logs instead of silently corrupting
files.

Bug: T350917
Change-Id: I37c5c8ffc882026a9fab252b20a10cf4c43d48bc
2024-02-22 20:37:42 -08: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
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
jenkins-bot
11701c34d3 Merge "layering: UploadBase should not depend on API modules." 2023-12-16 01:52:44 +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
Giuseppe Lavagetto
f7393a3255 Convert PublishStashedFileJob to GenericParameterJob
Change-Id: If7166b813589413b575f8b458a65370ece6c2338
2023-12-13 09:07:20 +01:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01: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
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Bartosz Dziewoński
365a588238 Use real type hints for services etc. in api/ except ApiQuery*.php
Mostly used find-and-replace:

Find:
/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|)
Replace with:
\3 \1 \4

Followed by some manual review to make sure I'm not changing too much,
omitting some changes that looked too complicated and anything that
caused test failures, and some whitespace fixes.

Change-Id: I6ec7587607df4f1a4f448a096c3e44c4e5270b70
2023-08-29 01:04:26 +00:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Umherirrender
be67b9ba05 build: Remove unneeded newline from one line condition/foreach
Improve readability

Change-Id: I22ed08bbd8d821c4d4df620af4c5e97b043c305a
2023-08-22 21:49:58 +02:00
Thalia
e3e48dd5c7 Prompt temporary users without upload permissions to log in
mw.Upload.BookletLayout and ApiUpload prompt IP users to log in
if they do not have the permission to upload. Show the same
prompt to temporary users if they do not have the permission.

Bug: T331578
Change-Id: Ic35d8277772d69155fe95b24cc028f91b8a366bb
2023-05-24 16:05:21 +03:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
csimiyu
d16fa8968d Remove separate checks for global blocks from APIUpload and SpecialUpload
Since f102d7b42e882b330030021bb3419af708b26fa5 in the
GlobalBlocking extension, global blocks are found when checking
for blocks, and do not need to be checked for separately from
core.

Bug: T317325
Change-Id: I7e93ec2d8125fd4a41ed3dec7c0ef9148ab1afe2
2022-11-09 16:40:48 +00: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
Reedy
f45fefec0e api: Replace numerous more deprecated constants
Change-Id: I498a315b8b4b56d5e2f939e797adbe0487cd7d07
2022-06-06 02:24:41 +01:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
Ammarpad
b24332fbcc ApiUpload: Pass empty tags as empty array instead of null
If no tags are specified, null shouldn't be passed as it may
cause problems down the stack

Bug: T302918
Change-Id: I46033d5ddda055c275dbda71d5c38c4a7a858c9d
2022-03-03 12:29:01 +01:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Umherirrender
04b07ee746 API: Using @return never documentation on more functions
Due to a bug in phan the usage needs suppression

Bug: T240141
Change-Id: Ic2da20b663ff2ff291c73329ac1f152d61d1df56
2021-09-11 21:35:37 +00:00
Umherirrender
a7bb7cc5c5 Remove unreachable code after exception/die/exit
Change-Id: Ia81903fb2a8157625fbe63115097eccc1161b5db
2021-09-03 23:14:28 +00:00
Umherirrender
d146800ee8 api: Inject services into ApiWatchlistTrait
Bug: T259960
Change-Id: I73596f8c924ec4a02a7042608d19a35f82bb752a
2021-07-06 20:15:30 +00:00
Umherirrender
4a74f71af6 api: Inject services into ApiUpload class
Bug: T259960
Change-Id: I2d02dd433fbf6b534a8af1f405fee761feed3654
2021-07-02 14:51:26 +02:00
Petr Pchelko
ee7d3e9335 Convert ChangeTags public interface to Authority.
Bug: T275507
Change-Id: I3b7f99391ab299df2b046a2878010cf6afe7fed7
2021-02-24 14:09:16 -07:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
Thiemo Kreuz
6f901ef17c Make use of native array_column() function where possible
Change-Id: I78108e7dc5a10d892e97b0101c1b72cb8d363e97
2020-11-11 22:48:53 +00:00
Ammar Abdulhamid
cf004d524d Remove requirement for ApiWatchlistTrait to be in ApiBase.
This trait is not needed in ApiBase and its presence here is
proving to be problematic. See I795db12.

In this patch, the trait usage (more precisely the 'use statement')
has been removed from ApiBase and accordingly the signatures of
ApiWatchlistTrait::getWatchlistValue() and ::setWatch() have been
altered to now require User object.

With these changes, the abstract getUser() method in the trait is no
longer needed, so it has been removed also.

All core usages of the affected functions are fixed in this patch.

The trait is used in only one extension according to codesearch tool,
the extension will be fixed in  Ic22e163.

Bug: T262175
Bug: T248512
Follow-up: Ia18627b9824dca81f44f0571e8420d89b7626cf6
Change-Id: Idabcea71edfca9e7ed42000a258c99ff407873d4
2020-09-07 01:13:57 +01:00
jenkins-bot
e9ad97eead Merge "Add watchlist expiry support to applicable APIs" 2020-07-14 04:37:44 +00:00