Commit graph

383 commits

Author SHA1 Message Date
jenkins-bot 30921ae5fe Merge "DiscussionParser: Don't construct Users with invalid names" 2024-11-21 12:24:57 +00:00
jenkins-bot c532845d48 Merge "DiscussionParserTest: Add some test case names" 2024-11-21 10:47:12 +00:00
Bartosz Dziewoński 124162fee4 DiscussionParser: Don't construct Users with invalid names
The comment said "don't validate the username - anon (IP) is fine!"
– but it also allowed invalid names, not just IPs, and those are not
really fine.

Also add more test cases and remove some unused test code.

Bug: T380242
Change-Id: Id98f14a0663f33eb5e45045bcd2df6a1e1f52de6
2024-11-20 21:04:34 +01:00
Bartosz Dziewoński 09daeb5ba2 DiscussionParserTest: Add some test case names
PHPUnit will display them if the tests fail.

Change-Id: Iff695d801819e13c238929912433e6a97e14ec54
2024-11-19 23:58:21 +01:00
Matěj Suchánek 11b9e66f9f Disallow anonymous non-IP agents, handle truncated names
Why:
* Echo stores agents by their user id or by the name if the user
  is not registered. This works for IPs since the "event_agent_ip"
  field has limit of 39 bytes (32× [0-9A-F] + 7× colon for IPv6).
* However, it's possible to hold a user identity that is not
  an IP address, but the user name has not been or cannot be
  registered (e.g., external users). Echo wouldn't validate this
  and would attempt to insert the user name into "event_agent_ip",
  possibly causing silent truncation and data corruption.

What:
* Do not let events with such agents be saved. For now, log an
  error in the production. Wikibase, the only known source of this
  problem, has already been fixed.
* In runtime, replace every possibly corrupted user name with
  a placeholder to avoid unexpected null values and exceptions
  in production.

Bug: T367638
Change-Id: Ic2bd218b10651d13da9e9aea54dd2d668a33d946
Depends-On: I03b4367355dc5a3fc0c14aad5fdf19fbcd0caa3d
Depends-On: I92eb93983e81708b289e9f7d837884d539dade0b
2024-11-14 11:44:19 +01:00
Aaron Schulz 88ab531e17 Explicitly call DeferredUpdates::tryOpportunisticExecute() in ThankYouEditTest
Change-Id: I423f9a856fddab30e691d78cbcd0b70a292e3916
2024-11-07 12:16:46 -08:00
jenkins-bot e6a51beca1 Merge "Avoid event insertion if possible" 2024-10-30 15:06:30 +00:00
Andre Klapper 4da4dad97b Use explicit nullable type on parameter arguments (for PHP 8.4)
Implicitly marking parameter $... as nullable is deprecated in PHP
8.4. The explicit nullable type must be used instead.

Bug: T376276
Change-Id: I251cb37401c37242f493816b6f70ab61a64a4c32
2024-10-26 15:05:13 +02:00
Umherirrender 7e5eceb5a6 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Iab065a2005acccfe05cc827fdafc7861687d053d
2024-10-20 00:55:03 +02:00
Matěj Suchánek 4ae63d1b4d Avoid event insertion if possible
Why:
* On wikis with lots of bot activity like Wikidata, there is a large
  volume of edits which can potentially create an article-linked
  notification. These notifications are now actually rarely sent
  because they are disabled for bots (T318523). However, the event
  record is always inserted into the database, with no reference to
  it, bloating the database.

What:
* Do not unconditionally insert an event into the database when
  Event::create is called. Pass it to downstream calls and have
  it inserted when it's clear it will actually be needed (i.e.,
  a notification is definitely going to be created).
* Pass the event's payload to the job queue instead of requiring
  its ID. Introduce Event::newFromArray, which unlike ::loadFromRow
  handles ::toDbArray values that haven't been inserted into
  the database yet.
* Introduce Event::acquireId which ensures the event has been
  inserted prior to returning its ID as well as it does not get
  re-inserted.

