Commit graph

191 commits

Author SHA1 Message Date
Petr Pchelko
7136d671d2 Replace User::idFromName with ActorStore
Depends-On: I87fdac02a88aba52a2174949f8736a9a36d3edf7
Depends-On: I812c49009665515778cd354d6c62a17ee24f3625
Change-Id: I5369e9714a3ec653c19ad81f02402e4aa1b22553
2021-05-11 07:44:38 -07:00
James D. Forrester
6bbad15444 User: Hard-deprecate the confusingly-named isLoggedIn() method
This was soft-deprecated in 0171846c, since when all uses in Wikimedia
production code have been removed. As this is such a vital and widely-
used method, we'll want to deprecate it for at least two releases. and
so we should get this in at a time when we're willing to fix many such
uses. Why not now?

Bug: T270450
Change-Id: I8ac4a91d77c2bb748183b69b3e901cce93cbc940
2021-05-10 07:30:23 -07:00
DannyS712
31676abea5 Add DummyServicesTrait::getDummyInterwikiLookup
Replacing the mock InterwikiLookup used in
MediaWikiTitleCodecTest revealed that that test was,
because of the mock not behaving correctly, testing the
wrong thing - interwiki prefixes are *not* case sensitive,
and are always converted to lowercase in the actual
ClassicInterwikiLookup. Fixed those expectations.

Change-Id: I242431e88860b7700a9f93f77a0fe195fd748800
2021-05-05 10:57:59 -07:00
jenkins-bot
67d261449a Merge "Hard deprecate watchlist methods in User" 2021-05-05 17:25:02 +00:00
jenkins-bot
d7083856d9 Merge "Revert "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName"" 2021-05-05 02:45:35 +00:00
Ppchelko
ecf826a2ee Revert "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName"
This reverts commit b491279268.

Reason for revert: caused CentralAuth tests to fail.

Change-Id: Icb3ed094578df427622e0da2a7462645adcc3d6f
2021-05-05 02:14:47 +00:00
jenkins-bot
1ed7dcd022 Merge "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName" 2021-05-04 23:35:53 +00:00
DannyS712
40eda16b0e Remove deprecated talk page message handling in User class
Most needed for moving forward with the removal of uses
of the Revision class, and remove User::getNewtalk at
the same time to be consistent. All of this code was
already hard deprecated in 1.35.

- User::getNewtalk
- User::getNewMessageLinks (could return Revision objects)
- UserRetrieveNewTalks hook (could return Revision objects)
- User::getNewMessageRevisionId (used ::getNewMessageLinks)
- User::setNewtalk (accepted Revision object parameters)

Bug: T247143
Bug: T277511
Change-Id: Ib4fd1e4cbc5ba1497658190b6c6ea3c6a5dc97f0
2021-05-04 19:21:06 +00:00
vladshapik
b491279268 Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName
Bug: T275030
Change-Id: I60689ee6519c2dbd6d000afa8ac05c3e6b7895d2
2021-05-04 21:20:50 +03:00
DannyS712
c6216377bb Remove deprecated https-related hooks
All hard deprecated in 1.35
* BeforeHttpsRedirect
* CanIPUseHTTPS
* UserRequiresHTTPS

Also soft deprecate the wfCanIPUseHTTPS
method, which always returns true. Will
be hard deprecated once callers are updated

Change-Id: Ie6d71809d09edf6be9b8280debeb152ef7fce398
2021-04-30 11:53:18 -07:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Cindy Cicalese
3069e1c428 Hard deprecate watchlist methods in User
Bug: T281187
Depends-On: Id380a5441e30041b6fb79f6ad1fc0506b6a770f9
Depends-On: Ib8bf129a8f31ca054a74a9ec07a1ca0f7ac3e68c
Depends-On: Iddcd1cbf67ad1f8e918c1da07347dd19e5f6f7d9
Change-Id: Ief54eeb149e44ca7ffb2fddb1ba7fbe0e3eb62ea
2021-04-28 23:38:27 +00:00
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
jenkins-bot
d245e4cfbb Merge "Move watchlist-related methods from User to WatchlistManager" 2021-04-19 03:40:32 +00:00
Cindy Cicalese
47998b0783 Move watchlist-related methods from User to WatchlistManager
Deprecate the watchlist-related methods in User.

Change-Id: I1cde60252dd0f9659c718e27c7f2193294de63cd
2021-04-19 01:47:53 +00:00
jenkins-bot
7d7a313e8a Merge "User: use ActorNormalization to insert actor" 2021-04-16 22:29:17 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Petr Pchelko
021206c232 User: use ActorNormalization to insert actor
While creating users, we have several interesting corner cases:

