Commit graph

17 commits

Author SHA1 Message Date
Dreamy Jazz
d814e25a81 Test exportSites.php and importSites.php
Why:
* Maintenance scripts in core have low test coverage.
* Testing scripts which are not overly complex should create
  less complex tests that easily raise test coverage.

What:
* Create a test for both exportSites.php and importSites.php which
  checks that the XML file produced by exportSites.php can be
  parsed and produces the same sites table config as was exported.

Bug: T371167
Change-Id: I3eb1b86803ee2413e624f9ffe699a60161103758
2024-09-16 11:51:34 +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
James D. Forrester
4cf719019a Namespace remaining files in includes/site
Bug: T353458
Change-Id: I38da09f28cd68add721ba7b05f351acb56515d95
2023-12-14 14:57:34 -05: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
Alexander Vorwerk
0961f9e698 (import|export)Sites.php: Move parent::__construct call above addDescription
Bug: T314258
Change-Id: Ie0cfbe719d3d2b743f3ef629fb3062c06a39beb1
2022-07-31 22:08:45 +02:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
DannyS712
2e3bdb3498 Miscellaneous documentation updates
Update references from .txt to .md when files have moved, a few other
tweaks, no changes to code.

Change-Id: I0bfd38c47b9fb0fc11ae98a0a674af66fb4c5a84
2020-02-16 04:38:38 +00:00
Kunal Mehta
e0193327bd Fix MediaWiki.Commenting.LicenseComment.InvalidLicenseTag errors
Change-Id: I936c3f5fca1a0061f215e80469f5d882cb32ee29
2018-05-23 16:23:42 -07:00
Umherirrender
69dbaf3f88 build: Updating mediawiki/mediawiki-codesniffer to 17.0.0
Change-Id: Ib494b47c54fe6354d166055b1e1b31d3583bb992
2018-03-29 21:53:10 +02: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
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
daniel
eb46307b00 Introduce top level service locator.
The service locator, MediaWikiServices, is intended to facilitate
"manual" dependency injection in static entry points.

See also the Dependency Injection RFC T384 and Service Locator
RFC T124792 for details.
The following key points were implemented according the
discussion surrounding these RFCs:

* a configurable DI container that allows extensions to add and replace services.
* no auto-wiring, since it's prone to add confusion in large and complex applications.
* no 3rd party framework, since they typically do too much.

The following services in MediaWiki core are made accessible via the service locator
mechanism to showcase the bootstrapping mechanism:

* ConfigFactory and MainConfig
* SiteLookup and SiteStore

However, the implementation of these services was not yet converted to using proper DI
throughout the code.

Bug: T124792
Change-Id: I3c25c0ac17300d3dd13e1cf5100558a605eee15f
2016-04-02 18:07:28 +03:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Vivek Ghaisas
96c93a8cce maintenance/exportSites: Fix minor whitespace issue
Opening parentheses should be followed by a single space.

Change-Id: I9d73334c3c79bf5277248c56e0f146a91938b35c
2015-06-20 23:49:49 +03:00
paladox
dca469bb87 Fix phpcs warnings
Bug: T102614
Change-Id: Iecea365f83bbb0c336b58f1cfdebfc9b1112087e
2015-06-18 20:13:37 +00:00
umherirrender
d8821f2b0b Fixed spacing
- Removed space after casts
- Removed spaces in array index
- Added spaces around string concat
- Added space after words: switch, foreach
- else if -> elseif
- Removed parentheses around require_once, because it is not a function
- Added newline at end of file
- Removed double spaces
- Added spaces around operations
- Removed repeated newlines

Bug: T102609
Change-Id: Ib860222b24f8ad8e9062cd4dc42ec88dc63fb49e
2015-06-17 20:22:32 +00:00
daniel
ca3be1e13d Maintenance script for exporting site definitions
Bug: T87178
Change-Id: I40fd6aaa8f47bad3d595d5c190036bf04d13c12a
2015-02-20 12:09:34 +01:00