Commit graph

56 commits

Author SHA1 Message Date
Umherirrender
06947613d7 maintenance: Use namespaced classes
This does not include use of MediaWiki\Maintenance\Maintenance,
assuming the maintenance scripts going into the same namespace

Change-Id: I488f95b537ce86eb5e463be7bce3653610dd13d9
2024-10-21 19:08:08 +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
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
daniel
cea8aee05e Make Maintenance::finalSetup require a SettingsBuilder
Maintenance::finalSetup should have access to a SettingsBuilder so it
can manipulates config settings without resorting to global variables.
MaintenanceRunner will always provide a SettingsBuilder when calling
this method, so implementations should be able to rely on always getting
one.

The $settings parameter was introduced as optional in order to maintain
backwards compatibility with implementations that did not declare the
parameter. But these should all have been fixed since.

Depends-On: I8a3699b13bfb4dc15f3bed562731ed9d525651cc
Change-Id: I334a103e02fd905faafc43c7c5b95996bc91fd18
2024-01-08 09:40:18 -05: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
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04: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
Matěj Suchánek
884efbe0e3 Remove WikiRevision::downloadSource
It has been deprecated since 1.31 and it is unused.

Change-Id: I695e7f5d253076829ba9b58bccd7bfc77624c393
2022-11-04 09:24:15 -04:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Umherirrender
5410a5691d snapshot: Add @var documentation for class properties
Change-Id: I80ba53bdeb730a115ab3eec4849a38a13a896cdb
2022-03-09 21:54:18 +00:00
daniel
cf499e8491 Allow config merge strategies to be bypassed.
Sometimes, we need to force an exact value and bypass the default
behavior of merging config variables.

This also renames setConfigValue to putConfigValue, to avoid confusion
about the behavior of that method.

Change-Id: I82c606632b94f974e655a44a0b63394de7a0804b
2022-02-22 22:59:25 +00:00
Ppchelko
44edde6295 Reapply "SettingsBuilder: allow maintenance scripts to manipulate config"
This reverts commit 4f7a4a2477.

Reason for revert: This change is good, just need some preparation in extensions.

Depends-On: I24221be2cedfa132fc94d39d72e4a133cc3cdb12
Depends-On: I5e6119b650e581c6aa5a1132aa071b49cff8b8ca
Change-Id: I5a5a9000751fa3914c9d432eb49475091b3bdb80
2022-01-26 19:21:58 +00:00
Ppchelko
4f7a4a2477 Revert "SettingsBuilder: allow maintenance scripts to manipulate config"
This reverts commit a652f306a5.

Reason for revert: need to prepare extensions first

Change-Id: Iccedf38a8dc964db7c49fd51c971912655122081
2022-01-26 17:24:31 +00:00
daniel
a652f306a5 SettingsBuilder: allow maintenance scripts to manipulate config
Maintenance scripts often need to manipulate configuration settings.
This introduces a way to do this cleanly via SettingsBuilder,
removing the need to rely on global variables.

Bug: T294739
Bug: T294742
Bug: T300128
Change-Id: Ibf443fd564bbbf388cce8ab4dabba55ebca0dfa4
2022-01-26 12:02:56 +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
jenkins-bot
da99ed653f Merge "maintenance: Remove preprocessDump.php" 2021-03-04 22:09:53 +00: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
Timo Tijhof
ec7d35795d maintenance: Remove preprocessDump.php
This script takes an offline XML dump file, containing wikitext pages, and
feeds them through the Preprocessor without actually importing any content
into the wiki as revisions or pages.

The documented purpose of the script is to "get statistics" or "fill the cache".

- I was unable to find any stats being emitted.

- I did find that the called Preprocessor method indirectly writes to
  "preprocess-hash" cache keys, which have a TTL of 24 hours (e.g. Memcached).
  I could not think of a use case for populating Memcached with parse results
  for pages that do not exist on a given wiki.

It was created in 2011 with r80466 (ad8b42449d) without a use case described
or referenced. I suspect it may've been used to help inform the development of
a major change to the Preprocessor around that time, but it doesn't appear to
be needed for that any more, and does not appear to have been aimed at general
usage by site operators. If and when something it is needed for new
developments, it can be easily brought back rather than maintained as-is.

