Commit graph

64 commits

Author SHA1 Message Date
jenkins-bot
771be6c7aa Merge "Restore password reset invalid email message" 2024-08-04 16:58:25 +00:00
Bartosz Dziewoński
6f82b91873 Restore password reset invalid email message
This mostly reverts commit 28ad29ea0f.

Checking the validity of the provided email doesn't reveal any
information about any users, and it could help catch genuine mistakes,
e.g. if someone inputs the username in the email field.

Previously if an invalid email was provided, we showed a success
message that is an obvious lie (saying we sent an email to something
that isn't an email address).

Change-Id: Idec437b29b22e5b1e5aaff3846632fbc413a3dcb
2024-07-30 14:19:13 +00:00
Bartosz Dziewoński
88cd6cc918 PasswordReset: Fix field name in log message
Change-Id: Ia6f48af3d907df2b0a98c67e65f58c92804d66eb
2024-07-27 04:43:59 +02:00
Timo Tijhof
b719a104ee user: Minor clean up of PasswordReset isEnabled/isAllowed
* Favour early returns instead of long elseif chains that require
  more context and awareness to understand and verify.

* Remove needless creation of newGood() for all but one return.

* Move $providerStatus out of conditional block, and remove the
  apparent conditional check that implies that it can be falsey.
  allowsAuthenticationDataChange() only returns Status.

* Flip the isListed condition to more clearly read as
  setting isListed to false when disabled/!enabled, and delegating
  to the parent method for other cases.

Change-Id: Ibd42b63b034e82b2e97c9a7f0ad074c14c45a6b9
2024-03-29 02:56:28 +00:00
Timo Tijhof
b1f20c09e6 search: Avoid user block/rights compute in SpecialPasswordReset->isListed
Follows-up 64e6a78af3 (I1cb5f4c3ce), which started calling isListed
from ApiOpenSearch via PrefixSearch. These calls are pretty cheap,
and won't show up in production latencies or flame graphs since they're
limited to queries that explicitly search for "Special:" (including
colon).

However, when profiling it anyway, I noticed locally that the majority
of getListedPage is spent in one page, SpecialPasswordReset->isListed,
because it appears to be the only one that varies its response by
current User.

Varying access by user is perfectly fine, but this is something we do
at runtime via SpecialPage::execute/SpecialPage::checkPermissions/
SpecialPage::userCanExecute, e.g. as configured via the `$restriction`
parameter to the constructor, or getRestriction.

* The code comment above isListed implies that this varies by
  feature enablement, which is now correct after this change.

* This change does not change who is allowed to reset passwords.
  The definitive permission checks are elsewhere in PasswordReset,
  we're only changing the inclusion of the page in UI listings.

* This change does not affect Special:Specialpages, because that
  calls getUsablePages(), which applies the same permission
  checks still via SpecialPasswordReset::userCanExecute().

Bug: T358938
Change-Id: I546ff0fd475fd386de5014cfdc30543aecaffd09
2024-03-28 19:06:34 -07:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
Umherirrender
72d6b46339 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: I443aada1c18c8628b02671aa9fd6f441961e5c2e
2023-12-11 16:07:18 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
DannyS712
53f4b1526a Add some typed properties to User-related services
Change-Id: Ia73c3a044dfa50e9d9d43bf0e28eed2f65edcdce
2023-09-28 18:26:27 +00:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +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
Tim Starling
4edbb29307 Add User::newQueryBuilder()
Replace all core calls to User::getQueryInfo() with an equivalent
SelectQueryBuilder.

Bug: T311866
Change-Id: Ib249a9d9098b1c09907a90607206edd8331bad3d
2023-06-27 11:45:39 +10:00
Daimona Eaytoy
8adf1bfb93 Replace some more usages of deprecated MWException
Bug: T328220
Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
2023-06-09 02:07:08 +02:00
Amir Sarabadani
1f695f0368 user: Clean up most calls to LoadBalancer in user-related services
Bug: T330641
Change-Id: Iab0b4a6fca493e003a57df2d85628118ed5ab2fe
2023-06-01 16:56:22 +00:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
jenkins-bot
d86521fe2b Merge "Remove separate Global blocks check from PasswordReset::isBlocked" 2022-11-09 17:05:27 +00:00
AnaïsGueyte
80af71d45b Remove separate Global blocks check from PasswordReset::isBlocked
Since f102d7b42e882b330030021bb3419af708b26fa5 in the
GlobalBlocking extension, global blocks are found when checking
for blocks, and do not need to be checked for separately from
core.

Bug: T317334
Depends-On: If0b19ef4cef084e83af27bd851ad3dd69bb0b4d9
Change-Id: I8415ff7bc2bfe2c935b986e1b99fd8684d1b330e
2022-11-09 16:30:07 +00:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03: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
Daimona Eaytoy
e0d3b3e8fc Use getWithSetCallback() instead of get() + set()
This allows the backend to do whatever it can to ensure atomicity, and
is also easier to read, since the intent is obvious.

Change-Id: Ibbfecd92a2c6d9a5997ca37ea101e068bd1e8202
2021-11-18 18:58:13 +00:00
DannyS712
d1cf9f4784 PasswordReset: remove use of PermissionManager
Use Authority::isAllowed() instead of
PermissionManager::userHasRight()

Change-Id: Id4a9a0497099abccd32f627ff31f5c338d5220c5
2021-05-26 03:26:02 +00:00
Umherirrender
201980999a build: Updating mediawiki/mediawiki-phan-config to 0.10.4
Change-Id: I56538eaa498ab6d312240f9a534c2d2da11c34cb
2020-11-20 17:33:22 +01:00
DannyS712
4db93b3be4 Inject dependencies into PasswordReset, and cleanup
* Convert everything that is protected to be private,
since the class is not stable to extend

* Remove PasswordReset::$hookContainer, unneeded

Additionally, add missing UserFactory::newFromRow,
for now just a wrapper for User::newFromRow

Bug: T253432
Change-Id: I1de57a08605ff6e0d2be8e276b7fcb08934fb5da
2020-10-03 00:23:59 +00:00
Petr Pchelko
eb4aa6fb4b Drop null fallbacks in PasswordReset constructor
The class is not @newable, and indeed is
not instantiated directly.

Change-Id: I72f98f9bb35523898875e8a09ee160eaba6a13c6
2020-10-02 15:56:32 -06:00
Tim Starling
7a8dd86feb Deprecations from HookRunner call site migration
Deprecate lack of $hookContainer parameter to DefaultPreferencesFactory,
LinkHolderArray and PasswordReset constructors

This was split out from the main patch to create a migration window,
since deprecation messages from extensions now cause Jenkins to vote -1.

Depends-On: Ie097d8e12758f066aee14c740f9e07955aa510c1
Change-Id: I559640c9f4dc7ad5444fe1ef39d50e4504ae0b63
2020-09-18 08:12:51 +10:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
These were never meant to be part of the public interface and should not
ever have been marked with @since. They're only useful for constructing
the respective objects, which no outside users should be doing.

Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
2020-08-21 00:18:45 -04:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +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
hmonroy
51063b1402 Clean up validation order
Reorder validation so that some validation is done sooner rather than
later.

Bug: T247017
Change-Id: I1aad1b2b5cfc0a15754c27282a886c47da46a3c1
2020-04-30 20:06:51 -07:00
hmonroy
28ad29ea0f Remove password reset invalid email message
Followup patch for: b64b0f5. Show general message when an invalid email
is submitted.

Bug: T249730
Change-Id: I98a35af26930f3d66308065e271e9617fdbf5076
2020-04-21 11:21:13 -07:00
suecarmol
632fa50065 Optimize email sending on password reset
Improve performance of sending emails when a user resets a password.

Bug: T247017
Change-Id: I9edb0e4c8845f7a9082035de66f5965c3f9b762d
2020-04-16 13:59:08 -05:00
hmonroy
b64b0f525c Include throttle message in password reset success
Update password reset success message to include throttle message.

Bug: T249730
Change-Id: Ia247034ec9a93689218c619d391a666c6b92991a
2020-04-15 16:43:06 -07:00
jenkins-bot
269e2184c6 Merge "Clean up unused $displayPassword return value" 2020-04-13 15:11:04 +00:00
Sam Wilson
ed788eafed Clean up unused $displayPassword return value
This is a follow-up to f12a3edff7
to remove the now unused $password return variable.

Change-Id: I2b12bd7c9f84e915f1bda659a95bab3d63a611d2
2020-04-13 10:32:17 +08:00
hmonroy
6e617895fb Handle the undefined offset in Special:PasswordReset
Add logic to reset users array that will receive the reset password email with
numeric keys. The array should have index 0 if it is not empty so that the
password reset process can run without 'Undefined' ErrorException.

Bug: T249709
Change-Id: Idc5456e0d3e77f2ae0542f6b972d168049e51d77
2020-04-08 18:43:19 -07:00
hmonroy
1426f6354c Enhance passwored reset message
Add a more general message for password reset request submissions.

Bug: T246844
Change-Id: I45e9db992ea113c44f7603081754ac9a575a5da6
2020-03-13 16:18:48 -07:00
Sam Wilson
b6b0a99e34 Don't tell user when email is required but not supplied
Hide the `requireemail` status from the resetting user when
requesting a password reset without supplying an email address.

Bug: T238961
Change-Id: Iee07564aac78d013ecc52192b536e92cb1ed4e8b
2020-02-17 08:34:19 +08:00
Sam Wilson
5b1978f797 Standardize information on Password Reset success page
For all successfully submitted (i.e. valid input) password reset
requests, display the same information. This removes the
distinction between email and username resets, and only shows the
user what they've already submitted.

Bug: T238961
Change-Id: Ic17acecf1e44401f7607cdaf90dcee1a26b8405f
2020-02-10 10:23:13 +08:00
hmonroy
fa8272b600 Email only users with require username and email option off when only email given
Add functionality that does not send password reset email to user accounts that turned on preference
that requires both username and email to be submitted in the PasswordReset form when only email is
provided.

Bug: T234401
Change-Id: I9bddc7073b8bcb52c4287b3d6c7343be29b717f2
2019-10-24 15:08:16 -07:00
James D. Forrester
662b27776b Services: Convert PasswordReset's static to a const now HHVM is gone
Change-Id: I77e0d9ce86cf96824eb672d0f35c32b5f4c484be
2019-10-08 11:26:17 -07:00
Max Semenik
1de3611539 Optionally require both username and email for password resets
Bug: T232694
Change-Id: I70ed25ea4f810bf642fcb3df6f9b2663732b5dcf
2019-10-01 14:42:22 -07:00
Max Semenik
631f56c576 Turn PasswordReset into a service
My team has plans to work in this area, better make it more testable.

Bug: T232694
Change-Id: I200874ec10db69378ada1743b2a7953b3fa01e3e
2019-10-01 14:42:18 -07: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
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
jenkins-bot
405932d6e6 Merge "Move logic for checking block behaviour to Block class" 2019-03-27 17:17:41 +00:00
Thalia
79706a8c93 Move logic for checking block behaviour to Block class
User::trackBlockWithCookie and PasswordReset::isBlocked make decisions
about block behaviour based on the block parameters. This should be
done in the Block class.

Bug: T218905
Change-Id: Ia3f46abacdaf70e720b715b39dc60aed53be2d0a
2019-03-27 12:54:55 +00:00
Thiemo Kreuz
204fe4c4b1 user: Remove not needed array_values()
Change-Id: I0a2321d5f363b86d01ab7ad94df920008e607390
2019-03-27 13:54:02 +01:00