Commit graph

41 commits

Author SHA1 Message Date
Reedy
499dbfb4cb maintenance: Use more of namespaced Maintenance class
Change-Id: I53f2e32c73c92cc3a0deee48ebe6d13329a7a0cf
2024-10-16 01:09:19 +00: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
Umherirrender
fc9e42823b rdbms: Create IReadableDatabase::andExpr() / ::orExpr()
Avoid the call to internal constructor of AndExpressionGroup and
OrExpressionGroup by creating a factory function similiar as the
IReadableDatabase::expr function for Expression objects.

This is also a replacement for calls to ISQLPlatform::makeList with
LIST_AND or LIST_OR argument to reduce passing sql as string to the
query builders.

Created two functions to allow the return type to be set for both
expression group to allow further calls of ->and() or ->or() on the
returned object.
Depending on the length of the array argument to makeList() it is
sometimes hard to see if the list gets converted to AND or OR, having
the operator in the function name makes it easier to read, so two
functions are helpful in this case as well.

Bug: T358961
Change-Id: Ica29689cbd0b111b099bb09b20845f85ae4c3376
2024-07-11 15:29:20 +00: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
Taavi Väänänen
9553121e2a
maintenance: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I9eb336837b21aa37327f571aad4f973592bdddf7
2024-04-21 23:06:00 +03:00
Umherirrender
8018e157e8 maintenance: Migrate to IDatabase::newUpdateQueryBuilder
Bug: T353219
Change-Id: Ic278c8534dad40a3f34674db2d5fbfbca5984da8
2024-04-14 18:47:55 +00:00
Bartosz Dziewoński
166748e3ac maintenance: Replace unnecessary uses of LBFactory and LoadBalancer
* Change `$services->getDBLoadBalancerFactory()->waitForReplication()`
  to `$this->waitForReplication()`
* Change various complicated expressions to `$this->getReplicaDB()`
  and `$this->getPrimaryDB()`
* Remove unused variables

Change-Id: Ia857be54938a32bb6288dcdf695a35cd38761c3c
2024-01-23 16:48:36 +00: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
Amir Sarabadani
ad118dbb75 maintenance: Migrate $db->buildLike() to expression builder
Bug: T210206
Change-Id: Ie7bf3701fa9d51a43167ce7ec0c1f30bc090296b
2023-11-06 14:27:03 +01:00
Bartosz Dziewoński
be2909da2a Fix use of buildComparison() in uppercaseTitlesForUnicodeTransition.php
$cont will be an empty array the first time, which is invalid.
Follow-up to 865002b57c.
Caught by Phan in I0d69ea6788304e8a073b7521a217882be7a92993.

Change-Id: I5c219e70e41c34869c03d6cd1ee6b7f1876a2a22
2023-10-24 16:22:49 +02:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
f90d18fe80 maintenance: Migrate some Database::select() calls to SQB
Done semi-automatically via migrateselect[1]. The script only accepted
ascii chars until I found out and fixed it and now I can run it in more
places.

[1] https://gitlab.wikimedia.org/ladsgroup/migrateselect

Bug: T344971
Change-Id: I83b6c424c62a517a0ab3635b64488ea53fd88bab
2023-09-15 18:18:15 +02:00
jenkins-bot
f1db8173fd Merge "maintenance: Replace usages of deprecated WikiPage::doDeleteArticleReal" 2023-09-11 22:24:55 +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
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
jenkins-bot
ca0b7a8053 Merge "Use more narrow database interfaces in maintenance scripts" 2023-02-28 10:44:57 +00:00
thiemowmde
d923d7aa8d Use more narrow database interfaces in maintenance scripts
This makes this code easier to read and to maintain because it's more
obvious why a DB connection is passed. For now this patrch focusses
exclusively on private methods.

Change-Id: Id60dc90b124f4cae1dfbede990f45e3c69491a25
2023-02-27 15:58:37 +00: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
Bartosz Dziewoński
865002b57c Use buildComparison() instead of raw SQL in more maintenance scripts
Bug: T321422
Change-Id: Ibe46e5df64a3a6a6e8042a56e10aa286dd3797dd
2022-11-15 09:54:05 +01:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Umherirrender
6caf78c2c8 phan: Remove PhanPossiblyUndeclaredVariable suppression
Make phan stricter about conditional variable declaration
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T259172
Change-Id: I1f200ac37df7448453688bf464a8250c97313e5d
2022-03-30 19:47:15 +00:00
Reedy
c054b10423 Remove or replace usages of "sane"
Bug: T254646
Change-Id: Ia660ab95353cd8f05c50e60f30d29fd22b018a43
2021-11-22 15:48:03 +00:00
Daimona Eaytoy
762de4cca7 maintenance: Replace usages of deprecated WikiPage::doDeleteArticleReal
Use DeletePage instead.

Change-Id: Icf064d6f8ce609d1119b45377af037ed03e464a4
2021-11-08 14:39:28 +01:00
Petr Pchelko
756eefa6bf uppercaseTitlesForUnicodeTransition: improve userlist format
This script is used to rename things to prepare for unicode
update. The script does not rename the users, instead it generates
a list of users to be renamed with renameInvalidUsernames.php,
but this script output is incompatible with the other script input.
It would be more convinient to be able to directly feed the result
of this script as input to the other script.

renameInvalidUsernames.php expects input as TSV with domain, user_id,
new_user_name. That's what we want to output. Also opening the
output file in append mode is more convenient - that way we can
collect all usernames for renames for all wikis when running
the script with foreachwiki