Change-Id: I139aa4ee8c2f92a40e94824c709556dda7ec74ff
2021-01-28 04:09:13 +00:00
Ammar Abdulhamid
d4979d0c10 DumpIterator: Replace deprecated WikiRevision::setText()
Change-Id: I4646ce4890a89df34d3f8b6d055f9cedc9bda9fc
2021-01-25 13:22:28 +02:00
Ariel T. Glenn
a411a8da9a set revision Title before setting text, or there may be no content model
with the reverse order, the content model of the rvision is null,
and it can't be gotten from the title, so dumpIterator dies when
the file option is used instead of a dump.

Change-Id: Ia67097565953f00068399da3225b939fb105ba4a
2021-01-22 13:35:22 +02:00
Umherirrender
eec141e3cc Fix bad use of |= PHP bit operation where = … || bool is intended
Do not use bit operator on bool as it does not work the same way.

|= is not a short form of bool or (||) and assignment (=).
It is the short form of bitwise or (|) and assignment (=)

Change-Id: I64988cd3aeb8f4cbc53b0b866f1ac96f12976cca
2020-08-12 02:33:01 +00:00
Reedy
3b94e2af1c Narrow MediaWiki.Commenting.FunctionComment.WrongStyle
Change-Id: I95d1195f09a806910559a0c5106d472addd3dec4
2020-05-20 03:33:39 +01: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
Umherirrender
b4fe9c4bcc Set method visibility on maintenance scripts
Change-Id: I44c82fbe65e1d002803ce065df6563f06dd39cd4
2019-11-16 22:54:17 +00: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
Umherirrender
a4caa4d0c6 build: Updating mediawiki/mediawiki-codesniffer to 22.0.0
Added spaces around .
Removed empty return statement which are not required
Removed return after phpunit markTestIncomplete,
which is throwing to exit the test, no need for a return

Change-Id: I2c80b965ee52ba09949e70ea9e7adfc58a1d89ce
2018-09-16 15:51:11 +00: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
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
Aaron Schulz
21e71e0235 Use IDatabase type hints in /maintenance
Relatedly, move lockTables()/unlockTables() to IMaintainableDatabase

Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9
2017-04-07 23:37:41 +00:00
Aaron Schulz
30f4b3c103 Replace DatabaseBase => Database in more places
Change-Id: If37a7909056bf2c31a8228cbc84f0fbbf5f1c517
2016-09-28 15:53:02 -07: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
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
Kunal Mehta
4a2ecaa046 Import.php: Use Config instead of globals
Change-Id: I4d1a8c443cfa360c5d388364c580d48fa7124099
2014-10-22 10:35:29 -07: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
umherirrender
e78776373e Fixed some @params documentation (maintenance)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I727deec35a712de0f0c676cc87dfa661f1ee965b
2014-04-17 22:48:32 +02:00
Ladsgroup
16a5102765 Change URLs to mediawiki.org in comments to HTTPS
These are only documentation fixes
http://www.mediawiki.org --> https://www.mediawiki.org

Change-Id: I62ad42be1a3aac410cc53e98ce79389ceddd8988
2014-03-20 16:59:46 +00:00
Siebrand Mazeland
e711503e7a Remove underscore from classes LCStore_*
iPart of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core, and are updated in
this change.

Change-Id: I432dc249d22053728013ae7d0d56c3c398021c5e
2013-11-17 22:09:31 +01: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
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
umherirrender
15abcf71ca Added/Removed spaces around string concatenation
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !

Fixed windows newline style

Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
2013-04-13 13:36:24 +02:00
daniel
ff03cf38cc get rid of Revision::getText
Change-Id: Ia0b16813fa1688b6faccbe8ca81b1099001b1f3b
2012-09-14 18:23:21 +02:00
daniel
b6fe213226 merge latest master.
some tests fail due to logical changes, will fix that in a follow-up

Change-Id: I8a5e4087ecf674fbcf6327c5d168cd401be12400
2012-09-05 17:50:13 +02:00
daniel
9994968774 merged master
Change-Id: Ib2b879c4daa17401eeeb50767c0e5a54254855c3
2012-08-29 15:20:15 +02:00