Commit graph

112 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
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02: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
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08: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
Bartosz Dziewoński
64001f0ecd WikiImporter: Pass Authority for permissions instead of global context
Pass Authority to WikiImporter constructor, instead of looking at the
user from RequestContext::getMain(), and skipping this check if
$wgCommandLineMode is true.

Maintenance scripts now use UltimateAuthority, to match the original
intent of skipping permission checks, see 2ed55f42 / r96311.

The Authority parameter to WikiImporterFactory::getWikiImporter() is
optional for now for backwards-compatibility. It should become
required later after deprecation.

Change-Id: Iea1d03dcdcbda2f9a9adbff1b0d319efd22c4d86
2023-12-11 19:15:11 +01:00
Reedy
bcf40299e4 importDump: Unconditionally call $importer->setUsernamePrefix()
In the current form, it results in `assignKnownUsers` being set to false.
Which is contradictory to the docs for `--no-local-users`.

Also document the default `username-prefix` and mention trailing `>` being added.

Bug: T346898
Change-Id: I00d3ecbfb468a38b03eb6c98f224d1868006a2ee
2023-09-20 13:45:51 +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
Daimona Eaytoy
0d29958cc1 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ib619ead0f397188d828e6e5dfc80ed1fa7175c7d
2023-06-08 21:37:07 +00:00
Aaron Schulz
c4db454cab rdbms: remove IMaintainableDatabase::deadlockLoop()
This method does not actually work since deadlocks cause transaction
rollback on the service side, which does not match the way it uses
begin() and commit(). Deadlocks would just become transaction state
errors.

Change-Id: I64ce8a406ac05b997d947cd5f30b26f68bbb8e18
2022-12-20 23:34:46 +00:00
Umherirrender
eaac04cd3b Replace deprecated wfReadOnly/wfReadOnlyReason
Bug: T283978
Change-Id: I49f8c7bf1162dc834a1708e2e581f6fb264bbd0a
2022-06-20 15:35:24 +00:00
Umherirrender
5410a5691d snapshot: Add @var documentation for class properties
Change-Id: I80ba53bdeb730a115ab3eec4849a38a13a896cdb
2022-03-09 21:54:18 +00:00
Gergő Tisza
d3004df478
importDump.php: handle fopen error
Bug: T293569
Change-Id: I13c05d754513f01f6a3f293d299cb9d55cc19265
2021-10-17 21:34:41 -07:00
Umherirrender
a7bb7cc5c5 Remove unreachable code after exception/die/exit
Change-Id: Ia81903fb2a8157625fbe63115097eccc1161b5db
2021-09-03 23:14:28 +00:00
ZabeMath
3c978f6fc6 WikiImporter: inject services
This patch injects services into WikiImporter. It also adds
a WikiImporterFactory service for creating WikiImporter
instances.

Change-Id: I2966297e5728fca1ae8280361f1008cef6c6041b
2021-05-24 23:10:07 +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
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Reedy
c7eb28aac9 Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
2020-05-21 01:06:05 +00:00
DannyS712
883469ad6f Fix parameter documentation for dump methods for handling revisions
The only caller passes a WikiRevision, which does not extend the
Revision class; the parameter is a WikiRevision, not a Revision

Bug: T246284
Change-Id: Iaf25b692e6093eab6e12439864bae97c96a3b9db
2020-05-05 02:04:32 +00:00
Reedy
8ba1c75559 Replace wfWaitForSlaves() with LBFactory::waitForReplication()
Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
2020-05-02 02:00:01 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Reedy
8f9b0e9157 Mark some more BackupReader functions public
Partial revert I44c82fbe65e1d002803ce065df6563f06dd39cd4

Bug: T241426
Change-Id: Ic35f6765f308d2a6676c788c7066a7124cec3108
2019-12-24 21:28:25 +00:00
Reedy
4b96c825f3 Mark BackupReader::reportPage() public
Partial revert I44c82fbe65e1d002803ce065df6563f06dd39cd4

Bug: T238984
Change-Id: If7f7899c626c96b7024f84e73886bd80636a3a2d
2019-11-25 18:48:27 +00:00
Umherirrender
b4fe9c4bcc Set method visibility on maintenance scripts
Change-Id: I44c82fbe65e1d002803ce065df6563f06dd39cd4
2019-11-16 22:54:17 +00:00
Umherirrender
7363e38ddf Set public for override of Maintenance functions
The following function are set to public in the parent class and cannot
have another visibility in subclasses
Maintenance::__construct
Maintenance::execute
Maintenance::getDbType
Maintenance::validateParamsAndArgs
Maintenance::setDB

Change-Id: I0cd6514642d479aca20f1221bf673b0713c21631
2019-10-09 20:41:33 +02: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
Daimona Eaytoy
5d40cff293 maintenance: Explicitly declare all used properties
All uses were checked with codesearch, and the visibility was chosen as
strict as possible.

Change-Id: I56666299cc04ccc418e05949422876583982eb3c
2019-09-09 09:47:41 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Thiemo Kreuz
06c1a5976c maintenance: Deprecate Maintenance::hasArg/getArg with no param
Benefit of keeping the parameter optional:
- In maintenance scripts that really only have one parameter, it's a
  little more convenient to be able to ask for *the* parameter via an
  empty getArg().

Disadvantages:
- It's unclear what getArg() means when there is no indication *which*
  argument the code asks for. This might as well return the last
  argument, or an array of all arguments.
- In scripts with two or more arguments, it's confusing to see
  getArg( 1 ) next to an empty getArg().
- The methods are more complex and a bit more complicated to use with
  the extra feature of this parameter being optional. Users need to
  look up what the default is to be able to use it safely.