Bug: T219279
Change-Id: I27e182247d55c635e75027065546285be74934b6
2021-10-04 14:56:01 -07:00
Gergő Tisza
926cfa3b3d Use a constant for 'Maintenance script' username
The user 'Maintenance script' is often used to perform various
automated tasks. Providing it everywhere as a string literal is
error-prone, and errors can be somewhat disruptive (e.g. with
User::newSystemUser with steal=true it can erase the credentials
of a legitimate account). Provide a constant instead.
Also replace existing uses for consistency.

Change-Id: I685a5bfe56bbf1a47f35072f7f7c8be320ee27db
2021-05-03 23:34:26 +02:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Reedy
354848b0cd maintenance: Mark some closures as static
Bug: T274036
Change-Id: Ic959dfddcf2867e4cf26970f375b347f4b41584d
2021-02-07 02:18:30 +00:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
Umherirrender
a3194f2194 Replace deprecated WikiPage::factory/newFromID in maintenance scripts
Change-Id: I5b2d4313f986484368da9b63c9a19892c2328dae
2020-11-12 21:48:21 +00:00
Ammar Abdulhamid
3b19b85ab7 Use MovePageFactory in uppercaseTitlesForUnicodeTransition.php
Bug: T252934
Change-Id: I4029ef79a174270942a1c0d0a7d7829fe8c5a7a0
2020-10-21 19:40:01 +00:00
DannyS712
77781b08c7 Add delete-redirect for deleting single-rev redirects during moves
A new user right, `delete-redirect`, is added (not given to anyone
by default). At Special:MovePage, if attempting to move to a single
revision redirect that would otherwise be an invalid target (i.e.
doesn't point to the source page), the user is able to delete the
target.

Deletions are logged as `delete/delete_redir2`, and the move is
then logged normally as `move/move`, mirroring current delete and
move logging.

To allow for separate handling by Special:MovePage,
MovePage::isValidMove now returns a fatal status `redirectexists` if
the target isn't valid but passes Title::isSingleRevRedirect.
Otherwise, `articleexists` is returned (as previously). Other callers
that don't intend to treat single revision redirects differently
should treat `redirectexists` the same as `articleexists`.

Currently, this deletion (like normal delete and move) cannot be
done through the move api. Since the deletion is only valid when
moving a page, unlike for normal deletion, deleting redirects with
this right cannot be done via the delete api either.

Bug: T239277
Change-Id: I36c8df0a12d326ae07018046541bd00103936144
2020-09-04 03:50:17 +00:00
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
Brad Jorsch
6a8aa4af83 uppercaseTitlesForUnicodeTransition.php: Delete useless redirects
If the lowercase title is already a redirect to the uppercase title, or
the lowercase and uppercase titles are both redirects to the same
target, there's probably no point in renaming it.

Note we still do the rename to the prefixed/suffixed title before
deleting, so the resulting archive and logging rows wind up under the
correct title.

Bug: T219279
Change-Id: I6c5e3ab39a0e136b4a3f96e9c78d36eea636bc4d
2020-04-10 15:08:31 +00:00
Brad Jorsch
79f1338254 uppercaseTitlesForUnicodeTransition.php: Fix suffixing for files
File moves have to have a correct extension. Insert the suffix (if any)
before the extension rather than after it.

Bug: T219279
Change-Id: I244169c43e4cf913b84dc8b2bc09fbf765396b4c
2020-04-06 16:32:59 -04:00
Brad Jorsch
66e88d3bf4 uppercaseTitlesForUnicodeTransition.php: Improve handling of non-moves
Doing the actual page moves first caused the entries in archive,
logging, and so on to either not be moved or to be put to the
prefixed/suffixed title, because the page move created the title and
then mungeTitle refused to use it again later. If we do archive,
logging, and so on first, that doesn't happen.

Also, shouldn't apply the prefix or suffix at all when processing the
redirect table (rd_title), as we're not changing the actual wikitext. We
should only uppercase the rd_title to match what MediaWiki would do if
the redirect were purged.

Bug: T219279
Change-Id: I2224ac7cb7e952c7cff5a576583d4cf1bc05e462
2020-04-04 11:02:20 -04:00
Brad Jorsch
949f853f6f uppercaseTitlesForUnicodeTransition.php: Output moves with --run too
We'll probably want that for reporting back to the communities.

Bug: T219279
Change-Id: Ide03ee43c95b30392fcb9873cfa4b4403ba3e8b4
2020-04-04 10:35:18 -04:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
daniel
9171cbe4ca Title: make newFromText, isValid, and canExist behave consistently.
This patch fixes the documentation of newFromText and makeTitleSafe to
no longer state incorrectly that any Title they return is guaranteed to
be valid. That has never been true.

It also makes canExist() checks a lot stricter, to match the assumptions
of current callers, namely that the title can exist as a wiki page.

Finally, it replaces several existing calls to isValid() with calls to
canExist().

Bug: T229705
Change-Id: I2a483136ec6acca49afb5eb32cb94616672b8fb2
2019-10-08 11:16:11 +02:00
Brad Jorsch
9ef8c9608d maintenance: Script to rename titles for Unicode uppercasing changes
This uses MovePage where possible to try to better keep data in sync.
Archives, log entries, and so on can't do that though.

The script skips User and User_talk pages for registered users, as
renaming the users is more complicated than makes sense to try to
implement here. Use something like Extension:Renameuser to clean those
up; this script can provide a list of user names affected.

Bug: T219279
Change-Id: I157577cb5bedfd347b808c254fb19ae8088818ab
2019-07-09 13:53:43 -04:00