Commit graph

128 commits

Author SHA1 Message Date
Sergio Gimeno
37985a198d ConditionalDefaultsLookup: allow to dynamically add conditions for evaluation
Why:
To facilitate the evaluation of conditions not directly
"known" by the lookup, eg: owned by extensions

What:
- Add ConditionalDefaultOptionsAddCondition hook which
runs before instantiating ConditionalDefaultsLookup allowing
to add conditions for evaluation in the $extraConditions
array.
- Evaluate the configured conditional default against the
 extra added conditions after evaluation of "known"
conditions.

Bug: T376918
Change-Id: Ife6f96397eafd61fdb40528aac315ddde1ef2774
2024-10-16 17:39:12 +02:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
jenkins-bot
426bf0f280 Merge "Add support for user-groups-based conditional options filter" 2024-07-23 17:56:46 +00:00
jenkins-bot
950039f924 Merge "Deny temp account autocreation when temp accounts are disabled" 2024-07-22 18:12:10 +00:00
Dreamy Jazz
560197c660 Deny temp account autocreation when temp accounts are disabled
Why:
* When temporary accounts are disabled, no new temporary
  accounts should be created either on edit or through
  a CentralAuth autocreation.
* UserNameUtils::isUsable is used to prevent the
  CentralAuth autocreation making the temporary account
  username not usable for login or account creation.
* However, this check to determine if the name is
  reserved by the temporary user system still considers
  the name as a valid temporary account if the system
  was once enabled (but since disabled).
* This is a bug, and instead if the feature is disabled
  the username should be considered unusable. This then
  prevents the CentralAuth autocreation on a wiki which
  knows the feature but has it disabled.

What:
* Update UserNameUtils::isUsable to return false if
  the name is reserved by the temporary user system
  and TempUserConfig::isEnabled returns false.
* Test this new behaviour with a unit test.

Bug: T370513
Change-Id: I467c39538796a660a7417397c99928a1a25007bc
2024-07-19 16:32:35 +00:00
Thalia
578f5ea339 RealTempUserConfig: Ensure match pattern is available when known
Why:

* When temporary accounts are known, the match patterns need to
  be available. If no match patterns are set, the match pattern
  is set to an array containing the generate pattern. Therefore
  the generate pattern must also be available if temporary
  accounts are known.
* This was not the case before this commit, and certain settings
  caused an error to be thrown from isTempName.

What:

* Use the generate pattern for the match patterns if temp accounts
  are known and no match patterns are set.
* Update the tests to use a generate pattern but no match pattern
  (the same as the default config).

Change-Id: Iadfbed40b14378a9309e8d7afab6064e25480514
2024-07-19 15:08:15 +01:00
xtex
a668a1bbea Add support for user-groups-based conditional options filter
Bug: T363059
Change-Id: I728cacf6acfc02ecb0ef9b3695e7770c2d3f8d83
2024-06-29 07:07:06 +00:00
Thalia
2c3b456ffc
[temp accounts] Introduce 'known' config flag
Why:

- We want to distinguish temp account creation being enabled from a
  configuration state where MediaWiki knows about temp accounts
  existing (and can identify and manage them accordingly) while temp
  account creation is disabled

What:

- Introduce a 'known' configuration flag to TempUserConfig
- If 'enabled' is set to true, then 'known' is automatically overridden
  to true
- If an administrator wishes to disable temp account creation after
  temporary accounts have been created, the administrator should set
  'enabled=false' and 'known=true'

Co-authored-by: Tchanders <thalia.e.chan@googlemail.com>
Co-authored-by: Kosta Harlan <kharlan@wikimedia.org>
Bug: T356524
Change-Id: I4ce534a847461230f7fa276a565bdc1d6c9857e1
2024-06-13 22:11:27 +02:00
Kosta Harlan
2ed2467a7a
ApiQuerySiteinfo: Use TempUserConfig class
Why:

- Using TempUserConfig is more flexible as it doesn't require us to know
  about the internal details of the AutoCreateTempUser config object

What:

- Use TempUserConfig service instead of loading the AutoCreateTempUser
  object
- Remove properties from ApiQuerySiteInfo that don't already have
  getters. If someone has a need for more this information to be exposed
  in ApiQuerySiteInfo, they can be added in a separate patch
  - This seems compatible with the goals of T335532 which was about
    making it possible to discover via the API if an action would result
    in a temp account
- Implement __toString for Pattern, so that it can be used in
  ApiQuerySiteInfo

Bug: T335532
Change-Id: Ica84b3e9b9865b8b83a9e9e513c99cd2e47661c9
2024-06-13 22:11:27 +02:00
jenkins-bot
78637143f1 Merge "Remove all @package comments" 2024-05-13 12:21:22 +00:00
thiemowmde
52ddf3e8ce Remove all @package comments
I don't think these do anything with the documentation generators
we currently use. Especially not in tests. How are tests part of a
"package" when the code is not?

