Commit graph

182 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
Umherirrender
6eec17e9a9 Add missing documentation to class properties (miscellaneous classes)
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I1da4b272a6b28c419cc8e860d142dae19ca0bbcf
2024-09-14 10:12:18 +02:00
Ebrahim Byagowi
aa16b5e7e6 Avoid use of deprecated wfExpandUrl in various places
Bug: T319340
Change-Id: I98e8e3a8fd135a554a85f6399033756c88ea415f
2024-09-09 20:55:52 +00:00
Bartosz Dziewoński
c045fa0291 Replace gettype() with get_debug_type() in exception messages
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() and get_resource_type() 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

To keep this safe and simple to review, I'm only changing cases where
the type is immediately used in an exception message.

Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
2024-07-31 19:24:39 +02:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Novem Linguae
a377aaa495 UserMailer: delete method rfc822Phrase()
Git blame on the line `wfDeprecated( __METHOD__, '1.38' );` is
3 years old.

Unique method name that does not appear in codesearch.

https://codesearch.wmcloud.org/search/?q=rfc822Phrase&files=%5C.php%24&excludeFiles=&repos=MediaWiki+core

Bug: T362636
Change-Id: If18cc8c35fb0b274ecf2d8c91654540918ffe229
2024-06-27 18:31:50 +00:00
jenkins-bot
a8efaa1429 Merge "EmailNotification: Link to editor's talk page, not user page" 2024-06-19 22:31:44 +00:00
Bartosz Dziewoński
ccd423225f Add "implements Stringable" to every class with "function __toString()"
In PHP 8, but not in PHP 7.4, every class with a __toString() function
implicitly implements the Stringable interface. Therefore, the
behavior of checks like "instanceof Stringable" differs between these
PHP versions when such classes are involved. Make every such class
implement the interface so that the behavior will be consistent.

The PHP 7.4 fallback for the Stringable interface is provided by
symfony/polyfill-php80.

Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
2024-06-13 00:23:39 +00:00
Timo Tijhof
b432fd2f20 Move various job classes to relevant component directories
Motivation:

* Remove need to hardcode out-of-component files in various places.
  Especially for Gerrit queries, this not only reduces effort but
  also makes these files more likely to show up in the first place.
* Clarify component boundaries and ownership, e.g. when filing tasks
  with a stack trace.
* Now rather than later, to avoid need for multiple class renames and
  aliases when PSR-4 namespaces are applied later (T166010).

Background:

Similar to how jobs in extensions belong to that extension, the same
is true within core. There is a distinction between the JobQueue system,
and individual jobs belonging to a specific feature or component,
likewise for deferred updates, and special pages.

To make a begin with this, I propose moving the job classes to their
respective components for cases where component boundaries are already
clear. E.g. due to exclusively being queued by that same component,
being named/introduced by the same commit, being already documented
as such in component descriptions on mediawiki.org.

Bug: T364652
Change-Id: I73d6b97c6ca9f5abd29f4277d0f845426aa23bd0
2024-05-10 20:14:00 +01:00
Timo Tijhof
949c9c932e mail: Improve docs, fix file headers, widen @covers
* Add missing `ingroup` to class blocks (and remove from any file blocks)
  as otherwise the file is indexed twice (e.g. in Doxygen) which makes
  navigation on doc.wikimedia.org rather messy.

  Remove duplicate descriptions from file blocks in favour of class
  doc blocks. This reduces needless duplication and was often
  incorrect or outdated, and helps make file headers more consistently
  (visually) ignorable.

  Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged

* Widen `@covers` tags in phpunit tests

  Given all called methods are de-facto and liberally claimed, and
  that we keep the coverage limited to the subject class, it maintains
  the spirit and intent by listing the class explicitly instead.

  PHPUnit offers a more precise tool when you need it (i.e. when testing
  legacy monster/god classes), but for well-written code, the
  class-wide tag is exactly what you want.

  We lose useful coverage and waste valuable time on keeping tags
  accurate through refactors (or worse, forget to do so).
  Tracking tiny per-method details wastes time in realizing (and
  fixing) when people inevitably don't keep them in sync, and time
  lost in finding uncovered code to write tests to realize it was
  already covered but "not yet claimed".

  Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:

- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
  later moved to a separate file in bf8810d6bc (Ic435bbdbb6).

- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.

- UserMailer converted to class with ::send in r26357 (1.12.0),
  git 353f203ce2.

Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 19:48:43 +01:00
jenkins-bot
cb91a1081b Merge "Watchlist: Fix non-functioning URLs in ENOTIFs by wrapping in <>s" 2024-05-04 09:48:59 +00:00
sjoerddebruin
5afe62d3eb Watchlist: Fix non-functioning URLs in ENOTIFs by wrapping in <>s
Wrap the links in emails in angle brackets to avoid punctuation to become part of the url.

Bug: T350535
Change-Id: Ida52f50dcf22b206a107e8e8d7a985bd9c62c39a
2024-05-04 08:47:36 +00:00
James D. Forrester
8f6939f594 docs: Adjust all @deprecated tags to use 'since…' for consistency
This skips ones that have been marked but were never in the then
RELEASE-NOTES and later HISTORY file, and so weren't properly
deprecated ever.

Change-Id: I31df2d7e83182b5bf9524237fc4a1862356bfd5a
2024-05-01 07:41:18 +01:00
jenkins-bot
8597265639 Merge "Replace trivial UrlUtils use with parse_url()" 2024-02-13 14:25:57 +00:00
Timo Tijhof
16f1d0132c Replace trivial UrlUtils use with parse_url()
For precedent see also change I6492f51428, I1e76d2f5ae, I98ea4670e8,
and many other results for "parse_url" in Codesearch (WMF Deployed).

This follows recent commits that clarified dependency on UrlUtils:

* I3f1d7a2da2f67a38a7d7a7b4268a93e01a01bf1e: Setup.php.

  Same as before, no fallback check, because $wgServer must be valid.

* I5e36ee80e5c30e95b79bf45e7b26860cb2668d56: UserMailer.php.

  Fallback to empty string, same as before.

* Id82a9fba6b3cdae3caf169eef5192766b33f0550: ParsoidHandler.php.

Change-Id: I57a8e7ea1b379779f31f562920888acc6656569e
2024-02-13 13:06:51 +00:00
Amir Sarabadani
f40a4952ff mail: Still update the notification timestamp for bot edits
This is not super optimal but keeps the highlighted functionality.

Bug: T356984
Change-Id: I7f1b6f2adcbb22703f52d7ac0e4322379f81ebdc
2024-02-12 11:03:48 +01:00
jenkins-bot
0d01c1c1b3 Merge "mail: Stop sending notification email if edit is done by a bot" 2024-02-09 22:54:37 +00:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
Amir Sarabadani
9dc68fb042 mail: Stop sending notification email if edit is done by a bot
This reduces the mail spam making the email on page changes option much
more bearable.

Bug: T356984
Change-Id: Id6428ae6f128b20b482e4b03599492d49d7981c0
2024-02-08 11:32:33 +00:00
RazeSoldier
bdc4ac20d3 Hard-deprecate UserMailer::rfc822Phrase() because it has not been used by anything.
Bug: T207621
Change-Id: Iba9c5ffcb77ff2e7dc9a9b853404f5639eea7aa7
2024-01-13 19:38:12 +00:00
Gergő Tisza
489ae9052d
UserMailer: Log emails
Change-Id: I995fcd2e75074aef6bf9bc1dc560f9eeef30fae1
2024-01-11 23:31:47 -08:00
Dogu
54b1731f88 Replace deprecated wfParseUrl with UrlUtils::parse
The wfParseUrl function is deprecated as of MediaWiki 1.39 and has been
replaced with the UrlUtils::parse method provided by the UrlUtils class.

List of affected classes:
- deleteSelfExternals
- UserMailer

Change-Id: I5e36ee80e5c30e95b79bf45e7b26860cb2668d56
2024-01-07 10:24:37 +00:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
jenkins-bot
4cd17c3f1e Merge "mail: Link to page log if not to a diff" 2023-11-13 11:38:45 +00:00
Midgard
76945f42be mail: Link to page log if not to a diff
When a page has been marked for translation or marked as reviewed, the
parameters that enotif receives include pageStatus='change', which is
the same as for revisions of a page's content. Thus the same wording in
the mail's body is used. This resulted in confusion for users ("Why did
I receive an email notification when there is no change in the page
revision history?").

