Commit graph

281 commits

Author SHA1 Message Date
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
Dreamy Jazz
102424bfb3 Update wgAutoCreateTempUser config defaults
Why:
* The default value of wgAutoCreateTempUser has not changed since
  the decision to use a different prefix for temporary accounts
  (T332805).
* The default needs to be updated to reduce the number of overrides
  in operations/mediawiki-config and also to make the development
  experience more consistent with what is happening on WMF
  production.

What:
* Update the wgAutoCreateTempUser default in the following ways:
** Set expireAfterDays as 365
** Set notifyBeforeExpirationDays as 10
** Set genPattern and reservedPattern to '~$1'
** Set matchPattern to null, which will mean that the genPattern
   is used as the value.
* Update RealTempUserConfig::getPlaceholderName to add the year to
  the placeholder name so that if the match pattern includes the
  first digit of the year, then the placeholder name still is
  considered a valid temporary account username.
* Replace modifications of the wgAutoCreateTempUser config in
  integration tests with a use of the TempUserTestTrait to make
  the code cleaner and make it easier to find tests that relies on
  the values in wgAutoCreateTempUser.
* Update multiple tests to handle the new defaults for the config.

Bug: T359335
Change-Id: Ifa5a0123cd915bdb7c87e473c51fb93321622f12
2024-04-03 16:25:47 +00:00
jenkins-bot
260fc1b50f Merge "Remove IDBAccessObject from being implemented in many classes" 2024-02-21 17:35:07 +00:00
Reedy
2295da3004 Fix more incorrect casing of MediaWiki
Change-Id: I331e5636823a0beae8d804148f648cfaffd6a1f8
2024-02-19 14:35:34 +00:00
Amir Sarabadani
c04f1d64d6 Remove IDBAccessObject from being implemented in many classes
This is inconsistent with the access pattern of other constants in
MediaWiki. it's also confusing (e.g. it's unclear to a newcomer why
UserFactory is implementing IDBAccessObject) and it's prone to clashes
(e.g. BagOStuff class has a clashing constant).

It has been already announced: https://w.wiki/9DAX

Bug: T354194
Change-Id: Ic2357634b8385d65b55db2b557191419b06c40e0
2024-02-19 10:50:02 +01:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Samuel Guebo
15402237af Split User::getRightDescription into two methods
- Add getRightDescriptionHtml() to return HTML
  the change handles cases where the message contains wikitext
- Use the new method getRightDescriptionHtml() in createBotPassword

Bug: T312819
Change-Id: If3b9bce2f02806572cc6cc1194a07cb7d5b8d6da
2024-01-31 15:28:37 -05:00
Umherirrender
a3a9cf99cb tests: Use namespaced class names in @covers annotations
Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733

Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
2024-01-27 01:11:07 +01:00
jenkins-bot
f26ea2f2fc Merge "Set user.user_is_temp when creating a temporary user" 2024-01-22 08:57:38 +00:00
Umherirrender
16a436ce6c tests: Remove cleanup of blocks, done by ChangedTablesTracker
In DatabaseBlockTest changed from addDBDataOnce() to addDBData() as
ChangedTablesTracker cannot reset tables changed by addDBDataOnce()
between each test run.

Remove also User::clearInstanceCache done together with the deletion as
the TestUser class is calling this already between tests.

Change-Id: Ibd5e544138a2a9b554abc2dea54a5db38f9a828f
2024-01-20 11:41:15 +01:00
Thalia
6e68107b3a Set user.user_is_temp when creating a temporary user
TempUserCreator calls AuthManager::autoCreateUser, which calls
User::addToDatabase. Set user_is_temp from addToDatabase.

Inserts to the user table are done elsewhere, but they are not
updated here. They don't insert temporary users, and
user_is_temp defaults to false.

Bug: T333223
Bug: T355175
Change-Id: I7c71fc7b4fd44e23cd4a68425f64bc631284a9b7
2024-01-19 19:46:52 +00: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
Martin Urbanec
c9908da103 IP Masking: Expire temporary accounts in 1 year
Why:
Temporary accounts (introduced as part of IP Masking)
are supposed to expire 1 year after their registration.
Automatic account expiration can be done via a maintenance
script, which would be periodically executed via cron / systemd.

Make it possible for extensions to provide their own logic
for generating a list of temporary accounts to invalidate.
This is used in CentralAuth to base registration timestamp
on the global registration timestamp.

The default behavior is "temporary accounts do not expire",
given the feature requires a maintenance script to run
periodically, which will not be the case on third party
instances.

