Commit graph

70 commits

Author SHA1 Message Date
Umherirrender
465777f188 Use const keyword for constant list of strings or ints
Also changed visiblity of some to private

Change-Id: I113b040321d27c84fe9b807c162736909e96fb20
2024-09-11 23:16:24 +02:00
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
Daimona Eaytoy
4637824f68 Replace unchecked MWException with SPL exceptions
Bug: T328220
Change-Id: I4e0454ce3ad3741756e2010a76e548d6c9a6bcb5
2024-01-28 22:41:46 +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
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Derick Alangi
74033c50cd maintenance: Begin using Maintenance::getServiceContainer()
Maintenance class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.

NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.

Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
2023-09-04 10:39:58 +00:00
Umherirrender
21ec8b1385 maintenance: Remove UserRightsProxy from CreateAndPromote::addLogEntry
The type is not created in the script,
looks like a copy from other code area (added in 01a60e52)

Bug: T255309
Change-Id: I1e55a39ba1f35e9f047dd273f7561f566b1f6a6f
2023-07-26 20:06:14 +02:00
Martin Urbanec
d030fd3d9c createAndPromote: Fix logging of user right changes
This patch fixes three issues:

    * Prior to this patch, it logged weird entries, such as
      "changed group membership for Test user 22 from (none) to (none)",
      when no promotions were actually configured.
    * Promotions happen at two places within the script, which directly
      results in the following issue.
    * When a promotion was requested, the entry (falsefully) said
      "changed group membership from administrator to
      administrator and administrator", as it loaded the groups from
      the database after doing the promotion for the first time.

Follow-up for I6a02042f6972ec718bae3adb2b7afbb2782c5673.

Bug: T340875
Bug: T168205
Change-Id: I8cd1fe4308a08aea6e9ab7c464184697eafc368f
2023-06-30 19:11:49 +02:00
Ed Sanders
6fd9b88f54 Follow-up I6a02042f: Ensure reason is always a string
Change-Id: Ia21af5599ac3867c077910c810a23c6b3544797b
2023-06-07 12:16:28 -04:00
Owen
01a60e5268 Maintenance: Add --reason option to createAndPromote.php
Allows specifying a reason for promoting users through createAndPromote.

Bug: T168205
Change-Id: I6a02042f6972ec718bae3adb2b7afbb2782c5673
2023-06-07 13:16:44 +00:00
James D. Forrester
88a7cac843 maintenance/createAndPromote: Don't use " where ' will do
Change-Id: Ia68617ee15f4b8ffa5a3f86a1509faacef021ca8
2023-05-19 12:35:17 +03:00
jenkins-bot
7532a620d7 Merge "createAndPromote.php: Do not show stack trace on user error" 2023-05-06 14:34:44 +00:00
mainframe98
8b89d0eb33 createAndPromote.php: check password before creating the user
Also change the groups before changing the password; the password policy
can differ based on group membership, resulting in an invalid password
being set because the user was not yet part of the group with a strict
password policy.

Bug: T335702
Change-Id: I0ce7c2cd3eed958bb99f1a2e7c4a45c51668869d
2023-05-06 13:30:32 +00:00
Gergő Tisza
d202ac8248
createAndPromote.php: Do not show stack trace on user error
Bug: T335702
Change-Id: I500b9c85d96e74eb7b885a76e96608f905ef87fa
2023-05-05 22:26:54 +02:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
DannyS712
28c4214d37 createAndPromote.php typo fix: acccount -> account
Change-Id: I85a08df54c50d45d92f2578175a295bef90d5ccd
2022-04-27 16:10:40 +00:00
TChin
1f673d8e8f Create new UserGroupManager::addUserToMultipleGroups method
Bug: T287247
Change-Id: I40f560a2143a2c0fda8cb7233d9954dc645749a3
2021-08-30 10:24:46 -04:00
vladshapik
c7e6c67dc5 Hard deprecate User group methods
1) The following methods were hard deprecated:
- User::addAutopromoteOnceGroups
- User::getEffectiveGroups
- User::getAutomaticGroups
- User::getFormerGroups

2) User ::getGroups, ::getGroupMemberships, ::addGroup,
::removeGroup were replaced in the production code,
but they were not hard deprecated because of conflict
with UserRightsProxy class.

Bug: T275148
Change-Id: Ia69598316f5dc5dd9511f6112b5b13e1aa07575a
2021-07-23 15:00:16 +03:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
Umherirrender
fd666afbb0 Use MediaWikiServices::getAuthManager instead of AuthManager::singleton
Change-Id: I92c31b963095eab751df9f8c1715e8e23b7e8485
2020-06-22 00:57:08 +00:00
Martin Urbanec
894ae3a3fc docs: createAndPromote.php: Password is required even when --force is supplied
Change-Id: I93971559701418c5d887ab3e6a581d933bc71fe0
2020-03-17 03:56:38 +00:00
Umherirrender
1eb5d8e44d Do not output wikitext in maintenance script
Also remove print_r with a string
Always use english for maintenance scripts

