Commit graph

11 commits

Author SHA1 Message Date
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
Amir Sarabadani
d9370003fb maintenance: Introduce getReplicaDB() and getPrimaryDB()
And start using them instead of wfGetDB(), LB/LBF connection methods or
worse, $this->getDB().

$this->getDB() reuses the database object regardless of whether you're
calling a replica or primary, leading to returning a replica on a
primary and other way around.

Bug: T330641
Change-Id: I9e2cf85ca277022284fc26b9f37db57bd12aaa81
2024-01-18 15:12:04 +01:00
Amir Sarabadani
69cabb628c maintenance: Migrate to expression builders
This was somehow left out

Bug: T210206
Change-Id: I70851b5b99fa865dbfd629caf2c1866c85418350
2024-01-17 20:27:08 +01:00
Bartosz Dziewoński
6183896a0f TempUser\Pattern: Use SQL expression builder instead of buildLike()
Bug: T350969
Change-Id: I44bb326539f68b1c6591a015424940a9c7de5030
2023-12-06 18:20:39 +00:00
Bartosz Dziewoński
0454c52dde Improve uses of ->where( array_merge( … ) ) in query builders
Replace ->where( array_merge( a, b ) ) with ->where( a )->andWhere( b ).
It's shorter and I find it easier to read.

Change-Id: I94fef6219b5611659f7a09fd3a555aba001f5339
2023-10-26 19:44:02 +02: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
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
Tim Starling
35d281d4e0 renameUsersMatchingPattern.php: canonicalize and check for existence of target
Respond to Krinkle's comments on the bug.

* Canonicalize the destination username
* Check for existence of the target. Previously it would throw a
  duplicate key SQL error if the target existed.

Bug: T307064
Change-Id: I6cb2bd50a824c34c43dd2c9d431343196dd824e5
2023-05-30 11:20:59 +10:00
Tim Starling
e8bbca2690 Renameuser: Also rename user talk pages
Fix regression from Iaefdcec05ea2a858066b43b

Change-Id: I637067de3874f86e7682753afe304fe4947841f6
2023-03-14 13:00:12 +11:00
Tim Starling
365005ff08 Add renameUsersMatchingPattern.php
Add a maintenance script which can do a bulk rename of users matching a
given pattern.

Bug: T307064
Change-Id: I824cadeb23ec435ded6110030905058fe807ef2a
2023-03-13 10:19:56 +11:00