Commit graph

468 commits

Author SHA1 Message Date
Tim Starling
edea1bc177 block: Fix DBS::acquireTarget() race using GET_LOCK()
A crude solution for the acquireTarget() race condition. Use SQL
GET_LOCK() to lock the target from the acquireTarget() call until the
transaction is committed.

Add FOR UPDATE to the acquireTarget() SELECT, otherwise it just sees the
snapshot version of the row and inserts a new row anyway.

Add a test which reliably failed prior to the change.

Reword the ipb-block-not-found message. This is normal for simultaneous
blocks of the same target. Don't contact us. In the API, remap it to
"alreadyblocked".

Bug: T389028
Change-Id: I1fa35bf08d456a93930194786f77df389217ba61
(cherry picked from commit 2b65587e4d92e7f27661e8821b14f74ade939cfa)
2025-04-07 11:43:34 +00: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
Gergő Tisza
38ecc981bc block: Invalidate sessions on BlockDisablesLogin blocks
Use SessionManager::invalidateSessionsForUser() rather then just
resetting the user token when logging out a user who is blocked
on a $wgBlockDisablesLogin wiki, so they are properly logged out
even when an authentication extension like CentralAuth is active.

Doesn't entirely fix the todo in that that it will invalidate
sessions for the local user with the same name as the blocked
user, and if that's a cross-wiki user there's still no guarantee
it is the same user. But in practice it's unlikely not to be.

Change-Id: Ic48814fcfeb71ca0736bac5f133ff407cf494021
2024-10-11 12:24:16 +00:00
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
Dreamy Jazz
6547b639d8 Add SpreadAnyEditBlock hook
Why:
* A hook is needed which is called when User::spreadAnyEditBlock
  is called, so that extensions which provide alternative blocking
  mechanisims (such as the GlobalBlocking extension) can spread
  their blocks when local blocks are spread.

What:
* Add SpreadAnyEditBlockHook which is called from User
  ::spreadAnyEditBlock when it is called except when the user is
  not registered.
** The hook is called even if the user is not locally blocked
* The return value of User::spreadAnyEditBlock is modified to
  return true if either a local block or alternative blocking
  mechanism spread blocks.
* Update UserTest to test this new behaviour.

Bug: T374857
Change-Id: Id302a6362d6177c89da9cdf4e677b3822ecb85f1
2024-09-24 12:04:20 +01: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
Matěj Suchánek
82d7b894bf Fix some typos
Change-Id: I1a41f33c65bc9edf2df248581a2c45c5c79c4f93
2024-08-18 18:59:44 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
Bartosz Dziewoński
13289a1269 Use real type hints for services etc. in includes/block/
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: I819ed771c915293663856c577a481d607b76ed80
2024-07-31 08:54:31 +00:00
Jayden Bailey
673171fe89
Return early in BlockManager::trackBlockWithCookie if cookie blocks are disabled
This prevents an unnecessary database lookup on every web request.

Bug: T371249
Change-Id: Idc3035996fccbfc661580ba459fec8f44a0b526c
2024-07-29 13:37:33 +01:00
Umherirrender
fc9e42823b rdbms: Create IReadableDatabase::andExpr() / ::orExpr()
Avoid the call to internal constructor of AndExpressionGroup and
OrExpressionGroup by creating a factory function similiar as the
IReadableDatabase::expr function for Expression objects.

This is also a replacement for calls to ISQLPlatform::makeList with
LIST_AND or LIST_OR argument to reduce passing sql as string to the
query builders.

Created two functions to allow the return type to be set for both
expression group to allow further calls of ->and() or ->or() on the
returned object.
Depending on the length of the array argument to makeList() it is
sometimes hard to see if the list gets converted to AND or OR, having
the operator in the function name makes it easier to read, so two
functions are helpful in this case as well.

Bug: T358961
Change-Id: Ica29689cbd0b111b099bb09b20845f85ae4c3376
2024-07-11 15:29:20 +00:00
Bartosz Dziewoński
ccd423225f Add "implements Stringable" to every class with "function __toString()"
In PHP 8, but not in PHP 7.4, every class with a __toString() function
implicitly implements the Stringable interface. Therefore, the
behavior of checks like "instanceof Stringable" differs between these
PHP versions when such classes are involved. Make every such class
implement the interface so that the behavior will be consistent.

The PHP 7.4 fallback for the Stringable interface is provided by
symfony/polyfill-php80.

Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
2024-06-13 00:23:39 +00:00
Umherirrender
a9adc61d35 Use RawSQLValue for some SET clauses in update/upsert
Change-Id: I03c068c4bf098ab073989a0ea32a0f87fe878727
2024-05-29 19:48:09 +00:00
Umherirrender
be157850ad Replace IDatabase::buildLike with expression builder
Bug: T361023
Change-Id: I0fcb61ff1b15931477bce3c8f850a8ce97405a36
2024-05-18 12:29:17 +00:00
Tim Starling
a5372218b7 block: Deprecate and stop using $wgBlockTargetMigrationStage
* Deprecate and stop using $wgBlockTargetMigrationStage. Remove
  block_target migration code.