Note how most of these are simply identical to the namespace. They
are most probably auto-generated by some IDEs but don't actually
mean anything.

Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
2024-05-10 13:53:15 +02:00
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
Tim Starling
2998d9bd47 block: Migrate to the new block schema on non-WMF wikis
Migrate from ipblocks to block/block_target and drop the ipblocks
table. Update tests.

In PostgresUpdater, change some schema update functions to skip field
updates if the table doesn't exist, by analogy with
DatabaseUpdater::modifyField.

Bug: T346293
Change-Id: Icf91b35f7f729cead7c800429653eb30731762a1
2024-05-09 10:14:43 -04:00
Steph Toyofuku
1e26f420dc Add new conditional default conditions for user options: anon and named
Adds two new conditional user option default conditions CUDCOND_ANON and
CUDCOND_NAMED, for the purpose of allowing the specification of a
separate default user option for logged-out users.  We're taking two
different approaches to the targeting of logged-out users (anon vs
named) because of the temporary users project - anon will not include
temporary users while named will allow us to target only fully created
user accounts.  This will be ultimately be used for the rollout of the
reading accessibility settings menu

Bug: T360098
Change-Id: I316d231330159770f05234dd2f5fdb7d07531002
2024-04-02 14:46:53 -07:00
Tim Starling
768fd92fc0 block: Clarify function of HideUserUtils aliases and use them consistently
* Add a comment explaining why we need table aliases in HideUserUtils
  subqueries.
* Use the table aliases consistently in inner field references. While
  this does not appear to be strictly necessary, since unprefixed fields
  refer to the inner query by default, it helps to improve the clarity
  of the code.

Change-Id: Id68684ea12060a259dc87e66edd63b925da2c3b1
2024-03-19 11:31:03 +11:00
jenkins-bot
01e48eeb33 Merge "Add additional IP range validation to isValid function" 2024-03-18 23:10:17 +00:00
sbassett
fa4d2ace18 Add additional IP range validation to isValid function
* As a hardening measure, add a couple different types
  of IP range validation to UserNameUtils::isValid.  Such
  username patterns are often blocked on Wikimedia wikis
  via Title_blacklist, but not every MediaWiki operator
  has implemented such validationi, and it is trivial to
  just add this to core.

Bug: T358535
Change-Id: Ib05bcc8568ad4158b97a5073ccc47baeb304bec1
2024-03-14 15:50:20 -05:00
Bartosz Dziewoński
2cbc82edbb TempUserConfig: Deduplicate code generating match conditions
The idea is similar to the one behind TempUser\Pattern::toLikeValue(),
which has been effectively deprecated by allowing multiple patterns.

Change-Id: Iddb284bff21355deb8ceaa6925d3c2aea34d727e
2024-03-06 18:28:14 +01: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
Doğu Abaris
591e52b67a test: Convert LocalizedNumericSerialMappingTest to a unit test
This commit refactors the LocalizedNumericSerialMappingTest to make
use of mocks for Language and LanguageFactory. Introduced a data
provider for comprehensive testing of getSerialIdForIndex with various
scenarios. Added testConstruct to verify constructor functionality
and LanguageFactory integration. This refactor changes the base test
class from MediaWikiIntegrationTestCase to MediaWikiUnitTestCase,
shifting focus to unit testing.

Change-Id: I00d80d0a1d6d0bb8f7fc5c6e7c6fa4732ef04abb
2024-02-09 10:57:19 -05:00
Thalia
6909b2016e Always allow local IP actors to be created when importing
Why:

* Following T345578, the ActorStore throws an error on
  attempting to create an actor whose name is their IP address
  if temporary accounts are enabled.
* For the specific case of importing old revisions, we need to
  be able to create new actors whose name is their IP address,
  while still generally disallowing it.

What:

* Add $allowCreateIpActors flag to ActorStore, and check for
  it during actor name validation.
* Set the flag from ActorStoreFactory::getActorStore depending
  on whether temporary users are enabled.
* Add ActorStoreFactory::getActorStoreForImport, which sets
  flag to true.
* Add RevisionStoreFactory::getRevisionStoreForImport, which
  uses getActorStoreForImport. Use this from classes handling
  imports, so that IP actors can always be created.
* Add $forImport flag on ActorMigration, since RevisionStore
  uses an actor store obtained via ActorMigration.

