Commit graph

59 commits

Author SHA1 Message Date
Timo Tijhof
4ef0891994 rdbms: Consolidate logger channels into one
Notable changes:

* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
  injected. The rest implicitly got a NullLogger due to being absent.
  These are now effectively unsilenced.

* Database::__construct() required almost all parameters, even the
  loggers. I've wanted to move some of DatabaseFactory into the ctor
  here for a while. In order to make this change not a breaking
  change, the new 'logger' parameter is optional with NullLogger as
  default. This allowed some of the test cases, which were simply
  passing NullLogger, to be fixed by passing nothing instead of
  passing the new option name.

  The Database class is behind a dozen layers of indirection for
  real use, so this will still be injected just fine (DBF, LB, LBF,
  MWLBF, etc.).

* In LegacyLogger, the handling for $wgDBerrorLog was previously
  limited to DBConnection and DBQuery. This now includes errors
  from other (generally, newer) parts of Rdbms as well, which were
  previously missing.

  This only affects sites (typically CI and dev setup) where
  $wgDBerrorLog is used, as opposed to the more common
  $wgDebugLogGroups by-channel configuration.

* TransactionProfiler gets its logger injected in a rather odd way,
  via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
  as opposed to service wiring. This is kept as-is for now.

* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
  there are cases that intentionally produce failures of which
  the result is then observed. In CI we assert that dberror.log is
  empty so instead of adding the missing logger fields to that
  LBFactory instance, the only one set (replLogger) is removed.
  The alternative is to set 'logger' now, which would naturally
  cause CI failures due to unexpected entries coming through to
  non-mocked error log.

Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
2023-01-03 22:46:38 +00:00
Derick Alangi
f88eab53a6 tests: Use overrideConfig(Value|Values) where needed
This continues the work in the child patch to replace callers
of setMwGlobals() with the appropriate method. Directory this
patch covers is `tests/phpunit/integration/`.

Change-Id: I0a9abf0d2a43587f2ffa029b68024a1ba5165fc7
2022-07-12 14:40:46 +01:00
daniel
7f8e3c5360 Docs: remove references to DefaultSettings.php
Bug: T300129
Change-Id: I1e83a0dde6235bed91d28d7d43691c6a5d979f2f
2022-05-30 21:27:09 +02:00
jenkins-bot
bd8691818a Merge "TempUser infrastructure and services" 2022-04-14 15:33:50 +00:00
Amir Sarabadani
280c2ed0d3 rdbms: Fold MaintainableDBConnRef into DBConnRef
We really don't need this complexity and it prevents us from improving
connection management.

MaintainableDatabase should stay but the connection ref shouldn't.

Bug: T255493
Change-Id: I867301dc7fa07cac298f8faba9cf82ca4617f50e
2022-04-14 01:57:11 +02: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
Martin Urbanec
8ce472ce91 UserSelectQueryBuilderTest: Test behavior of hidden()
Bug: T291966
Change-Id: If22d5db53e71bb7a49a71a8d00be42ccc3b158c3
2021-12-20 15:59:15 +01:00
Majavah
7e3df796b0 Revert "Remove last User dependencies from File"
This reverts commit 73a25838b4.

Reason for revert: T296508

Bug: T296508
Change-Id: I8af37665eeb284b85157a72459d43261ec4829ed
2021-11-26 17:06:36 +00:00
Petr Pchelko
73a25838b4 Remove last User dependencies from File
Change-Id: I953fcc66b5cde1ef481178b08e16c50b8a118702
2021-11-26 05:42:00 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Thiemo Kreuz
ee0f97378b Replace new stdClass with more compact array syntax
It does the exact same. The resulting object is still an stdClass
instance.

Change-Id: Ief68609943ee30aa95732d24021c921dfbad166c
2021-11-02 09:43:03 +00:00
Alexander Vorwerk
0a86c3655d phpunit: Fix parameter order on two assertSame() calls
The first parameter of assertSame() is the expected value, the second
one the actual value.