Bug: T229843
Change-Id: I539a1ac1f6a201dd8ee9ce89599cc34bebfba79f
2019-09-20 18:28:34 +02:00
DannyS712
a4835b43c7 docs: Fix typos for 'parameter' and 'perform'
Bug: T201491
Change-Id: I37ed48907bf7c1a1d4ebab7b10b41a77623eba8a
2019-08-20 09:45:52 +00:00
jenkins-bot
1cc50ab8f5 Merge "Migrate various callers away from wfWikiId() to WikiMap" 2019-07-12 17:33:51 +00:00
Aaron Schulz
7710afe569 Migrate various callers away from wfWikiId() to WikiMap
Change-Id: Idc2980c05873c428fb5ffa6ab89f723d33217a8e
2019-07-12 01:02:00 +00:00
Aaron Schulz
c6c422cfd1 Avoid using deprecated SiteStatsUpdate constructor
Change-Id: I7eb02d1b91ee08049777c203502a4959dfa8f20f
2019-07-05 23:26:17 -07:00
Bryan Davis
ef2ba25b77 createAndPromote: use AuthManager::autoCreateUser
Use AuthManager::autoCreateUser when creating a new user via
createAndPromote.php so that configured AuthManager providers have
a chance to perform validations and extra actions beyond local account
creation.

Bug: T212689
Change-Id: I4972507bbaf65bb542934c281c37bd8a5c7a26b7
2019-01-08 20:45:12 +00:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Gergő Tisza
db888bc5ad
Segregate right to edit sitewide CSS/JS
To limit the likelihood of incidents like T189665, the ability to
edit sitewide CSS/JSON/JS is split out from editinterface, into
separate 'editsitecss', 'editsitejson' and 'editsitejs' rights.

editsitecss, editsitejs, and the right to edit another (potentially
more privileged) user's personal CSS/JS is removed from sysops, and
a new user group, interface-admin, is created specifically for that
task (along with a new grant group 'editsiteconfig').

interface-admin is granted to the first user of a new wiki, along with
sysop and bureaucrat.

Bug: T120886
Bug: T190015
Depends-On: Ia9b2ea1450aff6121dc0f3777bf029292c8aaad9
Change-Id: Ifefd872640642441e26f8b2f144ffe4b88d2eb12
2018-07-22 12:37:32 +02: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
Gergő Tisza
854a462dc0 Remove $wgDisableAuthManager
Change-Id: I2b2c9693a275fcc026916bd97f303e7a5c8df341
2016-08-09 23:00:27 +00:00
Gergő Tisza
b568497e9a Add new convenience User method for authentication data change
Also update createAndPromote.php to use it so it can display errors.

Note that there are two possible approaches. The other is to
do the update for all requests for which the test passed,
even if some tests fail. The approach of the patch seems
more manageable from the caller's point of view
(either the operation was a success, or it failed and
nothing happened).

Change-Id: I86abed4b80472cd888337444fac0cbcb870b1246
2016-06-08 21:19:11 +00:00
Reedy
16fc39d17c Don't allow createAndPromote.php to add users to invalid groups
Bug: T131704
Change-Id: Ibe8839e62af8db002adea68ffa87b3adf2b505ea
2016-04-03 12:28:48 +01:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Brad Jorsch
b6f5529236 Disallow User::setPassword() on users not in database
Change I2c736ad mostly removed the password handling from the User
object, but left in a little password handling to preserve the existing
ability to call $user->setPassword() before the user was actually added
to the database. That ability is now removed.

Bug: T47716
Change-Id: Id3d40742f2e2b197ad6facd149cc6350006bf289
2015-10-30 11:33:58 -04:00
Matthew Flaschen
ab23aad688 Allow using createAndPromote.php with custom groups
This lets any group(s) be added using a comma-separated argument,
in addition to the --sysop, --bureaucrat, and --bot that already
existed.

Bug: T105079
Change-Id: I1274b065e3dad917e545f9278b996da014d87ae9
2015-07-07 20:43:30 +00:00
Siebrand Mazeland
f2f31fadc7 Update formatting in maintenance/ (2/4)
Change-Id: I2b791d3bff0de464b6bdaaeae0622c065389c31c
2014-04-23 20:08:42 +02:00
Siebrand Mazeland
752c708149 Pass phpcs-strict on maintenance/ (6/8)
Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286
2014-04-23 09:27:41 +00:00
Hazard-SJ
7bb5b846ec Add bot to createAndPromote.php groups
- Added 'bot', a default usergroup, to $permitRoles
- Changed 'administrator rights' to just 'rights',  since the script isn't just for administrator rights

Bug: 45160
Change-Id: I61348e2d45b90b65a117efcce65d7c581105e612
2013-05-30 18:03:04 -05:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
umherirrender
bfb75bc8e2 Fixed spacing around parenthesis in languages/tests/maintenance
Change-Id: Idd4299d17f1fcf98ab1d635484cb4e880f35ee24
2013-04-28 15:57:34 +00:00
umherirrender
dbd0b590e9 else if -> elseif
Also fixed some spacing while at it
Added some braces for one line statements

Change-Id: Iebfa2b17091509daabc76248121c7763e2295d20
2013-04-17 16:52:47 +02:00
Mark A. Hershberger
f04d486e37 Bug 35623 - createAndPromote.php: Change to allow promotion only
Introduces the --force option to promote the user even if it already exists.

Change-Id: Id0cd0e49a46f78fdbff3560adf23ba0c33aae430
2013-02-11 17:30:26 +00:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
9eee3153ae Improve documentation of maintenance scripts.
Change-Id: I328a3d42a09f2b082ebc153c2f399793e23942d7
2012-06-16 22:59:39 +02:00