Commit graph

21 commits

Author SHA1 Message Date
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
Why:
* Maintenance scripts in core have bolierplate code that is
  added before and after the class to allow directly running
  the maintenance script.
* Running the maintenance script directly has been deprecated
  since 1.40, so this boilerplate code is only to support a now
  deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
  not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
  coverage reports as it cannot be marked as covered and also
  is for deprecated code.

What:
* Wrap the boilerplate code (requiring Maintenance.php and then
  later defining the maintenance script class and running if the
  maintenance script was called directly) with @codeCoverageIgnore
  comments.
* Some files use a different boilerplate code, however, these
  should also be marked as ignored for coverage for the same
  reason that coverage is not properly reported for files.

Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
2024-08-27 13:22:29 +01:00
Bartosz Dziewoński
4108bbe1af Maintenance: Print errors from StatusValue objects in a consistent way
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.

Thoughts on the previously commonly used methods:

- $status->getMessage( false, false, 'en' )->text()
  Almost the same as the new output, but it allows on-wiki message
  overrides, and if there is more than one error, it prefixes each
  line with a '*' (like a wikitext list).

- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
  As above, but these forms do not expand parser functions
  such as {{GENDER:}}.

- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
  These forms output the message keys instead of the message text,
  which is not very human-readable.

The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.

Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
2024-06-12 00:07:02 +02:00
Reedy
5ab70409f5 Namespace includes/password
Bug: T353458
Change-Id: I1a701b5b7ff65356692abb0efde9a2207b6135b6
2024-05-18 16:17:38 +01:00
daniel
4dcb6e13cc Maintenance: use getServiceContainer() method
Use getServiceContainer instead of calling
MediaWikiServices::getInstance().

Change-Id: I3901ef866963d33649f8fa170ad6fbc7ca81f0fb
2023-10-13 10:19:26 +02: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
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Func
fc364c6b5c resetUserEmail: Add an option to send temporary password via email
I found this feature useful for resetting password for users didn't
set email before. It's also helpful when using this script without
the no-reset-password option.

Change-Id: Ic93038a3e49979dce201bdcb27840ebc0053d216
2023-09-04 10:22:12 +08:00
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Umherirrender
4de76550a3 Fix various real types related to scalar types
Swap null/false or use real strings if needed

Found by phan strict checks

Change-Id: Id82ea609f05a76c5cb8c661d5cf2b7922d6cfbc1
2022-03-10 19:35:34 +00:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00
Petr Pchelko
c44d44639b Make stricter type checks on user email and real name
Currently both email and real name are documented as
non-nullable, but it seems there's code that breaks
this contract. Try stricter type checks.

Depends-On: Ie8fa1e7881e1b016dccdc9097a1763a07cc140b9
Depends-On: Id3bf35fe56c459597ed6a602bdf6ca4860271f6e
Change-Id: I2f4b7b3500a2b25f7d5cf25147f65ad412d61955
2021-04-01 15:21:41 -06:00
Martin Urbanec
82cd2ca311 resetUserEmail.php: Treat empty string as valid email
User::setEmail with an empty string removes the mail, which
is something necessary to do.

Change-Id: I0954f31e9214f05549697750ecc50c482c889047
2021-03-26 22:05:18 +01:00
Ed Sanders
cb871d2c2e ResetUserEmail: Call parent constructor first
This fixes the logic for working out which options
are script-specific, and which are generic.

Change-Id: I8fcdcda04c34b464fe0fc74aca57d3609feaa7a6
2021-02-27 00:10:09 +00:00
Ammar Abdulhamid
0be0ce2132 Remove call to deprecated setPassword() User method
The method has been hard deprecated since 1.27

Bug: T249181
Change-Id: Ic2a5dcd00f8a75cd201cc1fcf2e62adb45bdcd9a
2020-06-12 19:16:11 +00:00
Derick Alangi
c0927cba65 maintenance: Remove arguments that match their default values
Calls to methods with arguments as default values can safely be
removed as there is an exact match. With or without them, code
will still work as intended.

Change-Id: Id8141626a51d9cc8bf8bc0baeb5e38d120664da5
2019-02-27 21:13:57 +00:00
Reedy
39d55d812c Output Done! at end of resetUserEmail.php
Change-Id: I8e5572f0a60e74eec300031e75b79ee71ffc008d
2018-10-20 23:48:55 +01:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Bryan Davis
9e34eeff23 Maintenance: add fatalError() method
Deprecate the second argument to Maintenance::error() in favor of a new
Maintenance::fatalError() method. This is intended to make it easier to
review flow control in maintenance scripts.

Change-Id: I75699008638f7e99b11210c7bb9e2e131fca7c9e
2017-11-21 21:34:16 -07:00
Matthew Flaschen
5ef414072c resetUserEmail: Allow resetting email without scrambling password
There is an mini-script in MediaWiki-Vagrant (set_user_email.erb)
that could be replaced by this.

Change-Id: Ieb0da6cc358506174f1ff01116d0b286f814b2c7
2016-02-18 16:04:49 +00:00
addshore
4db074ef0b Use addDescription in resetUserEmail maint script
Change-Id: Ib1eb8e3adc8deed0d09c1f655218144b2305d137
2016-01-30 14:55:27 +01:00
Max Semenik
362403ccd5 Add script to reset user emails
Current way to do it, via eval.php, is slightly scary.

Change-Id: I2b875326a0eb1e6d1f4bc758b8ac97b8f9324c4e
2016-01-30 13:53:36 +00:00