This change aims to avoid that confusion by linking to the page log when
there is no revision to link to. This will at least happen for deletions
and for special changes such as those I mentioned earlier.

Bug: T115183
Bug: T145933
Change-Id: I12c09759f87f32f0df94d8441021b16e0e10c91c
2023-11-13 11:21:33 +00:00
James D. Forrester
b63c1de131 mail: Inline @var types
Change-Id: Id191717c1b88cc00368e1c038627250e118b563b
2023-11-06 14:45:45 +00:00
ArtBaltai
012a4a93ff Use Emailer class instead of UserMailer
Bug: T247393
Change-Id: I5d682d434b4bc1dc0fa040b91854ef1a43779473
2023-11-06 09:17:54 -05:00
thiemowmde
f5cd1ba7ca Improve performance of trivial encoding/decoding regexes
Instead of replacing 1 character at a time the functions used here
can replace sequences of any length. This can dramatically reduce the
function call overhead.

Also make use of the `fn ()` syntax because we can.

Change-Id: I2dbc2271aa7847d9b687703f837cb0d850596ef0
2023-10-04 11:09:44 +02:00
Ammarpad
eb344c676c mail: Encode period (ascii 46) if it appears in encoded email header.
Strings that do not need encoding like 'Foo.Bar' are already quoted;
but where the string is encoded, the character appears literally which
makes the string to fail pear/mail validation.

Bug: T344912
Change-Id: I9bce80c1c99c67a65bce1a30b1d9a77e00b0bc18
2023-10-01 18:26:59 +01:00
Daimona Eaytoy
8af16b7945 Make EmailUser stable, deprecate old methods
Bug: T265541
Change-Id: I09276e2bc12d474e1a5defe6a23fff4e633aeaaf
2023-09-26 23:27:29 +00:00
jenkins-bot
3aee50e48f Merge "EmailUser: use authorizeAction()" 2023-09-26 20:03:20 +00:00
daniel
710867ebc3 EmailUser: use authorizeAction()
EmailUser should distinguish between pre-checking permission, and
authorizing the sending of emails, so we can call authorizeAction()
at the appropriate time. This way, rate limits get enforced
implicitly.

This change demonstrates the motivation behind Iebd62b0487a
and I0c2ce8bdf07.

Change-Id: Ic30c36f82ab142130b5f4167c13284aeed899231
2023-09-26 21:20:32 +02:00
Umherirrender
f4ef430d28 Use ::class for class name resolution
Change-Id: Ic74a3d317c9d36509a50c658e52fad65026e7ac7
2023-09-21 23:27:28 +02:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
459cbb0494 Namespace remaining 'specialpage' files under \MediaWiki\SpecialPage
SpecialPageFactory is already here, but none of the others were yet.

Bug: T166010
Change-Id: I9689bf0a1ab329625e23669b99f019b96295fffd
2023-09-18 18:23:13 +01:00
Daimona Eaytoy
154f04299c Remove redundant empty() constructs (2)
empty() only makes sense when the expression it checks is possibly
undefined, otherwise it's equivalent to a truthiness check with the
additional downside of suppressing errors when it's not wanted.

Replace it with simple truthiness checks, using strict comparison when
that seems to help with polymorphic variables.

These were caught by a bespoke phan plugin.

Change-Id: I70b629dbf9e47cf3ba48ff439b18f19e839677f4
2023-09-08 23:28:11 +02:00
Amir E. Aharoni
2705b6777b Remove CHANGEDORCREATED from email templates
It was deprecated in 2013, and
"scheduled for removal in MediaWiki 1.23",
but never actually removed.

Now this parameter doesn't seem to be used anywhere
in the core code or in translations, so it, as well
as the associated messages, can be removed.

Follow-up to
Ibb7953741e4189127d1cd6718ac58492f254671e
and
I7d9fd90519a68dd66f99479a7c92f6c664485a9c

Change-Id: I1e8eed2f5b4421b0d387c27c9714b9ed7272a481
2023-09-07 03:07:02 +00:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Daimona Eaytoy
1e27f61cc5 mail: Final round of EmailUser refactoring
- Replace MessageLocalizer with message formatters. This is still not
  very pretty, but at least now callers don't need to obtain monster
  classes like RequestContext to use this service.
