Commit graph

29 commits

Author SHA1 Message Date
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
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Tim Starling
e8dbf5f80c TempUser infrastructure and services
Add services and utilities for automatic creation of temporary user
accounts on page save, in order to avoid exposing the user's IP
address.

* Add $wgAutoCreateTempUser, for configuring the system
* Add TempUserConfig service, which interprets the config.
* Add TempUserCreator service, which creates users during page save as
  requested by EditPage. With proxy methods to TempUserConfig for
  convenience.
* Add table user_autocreate_serial. Table creation is necessary before
  the feature is enabled but is not necessary before deployment of this
  commit.

Bug: T300263
Change-Id: Ib14a352490fc42039106523118e8d021844e3dfb
2022-04-14 09:23:55 +10:00
Tim Starling
1b0b40016c Fix UserFactory::newAnonymous() performance
When newAnonymous() was called with a specified IP address, it called
newFromName(), leading to a DB query on User::load() as if the IP
address could be in the database.

Instead, use User::setName() which is documented to work for this
purpose and indeed appears to do so.

Change-Id: I8e8be719c89b1d1e4ae2cf9063db68b929bb3651
2022-03-30 17:31:38 +11:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
DannyS712
6e92db149a UserFactory: remove outdated documentation about not doing anything
Originally was used as just a wrapper for the User class constructors,
but that has not been the case for a while.

Change-Id: I34027b36edab68ed71921da8443f22c7020cd334
2022-02-11 22:18:26 +00:00
jenkins-bot
48a3b2e7f8 Merge "UserFactory: Simplify and type hint newAnonymous" 2021-08-18 00:16:42 +00:00
Umherirrender
e436beef31 UserFactory: Simplify and type hint newAnonymous
Swap if/else branches, because the old else branch throws and than no
explicit else is needed in the new code.
Also avoid the local variable

Typehint newAnonymous, because the called UserNameUtils::isIp and
self::newFromName are also type hinted and needs a safe value

Change-Id: I2340cc1a49c12ff07f6e38dfbb3937032ff68deb
2021-08-17 20:52:54 +02:00
Umherirrender
820a4a931b UserFactory: micro optimisation in newFromUserIdentity
Also use strict equal, because the compared values are from type hinted
functions.

Change-Id: Ib70609300202831395030577588a4901c7495a7b
2021-08-13 22:18:30 +02: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
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00: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
7e2f7efa27 Convert Language to UserIdentity
This also introduces minimal instance caching into UserFactory

Change-Id: I594c5668c537477516dda4beecd11b8aa840ae62
2021-03-11 20:23:23 +01:00
Petr Pchelko
ea185c872e Rename Authority::getPerformer() to ::getUser()
We started to call Authority argument $performer everywhere,
and $performer->getPerformer() doesn't look that good.

Change-Id: Id2cf3f27b18340314e4ed1ea9931ad9404b4df6f
2021-03-04 12:45:28 -07:00
Petr Pchelko
375e9f0a68 Rename Authority::getActor to Authority::getPerformer
Bug: T274947
Change-Id: I8f652816af00bf9fa413ba4b1fa7ac4c27290dc2
2021-02-22 14:53:21 +00:00
Petr Pchelko
30cf40568b Add Authority to Context
Bug: T271460
Change-Id: If1038c94ccf8f3e59b5242f5c33b66f076c60816
2021-01-20 09:07:27 -06:00
DannyS712
e9c0f8236c Migrate more User::newFrom* methods to UserFactory
Bug: T253432
Depends-On: If5e76f2ae570ef4ae58cb77b5281c4446a1cadff
Change-Id: I9286d4a69911a84661cba40c55c0a4e3f1b7f7f3
2020-10-05 23:47:53 +00:00
DannyS712
4db93b3be4 Inject dependencies into PasswordReset, and cleanup
* Convert everything that is protected to be private,
since the class is not stable to extend

* Remove PasswordReset::$hookContainer, unneeded

Additionally, add missing UserFactory::newFromRow,
for now just a wrapper for User::newFromRow

Bug: T253432
Change-Id: I1de57a08605ff6e0d2be8e276b7fcb08934fb5da
2020-10-03 00:23:59 +00:00
DannyS712
717433bf25 Add UserRigorOptions interface
Bug: T253432
Change-Id: I6618fc862da7043449ffda02e4428a5df0303e1c
2020-09-29 17:11:16 +00:00
DannyS712
84ec8f0735 Move User::newFromName logic to UserFactory
Bug: T253432
Change-Id: I0df34c01fdaf139848be47178f7e26c9d63929d6
2020-09-29 13:36:38 +00:00
Reedy
7daea74dba Mark UserFactory::newAnonymous() as @since 1.35 after backport
Change-Id: I6b49e94023eb321f28bc4160afe061270c6d5538
2020-08-06 15:14:15 +01:00
jenkins-bot
383704c2e5 Merge "UserDef DI" 2020-08-05 17:02:02 +00:00
Nikki Nikkhoui
83d65d0962 UserDef DI
- Begin injecting services into UserDef to support
unit tests.
- Replace static User class functions with
UserFactory functions.

Bug: T259145
Bug: T257464
Change-Id: Iccc0c39e013679f15f2e62738c56df09ba56c494
2020-08-05 16:36:53 +00:00
daniel
cd1aea867e reassignEdits: Update script to use User::newFromName for anon users
Bug: T249521
Change-Id: Id718ad95f644e128470d5c81071bef06d301af29
2020-08-03 10:49:18 -04:00
DannyS712
80027cdbbc User is not @newable in 1.36
Bug: T257464
Change-Id: I0d78cfb18166f46a65a65755ca2bef57d504a0b3
2020-07-16 12:14:33 +00:00
Nikki Nikkhoui
6c8187d4f8 UserFactory method for getting anonymous user
Create a method in UserFactory to instantiate an anonymous
user with an optional IP address.

Bug: T257464
Change-Id: I557620f9bcd4b646288b4a76b26c4730fccbc3d8
2020-07-15 00:07:45 +00:00
Thalia
14bb09fe7f UserFactory: Document that newFromName expects a validation constant
When no validation is wanted, a UserNameUtils constant must be passed
to UserFactory::newFromName, whereas User::newFromName accepts false.

Also pass a constant as the default parameter, rather than the string
value of that constant.

Bug: T255611
Change-Id: Iffd405cb8b38debe9d0a7106a76c430956351583
2020-06-17 12:51:13 +01:00
DannyS712
2d7d99f036 Move User::newFromIdentity logic to UserFactory
Simplest static constructor for Users, no dependencies on anything else

Bug: T253432
Change-Id: Ibe422de4f1753334f2737bc39e077b1e4173ad45
2020-06-12 18:24:49 +00:00
DannyS712
61a3a8f734 UserFactory v.1 - wrapper for User::newFrom* static methods
Makes it possible to mock static User methods in tests;
actually introducing dependency injection to the User class is left for
the future.

New class has 100% code coverage

Bug: T253432
Change-Id: I0b93da09124d95beafd84e932b214909ce920230
2020-06-10 20:38:26 -07:00