Commit graph

133 commits

Author SHA1 Message Date
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
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
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
Alexander Vorwerk
7d4a5d6e01 DatabaseBlock: Deprecate methods relying on global state
Change-Id: Idf8662deeac081acd1348e729ebd7f240864f7a9
2024-02-10 23:28:16 +01: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
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
jenkins-bot
440b56cbb2 Merge "Drop User::blockedFor() and AbstractBlock::getReason(), deprecated in 1.35" 2024-01-12 17:37:41 +00:00
Alexander Vorwerk
e838ef9773 Don't allow passing a db to DatabaseBlockStore::insertBlock
Bug: T291849
Change-Id: I5f5cec791eb2999d7295440248f74fba79156b6f
2024-01-01 14:23:24 +01:00
James D. Forrester
de07700e86 Drop User::blockedFor() and AbstractBlock::getReason(), deprecated in 1.35
Bug: T277511
Change-Id: I35c16f92470e65126db8961ee3599256c96ec554
2023-12-11 16:20:16 +00:00
Tim Starling
990acd88be Stop using nonexistent DatabaseBlock constructor options
Remove the 'user' option from the documentation and defaults. It has
been ignored since a3b4881f6f (2021, 1.37).

Fix tests which pass unknown constructor options. I found these by
temporarily patching the constructor to throw when an unknown option is
given.

Change-Id: I95cb2a38a5688d83c90ad501786f6d6bb02765ba
2023-11-06 12:03:51 +11:00
Tim Starling
cc40f0a12d Migrate callers of DatabaseBlock methods moved to DatabaseBlockStore
* Migrate callers of DatabaseBlock methods newListFromTarget,
  newFromID, newFromTarget, doAutoblock.
* Deprecate DatabaseBlock methods newFromID and getAutoblockExpiry.
  These are the methods with no extension callers in code search.

Bug: T255433
Change-Id: If0358459f53d32e7fe984c2fb8b61e0088f28922
2023-11-06 12:03:51 +11:00
Tim Starling
d06ac1a3cd Move DatabaseBlock read query methods to DatabaseBlockStore
* Move to DatabaseBlockStore the DatabaseBlock methods newFromID,
  getQueryInfo, getRangeCond, newFromRow, isExemptedFromAutoblocks,
  doAutoblock, updateTimestamp, getAutoblockExpiry, newFromTarget,
  newListFromTarget.
* Split DatabaseBlock::getBlocksForIPList. Now
  BlockManager::getBlocksForIPList() is responsible for XFF header
  validation and trusted proxy handling. DatabaseBlockStore::
  newListFromIPs() just does the queries and constructs the Block
  objects.
* In DatabaseBlockStore::newFromRow() and doAutoblock(), use the
  DatabaseBlock constructor instead of calling many setter methods. Add
  constructor options decodedExpiry, decodedTimestamp, id,
  parentBlockId and restrictions to support this.
* Move isExemptedFromAutoblocks() to its own service. Remove the cache
  since in my testing with production eval.php, the WAN cache fetch is
  10 times slower than just using the message cache, contradicting the
  comment written in 2008.
* Fix AuthManagerTest which was previously passing an unrecognised
  "restrictions" option to DatabaseBlock. Now that the option actually
  works, we have to use the right type.

Bug: T255433
Change-Id: I5049e60be1681f67fcca133e569e315792dc42dd
2023-11-03 11:00:57 +11:00
Amir Sarabadani
16cd567522 Migrate a couple more wfGetDb() calls to ICP
Bug: T330641
Change-Id: I1b5edf34151ef7a379d3f5787ac6c850d069cba0
2023-10-17 22:09:21 +02:00
Tim Starling
cdbd39bfdf Blocks cleanup
* Make BlockManager internal methods private, since nothing calls them
  anymore.
* In AbstractBlock and DatabaseBlock, remove deprecated public
  properties mExpiry, mHideName, mTimestamp, mAuto and mParentBlockId.
* In BlockRestrictionStore, remove all the "instanceof Restriction"
  checks. If someone passes in something that's not a Restriction, we
  should throw, not ignore it, because we don't know the caller's
  intention. Add a type declaration to $hasher in equals() so that it
  will throw.
* Remove the "m" prefix from all private and protected properties.
  AbstractBlock is not stable to override so this is not a stable
  interface break.
* In BlockRestrictionStore::restrictionsToRemove(), use an O(N)
  algorithm.
* In BlockRestrictionStore::rowToRestriction(), use a switch instead of
  a type map, so that the calls are statically analyzable.
* In BlockUser::__construct(), fix the initialisation order issue by
  inlining the relevant logic.
* Rename variable $actionRestriction.
* In Special:Block, fix call to deprecated method getTargetAndType(),
  and hard deprecate it. @deprecated has the effect of deprecating a
  method for both internal and external callers, there's no such thing
  as an external-only deprecation. So it's necessary to rename it if you
  want to keep it as a private method.