Bug: T354207
Change-Id: I0715bd0d23089fd8156e579913e6e823089809be
2024-01-29 19:35:14 +00:00
Daimona Eaytoy
4637824f68 Replace unchecked MWException with SPL exceptions
Bug: T328220
Change-Id: I4e0454ce3ad3741756e2010a76e548d6c9a6bcb5
2024-01-28 22:41:46 +01: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
4db4b4e87f Merge "CentralId: Use UserFactory::newAnonymous" 2024-01-22 21:34:55 +00:00
jenkins-bot
903c17c8a2 Merge "Add wfDeprecated call to RealTempUserConfig::getMatchPattern" 2024-01-22 20:53:06 +00:00
Umherirrender
a616847791 CentralId: Use UserFactory::newAnonymous
Bug: T325686
Change-Id: Ia8ed50e806aadec15cb78eabf3c52ee4f73578ec
2024-01-22 21:48:20 +01:00
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
Dreamy Jazz
4fcf7c46ba Add wfDeprecated call to RealTempUserConfig::getMatchPattern
Why:
* The TempUserConfig::getMatchPattern method was deprecated in
  7f588780a0 with a replacement of
  TempUserConfig::getMatchPatterns.
* All existing usages on WMF deployed extensions have been replaced
  so a call to wfDeprecated can be added.

What:
* Add a wfDeprecated call in RealTempUserConfig::getMatchPattern.
  The other implementation of this method calls this method, so
  this is the only call needed.
* Update the tests to expect the deprecation of ::getMatchPattern.

Depends-On: I122f001ab24e879a573b19468d642b8f579d1024
Bug: T354619
Change-Id: I74ea85429d083737c325c978e1cad04beb6a9325
2024-01-18 20:25:17 +00:00
Dreamy Jazz
7f588780a0 Support multiple matchPatterns in temp user autocreate config
Why:
* There is a need to update the generation and match pattern on
  WMF wikis to a new format that includes the year and starts with
  `~`. As such, the 'matchPattern' key needs to be updated.
* Removing the old 'matchPattern' from the wgAutoCreateTempUser
  config currently leaves existing temporary accounts as no longer
  recongnised as temporary accounts.
* Instead, the 'matchPattern' needs to be able to take an array of
  string patterns so that old patterns can still be used for matching.

What:
* Update the MainConfigSchama to indicate that 'matchPattern' in the
  wgAutoCreateTempUser config can be an array of strings.
* Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig::
  getMatchPattern. This is needed because ::getMatchPattern was typed
  to only ever return one Pattern, which is no longer the case with this
  config change.
* Update the RealTempUserConfig to support multiple patterns defined in
  the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method
  returns the pattern or first pattern if multiple are defined to allow
  time for existing usages of this deprecated method to be updated.
* Update the RealTempUserConfig to rely on other methods instead of checking
  object property values where possible (e.g. use ::isEnabled instead of
  checking $this->enabled) to allow easier unit testing.
* Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig
  ::getMatchPatterns instead of ::getMatchPattern.
* Update mediawiki.util/util.js to be able to parse the 'matchPattern' value
  when it is an array of strings.
* Update maintenance/userOptions.php to use ::getMatchPatterns instead of
  ::getMatchPattern.
* Add and update unit and integration tests for the new code, as well as
  expanding coverage over existing code that was indirectly affected.

Bug: T354619
Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-17 11:24:26 +00:00
DannyS712
f11bee20d4 DummyServicesTrait: add an ITextFormatter
To avoid duplicating the creation of mocks/implementations

Change-Id: Id1094a9009acd100092f1b7cd55016d78900ce5f
2024-01-09 13:16:59 +00:00
jenkins-bot
7057d995bc Merge "Add support for conditional user defaults" 2024-01-09 04:42:53 +00:00
Martin Urbanec
6c8b696020 Add support for conditional user defaults
Why:
Sometimes, it is necessary to have different behavior
for newly registered and existing users. For example,
this happens in the Echo or GrowthExperiments extensions.
As of now, this behavior is implemented by inserting
user_properties rows in onLocalUserCreated.

Over time, this results in a singificant amount of rows
inserted, which contributes to the user_properties table bloat,
which is already overly large (cf. T54777). This patch makes it
possible to remove such rows by supporting conditional defaults
for user properties.

What:
Add support for conditional defaults of user properties. This can be
configured via `ConditionalUserOptions` config option.

Bug: T321527
Change-Id: I1549c3137e66801c85e03e46427e27da333d68e2
2024-01-09 02:33:17 +00:00
Thalia
caf9912323 Use year in temporary user names and restart index each year
Why:

* Part of a temporary user name is generated from an index that
  increments, which is stored in the database.
* As specified in T345855, the index will be restarted each year.
* Also specified in T345855, the year will be included in
  generated temporary user names.

What:
* Since the year must be included in the name in order to avoid
  naming conflicts if the index is restarted each year, both are
  implemented together and controlled by a single config.
* Add a new config option that, when true, restarts the name
  generation index at the start of each year and add the year into
  the user name: $wgAutoCreateTempUser['serialProvider']['useYear']
