Commit graph

696 commits

Author SHA1 Message Date
jenkins-bot
0e67555656 Merge "Replace deprecated MWException" 2023-06-12 19:53:04 +00:00
Daimona Eaytoy
518a5da533 Replace deprecated MWException
Bug: T328220
Change-Id: I0408575ee71e58d1c9e9ebedabab35bd3813f515
2023-06-12 12:27:49 +00:00
Alexander Vorwerk
d93c9001f4 Migrate more usages of Database::update() to UpdateQueryBuilder
Bug: T330640
Change-Id: I094eea810886b13d832be575d9b9df8f8e4a77ea
2023-06-09 13:36:04 +00:00
Lucas Werkmeister
15f076efca Clean up UpdateQueryBuilder usage
This follows up change I608566700c, which was mainly generated by a
script. Most of the clean up here is fixing cases where it seems the
script for some reason collapsed multi-line arrays into single-line ones
and/or removed spaces after commas. A handful of other improvements are
included too (split merged conditions into ->where()->andWhere(), use
buildComparison()). In RevDelArchiveItem, a comment is restored that I
assume was removed accidentally (perhaps because the script didn’t
expect comments inside the conditions).

Bug: T330640
Change-Id: If27bafb12fdaa05d3dc1ae6da820e1630ae2742e
Follows-Up: I608566700c6d737ee986bf47dda87effc69614d6
2023-06-08 12:50:37 +02: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
Daimona Eaytoy
b469b342d0 Introduce EmailUserFactory
This is necessary so that EmailUser can behave as a command. EmailUser
now takes the performer as a constructor parameter; this, in combination
with the statelessness of the service, allows it to be reused for
multiple sends. Some BC code was also moved to the factory.

Bug: T265541
Change-Id: I2568359f00f429ef3ab3bfbfb803dc8e51cd8add
2023-06-01 11:17:44 +00:00
Daimona Eaytoy
ead6d3135b mail: Round 5 of EmailUser refactoring
- Use UserEmailContact for the sender; internally, we still fall back to
  User.
- Try to use Authority and UserIdentity instead of User where possible
- Replace PermissionManager with Authority
- Fix handling of block message in BC code for Special:EmailUser
  (currently throwing a fatal because of return type mismatch, as the BC
  code is not intercepting the Message object)
- Move the ratelimit check around the beginning of the method, instead
  of running it after having pointlessly built half of the email body
- Stop using User::isBlockedFromEmailuser and add a TODO about
  deprecating that method.

Bug: T265541
Change-Id: Icc06b816a553028d816e6ab1b43ad93605fd5b3f
2023-06-01 11:17:31 +00:00
Umherirrender
7fdae7fce5 user: Add @since to User::isTemp/isNamed
New functions from e8dbf5f
The information is visible on the interface doc-block,
but not in the implementation doc-block, so added for convenience

Change-Id: I1e30c908526df86b385b384648047803772d2643
2023-05-30 22:52:10 +02:00
Daimona Eaytoy
3c88aeafb5 Use EmailUser in User::canSendEmail, deprecate EmailUserPermissionsErrorsHook
The new EmailUser class encapsulates logic for email-related permission
checks, so this doesn't have to be in User anymore. The two methods are
roughly equivalent, but EmailUser performs the following additional
checks:
- User::isBlockedFromEmailuser
- Ratelimiter
- onEmailUserPermissionsErrors hook

Also deprecate the EmailUserPermissionsErrors hook: after this change,
it becomes equivalent to the UserCanSendEmail hook. The only difference
is that the former also takes an $editToken parameter, but it's unused.
The hook was added in 2009 in
372ee7b344%5E%21
with TorBlock as the intended consumer. At the time, the
getPermissionsError was using the $editToken parameter, so I guess it
felt natural to pass it to the hook as well; however, the hook in
TorBlock never needed it. The method no longer needs the token as of
38c7c8f895%5E%21/#F3
in 2010, but it was never removed from the hook. Also, it's unclear why
an internal detail such as the edit token should be exposed like this.

Note that the UserCanSendEmail hook is also going to be replaced
eventually, but that'll happen in a separate patch.

