Commit graph

680 commits

Author SHA1 Message Date
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
jenkins-bot
0ea2b08764 Merge "ApiBase: Restore 'user' support in checkTitleUserPermissions()" 2023-08-16 07:06:21 +00:00
Bartosz Dziewoński
dea66c8785 ApiBase: Restore 'user' support in checkTitleUserPermissions()
The support for passing $options['user'] has been lost in change
f6e1891c6f, despite being documented.

Change-Id: Ibcaa2739518f5b3d89beddeed058504d8093896d
2023-08-08 20:18:05 +02:00
Umherirrender
1bbee84b2f api: Show (no description) if apihelp-param message is missing
Showing the message key makes it look broken
This is the same message shown for missing apihelp-paramvalue

Change-Id: Ie83af8aae5acafce155e4b5fc32aeadc2b3813ac
2023-08-06 10:37:25 +00:00
Reedy
49a2f5cd12 api: Minor cleanup of some Api Base classes
Change-Id: Ieff6b5be8340571fe0f45a9213813b69869c9f36
2023-07-26 10:59:12 +00:00
jenkins-bot
6dfbb3c3e8 Merge "Consistently use LogicException for test-only methods" 2023-07-24 04:06:17 +00:00
daniel
a8ee61d9d6 Implement rate limiting in Authority.
Rate limits will automatically be checked by definitelyCan(),
authorizeRead() and authorizeWrite(). The authorize methods also
increment the counter.

UserAuthority tracks which limits have already been incremented during
the current request, to avoid duplicate increments caused by code that
still calls pingLimiter directly.

DEPLOY: Risky! We SHOULD not hit rate limits more often, but we might.
Rate limit metrics should be monitored closely, see
<https://grafana.wikimedia.org/d/8oA6CWr4z/mw-rate-limiting-overview>.

Bug: T310476
Depends-On: Iebd62b0487af9172edaeae41c9b31aaf2f20fd06
Change-Id: Ic349f03b7040343815b60b0a2c84a5780326c797
2023-07-23 17:16:56 +00:00
thiemowmde
ef84619cd3 Consistently use LogicException for test-only methods
"BadMethodCallException" sounds like it would fit, but it does
have a very different meaning, described as "exception thrown if
a callback refers to an undefined method or if some arguments are
missing". This is not what's going on here. These are methods that
should only be called from unit tests.

This appears to be a common mistake, often copy-pasted.

Change-Id: Ib39e28f596a883481d5f526460a5c871c75f5313
2023-07-22 16:21:42 +00:00
Reedy
06e5e82971 ApiBase: Cast $id to string in filterIDs
Bug: T341737
Change-Id: I3ac5ac314873e3cb30258fb97a6c9c56516d5dc9
2023-07-12 23:52:00 +01:00
Umherirrender
6c7dda1607 api: Change ApiBase::errorArrayToStatus to Authority
Change-Id: Ib05a7181cc68067a7ed02cbbbf534fbae46c6fa9
2023-06-19 20:16:10 +02:00
Daimona Eaytoy
8adf1bfb93 Replace some more usages of deprecated MWException
Bug: T328220
Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
2023-06-09 02:07:08 +02:00
Daimona Eaytoy
1c6e872bd4 Replace usages of deprecated MWException
Use SPL exceptions instead when the exception is unchecked.

Bug: T328220
Change-Id: Ia1e5edc2ef3269a44b670262b78b305d07559829
2023-06-06 17:05:32 +02:00
jenkins-bot
4245706ad3 Merge "api: Switch to use IConnectionProvider" 2023-05-02 11:14:54 +00:00
Bartosz Dziewoński
3fbd9c8153 ApiBase: Remove special error messages for blocks
Various tools want to display the full HTML error messages
when &errorformat=html&errorsuselocal=1 is specified.

Depends-On: I06c89534be605557ee9b0d90d2748f806fa2ae9e
Depends-On: I353e34d81afaa06750f8725181c808fabcebea42
Depends-On: Ib60ac795e9dda124b927816321aafe0853ee4500
Bug: T335319
Change-Id: Ie17987991d1e9a0d77da97e3a81fe0a21c6d7866
2023-04-26 17:57:36 +00:00
Amir Sarabadani
d7c8a0648f api: Switch to use IConnectionProvider
As much as possible

Bug: T330641
Change-Id: Icb943d6d65b210760ba8966419327c9603e768e0
2023-04-24 13:54:27 +02:00
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.

Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.

Do the same with the corresponding TitleFactory methods.

Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).

Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
2023-04-22 16:45:09 +02: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
Gergő Tisza
7c03a6f331
API: Allow use of multivalue parameter documentation for templates
Allow the use of PARAM_HELP_MSG_PER_VALUE for PARAM_TYPE='string'
and PARAM_ISMULTI=true, which is the setting used for templated
parameters (PARAM_TEMPLATE_VARS).

It's common for templated parameters to take the variable parts
of the name from some fixed set, but they are required to use
PARAM_TYPE=string so it makes sense to allow the use of multi-
valued parameter documentation for that case.
The other option would have been to allow templated parameters
to be enums, which also makes sense and could be a complimentary
improvement; there are two reasons to prefer the current approach:

* Getting the list of allowed values might have a performance
  impact that we only want to incur when the (optional) parameter
  is used, while an enum requires the value list to be generated
  every time the API module is used. So there would be some
  value in using string type for templated parameters with a
  known set of documentable values even if enum were also allowed.
* Per-value documentation might be useful outside the template
  use case for non-restricted multi-valued strings: maybe all
  values are allowed but there are some values with special
  meanings that are worth documenting.

