Commit graph

30 commits

Author SHA1 Message Date
Umherirrender
6f94bde337 tests: Migrate to IReadableDatabase::newSelectQueryBuilder
Bug: T344971
Change-Id: Ic6940fcc06225069a0c3618c22a0e62942e5dd88
2024-05-02 23:42:08 +02:00
Umherirrender
a89a00ffb8 tests: Migrate to IDatabase::newInsertQueryBuilder
Changed some inserts to use multi-row insert for small performance
benefit where possible and not already used.
InsertQueryBuilder does not return a value, deprecated since 1.33

Bug: T353219
Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
2024-04-14 21:56:07 +02:00
Umherirrender
523372df32 Migrate to IDatabase::newDeleteQueryBuilder
Change-Id: Idf42d67c1b0b311f81a1d60a7a8a6f875f99e864
2024-04-12 20:12:05 +02: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
Bartosz Dziewoński
fe3b56f1ce rdbms: Remove stray extra space from LIKE expressions
It doesn't do anything. It was added in ae57ab1eec (SVN r57989)
presumably by accident and carefully preserved through many
refactorings of this code.

Change-Id: Id2dfe3a379d8322e0dff81f7e009c3e44671b0de
2024-03-06 18:00:42 +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
Tim Starling
d6727856fd Support new block schema
Support migration stages when reading and writing blocks.

I tried to set it up for an easy next stage, in which support for the
old schema is removed. I tried to avoid factoring out of shared code
between the two schemas, so that the old schema cases can simply be
deleted without the need to revert unnecessary abstractions.

However, I added HideUserUtils to factor out ipb_deleted queries. Code
review showed that this was already quite complex, with multiple
approaches to the problem, so it benefits from refactoring even without
the schema abstraction.

HideUserUtils is a service rather than a standalone class to support
unit tests, since unit tests do not allow global config access. When
the migration stage config is removed, it will be a service with no
constructor parameters -- an unnecessary abstraction which should
ideally be resolved at that time.

When interpreting result rows, it is possible to share code by using
field aliases. But when constructing WHERE conditions, the actual field
names need to be used, so the migration is more intrusive in
ApiQueryBlocks and SpecialBlockList, where complex conditions are used.

Bug: T346293
Bug: T51504
Bug: T349883
Change-Id: I408acf7a57b0100fe18c455fc13141277a598925
2023-11-29 13:31:42 +11:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05: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
c638dac3f2 Add tests for new DatabaseBlockStore and BlockManager methods
Adapted from DannyS712's tests of DatabaseBlockFactory
Ie26b589c2ba5ec2715446944ec8cf761676be026

Co-Authored-by: DannyS712 <dannys712.wiki@gmail.com>
Change-Id: Ic4fa2ceea13658853eae48d754c4b84d6f8be3f8
2023-11-03 17:03:33 +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
abbb4281cb tests: Migrate more cases to SQB
Bug: T344971
Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
2023-09-21 18:30:37 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Daimona Eaytoy
660c1539e3 Do not use UTPage directly in tests
UTPage is a badly named page that should not be used directly. In fact,
soon it will no longer be guaranteed to exist (T342428). Tests should
create the fixtures they need, using titles/summaries that are actually
meaningful and that make it easy to identify what test is responsible
for creating a given page.

In ApiSetNotificationTimestampIntegrationTest, make separate assertions
because the order of the two pages in the result set is not stable
(ApiPageSet::initFromTitles has no ORDER BY).

Change-Id: Iecfb75e16deaa2f682afd916f58d8c548ee1cbac
2023-08-12 23:51:53 +02:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00: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
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
Timo Tijhof
fb7e47fd5a block: Use $wgUpdateRowsPerQuery for purgeExpiredBlocks()
Follows-up I052735edbfac.

Bug: T301742
Change-Id: Iec989945f4c592d7569e62199dd8190c535acae7
2022-03-04 22:40:53 +00:00
Derick Alangi
e894dc75fa tests: Use service container in integration tests cases
Since MediaWiki 1.36, this method is provisioned to replace creating
new instances of the services object. If one is already created and
seen by the service locator, just use it.

Change-Id: I9509497a8380194aa93310343b1896521070fc31
2021-09-05 22:14:36 +01:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
DannyS712
d290b63153 Add DummyServicesTrait::getDummyReadOnlyMode()
Returns an actual working ReadOnlyMode object
based on a ConfiguredReadOnlyMode and a mock
load balancer

Change-Id: I429c8e81343c24c536718b3fc112e797afbc05a2
2021-07-05 07:16:13 +00:00
vladshapik
e991dff925 Hard-deprecate AbstractBlock::getTargetAndType() and getTarget()
Replace all uses of AbstractBlock::getTarget with
Block ::getTargetName and ::getTargetUserIdentity.
Create AbstractBlockTest and two test cases for
AbstractBlock::getTarget and ::getTargetAndType.
It tests triggering of the deprecation warning.

Bug: T282247
Depends-On: I0543f363af66c57f5763b91320d87a69f23f9466
Change-Id: Iaeca824cac30172178de72f3cf7b7ae4cdd6f880
2021-06-22 16:59:00 +03:00
Roman Stolar
67cc77312f Update DatabaseBlock construct option 'by' and 'byText' usage to use User Identity only
Bug: T283641
Change-Id: Ic6d4a6e10bda0115c87a85d8a9ddfd4098cd1373
2021-06-02 17:01:32 +03:00
Petr Pchelko
7ba9cbcac7 DatabaseBlockStore: fetch correct ActorNormalization
DatabaseBlockStore is capable of inserting cross-wiki
DatabaseBlock, which works via passing non-local IDatabase.
Ideally, we'd want to make Block a WikiAwareEntity, have
cross-wiki DatabaseBlockStore, etc. But as a quick-fix for
a regression we can just fetch correct ActorNormalization

Bug: T281972
Change-Id: I796f54b7b7303b8c442d5b9ba1926b76d3805fb5
2021-05-05 13:13:20 +02:00
Tim Starling
57ce83d73a Stop using legacy ActorMigration fields in DatabaseBlockStore
Stop using ipb_user and rc_user fields in calls to ActorMigration.

Bug: T278917
Change-Id: I45a214a8647a21146b6f1de4a75ec53faeb3409c
2021-04-19 10:51:03 +10:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
DannyS712
23c3c70d7f Add a DatabaseBlockStore service
The new service replaces the following public DatabaseBlock methods:
* ::delete
* ::insert
* ::update
* ::purgeExpired

Bug: T221075
Change-Id: I5f95db14b1189fd62d2c2bd5dae2cab0a368f401
2020-07-29 15:55:09 +01:00