Commit graph

82 commits

Author SHA1 Message Date
jenkins-bot
a8efaa1429 Merge "EmailNotification: Link to editor's talk page, not user page" 2024-06-19 22:31:44 +00: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
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
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
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
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
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Timo Tijhof
b765222915 watchlist: Re-centralise former wgUseEnotif condition
Follows-up I9bfa502a0b (9b8f153f). Also document the reason for
this logic, to the best of my knowledge, and some ideas to improve
it.

Bug: T305093
Change-Id: I4c5bf4d4da83ff1e03d0fe0dd9891507b1f1e455
2023-02-02 08:48:50 +00:00
Umherirrender
09bd89214d mail: Increase readability of conditions
Inline one used variable and use correct indent for the lines

Change-Id: I9c1283b341aee4753db7d4b3077c032a518884cd
2022-11-19 23:46:28 +01:00
Umherirrender
1fcd09581d mail: Replace deprecated User::getOption
Bug: T296083
Change-Id: Id6497992210b32cac0ddb5149869402e60a53fa2
2022-08-05 22:31:05 +00:00
RhinosF1
12a3c76c9e notifications: prevent log spam when invalid user object listed.
Bug: T308967
Change-Id: I20bfb3c5b725405aaeb48f17d300a06428084cfe
2022-05-22 11:02:47 +00:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
DannyS712
73c7d7fea9 EmailNotification: fix misplaced tab
Change-Id: I2479e596f7c93d4527bb8db800e570d15bccce03
2021-09-20 22:25:20 +00:00
Fomafix
c7ebc1ec44 Fix various typos in documentation
Bug: T201491
Change-Id: I144c120cc88bda723c8608ed7fb0ccb709f295f1
2021-08-23 09:03:44 +00:00
Petr Pchelko
c621548cf8 Convert mail namespace to Authority/UserIdentity
Change-Id: I1e1ea72f94735ddaf66eab29aad1296e1abffb9b
2021-04-01 15:46:09 -06:00
DannyS712
c932f620d7 EmailNotification: clean up with modern coding conventions
Declare one variable at a time
Add some documentation
Add some whitespace for readability
Replace some globals with retrieval from MainConfig
Should be a no-op

Change-Id: Ie58e56d61808d00fea99c35cd1c83a30d6aa28af
2021-03-31 02:58:27 +00:00
Reedy
50fe6326ef Remove some space indenting
Change-Id: I82436948fdb1f9abc5c13d32c732e1bf122a0516
2020-09-14 22:58:25 +01:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
MusikAnimal
1ff6ca3fca Filter out expired watched items when sending email notifications
Bug: T253035
Change-Id: I9ebfee4042b6ac40726162fa8c887f757d7528b8
2020-06-24 12:07:08 -04:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Reedy
4cd8d9cff5 Fix numerous PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I2ec09c02c2e4ed399d993cb1871e67df02167ca8
2020-05-11 01:36:36 +01:00
DannyS712
4db7bf9615 EmailNotification: Link to editor's talk page, not user page
Bug: T241389
Change-Id: If050c480a28b55c845a79bd432dc0459eb85e4b2
2019-12-23 21:50:11 +00:00
Petr Pchelko
7b4eafda0d Replace usages of deprecated User::isAllowed. Step 2.
Bug: T220191
Depends-On: I509cd88355cfd0cc074f4135ec86399b4075f89f
Change-Id: I2341e6f1d108c92924620fba3c64ec090cb09918
2019-09-11 16:00:03 -07:00
Derick Alangi
3cc65c87e3 mail: Avoid use of global state and use MediaWiki services DI
Change-Id: If335cb6a220ebc5eb7487e51ee097f9d2afa0d2d
2019-08-27 14:19:49 +01:00
Derick Alangi
02bbbdfa53 Mail: Add visibility for some methods without method visibility
Carefully, I checked usage of these methods in our code bases and
added the best possible visibilities to them. Not sure if I missed
something but let me know if I did.

Used private & public where suitable for the various methods. As for
__toString(), this is a magic method, so should be public per PHP docs.

Change-Id: Ie0987f4a984cac2f5eb1d9e21a305ad9467a8eb2
2019-06-30 15:32:20 +00:00
David Barratt
e86a060284
Deprecate User::isBlocked()
The method User::isBlocked() attempts to answer two questions:
(1) Does the user have a block?
(2) Is the user prevented from performing this action?
The method can answer #1, but it cannot answer #2. Since User::getBlock() can
also answer #1, this method is redundant. The method cannot answer #2 because
there is not enough context in order to answer that question.

If access is being checked against a Title object, all access checks can be
performed with PermissionManager:userCan() which will also check the user's
blocks.

If performing all access checks is not desirable, using
PermissionManager::isBlockedFrom() is also acceptable for only checking if the
user is blocked. This method does *not* determine if the action is allowed,
only that the user's block applies to that Title.

If access is being checked without an existing Title, User::getBlock() can be
used to get the user's block. Then Block::appliesToRight() can be used to
determine if the block applies explicitly to a right (or returns null if
it is unknown or false if explicitly allowed). If the user is creating a new
Title, but the text of the title is not yet known (as in the case of Wikibase),
access should be checked with Block::appliesToNamespace().

Bug: T209004
Change-Id: Ic0ad1b92e957797fee8dcd00bd1092fe69fa58f1
2019-04-25 11:47:44 -04:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Derick Alangi
4ff82a335a i18n: Add line-break in email notificaton for minor edits
Added missing line-break in email notification specifically after
page summary or immediately before $PAGEMINOREDIT (for minor edits).
In addition, if the edit is not marked as a "minor edit", avoid the
line break.

Bug: T176595
Change-Id: I68cc249c3546eb7fed0834063f15304e3c245e55
2019-03-18 12:40:18 +00:00
James D. Forrester
4577b5f6dc Drop EmailNotification::updateWatchlistTimestamp(), deprecated in 1.27 and unused
Change-Id: Idad6f5aa579e41e941d1074465dd2f0e0f4577dc
2019-02-09 12:47:14 -08:00
Thiemo Kreuz
734a969d55 Safe replacement of a lot of !count() with === []
This was originally a global search and replace. I manually checked all
replacements and reverted them if (due to the lack of type hints) either
null (that would be 0 when counted) or a Countable object can end in the
variable or property in question.

Now this patch only touches places where I'm sure nothing can break.

For the sanity of the honorable reviewers this patch is exclusively touching
negated counts. You should not find a single `!== []` in this patch, that
would be a mistake.

Change-Id: I5eafd4d8fccdb53a668be8e6f25a566f9c3a0a95
2019-01-15 17:28:49 +01:00
Mark A. Hershberger
9d9e3117c7 EmailNotification should provide a getter for pageStatus
Extensions that have hooks for
UpdateUserMailerFormattedPageStatus (to provide additional
pageStatus indicators) need a way to make sure that, when their
hook is called in SendWatchlistemailNotification, they only
notifications handling their pageStatus indicator.  This allows them
to fetch the protected property.

Bug: T175104
Change-Id: I2beb5b3576f2cd739dab16b9adf613c96636edd3
2018-12-21 01:36:33 +00:00
Alangi Derick
b5ace113e7 mail: Correct return value of sendPersonalised() method
If email is not successfully sent, return Status (with appropriate
status error) and also, if successfully sent, return Status::newGood().

Change-Id: I602e30641b88614087d9aff83cf8c93e32af7b81
2018-12-03 16:23:25 +00:00