What:
* Add `expireAfterDays` to $wgAutoCreateTempUser, controlling
  how many days temporary accounts have.
* Add UserSelectQueryBuilder::whereRegisteredTimestamp(),
  filtering accounts based on user_registration.
* Add ExpireTemporaryAccounts maintenance script, which is
  @stable to extend.

Bug: T344695
Change-Id: If17bf84ee6620c8eb784b7d835682ad5e7afdfcc
2023-11-09 15:11:48 +01:00
Tim Starling
f0deaea120 Hard deprecate User::isBlocked(), isBlockedFrom() and isBlockedFromCreateAccount()
Bug: T274211
Bug: T345683
Depends-On: I7d19eda46b24650ec5534499d34936b754cd075a
Change-Id: I0ff9223c35ae9922eab2c171afb42c4ea5004df1
2023-10-20 10:10:19 +11:00
Tim Starling
924fd54950 Remove Block cache from User
* Remove User::$mBlock, mBlockedby, mBlockreason and mHideName, which
  cached block status for a user.
* Inline User::getBlockedStatus() into User::getBlock() and use
  getBlock() internally to implement the deprecated public methods.

Bug: T345683
Depends-On: I4898a23fcde34db8ef94b92d41722cedf9380dbc
Depends-On: If57d4e910d35f386028afd9cb900d78f3b6a0e13
Change-Id: I25b84b0a8f9cacd0908a415b3a4a50ff7ecc72f4
2023-10-12 13:42:58 +11:00
thiemowmde
46bed8ac6d Make use of assertStatusGood/Error and such in tests
Change-Id: I11eace3d9823ca28a1d9a64f959f5f8ca2945821
2023-10-04 17:16:00 +00:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02:00
jenkins-bot
9a4ece9b51 Merge "Drop User and PermissionManager's group permission methods, deprecated since 1.34/1.36" 2023-09-22 18:32:49 +00:00
James D. Forrester
ba283991a9 Drop User and PermissionManager's group permission methods, deprecated since 1.34/1.36
Bug: T325680
Change-Id: Id427453a0664bcfc072e0274a893841a0445421e
2023-09-22 13:24:58 +01: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
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Umherirrender
5ae59bad07 user: Hard-deprecate user group related User functions
The functions are:
- User::getGroups
- User::addGroup
- User::removeGroup
- User::getGroupMemberships
- User::getAllGroups
- User::getImplicitGroups

Bug: T275148
Change-Id: Ic56329716ff1d982c27bbf3710d8622f232ede63
2023-08-31 00:08:33 +00:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02: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
James D. Forrester
4ad1b2870d Drop User::incEditCount(), deprecated in 1.37
Bug: T325682
Change-Id: I4423ed671d978d45d09ff61749e7c7c145640061
2023-08-15 12:00:09 +08:00
jenkins-bot
591a851174 Merge "Drop User::idFromName(), deprecated in 1.38" 2023-08-12 19:58:14 +00:00
James D. Forrester
10e3426ccc Drop User::idFromName(), deprecated in 1.38
Bug: T325687
Change-Id: If3f27183fe6a95a75654d802fa7765da5ef77ec1
2023-08-08 09:30:53 -04:00
Thalia
13f4d6bc83 Ensure temporary users are blocked by configured IP blocks
Temporary users are blocked if their IP address is listed in
$wgDnsBlacklistUrls or $wgSoftBlockRanges.

Bug: T343704
Change-Id: Ia3383bd10c3c6c35c586550b68f4af5f4659e815
2023-08-07 14:14:54 +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
Tim Starling
4edbb29307 Add User::newQueryBuilder()
Replace all core calls to User::getQueryInfo() with an equivalent
SelectQueryBuilder.

Bug: T311866
Change-Id: Ib249a9d9098b1c09907a90607206edd8331bad3d
2023-06-27 11:45:39 +10:00
Alexander Vorwerk
9bbf2f6023 UserIdentityValue: Always throw a deprecation warning on passed actor id
Bug: T274179
Change-Id: Ibc5bd56cd41153591b0ee701cc1f92608e7c188c
2023-05-20 11:16:18 +03:00
Tim Starling
87160074d0 In User::clearInstanceCache() mark the $reloadFrom parameter as loaded
UserTest::testUserId() was failing when run alone, because getId() was
always fetched from the database following setId(), and the test does
not write it to the database.

It passed when run with other tests since more than 7 users were present
in the database since the last truncate. Adding 'user' to tablesUsed
makes the failure reproducible.

