Commit graph

1630 commits

Author SHA1 Message Date
Tim Starling 105f2a3845 Fix installer error when the task is run a second time
Fix task idempotency. Check if a table exists before running the schema
patch.

Bug: T352113
Change-Id: If6f0930ea327df35fe118d4a08993c6383f9d579
2024-11-28 14:54:42 +11:00
jenkins-bot 4897e2f2a6 Merge "Move addWiki.php special case to an installer task" 2024-11-22 10:38:32 +00:00
jenkins-bot 30921ae5fe Merge "DiscussionParser: Don't construct Users with invalid names" 2024-11-21 12:24:57 +00:00
Bartosz Dziewoński 39be79c1b0 SeenTime: Actually use an in-process cache
It doesn't work if every call to cache() returns
a different CachedBagOStuff :')

I found this thanks to log warnings I saw locally:

  SQLBagOStuff.WARNING: Duplicate get():
  "mediawiki:echo:seen:alert:time:1" fetched 2 times
  SQLBagOStuff.WARNING: Duplicate get():
  "mediawiki:echo:seen:message:time:1" fetched 2 times

Change-Id: I9a920de88275c1297942b064cc635d5c25424fd2
2024-11-21 03:00:19 +01: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
Tim Starling 3a45c2600b Move addWiki.php special case to an installer task
Bug: T352113
Depends-On: Ie7c466012d8d5644b1398452e3077416ab0270c5
Change-Id: I752edd8daaebb91a4bd9a7797747ade96d537526
2024-11-20 11:00:45 +11: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
Ammarpad b80f4294b5 Handle hidden revisions in user page edit notification
Bug: T378799
Change-Id: Ie68e024625c640f46e6af21a2829b33fbd57ec8a
2024-11-01 09:31:17 +01:00
jenkins-bot e6a51beca1 Merge "Avoid event insertion if possible" 2024-10-30 15:06:30 +00:00
jenkins-bot b58122fa3e Merge "special: Check login permissions before calling execute method" 2024-10-28 02:55:18 +00:00
Ammarpad 4303ab5f71 special: Check login permissions before calling execute method
Calling the parent method first means the form has to be built (as
well as various other things) and then it cannot be shown because
of permission and the user is redirected.

This also lead to confusing behavior where some code paths are
reached even though the user cannot actually access the page.

Change-Id: If354d98f9e51acef38cac114a7704d28c148017b
2024-10-27 10:03:09 +01:00
jenkins-bot 570d326543 Merge "fix ::getTruncatedSectionTitle() return type" 2024-10-26 22:19:15 +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 2edd88a166 Use type-declaration on api module constructor
Parent class constructor gets type-declaration in 1145328459
Remove simple doc-blocks without further information

Change-Id: I0ab283cd0510d8e85e93752a5ee7d65320a4ec2b
2024-10-25 19:14:31 +02:00
jenkins-bot 052dc0a3ef Merge "Fix for Watchlist Notifications for deleted pages created in 1.35" 2024-10-25 00:13:25 +00:00
Ammarpad 0a677f4675 fix ::getTruncatedSectionTitle() return type
This method can return false if getParsedSectionTitle() returns false

Both Language::embedBidi and Language::truncateForVisual return
non-string primitives unchanged if they're passed to them as first
argument.

Ideally the Language methods arguments should be string-typed but
I am not sure how easy that change would be now, so better to
document the possibility here.

