Commit graph

42 commits

Author SHA1 Message Date
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
Thalia
02cb7aefef Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)

This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom

Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-21 18:21:28 +00:00
Brad Jorsch
ac0c80a6d6 AuthManager: Don't invalidate BotPasswords if a password reset email is sent
There's a difference between addition of credentials, which doesn't
need to invaliate BotPasswords, and changing or removal of credentials,
which does.

It seems most straightforward for the caller of
AuthManager::changeAuthenticationData() to know which is intended, so
let's add a flag there.

Bug: T199809
Change-Id: Ib8405734e605b94f3f0b66596ad95784cb365e4f
2018-07-17 16:25:28 -04:00
Aaron Schulz
563026acf4 Convert PasswordReset to using MapCacheLRU
Avoid NULL user name that caused test failures

Change-Id: Ifc3b19cc7e172300123e7d2c7153b4357917ca74
2018-07-14 01:31:54 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Brad Jorsch
3488f49532 Replace selectFields() methods with getQueryInfo()
Several classes have a "selectFields()" static method to tell callers
which fields to select from the database. With the recent comment table
change and the upcoming actor table change, this pattern has become too
simplistic as a SELECT will need to join several tables to be able to
retrieve all the needed fields.

Thus, we deprecate the selectFields() methods in favor of getQueryInfo()
methods that return tables and join conditions in addition to the
fields.

Change-Id: Idcfd15568489d9f03a7ba4460e96610d33bc4089
2017-10-30 22:57:33 +00:00
Gergő Tisza
7582f0213e Do not disable password reset for blocks meant to force login
Also remove resetpassword right (killed in I3ab5962d) from tests.

Bug: T161860
Change-Id: Ic7e7e9b4ff7fe94001578a895962ef732b690384
2017-06-08 08:18:24 +00:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Brian Wolff
f12a3edff7 Remove passwordreset capture feature
If anyone wants such a thing, they can make their own extension.

I asked stewards, and they said they don't use this.

See also T32636 / 9de2bfd1fe

Bug: T150930
Change-Id: I3ab5962dba668e5d628e55ad0c0feae471d82b5e
2016-11-23 00:02:33 +00:00
jenkins-bot
1493438594 Merge "Fix SpecialPasswordResetOnSubmit parameter handling" 2016-11-15 03:48:31 +00:00
Gergő Tisza
f9a86b01c9 Fix SpecialPasswordResetOnSubmit parameter handling
Special:PasswordReset will take either the username or the email
into account but never both. Reflect this in the way parameters
are passed to the hook.

This also makes sure hook handlers never receive an unsanitized
email address.

Change-Id: I8d3b3d81e0cd5f92e5cd0a866a16695638610592
2016-11-15 02:41:57 +00:00
Brian Wolff
854d22ba3b Add better logging to password reset
In particular we definitely want to log capturing resets.

Change-Id: I5b47e5aa6efdc6414238d8e8f97a8f823111ff46
2016-11-13 02:49:47 +00:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Brad Jorsch
b648744746 Fix handling of error messages from the 'SpecialPasswordResetOnSubmit' hook
$error might be an array of key + values, but wfMessage() treats that as
an array of alternative message keys instead so the values are lost.
Message::newFromSpecifier(), on the other hand, does exactly what we
want.

Change-Id: I25765869f6888ac793c2af9caaa9bbdf2224d51a
2016-06-16 12:03:59 -04:00
Gergő Tisza
3617c982c9 Use AuthManager on special pages
Rewrite authentication-related special pages to use AuthManager.
All the changes mentioned below only take effect when
$wgDisableAuthManager is false.

LoginForm is rewritten to use HTMLForm and split into UserLogin
and CreateAccount; ChangePassword and PasswordReset are rewritten;
ChangeEmail and Preferences are updated. Four new special pages
are added to handle the new capabilities of AuthManager (linked
accounts, secondary authentication providers): LinkAccounts,
UnlinkAccounts, ChangeCredentials, RemoveCredentials.

The old form-based hooks (ChangePasswordForm, UserCreateForm,
UserLoginForm) are deprecated. A new, more generic hook is
available to alter the forms (AuthChangeFormFields);
form changes that involve new fields should be done via
$wgAuthManagerConfig.

UserLoginComplete is limited to web-based login; for more
generic functionality UserLoggedIn can be used instead.

Hooks that assume password-based login (PrefsPasswordAudit,
AbortChangePassword) are removed; the first functionality
is replaced by ChangeAuthenticationDataAudit, the second is
handled by AuthManager. LoginPasswordResetMessage is removed,
the functionality can be recreated via authentication providers.

There are several smaller backwards incompatible changes:
* Adding fields to the login/signup forms by manipulating the
  template via the extraInput/extrafields parameters is not
  supported anymore. Depending on the authn configuration the
  login/signup process might be multistep and it would be
  complicated to ensure that extensions can access the data
  at the right moment. Instead, you can create an
  AuthenticationProvider which can define its own fields and
  process them when the authentication is over.
  (There is B/C support for a transitional period that  works with
  the default login form, but might break with configurations that
  require multiple steps or redirects.)
* Removed cookie redirect check. This was added in 2003 in 9ead07fe9
  for the benefit of bots, but with MediaWiki having an API these days
  there is little reason to keep it. Same for the wpSkipCookieCheck
  flag (added in 2008 in 29c73e8265).
* Instead of embedding a password field on sensitive special pages
  such as ChangeEmail, such pages rely on AuthManager for elevated
  security (which typically involves requiring the user to log in again
  unless their last login was more than a few minutes ago).
  Accordingly, wgRequirePasswordforEmailChange is removed.
* Special:ChangePassword requires login now.
* Special:ResetPassword now sends a separate email to each user when called
  with a shared email address.
* the Reason field had a message with 'prefsectiontip' class
  which was sorta broken but used in extensions for formatting.
  HTMLForm does not support that, so this commit turns it into a help message
  which will break formatting. See https://gerrit.wikimedia.org/r/#/c/231884

Bug: T110277
Change-Id: I8b52ec8ddf494f23941807638f149f15b5e46b0c
Depends-On: If4e0dfb6ee6674f0dace80a01850e2d0cbbdb47a
2016-05-16 15:12:13 +00:00