Bug: T221258
Change-Id: I8b9a99a197d6af2845d85d9e35c6703640f70b91
2024-10-11 20:12:11 +02:00
James D. Forrester 291ea47dd3 tests: Namespace the PHP classes
This might make dependencies easier to find.

Change-Id: I158fd9f63f18a2b8da0368ac95d5fb5aa9bca3ff
2024-10-03 20:30:06 +00:00
Fomafix e03f7c3e82 Use overrideConfigValue/overrideConfigValues instead of setMwGlobals
Also use MainConfigNames.

Change-Id: I80d6b3ef9d7b857e35d8f93f424db1cfca1301f6
2024-07-26 12:47:09 +00:00
Wandji69 633682d56d Test:Replace db with getDb method
Bug: T316841
Change-Id: Ia135648c0666632165bfbe29b6587e6676082d54
2024-07-05 17:08:51 +01:00
thiemowmde e87cf704f4 Don't hold reference to MediaWikiServices instance in tests
There is no guarantee the MediaWikiServices instance is still valid.
Other tests can reset it.

Bug: T368390
Change-Id: I92de60b2ba5fb66af957a800ce85773db58303cc
2024-06-26 11:27:22 +02:00
Umherirrender a51c944567 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I3d7a1ffe167b69d3f4ce51d0c248c758e1cdd70c
2024-06-12 20:31:47 +02:00
jenkins-bot 7954f54451 Merge "More specific type hints and type declarations" 2024-06-07 03:06:57 +00:00
jenkins-bot b721cc23df Merge "configure main hook handler to pass StatsFactory service" 2024-05-27 11:48:12 +00:00
thiemowmde 7e3d73c11b More specific type hints and type declarations
Most notably:
* Use the much more narrow UserIdentity interface where possible.
* Make array type hints in PHPDocs as specific as possible.

Change-Id: Id189da4028b7874909277881dcf6539169dd13b6
2024-05-16 10:32:19 +02:00
thiemowmde 95fddc9228 Make all @covers tags in tests absolute
This is much less confusing for certain IDEs. Without the leading
backslash it looks like a relative patch, but isn't actually one.

Change-Id: I9c9f41869ea0ed063a67f8e65807833d1b3dba2b
2024-05-11 15:18:46 +00:00
Siddharth VP e27f4937ff Add API module for sending notifications
Allows users to send notifications to themselves (T306211). For sending
notifications to others, a new permission is created (echo-create),
assigned only to bots by default. For now, only one user can be notified
in one API request.

If the email flag is set in the API params, the notification is also
sent as an email, provided the user hasn't disabled email notifications
for the "api-triggered" category.

This feature is behind a feature flag. Set $wgEchoEnableApiEvents = true
to use.

Adapted from If0267a38be7d454e3d284d30f93c93a828288dd7.
Co-authored-by: TheresNoTime <starling-ctr@wikimedia.org>

Bug: T58362
Bug: T306211
Change-Id: I94642bff5dcb075cb9db862206d59c19edad9fd1
2024-05-04 17:43:39 +03:00
Cole White e4fd529dd6 configure main hook handler to pass StatsFactory service
Bug: T363590
Change-Id: Iadf0deeb8577a44554e66989ed432e119e6cbbe3
2024-05-04 08:10:41 +00:00
Umherirrender 96ef4cfd2d Migrate to IReadableDatabase::newSelectQueryBuilder
Also use expression builder to avoid raw sql

Bug: T312333
Change-Id: I6ce22de6637fccca8cf86a405bc023f268ff693b
2024-04-28 01:05:10 +02:00
Umherirrender 760cfad682 tests: Return FakeResultWrapper from mocked IReadableDatabase::select
To match the return type documentation of IReadableDatabase::select

Also fix a default value for IReadableDatabase::selectRowCount

Change-Id: I510bd261b64b5c2cef227c081a2fe34801f54121
2024-04-19 21:52:50 +02:00
Umherirrender 2feece8bad IReadableDatabase::select cannot return false
Remove check for false from IDatabase::select as this is not possible
A DBQueryError is thrown (documented since efda8cd3 / I056b7148)