Change-Id: I5a411403443f18b30c93ab9552f625a70c75f75c
2021-10-12 20:22:34 +00:00
Umherirrender
bcee220ad1 tests: Avoid non-namespaced aliases for Wikimedia\Rdbms namespace
Change-Id: I49cb151f64c578f41dc1236b2a8906694ca97b93
2021-09-18 20:24:08 +02:00
jenkins-bot
69a0352f38 Merge "Make UserRightsProxy implement UserIdentity" 2021-09-09 16:27:04 +00:00
Derick Alangi
e894dc75fa tests: Use service container in integration tests cases
Since MediaWiki 1.36, this method is provisioned to replace creating
new instances of the services object. If one is already created and
seen by the service locator, just use it.

Change-Id: I9509497a8380194aa93310343b1896521070fc31
2021-09-05 22:14:36 +01:00
Alexander Vorwerk
cdaff4efbc Make UserRightsProxy implement UserIdentity
This is done to allow a more easy transition away from UserRightsProxy.

Bug: T255309
Change-Id: I730d28c12ad389e001f18c12662d220cb74f998e
2021-09-05 16:51:25 +02:00
Daimona Eaytoy
9cca05a8e8 Add typehints to several methods
These not only make the code more robust, but also help a lot when
writing unit tests: if a method is return-typehinted and its class is
mocked, the mock method will automatically return a mock of its declared
return type. Otherwise it will return null, and developers are forced to
manually mock the method if the return value is used by the SUT in a way
that doesn't accept null.

Depends-On: I628fcb1807133390c7b9b47984f512f5b1ae58d0
Depends-On: I7080bc505f5838b2f51a368da562104e206063b0
Change-Id: I59068cfed10aabf6c6002f9e9312a6ef6e7e9441
2021-08-31 16:19:13 +00:00
Alexander Vorwerk
b1973d9a2d Add tests for the UserRightsProxy
Change-Id: I6e369fe37cecd783b1ed163ccb36cc5d4b5182a4
2021-08-25 13:02:16 +00:00
TChin
97716b4432 Rename where* methods in UserSelectQueryBuilder
Bug: T278254
Change-Id: I3f6d120b4426d8729b8db0336ce6db2b35163f71
2021-08-04 16:32:03 -04:00
jenkins-bot
93a1fd20bd Merge "Support ActorStore::newSelectQueryBuilder with query flags" 2021-07-27 21:41:02 +00: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
Petr Pchelko
7e0246a89c Support ActorStore::newSelectQueryBuilder with query flags
Change-Id: Ia731415f627d72811cf7a354721bb0fb28b128eb
2021-07-21 15:32:44 +00:00
Alexander Vorwerk
def29c6d06 ActorStore: avoid throwing in case of invalid usernames
When an username cannot be a valid actor,
ActorStore::newUserIdentityByName() should return null instead of
throwing an Exception.

Bug: T283167
Change-Id: Id04978cf2a417f2354d5e336ed1b0b67462603e9
2021-05-19 20:30:55 +00:00
jenkins-bot
efb73d0649 Merge "ActorStore: Always canonicalize provided user name" 2021-05-03 09:58:09 +00: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
Petr Pchelko
f870ea5232 ActorStore: Always canonicalize provided user name
We don't actually know where is the given user name coming from
and whether it's been normalized before hitting the storage layer,
so always check if it's a valid user name.

Bug: T273933
Change-Id: Ie9848188c81c95bedff9d18e6398bd3511c459e4
2021-04-29 06:34:03 -07:00
Petr Pchelko
8ef1a98260 Add ActorStore::deleteActor
This is an extremely dangerous method, but it's needed
for the temporary users magic in translate extension.
At least going via ActorStore we can keep our in-process
caches consistent and get rid of some static methods
and caching in user object.

Change-Id: I8157f7ccee7d72aee405e9b6109dfc1838e1f380
2021-04-29 05:13:55 -07:00
Petr Pchelko
f50c097b9a Keep ActorStore caches consistent on user rename
Multi-key in-memory keys for the actors is complicated
enough to have it's own small abstraction.