- When creating a new User, we actually rely on the 'unique'
constraint on actor_name. This is important if something calls
'User::createNew' with a name that is already occupied by an
existing anon actor with no user. This is quite a weird corner case,
but there's a test for that. We could probably assimilate this
nicly in actor store by checking whether the user id in the database
for the actor we found is the same as user id in the passed in user identity.
- Even more interesting use-case is 'subsuming' existing actors with
reserved user names. When we call User::newSystemUser, and there is
already an actor with the same reserved name, we 'subsume' that actor
and take over it's actor_id for our new system user. This can now be
done with an upsert. This state of having reserved actor with no user
is not easy to cause, but imports or updating from old MW versions
seem to be able to produce this state. Archeology revealed that
'subsuming' existing actor was added for installer.

Change-Id: I16b2f088217db0283215fc2ef5fb04a3742e1626
2021-04-15 13:42:39 -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
ZabeMath
a6f3aaaa3a Hard deprecate User::isValidUserName()
User::isValidUserName() is soft deprecated since 1.35 and unused. It should be replaced with the UserNameUtils service.

Bug: T274211
Change-Id: I7a9db0b083cbbb98de1d5728a2a8046b8106233e
2021-03-25 21:23:02 +01:00
ZabeMath
54c9b830a4 Hard deprecate User::getFirstEditTimestamp() and ::getLatestEditTimestamp()
User::getFirstEditTimestamp() and User::getLatestEditTimestamp() are soft deprecated and unused and thus should be hard deprecated.

Bug: T274211
Change-Id: Ib2da53256d7290f6d9a768c0c0708ab9e8e072ed
2021-03-17 16:58:33 +01:00
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
daniel
4dce6dd0c3 Deprecate UserIdentity::getActorId()
Note: User::getActorId() is not (yet) deprecated.

Bug: T274179
Change-Id: Ic2ca6d489db821fc2334e53bf2496c7b0d3ea5b1
2021-03-13 19:45:57 +01:00
daniel
806792281f ActorNormalization should require a DB connection.
ActorNormalization should only be used in contexts where a DB connection
is already being used, or at least easily available.

Bug: T276986
Change-Id: Ie8aadaffa4a30e63fcad0502d45b8ec364fc79ef
2021-03-10 21:43:49 +01:00
Vadim Kovalenko
493105109e Avoid using UserIdentity::getUserId
Replace UserIdentity::getUserId with ::getId
Add $wikiId = self::LOCAL as an optinal parameter to User and
UserIdentity

Bug: T275482
Change-Id: I44494845c469a14284c3e23cb620e5a7cbf59cd5
2021-03-02 16:12:55 -07:00
jenkins-bot
19a52c8115 Merge "Hard-deprecate User::newSystemUser validation parameter." 2021-03-01 19:12:37 +00:00
Cindy Cicalese
2d302a936e Hard-deprecate IDatabase parameter for UserIdentity:getActorId()
Bug: T273576
Change-Id: I0df4a2749afae74671dc4c49bac4e18309677703
2021-02-17 12:51:02 -05:00
jenkins-bot
9945d4e237 Merge "Drop mThisAsAuthority from User before serializing." 2021-02-11 12:23:35 +00:00
Petr Pchelko
8ee8c1295d Hard-deprecate User::newSystemUser validation parameter.
Broad goal: we would like to stardadize better on normalizing user names.

Idea of this patch:
1. The 'validate' parameter is not used anywhere.
2. For possible validation levels:
- NONE will create a user with non-canonicalized user name in DB,
which in many codepaths will be inaccessible, since in many codepaths
we canonicalize the user name. It could be potentially useful for
creating system users with IP as a name, but I would argue it's a very
bad idea.
- VALID is the default.
- USABLE/CREATABLE - these check for reserved user names, so most of
the use-cases will want a system user with a reserved name. Passing
USABLE/CREATABLE essentially means you want to subsume a usable
non-reserved user account for system user, which is not a great idea.
if some code ever needs to do it (now none passes these options) -
then it can just use UserNameUtils and check explicitly.

Bug: T273933
Change-Id: I6f17349d84bd558df41fecfd19895e8c0dde4067
2021-02-10 12:56:36 -06:00
Petr Pchelko
29579c1557 Drop mThisAsAuthority from User before serializing.
User shouldn't be serialized, but it sometimes still is,
so until we introduce NotSerializableTrait in User,
clear-out Authority memoization.

Change-Id: I641c2721de8c6ebe9bfcd87cfcebff60dc091126
2021-02-09 08:39:23 -06:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Cindy Cicalese
5576727771 Make UserIdentity objects aware of which wiki they belong to.
Bug: T260933
Change-Id: Ic986640cc34e6ec6be239e410a8334f0e299c682
2021-02-02 16:10:51 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00: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
Reedy
56ba0a755a Revert "Remove usages and hard deprecate User::changeable(By)Group"
This reverts commit d70559796a.

Reason for revert: T273317 T273296

