Commit graph

29 commits

Author SHA1 Message Date
Tim Starling
d3d8dc9965 Schema migration for revison_actor_temp table removal
Introduce a new schema migration stage in which rev_actor is used
directly and the revision_actor_temp table is no longer needed. This
becomes the new "new" stage whereas the previous situation is now
termed SCHEMA_COMPAT_TEMP.

Introduce migrateRevisionActorTemp which copies data from
revision_actor_temp to rev_actor. The code is similar to
migrateImageCommentTemp.php except that it doesn't delete from the old
table.

Partial revert of c29909e59f. That change removed direct
references to $wgActorTableSchemaMigrationStage and made queries
involving revision_actor_temp be unconditional. Such changes need to be
reverted to make the use of revision_actor_temp be conditional again.

In ActorMigrationTest, I compacted provideGetJoin() and
provideGetWhere(), removing most of the duplication between expected
values. I gave all the stages a short name, and mostly used the name in
providers.

Bug: T275246
Change-Id: I7498107dd6433ab7de5bf2e7b3fe2aa5e10e345d
2021-07-14 08:29:04 +10:00
Tim Starling
1d0f30208b Deprecate legacy actor migration keys
For every table except revision, the use of ActorMigration was "soft
deprecated" in 1.34. Now, hard deprecate it.

Bug: T278917
Change-Id: I63d26d13026214d84b6b94f06b4ad0d2362d97ed
2021-05-03 15:14:06 +10:00
Tim Starling
3faf97c78d Split a base class out of ActorMigration
AbuseFilter needs a class which is almost identical to core's
ActorMigration, so I split out the generic facilities into
ActorMigrationBase, leaving the bits specific to core in ActorMigration.

I changed the way fields and tables are specified so that it's easier to
override in subclasses.

Proper injection of ActorStoreFactory in
ActorMigrationTest::testGetWhere() was necessary to avoid a test failure
due to a teardown issue.

Bug: T278917
Change-Id: I3a6486532f2ef360d1fd01b3a609de71d412f739
2021-05-03 15:14:06 +10: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
600f75010c Merge "ActorNormalization should require a DB connection." 2021-03-10 22:05:17 +00: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
DannyS712
7ccf89c56a ActorMigration: remove unused UserFactory
Follow-up: Icfa1daca960c696a8cef8adab5eab53985802858
Change-Id: I8e38716ca6c92050c10c838666f1c299102c2636
2021-03-10 14:30:12 +00:00
Thiemo Kreuz
1f34e5c679 Rewrite ActorMigration test to not manipulate the original
This is the same idea as in Ida13ce8.

Change-Id: I9945b5ee64ae6bb4b8e25476776f1e1f448b3e42
2021-02-16 09:44:15 +01: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
Petr Pchelko
8d2c674ab0 Introduce ActorStore, ActorLookup and ActorFactory.
The ActorNormalization factory methods create
UserIdentityValue from the database rows, either via
fields of a joined table, or via a row from actor table.
They assume that the actor_id exist and throw othervise.

ActorNormalization is a storage-layer service providing
access to finding and acquiring actor_id.

The UserIdentityLookup methods do not instantiate new actor
on demand, they just find an appropriate row in the actor
table and return the result.

Bug: T272689
Depends-On: I74d81f3f0233efb17fc8df5178e4c477cc669c6f
Change-Id: Icfa1daca960c696a8cef8adab5eab53985802858
2021-02-08 10:06:46 -06:00
Cindy Cicalese
f992c7d8a3 Add type hints for return types to methods on UserIdentity
Bug: T273285
Change-Id: I0ffc4963e8362264d1f10455af0f6222c05be7d8
2021-02-02 20:58:51 +00:00
Gergő Tisza
16c192f2af
Normalize IP addresses before writing/reading actor.actor_name
This was almost always happening already but handling it in
ActorMigration is less fragile.

Also recover some lost tests.

Bug: T272225
Change-Id: I24c82cfbd40595e79f64c6b0441c2cf789cfbbff
2021-01-26 22:56:30 -08:00
DannyS712
dcf682a521 Inject UserFactory into ActorMigration
Bug: T265311
Change-Id: Ie51ea0be0b09dc782365c4b201152b52fd5b3573
2020-10-13 19:34:19 +00:00
DannyS712
6b4edf2ad3 Inject UserNameUtils into ActorMigration service
Change-Id: Id14d96b9dfcb49909d1b24a787434212dd9f9733
2020-10-12 17:46:39 +00:00
daniel
4fe4407731 SECURITY: ensure actor ID from correct wiki is used.
This builds on top of Urbanecm's patch, now also covering the case
where the actor ID does not exist in the target DB, but does exist in
the local DB.