Bug: T265541
Change-Id: I2492b261505886d845260e2b63c5e71966a637ce
2023-05-21 13:23:12 +03:00
Daimona Eaytoy
7340a7fdf9 Replace usages of deprecated UserGroupMembership::getLink()
Bug: T183174
Change-Id: I34f40bd88404cfb7826dfd4d0ef3d662f6091c65
2023-05-20 21:21:19 +02: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
AnaïsGueyte
3e6c366fdc Update UserOptions classes to prevent temporary users having access to preferences
Bug: T332415
Change-Id: I232a7acf870068cdc3ee3532f7ed928079863ce2
2023-05-03 18:43:19 +00:00
Gergő Tisza
98efa261a2 ConfirmEmail: Show clearer error message on malformed token
Sometimes the email confirmation URL gets truncated by the email
client or during copying. The default error message warning about
token expiry isn't very helpful in that case. Add a new error
to be shown when the token does not match the expected format.

Change-Id: I6fac761efe93a863643c5e0bbcf2483529cb194f
2023-04-12 08:26:07 +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
jenkins-bot
57122dd8d1 Merge "Minor PHPDoc fixups and improvements in different places" 2023-02-14 17:00:55 +00:00
thiemowmde
bf90007dec Use the ?? operator in a few places where it makes sense
… and where it improves readability, in my opinion.

Change-Id: I4f3bc6067dfac16841ed74c00a4c81215d0f5249
2023-02-14 09:44:27 +01:00
thiemowmde
8b3083023f Minor PHPDoc fixups and improvements in different places
A series of minor documentation fixes I collected in my local
dev environment over the past months. I'm not sure if it's worth
splitting this further.

Change-Id: I1ef383b40271f1513cb03d0de1fe511f4ca51ada
2023-02-14 09:09:11 +01:00
jenkins-bot
6a25db1206 Merge "Change $wgLang to use Message::*Param functions" 2023-01-28 00:31:50 +00:00
Brian Wolff
6954193287 Fix docblock comment of User::sendMail $body parameter
$body can be a string or an array containing keys text and html
for the text and html version of the email body. Update types to
match UserMailer::send().

Change-Id: Ife2f36a2ec4ccb4b9d29d70b96fb36331922e756
2023-01-17 09:23:23 -08:00
Umherirrender
dabe7242f9 Hard-deprecate User::idFromName
Bug: T325687
Change-Id: I5dc13586c11ad49cd7c2646a65e103bb52f28512
2023-01-14 13:06:23 +01:00
jenkins-bot
ad0423a253 Merge "Hard-deprecate User/PermissionManager group permissions lookup functions" 2022-12-23 01:55:51 +00:00
Umherirrender
9ae99165af user: Hard-deprecate User::$mRights
Deprecated since dd6b940

Change-Id: Ifac5101103d34f39908b094ea9400888b6126cfe
2022-12-22 23:12:52 +01: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
jenkins-bot
c903124b77 Merge "Make use of ?:, ?? and ??= operators in mostly trivial cases" 2022-12-16 02:51:26 +00:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
daniel
c6ca5baa16 phpunit: improve isolation by calling User::clearInstanceCache
User objects may hold references to service objects. They need to be
reset when services are reset between and during tests.

Change-Id: I7fe767977f1fe01d508fddf7a92ade3ec8ba2662
2022-12-04 15:21:30 +01:00
Amir Sarabadani
02e5a33057 Drop more unused hard deprecated hooks
None are used in WMF-deployed extensions and have been hard deprecated
for multiple releases as well.

Change-Id: I62cfa22291f81295b4908192de8657a750c6716d
2022-12-01 03:36:48 +01:00
csimiyu
9ca7247af0 Deprecate global-blocks-specific methods and hook
Bug: T317337
Change-Id: If7cfb8faaf62c1a7169b1a1cc1f344ea83857836
2022-11-28 15:33:44 +00:00
Tim Starling
0f7a8621e9 Clean up PHP 7.1 reference hacks
These callers are not passing $this by reference. The hook signature
probably changed in 1.35.

Change-Id: I0b97487018310be66551d432fe4c2c419025a2be
2022-11-16 12:42:42 +11:00
Umherirrender
1b342a8893 Various doc fixes about false and null on method arguments/return types
Doc-only changes

Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
2022-11-03 18:55:47 +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
Timo Tijhof
1cf6f04768 objectcache: Remove WANObjectCacheReaper feature
Introduced in 2017 with I7f14b9ca2533032 (2e5eb693) but remains
unused at WMF, and disabled by default.