Bug: T345683
Change-Id: If4a4a18d7b5fec825417de81302266119c215fd3
2023-09-20 09:40:52 +10:00
jenkins-bot
796f3b174a Merge "Blocks documentation review" 2023-09-06 19:39:13 +00:00
James D. Forrester
35b934ffcb General whitespace clean-up of tabs followed by multiple spaces
Change-Id: I22090062274dceec96d43e23eb227a7e3b1e36fa
2023-09-06 14:28:43 +01:00
Tim Starling
1ee50f1a77 Blocks documentation review
* Use a consistent single-line comment style.
* Start each sentence with a capital letter.
* Use imperative mood.
* Put a space between the adjective and the noun in "hardblock" and
  "rangeblock".
* Capitalise acronyms.
* Break long lines.
* Remove excessively obvious or off-topic comments.
* Indent the non-initial lines of a multi-line @ command.
* Don't try to apply @deprecated to a parameter. Doxygen and PHPStorm
  interpret this as method deprecation.

Bug: T345683
Change-Id: I7df126f7a031dde241dd46f66e5e83722f9b383c
2023-09-06 13:48:07 +10:00
Amir Sarabadani
e1b3323312 Migrate calls to wfGetDB() in static methods
wfGetDB() has been deprecated since 1.39 (or more?) and it's better to
inject LBF and call ::getReplicaDatabase() or ::getPrimaryDatabase()
which is not straightforward in classes but for static functions, there
is no way to inject the method so we can simply call
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()

While I was here, I migrated one call to SelectQueryBuilder.

Bug: T330641
Change-Id: Idd2278cef647035dce05a2d461a620e145fe1167
2023-09-05 10:48:31 +02:00
jenkins-bot
65ca23c095 Merge "Ensure that soft blocks block temporary users" 2023-08-17 10:32:07 +00:00
James D. Forrester
984c540494 Follow-up 857d9d80f: AbstractBlock: Hard-deprecate getReason()
This is unfortunately by necessity a breaking change to the soon-to-
be-removed mBlockreason from string to CommentStoreComment. Oh well.

Change-Id: Iac918def95fb0600f2d805d2d95732b280d8fd81
2023-08-16 09:59:51 +08:00
Thalia
3eff3be2a4 Ensure that soft blocks block temporary users
Why:

* A soft block against an IP address does not block logged-in
  users, but it should block temporary users, otherwise anonymous
  users can circumvent it by creating a temporary account.

What:

* Return a block for a temporary user if a soft block is found
  against their IP address, from DatabaseBlock::newLoad
* Return soft blocks for temporary users in
  BlockManager::getXffBlocks
* Update documentation to make clear that soft blocks apply to
  temporary users, including where they are referred to as
  anon-only blocks

Bug: T343714
Change-Id: I5a2928eb3370bd47544b164b08014ef62297ce36
2023-08-15 14:26:44 +01:00
Dayllan Maza
a822b39d33 Blocks: Misc changes
* Removed un-used property
* Simplified return value and swift statement

Change-Id: I57db9d2f160bec5d9ae8afd6805e7ce07daf63c1
2023-08-02 23:23:09 -04:00
Umherirrender
2d055eea30 block: Normalize ip in DatabaseBlock::doAutoblock
When using $wgPutIPinRC the ip from rc_ip is used, which is stored as
::1, but blocks working with 0:0:0:0:0:0:0:1, so parse the ip with the
BlockUtils::parseBlockTarget and use that value.
Also reject possible invalid types, as this is a public function and may
called with something not wanted.

The ip given via User::spreadAnyEditBlock is also ::1 and the autoblock
would be inserted, when also a regular ip block exists against ::1

Change-Id: I9c1f429a7b0ff9b2274b72c46bf850d9db9492cd
2023-06-15 18:27:08 +02:00
Alexander Vorwerk
38b466c640 Load potential current ip block from correct wiki
When placing an autoblock we check wether the ip is already blocked by a
user or through another autoblock. In the second case we just reset the
expiry. In the first case we simply do nothing.

The problem here is that DatabaseBlock::newFromTarget(), which is used
here, is not cross-wiki compatible, so the correct blocks will not be
loaded here if the parent block is a cross-wiki block.

So, unfortunately, we have to manually implement the query here so that
the correct blocks are loaded.

Bug: T281972
Bug: T284873
Change-Id: Ia90e3578f7c103c40e88f3b68ddcba4a13734d80
2023-06-10 19:37:51 +00:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Alexander Vorwerk
6c9aa2242f Throw for mismatched wiki in AbstractBlock::getId()
Bug: T274817
Change-Id: I5b2c27ac3639ef92a55ff7b3cbc011a489c5705a
2023-05-29 23:42:30 +02:00
Alexander Vorwerk
31d063ca71 Deprecate passing a db to DatabaseBlockStore::insertBlock()
Instead of passing a custom database to DatabaseBlockStore::instertBlock
callers should rather just fetch a correct DatabaseBlockStore
using the new DatabaseBlockStoreFactory service.