It makes sense for setId() to mark 'id' as loaded, by analogy with
UserFactory::newFromId(). The test failure seems valid.

Fixing it in clearInstanceCache() instead of setId() seems correct to
me. There are only two callers of clearInstanceCache() with
$reloadFrom set to a field name in core and WMF deployed extensions.

So, when clearInstanceCache() is called with the name of a field to
reload from, mark that field as already loaded.

Depends-On: Iabe011bf796016b357ab2a317b810bea2568a9f5
Change-Id: Ibbf753d318a376c7c5819930dd5669d0e44eda30
2023-05-11 20:03:23 +10: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
libraryupgrader
7375f3a5fe build: Updating mediawiki/mediawiki-codesniffer to 41.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Usage.ForbiddenFunctions.eval

Change-Id: I6fd0a9296c88a77c3abec6e5e8d568bb469c2d6e
2023-03-11 19:04:09 +00: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
Umherirrender
dabe7242f9 Hard-deprecate User::idFromName
Bug: T325687
Change-Id: I5dc13586c11ad49cd7c2646a65e103bb52f28512
2023-01-14 13:06:23 +01:00
Timo Tijhof
4ef0891994 rdbms: Consolidate logger channels into one
Notable changes:

* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
  injected. The rest implicitly got a NullLogger due to being absent.
  These are now effectively unsilenced.

* Database::__construct() required almost all parameters, even the
  loggers. I've wanted to move some of DatabaseFactory into the ctor
  here for a while. In order to make this change not a breaking
  change, the new 'logger' parameter is optional with NullLogger as
  default. This allowed some of the test cases, which were simply
  passing NullLogger, to be fixed by passing nothing instead of
  passing the new option name.

  The Database class is behind a dozen layers of indirection for
  real use, so this will still be injected just fine (DBF, LB, LBF,
  MWLBF, etc.).

* In LegacyLogger, the handling for $wgDBerrorLog was previously
  limited to DBConnection and DBQuery. This now includes errors
  from other (generally, newer) parts of Rdbms as well, which were
  previously missing.

  This only affects sites (typically CI and dev setup) where
  $wgDBerrorLog is used, as opposed to the more common
  $wgDebugLogGroups by-channel configuration.

* TransactionProfiler gets its logger injected in a rather odd way,
  via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
  as opposed to service wiring. This is kept as-is for now.

* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
  there are cases that intentionally produce failures of which
  the result is then observed. In CI we assert that dberror.log is
  empty so instead of adding the missing logger fields to that
  LBFactory instance, the only one set (replLogger) is removed.
  The alternative is to set 'logger' now, which would naturally
  cause CI failures due to unexpected entries coming through to
  non-mocked error log.

Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
2023-01-03 22:46:38 +00:00
jenkins-bot
ad0423a253 Merge "Hard-deprecate User/PermissionManager group permissions lookup functions" 2022-12-23 01:55:51 +00:00
Umherirrender
c0794e1b6e Hard-deprecate User/PermissionManager group permissions lookup functions
- User::getGroupPermissions
- User::getGroupsWithPermission
- User::groupHasPermission
- PermissionManager::getGroupPermissions
- PermissionManager::getGroupsWithPermission
- PermissionManager::groupHasPermission

Bug: T325680
Change-Id: If9ae610037f049050c21ad0eab7bcb4d6e596f29
2022-12-21 21:15:00 +01:00
Umherirrender
e942074349 user: Hard-deprecate User::incEditCount
Bug: T325682
Change-Id: I700979b54b089ced057e608591c179f639d1f8e5
2022-12-21 18:33:44 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Umherirrender
f1db4bed17 tests: Use MediaWikiIntegrationTestCase::editPage for edits
Change-Id: I1db7294635bb85e03841c4f7b100e2243ddf013b
2022-09-23 22:49:59 +02:00
jenkins-bot
14308cd393 Merge "tests: Remove unused UserTest::makeEdit" 2022-09-11 11:03:23 +00:00
vladshapik
c7167284e8 Drop User methods which were deprecated since 1.38
The following User methods, deprecated in 1.38, have been removed:

* ::blockedBy
* ::getBlockId

Bug: T277511
Change-Id: I00e2fec4ababa3f9c12dee34c3d922d18e1c78d7
2022-09-05 15:29:14 -04:00
Umherirrender
9f17921627 tests: Remove unused UserTest::makeEdit
Change-Id: I6e89050fc501022a87c4625d8f22f022d2273e1d
2022-09-01 21:23:29 +00:00