Commit graph

10 commits

Author SHA1 Message Date
daniel
d0bbe78b23 RateLimiter: Fix peek mode
Why:
- Setting the increment to 0 should check the limit without bumping it.
- This was apparently broken by If3e66491306f22650.

What:
- Use LimitBatch::peek if the increment amount is 0

Bug: T381033
Change-Id: Ife76a1976a2063f051f00302e5adaebd701e6367
(cherry picked from commit e09606b3dc44711571cc6cf2d0d11bd7784d0cdd)
2025-03-01 15:51:16 +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
Bartosz Dziewoński
3781349e27 Use real type hints for services etc. in includes/Permissions/
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

More could be done, but to keep this patch reasonably sized, I only
changed the most obvious and unambiguously correct cases.

In some cases, I also removed redundant doc comments on the
constructor, and re-ordered the properties to match the constructor.

Change-Id: I3f8427ae4f5d55177ae18986ef15d84d0e7bf6f4
2024-07-31 08:56:17 +00:00
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01: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
daniel
e70e811ee3 RateLimiter: collect statistics
To prepare for changes to how, when and where we check rate limits,
we should start collecting statistics on how limits are checked and
enforced in production. This will alert us to unintended effects of
the refactoring. In addition, it provides information on the impact
each limit rule has.

Bug: T310476
Change-Id: I9dfbf3847b73ab5f145722c45b93056408ad9444
2023-06-19 21:18:56 +02:00
Tim Starling
8de63ae485 Make RateLimiter use WRStats
Bug: T261744
Change-Id: Ib947340cbac19fb26176257e1707e51426c7f76e
2022-07-16 11:00:22 +00:00
Tim Starling
8d90307c50 Fix typos
Change-Id: I2c01adb70e179abbeb6c5ae8bee3abcbdbac8edf
2022-06-30 09:44:00 +10:00
daniel
dd2e9905cd Extract RateLimiter from User
This moves the logic for rate limiting out of the User class into a
standalone service.

Change-Id: I2881913876c855a1538bac92f0dabac3b3bddcfc
2022-06-27 13:23:24 +00:00