Change-Id: I53f9ae840c0a7eee76c4b57f95390b5045707efd
2023-01-17 21:21:22 -08:00
Amir Sarabadani
523ab7cff8 Reorg: Move RawMessage to under language/
To follow Message. This is approved as part of RFC T166010.

Also namespace it but doing it properly with PSR-4 would require
namespacing every class under language/ and that will take some time.

Bug: T321882
Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
2022-12-16 11:30:19 +01: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
Umherirrender
75ec894af0 api: Validate timestamp in continue parameter
Bug: T321265
Change-Id: Ib46bc3e643938f56e0c58a3c5f5e093327e00964
2022-11-01 22:40:10 +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
Daimona Eaytoy
350e9b88c1 Fixes for the phan upgrade, part 1
Mainly, document some parameters as non-empty-array so that phan knows
the list of arguments won't be empty when unpacking.

In EditPage, account for hooks potentially unsetting the copyright
notice.

Also rewrite some code in LogPager, so it's hopefully easier for phan to
understand what's going on.

Change-Id: Ic0638571554424098d0743db32dd46723a08e103
2022-10-08 13:08:47 +00:00
Bartosz Dziewoński
a8c9e98661 Deduplicate code for parsing API 'continue' parameters
30+ API modules had nearly identical code to split and validate
the value of the 'continue' parameter.

Introduce the ApiBase::parseContinueParamOrDie() method and use it to
replace most usages of ApiBase::dieContinueUsageIf(). A few remain in
modules with more complex continuation handling.

Inline most single-use variables that remained after validation was
moved into the new method.

Change-Id: I66bd59ecd4ad16e2039e90f7d66cfa276e6c1c2a
2022-09-29 16:05:31 +00:00
Reedy
f15a759df1 api: Minor code cleanup
Change-Id: I1f20597093448d00435158a9ac861873000bb057
2022-08-14 13:10:53 +00:00
Thiemo Kreuz
e23b070b45 Make use of ?? and ?: operators where it makes sense
Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
2022-08-04 21:43:12 +02:00
Mark A. Hershberger
601048c559 Pass int to ApiUsageException::newWithMessage()'s $httpCode param
Bug: T311544
Change-Id: I4fd4557dbac889175eef4582fa57f6f2274f3a69
2022-06-29 08:56:21 +00:00
Umherirrender
8d41744de2 api: Replace deprecated WikiPage::factory/newFromID
Bug: T297688
Change-Id: I5537bd615484bf3a9eb5b597121fa4881c1a5961
2022-06-24 19:01:40 +02:00
Umherirrender
eaac04cd3b Replace deprecated wfReadOnly/wfReadOnlyReason
Bug: T283978
Change-Id: I49f8c7bf1162dc834a1708e2e581f6fb264bbd0a
2022-06-20 15:35:24 +00:00
daniel
461080899a ApiBase: Reset self::$filterIDsCache between tests
self::$filterIDsCache caches database state, it gets out of whack when
we reset the database between test cases.

The cache was originally introduced to fix T140302.

Change-Id: I9a05c60d84d92f6798154bfa77c6288576dc53bc
2022-06-13 15:00:58 +00: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
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Tim Starling
97b8262d1f Use UserRigorOptions directly
Conventionally, public constants are accessed via their declaring
class, except for self:: which is an acceptable shortcut.

Change-Id: If05eab72140267e6ef54736710d751d7f24a7860
2022-03-25 10:06:34 +11: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
daniel
cf581bb2ca Define MW_INSTALL_PATH constant and BaseDirectory config.
Application logic should use the BaseDirectory config variable.
Framework code should use MW_INSTALL_PATH to locate files should.

NOTE: Update https://www.mediawiki.org/wiki/Manual:$IP

Bug: T300301
Depends-On: I7142af16d692f26e90673b058029f572c1ea3991
Change-Id: Ib4caa80bb7007c4c7960a2fd370cf5da7d9ba344
2022-03-04 14:18:27 +01:00
Reedy
bec8ed61da ApiBase: Annotate deprecated constants individually
Change-Id: I30f2e21eb5d10a54fa5955586be14d9c3eddf056
2021-10-09 01:40:18 +01:00
Umherirrender
e27cb5e468 API: Fix null docs in ApiBase
Change-Id: I63399b1ee2f2c8d6f7f6a5781a5a61de5d21ede8
2021-09-21 17:57:56 +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
44fd53fee3 Using @return never documentation on always-throw-function
This helps phan to detect unreachable code and also impossible types
after the functions.
It helps phan to avoid false positives for array keys
when the keys are checked before

Bug: T240141
Change-Id: I895f70e82b3053a46cd44135b15437e6f82a07b2
2021-09-07 17:29:03 +02:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
Umherirrender
aa39959bc6 api: Inject GroupPermissionsLookup into modules
Remove the @internal getter for the global and
use MediaWikiServices directly at one remaining place.

Change-Id: I120f9c00d22d6dcf2a996eec5b9d5e5d41b68284
2021-07-06 20:48:35 +00:00
jenkins-bot
8e20e195eb Merge "Authority: expose user block info" 2021-06-30 15:12:06 +00:00
daniel
b3b70624c9 Authority: expose user block info
Expose info about user blocks from Authority. This allows calling code
to provide more detailed information to the user about why they are
denied some action on the wiki.

Bug: T271494
Change-Id: Ia84e469888866d72752aad355292666c31e12bad
2021-06-30 13:42:21 +02:00
Umherirrender
0c73d6df27 api: Replace deprecated User::newFromName/getOption in ApiBase
Change-Id: Idfb429549f0281e2edbc532efc347e83e77ab80c
2021-06-28 21:37:21 +02:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
jenkins-bot
bb0c0d446f Merge "Remove hard deprecated methods from ApiBase" 2021-05-10 17:47:45 +00:00