Commit graph

97 commits

Author SHA1 Message Date
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
Amir Sarabadani
45b5e066fb rdbms: Remove $domain support from ::getDBFromRecency
This method is a shallow component [1] which is an anti-pattern in
software design (yes, I'm aware I introduced that method). We should
avoid expanding its interface further and focus on the most common
usecase. Since it's not doing much under the hood, it's okay to just
copy-paste the logic into a method in UserGroupManager.

This partially reverts I9e2de1cc84d12443.

[1] Original idea from "Philosophy of software design" book but you can
find short TLDRs in the internet, like:
https://vladimirzdrazil.com/posts/deep-shallow-modules/

Bug: T355813
Change-Id: I8cac972ecc9e962f6605a8feaa24a9e00af07b66
2024-01-25 16:44:20 +01:00
jenkins-bot
e861d7ef8f Merge "UserGroupManager: Fix cross-wiki database access" 2024-01-25 10:15:37 +00:00
星耀晨曦
9ca8844902 ApiSiteInfo: Add siprop=autopromote to return $wgAutopromote data
Bug: T196059
Co-Authored-by: Reedy <reedy@wikimedia.org>
Change-Id: I92236cea845c10ef1725891a49d48a04d5d3bfad
2024-01-24 20:14:05 +00:00
Taavi Väänänen
9b781bcf61
UserGroupManager: Fix cross-wiki database access
Fixes a bug introduced in 72a8c3b433.

Bug: T355813
Change-Id: I9e2de1cc84d124432d244bec27cb52d7ae3116e2
2024-01-24 21:28:06 +02:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
Amir Sarabadani
72a8c3b433 Introduce DBAccessObjectUtils::getDBFromRecency()
And general clean up of db connection handling in core

Bug: T354194
Change-Id: Icb3685f1d7f8d1f4bcadf8e292ddf9450180fcdb
2024-01-19 16:54:05 +01:00
jenkins-bot
5a7862cba4 Merge "Directly call IDBAccessObject constants instead of implementing it" 2024-01-15 06:09:51 +00:00
RazeSoldier
16d5a04b26 Make logical operators recognized in $wgAutopromote public
To avoid hard-coded of the I92236cea845c10ef1725891a49d48a04d5d3bfad, share the allowed operators.

Bug: T196059
Change-Id: Ic3608097dadccb76f93da02c0611a36f0186a9c7
2024-01-13 21:56:39 +00:00
Amir Sarabadani
0daee7697d Directly call IDBAccessObject constants instead of implementing it
Instead of calling self::READ_* on these constants, just directly call
it.

Since these classes are public and might be relied on directly in other
places, we can't remove the "implements IDBAccessObject" yet but we will
start doing that soon.

Bug: T354194
Change-Id: I3e26b9fc7f93efdfc55a1790a7cdfa5c0d562303
2024-01-10 22:22:34 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Amir Sarabadani
9009c4cbd7 Migrate away from $db->makeList in favor of expression builder
Bug: T210206
Change-Id: I803a6130fff5ce6faaaa5221443a436195b03c75
2023-11-02 16:40:48 +00:00
Amir Sarabadani
17589adcc4 Migrate another batch to use $db->expr instead of raw SQL
Bug: T210206
Change-Id: I327517fef250c24392565a26bbe7b296dc19508a
2023-10-30 17:56:35 -04:00
Amir Sarabadani
d5adc3ca65 Mass migrate simple cases to use expression builder
Done via
'([A-Za-z_\.]+) ?(=|!=|<|<=|>|>=) ?' . (\$db(?:r|w|))->addQuotes\( (.+?) \)
to:
$3->expr\( '$1', '$2', $4 \)

And
'([A-Za-z_\.]+) IS NULL OR ([A-Za-z_\.]+) ?(=|!=|<|<=|>|>=) ?' . (\$db(?:r|w|))->addQuotes\( (.+?) \)
to:
$4->expr( '$1', '=', null )->or\( '$2', '$3', $5 \)

Bug: T210206
Change-Id: I109bf2a712bdefa9e074f775b1bee41ac5b9d665
2023-10-26 16:59:19 +00:00
DannyS712
53f4b1526a Add some typed properties to User-related services
Change-Id: Ia73c3a044dfa50e9d9d43bf0e28eed2f65edcdce
2023-09-28 18:26:27 +00:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00: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
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
4fccf6bf30 rdbms: Add support for per-domain calls in ReadOnlyMode
That would remove the need for passing around LB.

ReadOnlyMode code needs a lot of clean up. In follow up patches, I want
to inject WAN and possibly APCu to this and remove that from LB itself
to decouple LB/LBF from BagOStuff.

In even later patches, I want LB/LBF to set the ReadOnly in the service
instead and reverse the coupling.

Bug: T343917
Change-Id: Ibe7f80292d911fc8953e59f74264c499ab1700d0
2023-09-10 03:23:13 +00:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10:00
Reedy
bd193d3ac6 UserGroupManager: Fixup getUserPrivilegedGroups docs
Also update @since for backports

Bug: T208477
Follows-Up: I6536ef2909caeed047447e8b6a25831d6f00d827
Change-Id: I53f6df11cb0f9aa98e6df29530417583cf9a9e0b
2023-09-04 18:10:49 +01:00
Gergő Tisza
7a21b9a032 Add UserGroupManager::getUserPrivilegedGroups()
This moves the core part of wfGetPrivilegedGroups() out of Wikimedia
config and makes it possible to move functionality built on it into
core.

Bug: T208477
Change-Id: I6536ef2909caeed047447e8b6a25831d6f00d827
2023-09-02 11:59:25 +00:00
Matěj Suchánek
1c8896a0dd Fix various typos and documentation issues
Change-Id: I2cd4b647c01d84cfe0e1b4d55e155ced8c918b17
2023-08-27 12:05:11 +02:00
Timo Tijhof
af4324e3a4 UserGroupManager: Adopt IConnectionProvider
Bug: T330641
Bug: T343917
Change-Id: Ied7caa2716b8f4a2d2d1a459e37cd61a56d57242
2023-08-15 02:18:00 +00:00
jenkins-bot
bef1316ad2 Merge "user: Use database for given wikiId in UserGroupManager::purgeExpired" 2023-08-09 22:06:31 +00:00
Amir Sarabadani
98d6503f65 Mass migrate Database::insert calls to InsertQueryBuilder
Done automatically based on a php parser written on top of ANTLR4

Bug: T335377
Change-Id: Ie8fabc594edab18e55cb1d5bbf573762106e3d71
2023-08-07 19:44:27 +02:00
Umherirrender
67a8cf40a4 user: Use database for given wikiId in UserGroupManager::purgeExpired
The LoadBalancer is for a specific wiki,
so the database on purge should be connected to that wiki as well.

Change-Id: I6d89ff3df58d691474776764a48abd924c6405d5
2023-08-07 17:47:58 +02:00
jenkins-bot
dc3578a910 Merge "Migrate more calls of Database::select* to SelectQueryBuilder" 2023-07-26 11:21:08 +00:00
Amir Sarabadani
7432b21816 Migrate more calls of Database::select* to SelectQueryBuilder
Using a php parser written on top of ANTLR4, done semi-automatically.

I checked everything and made adjustments.

Bug: T311866
Change-Id: I6150c6909bce8f3dbd745a26380cc0af9d9c547f
2023-07-26 13:01:28 +02:00
Thalia
eba65c6d78 Remove isRegistered checks from some UserEditTracker callers
* PageEditStash and UserGroupManager: remove the isRegistered
  check, which isn't necessary since UserEditTracker will just
  return null for users not in the `user` table. Instead handle
  a possible null return value.
* LogFormatter: keep the check, to avoid instantiating the
  UserEditTracker if not necessary, but check getId instead of
  isRegistered, since the check is really for whether the user
  is in the `user` table, regardless of their registered status
  (e.g. they may be a temporary user).

Change-Id: I62faf9d042a9297bcd662f7908d73d8469b26c98
2023-07-24 15:09:52 +01:00
jenkins-bot
eedadc2743 Merge "user: Assert cross-wiki users in UserGroupManager" 2023-07-13 20:55:38 +00:00
AnaïsGueyte
bf3cc4628a Prevent saving groups to a Temp User
- Show error when viewing groups for a temp User from Special:UserRights
- Add a fatal error when trying to save groups for temp users from Special:UserRights
- Creating an exception from UserGroupManager when attempting to save groups to a temp user

Bug: T340468
Change-Id: I6892a5303b34a8c1608c81a46c684bcaf74817bd
2023-07-12 12:22:13 +00:00
jenkins-bot
0c705aa587 Merge "Disable autopromote-once for temporary users" 2023-07-04 08:13:04 +00:00
jenkins-bot
a74eaea765 Merge "Add temporary users to a 'temp' group, and stop adding them to 'user'" 2023-07-03 17:05:56 +00:00
jenkins-bot
cf4d427945 Merge "Revert "Throw an error from UserGroupManager::addUserToGroup if called on a temporary user"" 2023-07-03 15:17:28 +00:00
Tchanders
0074a7ddb7 Revert "Throw an error from UserGroupManager::addUserToGroup if called on a temporary user"
This reverts commit df1312b799.

Reason for revert: More updates to callers are needed to prevent
throwing errors.

Bug: T340468
Change-Id: I604bef13a550c1bd8fc10396284505f24cf17802
2023-07-03 14:56:24 +00:00
Umherirrender
c03ee0e2b6 user: Assert cross-wiki users in UserGroupManager
Assert the wiki id of the identity passed to the manager to avoid mixing
up database changes which does not belong to the user id given to the
manager

This removes comments added by first step a3f3e3c
This reintroduce b565ab8

Bug: T337590
Depends-On: Ic449aa0d6b874ac5a2b8bf652c2637188aa0edb6
Depends-On: I2dffe8b633cff182866803ce5cb693f31364f178
Change-Id: Icd2d4efdb84ae085402c9ca59ced7e14be511aa0
2023-07-01 10:17:51 +02:00
jenkins-bot
4690431357 Merge "Don't report temporary users as belonging to autopromote groups" 2023-06-30 14:19:36 +00:00
Thalia
88457aabd2 Disable autopromote-once for temporary users
Update the following UserGroupManager methods:
* addUserToAutopromoteOnceGroups returns an empty array as it does for
  IP users
* getUserAutopromoteOnceGroups returns an empty array

Autopromotion was disabled for temporary users in
d6a3b6cfa8.

Bug: T340464
Change-Id: I090bbd9f16070bf559f5bb87f04aabcf0bedbaf2
2023-06-28 18:43:21 +01:00
AnaïsGueyte
df1312b799 Throw an error from UserGroupManager::addUserToGroup if called on a temporary user
- Add new error message specifically for Temp Users
- Prevent calling UserGroupManager::addUserToGroup on a temporary user in Core

Depends-On: 932292
Bug: T340468
Change-Id: I782a16efb20e3b1e2ead4ce5e3bc030d066355de
2023-06-28 14:52:58 -02:30
Thalia
dd2f898f86 Add temporary users to a 'temp' group, and stop adding them to 'user'
When we first deploy temporary account autocreation, we want temporary
users to resemble anon users more than registered users, for minimal
community impact.

If we add them to the 'user' group, then they will automatically get
whatever rights a wiki currently assigns to registered users. If we
don't, they will only get rights that are currently given to everyone
(same as anons).

Therefore stop adding them to the 'user' group, and instead add them
to a new 'temp' group, in case site admins want to give them extra
rights.

Bug: T340457
Depends-On: I6333fa2289f3142d1b5cedf2cc910ced3ba5019e
Change-Id: Idb46252fe6533ab0a5410bdb3093043cb359c206
2023-06-28 18:22:47 +01:00
Thalia
827fa65c7f Don't report temporary users as belonging to autopromote groups
Autopromotion was disabled for temporary users in
d6a3b6cfa8. In that commit,
PermissionManager::getUserImplicitGroups, no longer checks autopromote
groups for temporary users, so PermissionManager::getUserPermissions
no longer finds autopromote groups for temporary users.

In this commit, UserGroupManager::getUserAutopromoteGroups no longer
finds autopromote groups for temporary users.

Bug: T340462
Change-Id: I189391bd9a41718648d198b83736d837c76ead52
2023-06-27 16:32:17 +01:00
jenkins-bot
13b16e1fb6 Merge "UserGroupManager: Make newQueryBuilder accept a IReadableDatabase" 2023-06-08 13:24:26 +00:00
Taavi Väänänen
79495f1d2c
UserGroupManager: Make newQueryBuilder accept a IReadableDatabase
Change-Id: If74a0cddf3ac6a2d7817646401537b024e23f467
2023-06-08 15:17:48 +03:00
Amir Sarabadani
b55c501fe0 Migrate Database::update() to UpdateQueryBuilder
I did this using a script written on top of antlr4 parser so it doesn't
have some clean ups a human would do but it's pretty nice already.

Bug: T330640
Change-Id: I608566700c6d737ee986bf47dda87effc69614d6
2023-06-08 12:34:20 +02:00
jenkins-bot
23c6cbc457 Merge "user: Avoid exception about cross-wiki users in UserGroupManager" 2023-06-07 22:17:36 +00:00
Umherirrender
a3f3e3c600 user: Avoid exception about cross-wiki users in UserGroupManager
First step to make UserGroupManager assert the wiki id of the identity
is to pass the check in UserIdentityValue::getId when a cross-wiki
identity is given to the UserGroupManager

Bug: T337590
Change-Id: I2dffe8b633cff182866803ce5cb693f31364f178
2023-05-26 22:47:04 +02:00
Umherirrender
015f4e7b7e user: Accept local wiki name on UserGroupManagerFactory
Normalize the local wiki name to UserIdentity::LOCAL.
This is similiar to DatabaseBlockStoreFactory.
Rename dbDomain to wikiId to make this difference visible in code

Change-Id: I89679402ef5d2c80809e7b9b5a57d798a2b98a94
2023-05-25 21:01:18 +02:00
Umherirrender
a80ba187db Merge "Revert "user: Assert wikiId in UserGroupManager"" 2023-05-21 12:28:09 +00:00
Umherirrender
99614fb88c Revert "user: Assert wikiId in UserGroupManager"
This reverts commit b565ab8404.

Reason for revert: CentralAuth not ready for this assertion

Change-Id: Ic59efaf8ea0e2807fef7ead58f27c6e03ab8913c
2023-05-21 12:26:15 +00:00