Bug: T291849
Change-Id: Ia1319f35bbc5bd786d1d96d330f94255d7b3582a
2023-05-20 11:02:45 +02:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
Amir Sarabadani
412bdc8eb2 Migrate several $db->update() calls to UpdateQueryBuilder
Bug: T330640
Change-Id: I85f94e4bab28348e48a32974389bf18b4700bdd3
2023-04-21 10:52:27 +02:00
Alexander Vorwerk
ed3f707556 AbstractBlock: Hard-deprecate accessing block IDs cross-wiki
Bug: T274817
Change-Id: I5c1ee557db9be3ebce8592d06dac520df2dd1cad
2023-03-10 16:09:43 -05: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
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
Alexander Vorwerk
ef52ed41bb Introduce a DatabaseBlockStoreFactory
The DatabaseBlockStoreFactory is a new service which allows fetching
of a wiki-specific DatabaseBlockStore by fetching the correct
LoadBalancer via a LBFactory and then injecting it into the
DatabaseBlockStore. It also creates a wiki-specific ReadOnlyMode
and BlockRestrictionStore, which are also being injected.

This is being done as a part of the project of supporting cross-wiki
blocking.

The future plan is that BlockUser and UnblockUser are being updated to
properly support creating, updating and deleting cross-wiki blocks.
BlockUser and UnblockUser are then going to use a newly injected
DatabaseBlockStoreFactory to fetch the correct DatabaseBlockStore to
then insert/update/remove the block into/from the correct database.

Bug: T291849
Change-Id: I1051beedfd67c4e2c546b9eec04b6d592d969af3
2023-02-13 01:59:55 +00:00
Derick Alangi
8eb423c4dc Use CommentStore service instead of deprecated method
Also, added a parameters to XmlDumpWriter so that they could be
inject via WikiExporter.

Bug: T325475
Change-Id: I84b82506509e2c09dad0691af2df958a5af5b5b0
2023-01-04 23:50:51 +00:00
Alexander Vorwerk
f6bd18d6c2 Split a base class out of CommentStore
so that extensions (i.e. CheckUser) can implement their own comment
store without having a lot of code duplication

basically the comment store version of I3a6486532f2ef36

Bug: T233004
Change-Id: Ib40f99e00a514d41776ce521baf113e46d37e9cd
2023-01-01 22:34:36 +00:00
jenkins-bot
c903124b77 Merge "Make use of ?:, ?? and ??= operators in mostly trivial cases" 2022-12-16 02:51:26 +00:00
Umherirrender
45e6a2b0f9 Use str_starts_with/str_ends_with/str_contains
Use the new function in conditions to avoid creating substrings or to
search the whole string

Change-Id: Ibad6b1b447a4f62cceb34359231f88ebb967a90b
2022-12-12 19:54:24 +01:00
DannyS712
948d91d0d4 DatabaseBlock: don't save parent block id as 0
Convert 0 back to null when loading from a row

Bug: T282890
Change-Id: Ic2b4da554469a1c0d5cc6dbc82f32d4e0ce0a887
2022-12-06 23:38:44 +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
20c3cc6ef1 Remove unused variable from unpacking arrays
Change-Id: Iac27cb4aa936cb494b3e491ce22c88c7fad375a1
2022-11-22 23:21:08 +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
Thalia
1f3de22cba block: Remove temporary logging for closed task from DatabaseBlock
Bug: T192964
Change-Id: I148547c7576615a9fe7ebab7bb023e5a24d7df50
2022-10-11 19:31:13 +00: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
Umherirrender
cbe949410d Improve docs of various ::getQueryInfo functions
Explict types helps phan to detect errors with keys like ef82d95

Change-Id: Iee4d964ecc58273eb9c73356ed34e13f29fbd275
2022-08-13 21:18:44 +02:00
Alexander Vorwerk
93e14502b1 block: Create wiki-aware target for autoblocks
AbstractBlock::setTarget() will fatal if the wiki of the target
doesn't match the wiki of the block.

Bug: T281972
Bug: T284873
Change-Id: Ie696bb6442abd039635ed58439c065a1eb2d1b4f
2022-07-08 22:59:27 +02:00
jenkins-bot
2268f8253e Merge "Respect the wiki when performing autoblocks" 2022-06-30 22:12:37 +00:00
Matěj Suchánek
012011d941 Hard deprecate access to public properties on AbstractBlock/DatabaseBlock
Change-Id: I3cca210627d94d72e09beb52f8b015181f14ed7c
2022-06-23 12:43:58 +02:00
Matěj Suchánek
50d0cdcb48 Remove DatabaseBlock::$mFromPrimary
It's been unused since 2c1270d744.

Change-Id: I3c004791080a64b6c84656cf1f64557c9ab0b52b
2022-06-22 13:47:34 +02:00