* Add a uas_year column to the user_autocreate_serial table, which
  is unique in combination with uas_shard, so the index can be
  stored for each shard/year combination.
* The year is added into the username just after the prefix, as
  specified in T345855. This is based on research that having the
  year near the start of the name aids understanding that the
  names are not IP addresses. The position of the year within the
  name is therefore not configurable (though whether to include
  it is). See T345855 for the research.

Bug: T349494
Bug: T349501
Depends-On: I6b3c640a4e74f52fd4a4f46de5a2cbe80fe3b665
Change-Id: If51acb3f4efa361ce36d919c862a52501a5a7d24
2024-01-05 17:14:19 +00:00
jenkins-bot
2d5499a89a Merge "Handle a negative exponent in TempUser/ScrambleMapping.php" 2024-01-02 06:33:46 +00:00
Thalia
e1cb9deacb Temp users: Add 'offset' option for PlainNumericSerialMapping
Why:

* Naming conflicts may arise on autocreation.
* For example, when generating temporary user names, the config
  wgAutoCreateTempUser['serialMapping']['type'] determines how
  the unique, numerical part of the name is generated, and naming
  conflicts may arise when changing types.
* Specifically we encountered the case of changing the
  $wgAutoCreateTempUser['serialMapping']['type'] from 'scramble'
  to 'plain-numeric'.
* In general conflict could be avoided in 'plain-numeric' mode if
  the highest number used in an existing username is known, by
  adding an offset.

What:

* Handle an 'offset' config option in PlainNumericSerialMapping to
  allow avoiding conflicts.

Bug: T353545
Change-Id: Id2f9a5b5cc808ce859b93b597cf7ea0efcd9e269
2023-12-18 12:20:42 +00:00
Thalia
a03b341aa6 Handle a negative exponent in TempUser/ScrambleMapping.php
This would happen due to an offset being configured too large so
can be fixed by changing the config.

Change-Id: Ie572a64e33322ce310bab09406db260fc27a6833
2023-12-18 12:12:32 +00:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Tim Starling
60911137ef Special:BlockList: Improve display of hidden users
With multiblocks the user might be hidden even if bl_deleted=0 in the
block row being formatted.

So:
* Add a subquery with a second block_target/block table which determines
  whether the user is deleted.
* When formatting each row, redact the name if it is deleted and the
  authority does not have permission to see it.
* Add a parameter to show which block is the one responsible for
  deleting the user.
* Similarly add a subquery in ApiQueryBlocks.

Change-Id: Id9900397618e1f626802ada6fe4ee4ad10f32495
2023-12-05 13:25:54 -05:00
Martin Urbanec
6ec01553c5 Move StaticUserOptionsLookup to the MediaWiki\User\Options namespace
Follow-up to I9822eb1553870b876d0b8a927e4e86c27d83bd52,
I missed the Static class in that patch.

Bug: T352284
Change-Id: I42653491c19dde5de99e0661770e2c81df5d7e84
2023-11-29 14:08:40 -05:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01: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
Amir Sarabadani
8fcd7726e9 Migrate all non-API code to use expression builder instead of buildLike
Bug: T210206
Change-Id: Icf3a2c5e5fb40ff31c65ba182937510d44186e46
2023-11-07 18:53:18 +01:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +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
Martin Urbanec
85e78d22bd Add UserRegistrationLookup
Why:
Temporary accounts introduced as part of IP Masking are supposed
to expire 1 year after their registration. Accounts can have
multiple registration timestamps when in a wiki-farm setup,
depending on which wiki we consult.

To implement the account expiration logic, we need to know the global
(first) registration timestamp.

Similar to CentralIdLookup, a concept of a registration date
provider is introduced. Unlike IDs, users can have multiple
kinds of registration dates (Wikimedia recognizes local and global,
but third parties can have different needs). For that reason,
any number of registration providers can be registered at any
given time; caller determines which one is requested. The default
is `local`, which is the only provider that is guaranteed to exist.

What:
* Add UserRegistrationLookup
* Add UserRegistrationProviders config variable

Bug: T344694
Change-Id: If9fa12a392064dd504590a861a175e3604a34fab
2023-09-15 11:38:23 +02:00
Tim Starling
07f1bc9f89 Make "temp reserved" usernames not be "usable"
If a username matches $wgAutoCreateTempUser['reservedPattern'], but the
username is not a valid temp user, return false from
UserNameUtils::isUsable().

This makes reserved patterns analogous to $wgReservedUsernames, and
provides a simple way to reject central sessions for temp users on wikis
where temp users are disabled.

Bug: T342475
Change-Id: I1d7f843e71e605fccf3de93fd145ff43e396619f
2023-08-25 15:06:22 +10:00