Commit graph

178 commits

Author SHA1 Message Date
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
Thalia
addb098c39 Deprecate DatabaseBlock methods moved to DatabaseBlockStore
Following 23c3c70d7f, soft deprecate the static methods on
DatabaseBlock that have been moved to DatabaseBlockStore:
* ::insert
* ::delete
* ::update
* ::purgeExpired

Update calls to the deprecated methods from core.

Change-Id: I1272eb978594fd4f386bda12cbc24131ad7d882f
2020-09-13 22:17:27 +00:00
jenkins-bot
ff51ff7fc6 Merge "user: Document User::add/removeWatch behavior on special pages" 2020-09-09 12:22:34 +00:00
daniel
f50240fe76 User: enforce pingLimiter() expiry time
This makes User::pingLimiter() include the expiry time in the payload of
the cache key that holds the current count. This allows us to ignore
stale counts.

Until now, we have been relying on the cache implementation to expire
the relevant keys in time. This however seems to fail sometimes.

Bug: T246991
Change-Id: Ifa3c558b4449f1ca133d0064781f26ac1bf59425
2020-09-03 15:57:01 +00:00
Thiemo Kreuz
fe562a64f1 user: Document User::add/removeWatch behavior on special pages
It's not the WatchedItemStore that throws this exception, but
really the methods in the User class that implement this behavior.
Hence it needs to be tested in UserTest. And documented. That was
missing before.

This patch also replaces some Title::newFromText with slightly faster
Title::makeTitle, if possible.

Change-Id: Id930a547329145c0703b4c97773a49fd78dd6332
2020-09-03 14:46:37 +00:00
daniel
e7a27f2db7 User::pingLimiter: add user-global rate limit type
"user" style rate limits can't be cross-site, since they are based on
the user ID. "user-global" uses CentralIdLookup to allow cross-wiki
rate limits.

Bug: T251661
Change-Id: Id680b96be2ea81d29447c4c1abafc8f98a339626
2020-09-02 19:38:04 +02:00
Petr Pchelko
ee5d922465 Remove hard-deprecated and unused User methods related to blocks
Change-Id: I0a4d7b5a1582f6249435cbedd49b1e414f86c4f6
2020-08-05 09:55:20 -07:00
Ammar Abdulhamid
6cbd116954 Remove selectFields User method
* Deprecated since 1.31
* Remaining call in Test replaced

Bug: T249181
Change-Id: Idb69f36a07055110fe0b7540186b23cc52dad76f
2020-07-12 15:21:48 +01:00
DannyS712
0637d80572 Hard deprecate the rest of the Revision class
Bug: T246284
Change-Id: I126d7892c90aa2200c668b5717820e729613bed8
2020-07-02 09:02:02 +00:00
jenkins-bot
a18a39f413 Merge "MediaWikiTestCase to MediaWikiIntegrationTestCase" 2020-07-01 18:39:57 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Tim Starling
c75eef91bf Introduce $wgForceHTTPS
Add $wgForceHTTPS. When set to true:

* It makes the HTTP to HTTPS redirect unconditional and suppresses the
  forceHTTPS cookie.
* It makes session cookies be secure.
* In the Action API, it triggers the existing deprecation warning and
  avoids more expensive user/session checks.
* In login and signup, it suppresses the old hidden form fields for
  protocol switching.
* It hides the prefershttps user preference.

Other changes:

* Factor out the HTTPS redirect in MediaWiki::main() into
  maybeDoHttpsRedirect() and shouldDoHttpRedirect(). Improve
  documentation.
* User::requiresHTTPS() reflects $wgForceHTTPS whereas the Session
  concept of "force HTTPS" does not. The documentation of
  User::requiresHTTPS() says that it includes configuration, and
  retaining this definition was beneficial for some callers. Whereas
  Session::shouldForceHTTPS() was used fairly narrowly as the value
  of the forceHTTPS cookie, and injecting configuration into it is not
  so easy or beneficial, so I left it as it was, except for clarifying
  the documentation.
* Deprecate the following hooks: BeforeHttpsRedirect, UserRequiresHTTPS,
  CanIPUseHTTPS. No known extension uses them, and they're not compatible
  with the long-term goal of ending support for mixed-protocol wikis.
  BeforeHttpsRedirect was documented as unstable from its inception.
  CanIPUseHTTPS was a WMF config hack now superseded by GFOC's SNI
  sniffing.
* For tests which failed with $wgForceHTTPS=true, I mostly split the
  tests, testing each configuration value separately.
* Add ArrayUtils::cartesianProduct() as a helper for generating
  combinations of boolean options in the session tests.

Bug: T256095

Change-Id: Iefb5ba55af35350dfc7c050f9fb8f4e8a79751cb
2020-06-30 15:38:11 +10:00
jenkins-bot
9c85246254 Merge "Deprecate PasswordCannotMatchBlacklist" 2020-06-26 10:07:52 +00:00
Clara Andrew-Wani
4093985c28 Hard deprecate User::getNewtalk and User::setNewtalk
Bug: T239640
Change-Id: I7f901963ea67e8cdac1611838570ff9717d11232
2020-06-25 12:12:32 -04:00