Change-Id: I7e2856862d6508ecd1aa57ad99b92942bc4d7bed
2024-10-24 22:46:00 +00:00
Reedy a76cc44a60 SpecialNotificationsMarkRead: Don't pass null to explode()
Bug: T377920
Change-Id: I426c76dbf2e8da4563e93fefe6bd628faa0e13b7
2024-10-23 15:16:04 +00: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
Umherirrender f95c0cc11d Pass function name to HttpRequestFactory::create
Change-Id: Ie48127731f0731f780e153f6aacce25961acc3ed
2024-09-19 22:48:37 +02:00
Gergő Tisza 89a3a1fc57 DiscussionParser: Do not create User objects from subpages
Bug: T375212
Change-Id: Id409a4f9adcda840400e529db72eb696ec55b3f4
2024-09-19 16:06:00 +00:00
jenkins-bot cae6fc46dd Merge "Replace deprecated LinksUpdate::getAddedLinks" 2024-08-23 20:06:58 +00:00
Dr4goniez 14b06b78e5 Consistent Casing for "iconUrl"
Replaced all occurrences of "iconURL" in the extension's repo with
"iconUrl" after spotting a typo in `mw.echo.dm.NotificationItem.js#13`,
"iconUrl" (find the correct "iconURL" in `mw.echo.Controller.js#394` in
the diff). Thankfully the typo was only in the documentation block, but
given the casing of other config object properties like "primaryUrl"
and "secondaryUrl", it would be best to make them all consistent to
prevent any bug that could happen in the future.

Change-Id: I56e6a1d2c7695204b35e767679a27ee22b3fe4bc
2024-08-17 07:09:41 +09:00
jenkins-bot f38a43f58d Merge "Remove obsolete PHPDoc copies from fully typed constructors" 2024-08-16 19:09:22 +00:00
Bartosz Dziewoński 22b05a1e3f Replace gettype() with get_debug_type() in exception messages etc.
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() where the new method already provides
the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

Change-Id: I54c2bf287b185e2526b0a8556166fd62182b2235
2024-08-16 16:53:47 +00:00
thiemowmde 2a4f186400 Remove obsolete PHPDoc copies from fully typed constructors
It's all in the code now. These comments don't add anything any
more.

Change-Id: I66a3723c4fe9ccce989f5b533390d5ce928dc195
2024-08-11 18:05:01 +02:00
Umherirrender 9380504852 Replace deprecated LinksUpdate::getAddedLinks
The current code uses deprecated TitleLinksTable::getTitleArray and that
is also using Title::newFromPageReference to get Title objects,
so performance issues or more memory usage are not expected.

Change-Id: I25d047ceb707837009e0a703693ebc2f49fc0ba9
2024-07-30 01:50:17 +02:00
jenkins-bot 2966c87804 Merge "Use namespaced MessageSpecifier" 2024-07-28 21:29:59 +00:00
Bartosz Dziewoński 88a5a4cbc6 Use namespaced MessageSpecifier
Depends-On: I9ff4ff7beb098b60c92f564591937c7d789c6684
Change-Id: I44aa53990bc11d24afa02399dc6dfec7d0c10b9a
2024-07-28 21:59:25 +02:00
Umherirrender 552f362cd5 Use expression builder instead of raw sql
Change-Id: I6516951fc855dc32e864a3f21187b0a73daba7c8
2024-07-21 22:52:17 +02:00
thiemowmde 7845b5fab1 Fix mistake in gender support for user group changes
This was a mistake in I53c0283, sorry. There are two users involved:
The "agent" is the user (typically an administrator) that made the
user group change, while the "viewing user" is the user for which the
user group was changed. When the "agent" moves the "viewing user"
into a new user group, the "viewing user" is the one that's now
a member of that group. They are what dictates the gender for the
"group-…-member" message.

Is this mistake bad enough for a backport?

Bug: T368249
Change-Id: I4916de2fb171873b625e51ee8823811e0296d323
2024-07-05 20:18:56 +02:00
thiemowmde eaa1fea890 Fix incomplete gender support for user group changes
This affects primarily the message
"notification-header-user-rights-add-only" which is very priminently
seen by every new editor that made their first few edits and gets
promoted to the next user group a few days later. Turns out the code
was just incomplete. All the information about the user and their
gender is already there, it was just not forwarded correctly.