Follows-up I62107789fa (9e49260fc9) which added reap to LinkCache
test cases in 2021.

Change-Id: I0654c29a671467dd6b366f462d1c09b90a273413
2022-10-25 23:09:39 +01:00
Daimona Eaytoy
947ff7c0f5 build: Update mediawiki/mediawiki-phan-config to 0.12.0
This patch only adds and removes suppressions, which must be done in the
same patch as the version bump.

Bug: T298571
Change-Id: I4044d4d9ce82b3dae7ba0af85bf04f22cb1dd347
2022-10-08 15:45:42 +02:00
Umherirrender
f077ac60c0 Change $wgLang to use Message::*Param functions
Delay the formatting of numbers/lists when the message should be shown.
That allows to use the language of the user given to the message and
avoids global state by the global variable $wgLang or it use the global
state of Message class, which needs to be fixed later.

Change-Id: I015cea3a585a647e160b94d8ef30fad5d5df6cff
2022-09-26 19:12:15 +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
Roman Stolar
3c3f33207e Hard deprecate User::getOption
Bug: T296083
Change-Id: Ifaf9b8308e00b7e3528da7ca63e253525ff78f80
2022-09-03 12:11:21 +00:00
Roman Stolar
5f53f2a8a2 Replace usage of User::getOption
Update tests

Bug: T296083
Change-Id: Id209abd408a1fdecb0a39c0910b12d34458ed458
2022-08-19 21:21:36 +02:00
jenkins-bot
ef650d66d8 Merge "Improve docs of various ::getQueryInfo functions" 2022-08-14 07:40:47 +00:00
Umherirrender
cbe949410d Improve docs of various ::getQueryInfo functions
Explict types helps phan to detect errors with keys like ef82d95

Change-Id: Iee4d964ecc58273eb9c73356ed34e13f29fbd275
2022-08-13 21:18:44 +02:00
jenkins-bot
9e41475b9b Merge "user: Move logic for unregistered HTTPS pref to User::requiresHTTPS()" 2022-08-06 22:11:39 +00:00
Umherirrender
a1ecd99fd3 user: Move logic for unregistered HTTPS pref to User::requiresHTTPS()
Move the User::isRegistered call into the function to let all callers
benefit from that check. This is more than an error check, it also is
business logic representing the effective default for unregistered users
which is non-obvious and benefits from being written down as part of
a central contract.

Update tests as the user must exists on the database to have
preferences.

Change-Id: Ibacdd642d03031d9659a821045788046f0187518
2022-08-06 21:50:32 +00:00
Andre Klapper
1616f6023a Fix code doc reference to removed function setOption
Bug: T314433
Change-Id: I9f23e1fa3a5938fb5ad6db63b9414b7f7721e9de
2022-08-02 22:06:17 +02:00
Máté Szabó
6a84db8577 User: Allow dynamic properties on PHP 8.2
Dynamic property creation on PHP 8.2 raises an E_DEPRECATED unless the
class specifically allows it via the new #[AllowDynamicProperties]
attribute. The User class has stated support for dynamic property
creation, used among others by the OAuth extension, so mark it as such.

Bug: T314099
Change-Id: Ie141d9795dbc410c49e5d450945423f39fbd8164
2022-07-29 02:56:25 +02:00
jenkins-bot
db4a5d4e71 Merge "Extract RateLimiter from User" 2022-06-28 06:19:17 +00:00
daniel
dd2e9905cd Extract RateLimiter from User
This moves the logic for rate limiting out of the User class into a
standalone service.

Change-Id: I2881913876c855a1538bac92f0dabac3b3bddcfc
2022-06-27 13:23:24 +00:00
Matěj Suchánek
1865180ae7 Do minor code cleanup
Remove dead code and fix typos. Should cause no change in behavior.

Change-Id: I5d293b842bc93a28b8bcd799a31b5e6e30fe692e
2022-06-24 13:52:42 +02:00
jenkins-bot
09b92847f8 Merge "Hard deprecate access to some public properties on User" 2022-06-24 09:42:37 +00:00
jenkins-bot
fa1208c0d3 Merge "Replace deprecated wfReadOnly/wfReadOnlyReason" 2022-06-24 01:14:35 +00:00