Bug: T260485
Change-Id: I2336954c665366a99f9995df9b08071d4de6db79
(cherry picked from commit ca4094db9e7f6f5e330d89db6bf70a8af48e1561)
2020-09-24 19:37:43 +01:00
Martin Urbanec
037e63c2f7 SECURITY: ActorMigration: Load user from the correct database
In ActorMigration::getInsertValues, when creating a User object, calling
User::getActorId triggers a call to User::load, which ignores
the database passed to getInsertValues, meaning incorrect actor IDs
are returned.

To ensure that the correct (foreign) database is used, try
to get the actor ID from the correct database within ActorMigration
service, and if that fails, let User class handle the actor ID creation.

Todo notes are left in the patch to fix the issue properly,
by making User object wiki-aware.

Bug: T260485
Change-Id: Iaa886a1824e5a74f4501ca7e28917c780222aac0
2020-09-24 18:20:02 +00:00
Nikki Nikkhoui
7b9695726c ActorMigration doc comment
Small addition to ActorMigration.php doc comment
to make it clear that classes should use this
instead of directly accessing db tables

Change-Id: Ibad838d35ea87f85966cda2b210f18196d50f844
2020-07-24 10:21:29 -07:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Reedy
a8467a0fd7 Fix numerous PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I157220c4e9ff516283a60f06af99efa2439332e3
2020-05-12 18:41:43 +00:00
Aaron Schulz
571f4c1a21 Avoid upsert() log warning spam in ActorMigration due to unique key array format
Bug: T248147
Change-Id: Id457ce70427bba5cbf11d7706b9de371356bbf21
2020-03-20 05:31:03 -07:00
Brad Jorsch
531399f5c7 ActorMigration: Improve getWhere() handling of $users
Some callers, when provided an invalid user name, will wind up passing
null or false. This raises a PHP warning and winds up treating it as the
empty array. In this case, it seems best to DWIM and continue that
behavior without the warning.

At the same time, let's more explicitly reject other values for $users.

Bug: T239772
Bug: T207217
Change-Id: I6027481f6cad222369911d5053fecc06c92b36ea
2019-12-04 16:00:02 -05:00
Umherirrender
337ecb0514 Add missing @param and @return to documentation
Change-Id: Ibc5849cc8ea7e7c4eb30ded9c1cfa5f52187c377
2019-11-10 22:12:58 +00:00
Daimona Eaytoy
cae0110e5a Fix new phan errors, part 1
First part, mostly doc-only.

Bug: T231636
Change-Id: Id59f585740fa5bfb53c257287121f51a30de38fe
2019-10-11 15:04:04 +00:00
Brad Jorsch
c29909e59f Mostly drop old pre-actor user schemas
This removes most of the pre-actor user and user_text columns, and the
$wgActorTableSchemaMigrationStage setting that used to determine
whether the columns were used.

rev_user and rev_user_text remain in the code, as on Wikimedia wikis the
revision table is too large to alter at this time. A future change will
combine that with the removal of rev_comment, rev_content_model, and
rev_content_format (and the addition of rev_comment_id and rev_actor).

ActorMigration's constructor continues to take a $stage parameter, and
continues to have the logic for handling it, for the benefit of
extensions that might need their own migration process. Code using
ActorMigration for accessing the core fields should be updated to use
the new actor fields directly. That will be done for in a followup.

Bug: T188327
Change-Id: Id35544b879af1cd708f3efd303fce8d9a1b9eb02
2019-09-09 11:38:36 -04:00
Gergő Tisza
d18c861aa9
Improve documentation of getJoin() methods for static analysis
Change-Id: I3943b4b4a630777d06d1689714d8f36c4430cd24
2019-07-03 15:45:01 +02:00
Thiemo Kreuz
2540c29b20 Use the ?? feature instead of isset() where it makes sense
Change-Id: I3a54f36b33d99ef3ff4c63e32e7dfcbcfc296135
2019-03-24 22:40:49 +01:00
Brad Jorsch
993baa3493 ActorMigration: Remove possibility of read-both
When this was originally written, the plan was to read both the old and
new fields during the transition period, while stopping writes to them
midway through. It turns out that the WHERE conditions to do read-both
correctly are generally not handled well by the database and working
around that would require a lot of complicated code (see what's being
removed from ApiQueryUserContribs here, for example).

We can simplify things greatly by instead having it write both fields
during the transition period, reading from the old for the first part
and the new for the second part, as is being done for MCR.

Bug: T204669
Change-Id: I4764c1c7883dc1003cb12729455c8107319f70b1
Depends-On: I845f6ae462f2539ebd35cbb5f2ca8b5714e2c1fb
Depends-On: I88b31b977543fdbdf69f8c1158e77e448df94e11
2018-10-11 12:12:00 +11:00
petarpetkovic
3f60fb5ad1 Remove duplicated article usages
Bug: T201491
Change-Id: I72b1e7609b49b9bf182c0872f8b780d9e9e08695
2018-08-09 10:29:38 +02:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00