Change-Id: Id0e091504b71a44ce52d418c5737d64ac70495e9
2021-04-26 14:02:00 -07: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
Petr Pchelko
50f5d65c81 Fix up ActorStoreTest with new UserIdentityValue
Change-Id: I60e2dfef9f7c20c98b02f9fed341d4290ee6ca0b
2021-04-14 09:54:54 -07:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00: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
jenkins-bot
28fbfbc910 Merge "Rename WatchlistNotificationManager to WatchlistManager" 2021-04-08 15:48:15 +00:00
Cindy Cicalese
f1dadbb4ca Rename WatchlistNotificationManager to WatchlistManager
Change-Id: Ic9707c6b74180ef111d128f9f00de218d191c175
2021-04-07 18:16:24 -04:00
Petr Pchelko
9e0c6afaae Support User:0 in ActorStore
Surprizingly, PHP treats string "0" as false, so user name "0"
was unconditionally rejected by ActorStore. Even more surprizingly,
we actually have an actor with user name "0" [1], so we need to
explicitly check for nulls instead of just checking for falsy.

[1] https://en.wikipedia.org/wiki/User:0

Change-Id: I535c2aee3e109c3f535e40b747a1c7e4508171cb
2021-04-06 19:49:53 -06:00
Petr Pchelko
0f170d0bb8 ActorStore: clean cache if transaction aborted.
In case acquireActorId was called as a part of a larger
transaction and it gets rolled back, we need to clean in-process
caches in case something else would try to acquire actor ID
for the same actor again within the same request.

Bug: T277795
Change-Id: I912ebb380a1beead3043ac4c5653df947d613b99
2021-03-22 14:59:27 -06: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
jenkins-bot
d7af1cdbe3 Merge "Convert Language to UserIdentity" 2021-03-11 19:53:34 +00: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
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
Petr Pchelko
1abe2e5318 Remove ActorStore::getUserIdentityByAnyId.
Adding this method was a mistake, there's no good use
for is really.

Change-Id: I0b2ecee7420573092f85f4e19da731a6bd56c50b
2021-03-01 17:41:42 -07:00
daniel
0ebf43b26d ActorStore: introduce findActorIdByName
The findActorIdByName method is intended to be used when we need to
select by actor ID, but all we have is a user name. We can't use
findActorId(), since it requires a UserIdentity, which would needlessly
force us to look up a user ID, resulting in two queries.

Bug: T274179
Change-Id: I0e65d3258fd3d23ebff793ae04d59e027eb51fba
2021-03-01 22:12:05 +01:00
jenkins-bot
5008ca185e Merge "UserQueryBuilder: abstraction for actor table queries." 2021-02-23 12:27:26 +00:00
jenkins-bot
9cd7d35500 Merge "Add a few tests for ActorStore corner cases" 2021-02-22 20:35:24 +00:00
Petr Pchelko
87a5cb4673 UserQueryBuilder: abstraction for actor table queries.
This introduces a specialized SelectQueryBuilder for
queries related to actor table. So far it's fairly basic,
but in future it is intended to grow.

This patch only introduces the new abstraction, using
it will be separated into separate patches.

Bug: T274223
Change-Id: Ibb1c58016e3956a46bfaf1a9f51f265114bb9ace
2021-02-22 11:47:07 -07:00
Cindy Cicalese
fd71596f97 Add caching to ActorStore
Bug: T273974
Depends-On: I8c18d86fe42056fbb676467a6657fd2f62e9c998
Change-Id: Iff5e3f07ac5b1192dd7a9f7f37589d8eae09a746
2021-02-22 09:25:13 -07:00
Petr Pchelko
49220ff4ab Add a few tests for ActorStore corner cases
Change-Id: Iba6c5d8fa15952cfef689f8f151f262aaff46417
2021-02-16 22:52:47 -06:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00