Change-Id: I465a9158aa6430e7ff8a5a83fe55c5944315aa40
2024-04-18 22:53:15 +02:00
jenkins-bot 71ec391deb Merge "Migrate to IDatabase::newInsertQueryBuilder/newUpdateQueryBuilder" 2024-04-14 18:00:20 +00:00
Umherirrender aa41e1e292 Migrate to IDatabase::newInsertQueryBuilder/newUpdateQueryBuilder
UpdateQueryBuilder does not return a value,
removed the return value from the functions as well,
deprecated since 1.33

Change-Id: I3b934a5e6d5a53c07ec5233da00d9f53ba7bae92
2024-04-13 22:51:32 +02:00
Umherirrender d2eb46e7b9 Migrate to IDatabase::newDeleteQueryBuilder
Change-Id: I516c179df464be68352809873dbff44dc3c642f1
2024-04-12 22:45:45 +02:00
Fomafix 5595193eb3 Inject services into TitleLocalCache
Change-Id: Ib1259484436591dd30b29651ccca474c0ce16d13
2024-03-17 21:22:00 +00:00
Reedy 2b58f29d8c Fix casing of MediaWiki
Change-Id: If581a54ac1025bb13ff8fce5e8f64b92c71de986
2024-03-12 15:25:19 +00:00
Umherirrender d60c797629 build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0
Change-Id: Ie03e1cdbf7f3a18c4e02e08fbd81c148f7da4d5a
2024-03-10 19:22:36 +01:00
Sergio Gimeno 152db8a06f Replace deprecated usage of wfGetDB
Bug: T330641
Change-Id: I863dc67e3196ea20c4f6145c5d3bb68b445b5195
2024-02-13 20:22:33 +01:00
Novem Linguae c71d826ede Remove $this->tablesUsed from PHPUnit tests
Deprecated in T342301 in v1.41. This is now tracked
automatically. The variable can be safely deleted.

Change-Id: I3864ee85e8b0ff74385eee88018a37f61927f5ef
2024-01-14 04:48:27 -08:00
Umherirrender 9c94786dea tests: Use TestingAccessWrapper::newFromClass in DiscussionParserTest
Currently using ReflectionProperty::setValue(), which is deprecated for
static values in php8.3

Change-Id: If53b7ae9d58e8e5d6eb95f6fff07038b9c1bdd42
2023-12-13 20:43:18 +01:00
Umherirrender a0ca1d89c6 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements done manually

Change-Id: Iad87245bf8082193be72f7e482f29e9f1bad11fc
2023-12-11 16:39:00 +01:00
gerritbot 2560aa4b7f Update UserOptionsLookup's FQN
User-options related classes are being moved to the MediaWiki\User\Options namespace in MediaWiki Core; reflect that change here.

Bug: T352284
Depends-On: I9822eb1553870b876d0b8a927e4e86c27d83bd52
Change-Id: Ic3e56c6e2ec606bbecbd630d8ad96d111cab24d3
2023-11-29 15:34:02 +00:00
Daimona Eaytoy 164b3b9148 Update tests for PHPUnit 9.6
- Avoid withConsecutive()

Bug: T342110
Change-Id: I1c68e9b259039d58b468f25ed2e6fd0f73d70776
2023-11-21 23:55:06 +01:00
Fomafix 829003cabf Use $this->getServiceContainer() in maintenance and tests
Use
	$this->getServiceContainer()
instead of
	MediaWikiServices::getInstance()
in maintenance and tests.

Change-Id: I845e8f083b19da093166d6551683f2013eec7bb1
2023-11-09 20:18:48 +00:00
Siddharth VP 035f39d76c Use dependency injection in hooks
Removal of globals for reading config to be done in a follow-up patch