Bug: T273317
Bug: T273296
Change-Id: I0709ad630f4443d4cd2e5ea51105e1c9f409c12e
2021-01-29 20:32:57 +00:00
Petr Pchelko
d70559796a Remove usages and hard deprecate User::changeable(By)Group
Bug: T254838
Change-Id: Ie7fd852c287e91f16122ecb2d1bef5353fd40ea9
2021-01-21 20:53:40 +00: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
Petr Pchelko
bc6f7e4bdc Make User implement Authority
Ideally, only User associated with the global request
should be associated with UserAuthority. For a random
user instance, not the current performer, checking permissions
should be based solely on user groups and perhaps an
existing block. Right now however, PermissionManager
is coupled with global request, so we still instantiate
a UserAuthority for non-current users. This mimics the
behaviour we've had before. As we refactor PermissionManager,
we will be able to replace Authority implementation in this case,
or even entirely prohibit non-performer authority.

Bug: T271459
Depends-On: Iebf2dca34eea751391d9740443c195287399aa5c
Change-Id: Ib094e498fd883db23f2763f171281b1c9e99217e
2021-01-19 18:08:12 -06:00
DannyS712
edb2072c68 Remove unused definition of NS_UNITTEST(_TALK) in UserTest
Change-Id: I813f188050183aa468feb9ca877b7d238c6dd09d
2021-01-15 10:37:02 +00:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
C. Scott Ananian
3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00
jenkins-bot
02342b9065 Merge "Don't access $wgRequest from User" 2020-12-16 05:06:16 +00:00
Tim Starling
6b2a52181f Don't access $wgRequest from User
Some User methods fail if they are called before $wgRequest is
set. But according to the Setup.php comment, it is only set for b/c.
The global request object can be lazy-initialised at any time.

This is sufficient to avoid T263911 (loss/obfuscation of the $wgServer
error message).

In tests, try to keep $wgRequest and RequestContext::$request in sync.
Introduce MediaWikiIntegrationTestCase::setRequest() which sets both at
once, and use that instead of setMwGlobals() or direct assignment.

BlockManagerTest was accidentally exploiting the fact that the global
context request and $wgRequest were separate objects. Making them the
same causes session cookies to appear in the response, breaking the
cookie counts. Use a new response for the test.

Bug: T263911
Bug: T245940
Change-Id: I2be99f7251a837bc6b62be0b152038157dec10f2
2020-12-16 12:21:00 +11:00
Matěj Suchánek
4633339894 Compute experience level correctly for accounts without registration date
These accounts are usually very old and User::getRegistration returns
null for them because user_registration is null. Treat these accounts
as old enough to be in the most experienced group and only decide
on edit count. Fix queries in recent changes to avoid comparisons
with nulls as well.

Also improve documentation of User::getExperienceLevel.

Change-Id: I6090cf9b9097069469e8e547b217f0d16f0fe372
2020-12-12 13:07:20 +01:00
Umherirrender
eaa5679adc Check for Title::canHaveTalkPage in User::addWatch
Also check Title::isWatchable
Same for removing from the watchlist
This avoids exceptions

Change-Id: Ibb9e6906c87ffc3a3b619be59f128d9d3ed4aaba
2020-11-22 22:43:38 +00:00
Umherirrender
a9e1ec135c [UserTest] Set defaults for $wgAutoConfirmAge/$wgAutoConfirmCount
My dev wiki has some settings for these globals,
which results in broken test
1) UserTest::testGetEffectiveGroups
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'autoconfirmed'
-    1 => '*'
-    2 => 'user'
+    0 => '*'
+    1 => 'user'
 )

Change-Id: Id062c92aefdf9381d7575ece95124d62ec315aa4
2020-10-30 16:17:02 +01:00
Martin Urbanec
016d2e401c Remove NonSerializableTrait from User object
User objects are apparently serialized somewhere, removing
the trait until this gets fixed.

Remove UserTest::testSerialization_fails to
allow this change for now.

Bug: T264363
Change-Id: Id804755653452dc94184e5e481efcac3053e6535
2020-10-01 23:16:08 +02:00
daniel
dc436c3cff Introduce and apply NonSerializableTrait
The NonSerializableTrait prevents object serialization via php's native
serialization mechanism. Most objects are not safe to serialize, and
NonSerializableTrait provides a covenient and uniform way to protect
against serialization attempts.

This patch applies the NonSerializableTrait to some key classes in
MediaWiki.

Bug: T187731
Bug: T259181
Change-Id: I0c3b558d97e3415413bbaa3d98f6ebd5312c4a67
2020-09-28 21:55:49 +02:00
Clara Andrew-Wani
79afec9457 User: Use "Unknown user" for bad user id
Without this, a user created from an invalid user ID would end up
representing the current requests IP address, which may lead to
confusion. Using the reserved name "Unknown user" seems safer.

Change-Id: Icbfe7c3a561ac927713b610ac9a0b5e6b88bf2f0
2020-09-24 22:23:38 +00:00
DannyS712
8af8aaad0f UserTest: No need to set $wgUser
Bug: T243708
Change-Id: I8ba28ac21a08a7c466ad70727a21fb7a0c1a6275
2020-09-15 21:22:33 +00:00