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
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
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
* Change `$services->getDBLoadBalancerFactory()->waitForReplication()`
to `$this->waitForReplication()`
* Change various complicated expressions to `$this->getReplicaDB()`
and `$this->getPrimaryDB()`
* Remove unused variables
Change-Id: Ia857be54938a32bb6288dcdf695a35cd38761c3c
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
$cont will be an empty array the first time, which is invalid.
Follow-up to 865002b57c.
Caught by Phan in I0d69ea6788304e8a073b7521a217882be7a92993.
Change-Id: I5c219e70e41c34869c03d6cd1ee6b7f1876a2a22
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
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
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
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
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
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
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
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
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
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
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
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