Notice there are two messages:
* "group-…" messages don't have gender support. This is the (ideally)
  gender neutral name of the group. Meant to be used as e.g. section
  heading for a list of users.
* "group-…-member" is the same with gender support. To be used in all
  contexts that are about a single, specific user with known gender.
  Which is exactly what's happening here.

Turns out we can even use a neat convenience function from the
Language class that does exactly what we need.

I can't tell why but the array_values is apparently critical.
Originally added via I49b5fe5. It can't hurt so I keep it.

Bug: T368249
Change-Id: I53c028375d77c93f399538fd38aa8f8af30934b0
2024-06-28 11:49:10 +02:00
thiemowmde c246f71eb6 Remove unused param from notification-bundle-header-page-linked
The duplicated parameter $6 is unused since 2016, see Iabeaae7.
Nothing is left that uses the parameter. I also checked for local
on-wiki overrides via GlobalSearch.

Bug: T368249
Change-Id: I8a5975347756f2fd5f5e065112ddc38d829e89ed
2024-06-26 13:20:05 +00:00
Wandji69 231ce97335 Use ObjectCacheFactory instead of ObjectCache method
Bug: T363770
Change-Id: I685ee42b11fab3bb56810af65a1334573d16da8a
2024-06-26 10:19:13 +01:00
thiemowmde b983ce7581 Fix copy-paste mistake in message documentation
This is a copy-paste mistake from the message directly below.
Happened in Ibe0092a not long ago.

Also add some comments to make it easier to find the places where
seemingly unused messages end being used.

Bug: T368249
Change-Id: I709c0f14978daad8c98f1f8edf52ef28029c6d40
2024-06-24 09:07:19 +00: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 63736536f5 Merge "hooks: remove use of IBufferingStatsdDataFactory" 2024-05-27 11:49:47 +00:00
jenkins-bot a538b2025a Merge "hooks: add StatsFactory support" 2024-05-27 11:44:28 +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
Cole White b29a6ae0e5 hooks: remove use of IBufferingStatsdDataFactory
Bug: T363590
Change-Id: Ib35ec605bf1ce3c0c026513f1f4636f991d36ea3
2024-05-15 02:31:08 +00:00
Wandji69 37cac555b8 Use ObjectCacheFactory instead of deprecated ObjectCache method
Bug: T363770
Change-Id: Ib1aaa8fc3e6099bfaf33ec45645f6774addec711
2024-05-14 19:30:17 +00:00
Umherirrender 1c257ea377 Revert "Suppress phan errors caused by UserMerge undeploy"
This reverts commit e8cbb4d662.

Reason for revert: phan dependencies are restored

Depends-On: I0d07c9412bbb63c947255587a88020637e70b80a
Change-Id: Ib6c1709483e4d8518510c4477bf15699cafc1313
2024-05-14 08:40:50 +00:00
Amir Sarabadani e8cbb4d662 Suppress phan errors caused by UserMerge undeploy
Bug: T364610
Change-Id: If52dfcb083995b08bb34b59d2c9e78bf04ca0199
2024-05-10 15:57:25 +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 706422006d hooks: add StatsFactory support
Bug: T363590
Change-Id: I88579655b72fb982f50f4304997bbba197f89f47
2024-05-04 07:41:54 +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
jenkins-bot e8541912d5 Merge "Make use of native str_starts_with() where possible" 2024-04-20 22:11:37 +00:00
thiemowmde fa23779a17 Stop using the Xml class in this codebase
Many of the Xml::… methods are deprecated. This code here is not
generating XML anyway, but HTML.

Bug: T341775
Change-Id: I69edf4606bc5cb429d48c8188c691b44575e2d93
2024-04-19 20:41:40 +02:00
thiemowmde d498e09e49 Make use of native str_starts_with() where possible
Change-Id: If95d0c801e397ca00b0c0d792c28f972c642b377
2024-04-19 20:36:31 +02:00