* Make the $schema parameters to DatabaseBlockStore methods default to
  SCHEMA_BLOCK. Avoid passing these parameters where possible.
* Remove cleanupBlocks.php
* Deprecate DatabaseBlock static methods which try to present the old
  schema for b/c.

Bug: T362133
Change-Id: I845bad8cc09a4528fef46a6f9d490ebdec881d99
2024-05-10 15:54:17 +10:00
Tim Starling
eb391335bb block: Fix overly broad block selection in getRangeCond()
In the new schema, getRangeCond() with a specified range of say
1.2.0.0/16 would match blocks of narrower range with the same start,
e.g. 1.2.0.0/24, because a match of bt_ip_hex was sufficient, but that
is the same as the start of the range.

So, when searching for single IP blocks, add a condition requiring
bt_range_start IS NULL.

This affects the bkip parameter to ApiQueryBlocks and searches from
Special:BlockList.

Add regression test.

Change-Id: Ie3943befb8a02cc4939624f7bad48ae50056cd7d
2024-05-08 09:12:43 +10:00
Tim Starling
6abb5aa080 block: Fix inadequate GROUP BY in HideUserUtils::addFieldToBuilder()
With the new schema and sql_mode=ONLY_FULL_GROUP_BY, we get an error
from LocalIdLookup::lookupCentralIds() due to user_name not being in the
GROUP BY.

So, just use a subquery, identical to the one used by getExpression().

Change-Id: If22561b5ce5762a33fc8aa13ee9406990c8ae8ce
2024-05-08 09:12:43 +10:00
jenkins-bot
b01108102d Merge "Migrate to IReadableDatabase::newSelectQueryBuilder with queryInfo" 2024-05-05 10:48:15 +00:00
Umherirrender
d38b9e4cfa Migrate to IReadableDatabase::newSelectQueryBuilder with queryInfo
This is using SelectQueryBuilder::queryInfo to interact with legacy code

In the long term this needs refactor to get a SelectQueryBuilder from
the class instead of a query info array.

Bug: T344971
Depends-On: I5dff80a2819bba4e923654ef31816a54269354b3
Change-Id: Ibf44e7de30e71fe8dd6447f77dfd0bf726be0a9b
2024-05-04 19:56:11 +00:00
WMDE-Fisch
21c5baff50 Block: Drop AbstractBlock::getPermissionsError
Bug: T362636
Change-Id: I6ddfa089aee47451819a92eaae100c1cc8486d20
2024-05-04 18:22:03 +03:00
WMDE-Fisch
3000c94e24 Block: Drop DatabaseBlock::purgeExpired
Bug: T362636
Change-Id: I85fe2ba5da844678bfeb66f84d0c406fd8f7b19c
2024-05-04 18:13:59 +03:00
Amir Sarabadani
8e183495e1 Stop using LoadBalancer::getConnectionRef() so it can be hard-deprecated
Bug: T326274
Change-Id: I90493d7cd4c21fdc022bcc19765fc04d986a9c8f
2024-04-30 13:31:08 +01:00
Taavi Väänänen
ed7e787f32
Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyle
Fix the real issues found by this sniff, and convert the remaining
false positive ignores to per-line ignores so that any more real issues
won't be added.

Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
2024-04-22 18:26:14 +03:00
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02:00
Umherirrender
98da56b588 block: Typehint delta in DatabaseBlockStore for sql safety
A non-typehinted argument could be a raw sql string ending in the sql
statement, using typehint makes sure this is an safe integer

Change-Id: I2c1eef4dd2a05b9bb1329b79749502a242804687
2024-04-18 21:41:52 +02:00
jenkins-bot
6d2ec5657e Merge "Use explicit value checks where "0" is valid input" 2024-03-30 21:45:32 +00:00
James D. Forrester
85d95dd458 Drop old class_aliases for before MW 1.39 that were missed
The RandomPage alias was dropped in an earlier commit, so
group the release note entry in with these.

Change-Id: I207d7463ced1a1bb8b8ac749eba175fc0037a217
2024-03-20 12:10:42 +00:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
Tim Starling
768fd92fc0 block: Clarify function of HideUserUtils aliases and use them consistently
* Add a comment explaining why we need table aliases in HideUserUtils
  subqueries.
* Use the table aliases consistently in inner field references. While
  this does not appear to be strictly necessary, since unprefixed fields
  refer to the inner query by default, it helps to improve the clarity
  of the code.

Change-Id: Id68684ea12060a259dc87e66edd63b925da2c3b1
2024-03-19 11:31:03 +11:00
jenkins-bot
873346377d Merge "block: Fix DatabaseBlockStore::newLoad index usage" 2024-03-18 23:57:04 +00:00
Tim Starling
652ac0b375 block: Fix DatabaseBlockStore::newLoad index usage
There's no index on bt_user_text alone, only one that is prefixed with
bt_ip_hex. So include a condition on bt_ip_hex when searching for blocks
by username.

