Commit graph

60 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
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05: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
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
jenkins-bot
cfd7c860f8 Merge "Deprecate ConfiguredReadOnlyMode service" 2023-09-13 07:23:19 +00:00
Amir Sarabadani
7d137d0452 Deprecate ConfiguredReadOnlyMode service
Currently, we have two services: ReadOnlyMode and
ConfiguredReadOnlyMode. The former takes the latter and can easily
support every functionality of CRO. I added methods to support that
functionality (the current class is quite small so it's not adding a lot
more to a monster class) and basically fully deprecate the service
itself to improve developer experience.

It is only called in two extensions in production with straightforward
fix so I directly went with hard-deprecation.

Bug: T343917
Depends-On: Icec0ad3f30c471b428efe80dfb9129f55a351194
Change-Id: I421fd5c8fee7af41c059419c2bbc85b8dccc04ed
2023-09-12 23:22:13 +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
Amir Sarabadani
82478bd60d Reorg: Move SiteConfiguration to includes/config/
And namespace it to MediaWiki\Config

This should be eventually deprecated and removed but this has been
blocking the reorg for long enough.

Bug: T321882
Change-Id: I7a1a073495469623f6f77e6f74b23b7b4c18033a
2023-09-11 18:43:47 +01: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
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
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Daimona Eaytoy
8ceb58c71d UserGroupManagerTest: clear all hooks before running tests
There are several user groups-related hooks that can interfere with this
test. For instance, if AbuseFilter is installed, some tests will fail
because AF hooks call some methods on a no-op User mock. This class is
already making sure that the needed hooks it wants to test are set, so
there's no need to run any other hooks.

Change-Id: Iff184b5de1b150fd8043af13f16f8e1c870eb3fe
2023-07-31 16:16:47 +00:00
jenkins-bot
1d2131c505 Merge "UserGroupManagerTest: Set wgConf wikis to it's valid" 2023-07-27 13:04:09 +00:00
Derick Alangi
c45152937b
UserGroupManagerTest: Set wgConf wikis to it's valid
Change-Id: I4407a1732e76f35a54813edbb5eb7d8c7c0777b4
2023-07-24 19:21:23 +01: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
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
e6204467cf Merge "Migrate assertSelect() to SelectQueryBuilder" 2023-07-03 10:52:04 +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
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
Tim Starling
5e665d8cdb Migrate assertSelect() to SelectQueryBuilder
* Add MediaWikiIntegrationTestCase::newSelectQueryBuilder(), which
  creates a subclass of SelectQueryBuilder with assert methods.
* Migrate most callers of assertSelect() to this new query builder
  interface.

Bug: T311866
Change-Id: I7392b37988067020d5f684276320dae0a474631a
2023-06-28 09:03:58 +10: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
Thalia
47d8c97460 Fix spelling in UserGroupManagerTest
Change-Id: I59bb85bdae91ee595e19aee30f204f33d4ad1efc
2023-06-27 16:11:01 +01: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
Umherirrender
b565ab8404 user: Assert wikiId in UserGroupManager
For interwiki userright changes a UserRightsProxy instance is passed to
UserGroupManager. UserRightsProxy does not implement a check for wikiId
in getId().
Without the check for the wikiId and the extra argument to getId() it is
not possible to pass non-local instances of UserIdentityValue to
UserGroupManager.

Bug: T255309
Change-Id: Ice67ff4337165c0f022267186c88332e0e574869
2023-05-04 00:39:24 +02: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
Umherirrender
c6fecd5ab0 tests: Replace assertEmpty with assertSame
assertSame avoids use of loose comparisons and
allows to check the expected type

Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
2022-11-25 00:42:53 +01: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
Derick Alangi
d4ae3e8839 tests: Migrate away from setMwGlobals() to overrideConfigValue(s)()
Change-Id: I1b0e8e2cf4d85ae5ce8ad090cfc47f5086350702
2022-08-14 22:23:25 +01:00
Tim Starling
d6a3b6cfa8 TempUser EditPage and permissions
* Allow EditPage to create a user on page save. This has to be enabled
  in config and then activated by the UI/API caller.
* Add an autocreate source for temporary users.
* Allow editing by anonymous users via automatic account creation when
  $wgGroupPermisions['*']['edit'] = false. On an edit GET request, use
  an unsaved placeholder user to stand in for post-create permissions.
* On preview or aborted save, the username to be created is stashed in a
  session and restored on subsequent requests.
* On a (likely) successful page save, create the account.
* Put regular non-temporary users in a "named" group so that they can be
  given additional permissions.
* Use a different "~~~" signature for temporary users
* Show account creation warnings on edit and preview.

Change-Id: I67b23abf73cc371280bfb2b6c43b3ce0e077bfe5
2022-04-26 14:10:53 +10:00
daniel
b0cbb9b8ba Remove &$references from $wgAutopromote in DefaultSettings
If we want to convert DefaultSettings to a schema, we can't use variable
references.

Change-Id: Ia53cf45f7f029e1ba4191324005fef25055d5296
2022-03-11 21:38:27 +00:00
jenkins-bot
fc6b80b464 Merge "Replace deprecated JobQueueGroup::singleton()" 2022-01-27 22:17:12 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
TChin
1f673d8e8f Create new UserGroupManager::addUserToMultipleGroups method
Bug: T287247
Change-Id: I40f560a2143a2c0fda8cb7233d9954dc645749a3
2021-08-30 10:24:46 -04:00
DannyS712
4a82f51d17 Inject JobQueueGroup into UserGroupManager
UserGroupManagerFactory takes care of getting the
correct JobQueueGroup for the domain.

Bug: T287808
Change-Id: I548f0c52b298bfcae386ca1a427521c81dc802fe
2021-07-31 07:09:27 +00: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
Ppchelko
1d3d790edb Move User::changeable(By)Groups methods to UserGroupManager
Bug: T254838
Change-Id: I5868ed76c7af2adb027bad0aab4bbc8adb6daeb2
2021-05-25 21:09:38 -07:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
Umherirrender
f20c0ac8bb Remove incomplete @param from test function
the @dataProvider should be a enough here

Change-Id: I36549dcac027a68244de042d48d90d4070771be8
2021-02-01 20:19:22 +01:00
Ppchelko
b4c67ac0eb Revert "Move User::changeable(By)Groups methods to UserGroupManager"
This reverts commit b68e7e10af.

Reason for revert: T273296

Bug: T273296
Bug: T254838
Change-Id: I5124ca5b20bfd247d0d96b53bf31818c1b91d021
2021-01-30 09:54:02 -06:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
Petr Pchelko
b68e7e10af Move User::changeable(By)Groups methods to UserGroupManager
Bug: T254838
Change-Id: Idb6050a38fb48e206129c12f20a0d017cbd2b5ba
2021-01-21 08:25:26 -06:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
Petr Pchelko
ae0b6c6a1e Introduce GroupPermissionsLookup
In order to break up cyclic dependency between UserGroupManager
and PermissionManager, introduce a lightweight service for checking
group permissions.

Bug: T254537
Depends-On: I99ab3a69c41b3ec6721f9504ad6c77d3122df591
Change-Id: I1acd55c07d07b4a0d43fd838e11374b6d9be98d9
2021-01-06 17:12:28 -06:00