Change-Id: I22a43bfdfc0f0c9ffdb468c13aba73b888d1f15e
2019-03-29 14:37:46 +01:00
jenkins-bot
9c0eeb1a2d Merge "Fix option name in maintenance/importDump.php" 2018-10-04 01:29:14 +00:00
Brad Jorsch
986dfa8f35 Fix option name in maintenance/importDump.php
Bug: T200138
Change-Id: Icc5d9878bc3ebdf03efec9161b220ad0bf55dc9a
2018-10-03 14:50:14 -04:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06: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
Yifei He
6db33c1a4b [WikiImporter::notice] use wfDebug instead of echo in notice()
Make the default notice implementation of notice() function to
send the notice to wfDebug() instead of simply echo to prevent XSS

Bug: T177997
Change-Id: I9ffb597e0642afc1603cdd15e2d09c6f2584b448
2017-12-22 12:24:42 +08:00
jenkins-bot
d0142faf25 Merge "Add missing @throws in Importers" 2017-12-06 12:49:50 +00:00
WMDE-Fisch
a2f68a58cd Add missing @throws in Importers
Change-Id: I02760e59d73f4278cca87483ab4578b6e76b2324
2017-12-06 12:38:08 +00:00
Brad Jorsch
96bd79b4a3 Avoid DB rows with usable names but ID = 0 by introducing "interwiki" usernames
Importing revisions in MediaWiki has long been weird: if the username on
the imported revision exists locally it's automatically attributed to
the local user, while if the name does not exist locally we wind up with
revision table rows with rev_user = 0 and rev_user_text being a valid
name that someone might later create. "Global" blocks too create rows
with ipb_by = 0 an ipb_by_text being a valid name.

The upcoming actor table change, as things currently stand, would
regularize that a bit by automatically attributing those imported
revisions to the newly-created user. But that's not necessarily what we
actually want to happen. And it would certainly confuse CentralAuth's
attempt to detect its own global blocks.

Thus, this patch introduces "interwiki" usernames that aren't valid for
local use, of the format "iw>Example".[1] Linker will interpret these
names and generate an appropriate interwiki link in history pages and
the like, as if from wikitext like `[[iw:User:Example]]`.

Imports for non-existant local users (and optionally for existing local
users too) will credit the edit to such an interwiki name. There is also
a new hook, 'ImportHandleUnknownUser', to allow extension such as
CentralAuth to create local users as their edits are imported.

Block will no longer accept usable-but-nonexistent names for 'byText' or
->setBlocker(). CentralAuth's global blocks will be submitted with an
interwiki username (see Ieae5d24f9).

Wikis that have imported edits or CentralAuth global blocks should run
the new maintenance/cleanupUsersWithNoId.php maintenance script. This
isn't done by update.php because (1) it needs an interwiki prefix to use
and (2) the updater can't know whether to pass the `--assign` flag.

[1]: '>' was used instead of the more usual ':' because WMF wikis have
many existing usernames containing colons.

Bug: T9240
Bug: T20209
Bug: T111605
Change-Id: I5401941c06102e8faa813910519d55482dff36cb
Depends-On: Ieae5d24f9098c1977447c50a8d4e2cab58a24d9f
2017-11-30 13:12:44 +11: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
Mark A. Hershberger
e8bad2adfb importDump.php: Declare uploadCount property
Bug: T174255
Change-Id: Ic5014821a8f10ab29b729104cd7d4e434085e2f2
2017-08-26 20:01:11 +00:00
Mehmet Mert Yıldıran
4951c2b54f Add skipping to nth page option/ability for dump importing process
Usage: php importDump.php --skip-to 271500 /path_to/dumpfile.xml.gz

When importing a database dump and the import process crashes
(for random reasons) after a certain number of pages, the
"--skip-to" parameter allows restarting the import process at
a certain page instead of starting the import from scratch.

Change-Id: Ib36063b69d6846fc197800bba44287493b0632c0
2017-06-09 01:01:05 +03:00
Subin Siby
1f8b491dd2 Disable statistics update on import with maintenance/importDump.php
Disable updating statistics in importDump.php to quickly finish imports from command line.

Bug: T144600
Change-Id: Ib827c068fb20cc03aab47e3106d489f18be1dac6
2017-01-03 20:26:09 +05:30
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
415953d91e Fix a bunch of call-time pass-by-reference errors
Change-Id: I3bd8e7c4d2dca465957a353cb7dc2a906699ff6a
2016-02-10 14:12:58 -08:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Reedy
44cebea941 Update wfGetDB calls in Maintenance scripts to use getDB()
Change-Id: I9ad6745d84506b736dae94747256caac89715899
2016-01-02 16:58:23 +00:00
Andrew H
8d7f00dad9 Add --rootpage parameter to importDump.php
The --rootpage parameter will import pages as subpages
of a specified page.

Bug: T72272
Change-Id: Ie026b091275668765ea06e947d45bed64354f2cb
2015-12-27 02:53:34 +00:00
georggi
b14d581dab Handle missing titles and usernames when importing log items
Bug: T121338
Change-Id: Idf95263e4f22225509da4ee07fcb14383028894b
2015-12-19 09:50:22 +00:00
umherirrender
96473ea6e4 phpcs: Fix some "Assignment expression not allowed"
Found by new version of mediawiki/codesniffer
https://integration.wikimedia.org/ci/job/mediawiki-core-phpcs/1939/consoleFull

Change-Id: I673f71fd0dfc8d6ba1ce6c3d5da21787ff95cb32
2015-11-01 21:07:00 +01:00
Aaron Schulz
f5e6756da7 Remove DeferredUpdates::doUpdates call in CLI scripts
Core already handles this by not letting them build up.
They run after each main DB commit.

Change-Id: I37c2a60e2df579ed59b2a8f3a7679d1d380e6337
2015-10-20 11:18:38 -07:00