Bug: T360165
Change-Id: I99ed17ed66449ab7c3f76c98d90f91a75fbd8fd5
2024-03-18 09:36:33 +11:00
jenkins-bot
f254f8b6c1 Merge "block: Use a scalar subquery in HideUserUtils::getExpression" 2024-03-17 22:21:29 +00:00
Tim Starling
8606c00b52 block: Use a scalar subquery in HideUserUtils::getExpression
On en.wikipedia.org, MariaDB chooses to materialize the subquery,
copying about 810,000 rows to a temporary table.

So, use a dependent scalar subquery, which is not eligible for this
"optimisation".

Bug: T360163
Change-Id: I7819a6870871687ea96f92dfd3f8fe581b54cc24
2024-03-15 13:47:48 +11:00
Umherirrender
8f5c33bfe0 Use IConnectionProvider in DatabaseBlockStore
Allows to type-hint IReadableDatabase for the replica

Change-Id: I7b08808c754e9570a78de03bf32deb6c7d561c9c
2024-03-14 00:24:29 +01:00
Tim Starling
dcbabb1a1d Fix autoblock update
When updating an autoblock due to a reblock, use the correct reason
message instead of the parent block reason.

If the reblock causes the parent block to expire before the autoblock,
adjust the autoblock expiry time downwards.

Adapt testUpdateBlock() to be a regression test for these two bugs.

Bug: T351173
Change-Id: I19843e4971106250cf9644ef68d68d6e33c6e3ab
2024-02-28 13:13:47 +11:00
Umherirrender
8df2cbe287 block: Pass wikiId to DatabaseBlock::getId in DatabaseBlockStore
For cross-wiki autoblock support

Bug: T358208
Change-Id: I9396f289237769a7b5fc9e1a8c575116abaf7609
2024-02-22 21:35:23 +01:00
Matěj Suchánek
7f6385e851 Use explicit value checks where "0" is valid input
User "0", page "0" and edit summary "0" are all valid.
Treating them as empty may cause subtle inconsistencies.

Change-Id: I90a92bfb972cca840e5d8060dac3f116a22990db
2024-02-22 09:59:32 +01:00
jenkins-bot
32e20dc873 Merge "block: Include bt_auto in acquireTarget() conditions" 2024-02-16 22:00:06 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
Tim Starling
45b88830d3 block: Include bt_auto in acquireTarget() conditions
When searching for an existing block_target row to use for a new block
of an IP address, include bt_auto in the conditions. Otherwise, if there
is an existing autoblock, the new block will fail due to a mismatch of
bt_count, leaking information about the private IP address.

Bug: T357366
Change-Id: If873ca590aadd29ab0b9d672a99438d70c4292d9
2024-02-13 13:20:38 +11:00
Tim Starling
3cdd4d6256 block: When inserting in write-both mode, ensure the ID remains synchronised
The block ID is exposed in various places and must be consistent between
the two schemas.

Bug: T357366
Change-Id: I5b104242341ebcfec8f33a904c771d61d236dca2
2024-02-13 13:20:36 +11:00
Alexander Vorwerk
7d4a5d6e01 DatabaseBlock: Deprecate methods relying on global state
Change-Id: Idf8662deeac081acd1348e729ebd7f240864f7a9
2024-02-10 23:28:16 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Alexander Vorwerk
8038cc1935 DatabaseBlock: Fetch correct DatabaseBlockStore
Bug: T284873
Bug: T291849
Bug: T291994
Change-Id: I2254e41d02ceaadff9b84e75127ca848bc920d08
2024-02-08 01:14:47 +00:00
jenkins-bot
d023c7fb99 Merge "Move creation of BlockErrorFormatter into FormatterFactory" 2024-02-02 22:29:47 +00:00
jenkins-bot
c388d91652 Merge "BlockUser: parse expiries using ExpiryDef::normalizeExpiry" 2024-02-02 11:37:53 +00:00
MusikAnimal
b179bbf9b4 BlockUser: parse expiries using ExpiryDef::normalizeExpiry
This should act identical to before, apart for support of expiry before
unix epoch. This shouldn't be a real world use-case, rather the check
for a negative expiry was for PHP 5 support when -1 was returned instead
of false.

Bug: T248196
Change-Id: I803c99f20844a4ccf151b454e75f7d4d128f429c
2024-02-02 11:13:15 +00: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
daniel
3d55397207 Move creation of BlockErrorFormatter into FormatterFactory
The idea is that all formatters that need the user language or
other request specific context should be instantiated by
FormatterFactory.

Change-Id: I8334cc89dcf0f293298b82e004116be50a90f0d1
2024-01-26 13:03:44 -05:00
jenkins-bot
37dcd4adf8 Merge "Allow temporary accounts to be blocked with 'hideuser' enabled" 2024-01-23 10:24:29 +00:00