- Update the documentation and add a couple notes about potential future
  improvements.

A subsequent patch will make the service stable for use, deprecate the
old stuff, and update the release notes.

Bug: T265541
Change-Id: Ic9b0ef7b3b410d48375836f4db565ffd46936319
2023-06-20 11:02:51 +00:00
Daimona Eaytoy
c7eb0db5d1 mail: Round 6 of EmailUser refactoring
- Rename methods to follow the more standard convention used for
  commands.
- Update doc comments.
- Add new hooks with final method names and parameter types, to replace
  the old messy hooks.
- Deprecate the remaining old hooks.

Bug: T265541
Change-Id: I609709a70fb58ce00b9f179ee4de2f6ac5e0a1cf
2023-06-20 11:00:07 +00:00
jenkins-bot
aaf16eadbf Merge "Update email for temporary users" 2023-06-13 21:28:51 +00:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Thalia
59dda9ab1f Update email for temporary users
Changes made in this commit:
* SpecialConfirmEmail treats temp users the same as IP users:
    * with no confirmation code, the page is unavailable
    * with a valid confirmation code, prompt login
* Add temp user handling in EmailNotification:
    * Custom message for notifications from a temp user
    * Custom debug message for notifications to a temp user

Bug: T331579
Change-Id: I5c3999addf185059ef310422a6bb0f5a472c9f93
2023-06-07 17:21:31 +01:00
Daimona Eaytoy
b469b342d0 Introduce EmailUserFactory
This is necessary so that EmailUser can behave as a command. EmailUser
now takes the performer as a constructor parameter; this, in combination
with the statelessness of the service, allows it to be reused for
multiple sends. Some BC code was also moved to the factory.

Bug: T265541
Change-Id: I2568359f00f429ef3ab3bfbfb803dc8e51cd8add
2023-06-01 11:17:44 +00:00
Daimona Eaytoy
ead6d3135b mail: Round 5 of EmailUser refactoring
- Use UserEmailContact for the sender; internally, we still fall back to
  User.
- Try to use Authority and UserIdentity instead of User where possible
- Replace PermissionManager with Authority
- Fix handling of block message in BC code for Special:EmailUser
  (currently throwing a fatal because of return type mismatch, as the BC
  code is not intercepting the Message object)
- Move the ratelimit check around the beginning of the method, instead
  of running it after having pointlessly built half of the email body
- Stop using User::isBlockedFromEmailuser and add a TODO about
  deprecating that method.

Bug: T265541
Change-Id: Icc06b816a553028d816e6ab1b43ad93605fd5b3f
2023-06-01 11:17:31 +00:00
Daimona Eaytoy
4634d4545e mail: Round 4 of EmailUser refactoring
- Remove getTarget(). Converting a username to a user object is not a
  responsibility of this command. This logic generally belongs to
  callers.
- Use Authority for the sender, as we need to perform permission checks
  on them. Internally, we're still converting to User.

Bug: T265541
Change-Id: Ib0cd86d97dbf1cd97dcb316480171e4fbf4a09f4
2023-05-21 07:56:01 +00:00
Daimona Eaytoy
ead444b208 mail: Make EmailUser::getPermissionsError() return StatusValue
This is non-trivial because:
- "blockedemailuser" is not a real message, so it can't be passed to
  StatusValue. For now, use BlockErrorFormatter to obtain a suitable
  message. In the future, we should simply rely on
  Authority/PermissionManager to set a message for us, but that's left
  for another change.
- The hooks used here return an error in the format accepted by
  ErrorPageError. There's no "official" way to do this with StatusValue.
  This patch uses StatusValue::value as a temporary workaround, but
  these hooks should be replaced with a new hook that uses StatusValue
  for errors.

As an aside, note that ApiEmailUser passes the return value of
getPermissionsError to dieWithError(), which doesn't work in the cases
above. This is a pre-existing issue that will be fixed in another patch.

Bug: T265541
Change-Id: I84cc521b24adef6406e0378a293438d5cd7db02a
2023-05-20 13:21:59 +00:00