Change-Id: I8652ca67375ce2f2d79de93e0a3b75ac998131e0
2023-10-14 23:44:57 +05:30
jenkins-bot 68d90d69a7 Merge "Make DB tests more robust" 2023-09-01 13:33:23 +00:00
Umherirrender 0b95ded538 tests: Small changes to DiscussionParserTest
- Remove set of $wgDiff, not used in core and seems not needed
- Avoid array_keys on foreach
- Save settings directly by UserOptionsManager for the fresh user
- Combine calls to overrideConfigValue into one
- Referer core config via MainConfigNames
- Remove unneeded reset after overrideConfigValues, get reset there
- Reset specific service and not all

Change-Id: Ia00efae85e17dfac1768b12b35f44eb834f879ec
2023-08-24 23:31:36 +02:00
Daimona Eaytoy 7b1a9582b2 Make DB tests more robust
In EventMapperTest, suppress notifications created by calling
getExistingTestPage. So far, this test only worked because the existing
test page is created in addCoreDBData (and not inside the test), but
this will no longer be the case after core change
I308617427309815062d54c14f3438cab31b08a73. Clear the PageSaveComplete
hook handlers to prevent that.

DiscussionParser has a static cache of revision data that can become
stale when data is deleted between tests (because revision IDs can be
reassigned to different pages, similar to T344124). This cache seems
needed, and converting the class to a service seems hard, so add the
page title to the cache key to try and avoid collisions. This can still
break if two tests are using the same page, which is hopefully quite
unlikely.

Change-Id: Ic4cbd8ff424e1260544ff9754e0c89dd4bb2f733
2023-08-19 19:59:51 +00:00
James D. Forrester da2fbe366f Switch uses of IDatabase to namespaced version
Bug: T344536
Change-Id: I6f4b158bdc3ef20a1660e66accca0ffc17104f49
2023-08-19 15:01:58 +00:00
Reedy 8f44150300 And a few more namespaced classes...
Change-Id: I57b56d285bac4b41e81f656f3c1ddceee4620fb5
2023-08-18 22:27:18 +01:00
Reedy b003945c34 Namespace a few more classes
Change-Id: Ie233a4c8291432da3bd25d29337db52a2e97b540
2023-08-18 21:48:15 +01:00
Reedy e576cbdca0 Namespace some more classes
Change-Id: If1405788a4adb550e8a7e8c58b0c2c55cf10ea67
2023-08-18 21:24:59 +01:00
Reedy 1bc5b6daf8 Namespace classes that need aliases
Change-Id: Ieeeaf80d04b060d6dbca1959d5e66f4c69c5a7f2
2023-08-18 19:00:41 +01:00
jenkins-bot 078788f411 Merge "Create HookRunner class and the hook handler interfaces" 2023-08-16 05:26:06 +00:00
Daimona Eaytoy ef50bfeda5 Make Title and Revision caches proper services
Singletons are bad, amongst other reasons, because they're never reset
in tests. They can therefore occasionally cause test failures if the
cached data stored in one of these singletons becomes stale.

As noted on the task, ideally these two classes shouldn't exist at all,
and core should be responsible for caching the information it deems
expensive to compute.

As a temporary (TM) workaround, make both classes actual services, so
that the setUp/tearDown logic in MediaWikiIntegrationTestCase can
properly reset them between tests.

Dependencies are intentionally not being injected, precisely because
these classes should just be deleted, not improved.

Bug: T344124
Change-Id: I58b8d9610f9447468235b94d25732528ab6acce6
2023-08-14 17:41:23 +02:00
Umherirrender 9de512d59c tests: Resolve phpunit filename deprecation errors
PHPUnit wants the filenames of the tests to match the class name being
tested.

Bug: T337333
Change-Id: I44f626d1bfdf151fecafc29c51b2cf2bb90481b0
2023-08-12 21:07:15 +02:00
Daimona Eaytoy 9f44f98e81 Do not assume what user IDs might be in DiscussionParserTest
The test was assuming that the ID 1 belongs to a user other than the one
being created in the test. This is not necessarily the case, so make it
use an ID that is guaranteed to be different.

Also rename the test fail to avoid a PHPUnit deprecation of test class
name not matching file name.

Bug: T342428
Change-Id: Ied1869e380b023c1a726a5be610e1de1b68c78c0
2023-08-07 16:27:28 +02:00