Commit graph

65 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
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00: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
Kevin Israel
2b1e5e6235 mergeMessageFileList.php: Drop support for PHP entry points
This is no longer needed for Wikimedia wikis; wmf-config/extension-list
now only lists JSON files.

Such support is probably now broken anyway, given that any legacy PHP
entry point would no longer be loaded from file scope since commit
9e708cece7.

Change-Id: Ide08c3aac8f5dc72b0e44f728cb2b6fa9e55d2e6
2023-05-20 16:42:17 -04:00
Daniel Kinzler
9e708cece7 re-apply "mergeMessageFileList.php: move code out of file scope."
This reverts commit 683cd2f4d7
to restore I349ef565a7c08f90a75b0fc6db49f030cb56f6cf.

Reason: fixed a typo that led to message dirs being ignored:
The correct name of the setting is "wgMessagesDirs", the original
patch had "wgMessageDirs".

I confirmed locally that the new version produces the same output
as the old.

Change-Id: I32f45438ba37ed08075aadc9b1d83db88ca5f014
2023-04-12 10:31:15 +02:00
Ladsgroup
683cd2f4d7 Revert "mergeMessageFileList.php: move code out of file scope."
This reverts commit 43f75a9cca.

Reason for revert: Breaks things

Bug: T333966
Change-Id: I279453867ced617b70164f8da9b49dd0620de4b9
2023-04-04 18:23:50 +00:00
daniel
43f75a9cca mergeMessageFileList.php: move code out of file scope.
Move code out of files scope, so mergeMessageFileList can be run from
run.php.

Change-Id: I349ef565a7c08f90a75b0fc6db49f030cb56f6cf
2023-03-31 11:30:20 +02:00
Aryeh Gregor
7b4b0135b9 Use str_starts_with/str_ends_with
All the other ways of doing it were ridiculous and much harder to read,
and usually required repeating the needle expression (to get its
length). I found these occurrences by grepping for various expressions,
but I undoubtedly missed some.

I didn't try replacing the many instances of strpos(...) === 0 with
str_starts_with(...), because I think they're readable enough as-is
(although less efficient). Likewise I didn't try porting strpos(...) !==
false to str_contains(...). For case-insensitive comparisons, Tim
Starling requested that we stick with substr_compare() because it's more
efficient than calling strtolower().

On PHP < 8 these functions will be included with a polyfill via
vendor/autoload.php. This is included at the beginning of
includes/AutoLoader.php, so if our autoloader has been included the
polyfill will be available. This means it should be safe to call these
functions from any code that would not be usable without our autoloader.

Three uses that Tim Starling identified as being performance-sensitive
have been split out to a separate commit for porting after the switch to
PHP 8.

Change-Id: I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9
2022-05-02 10:59:58 +03: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
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
Dan Duvall
aa5f902bee maintenance: Avoid missing l10n cache error in mergeMessageFileList
The `MergeMessageFileList` maintenance class is commonly run prior to
`RebuildLocalisationCache` in bootstrapping a multiversion MediaWiki
installation. However, when the l10n cache is configured but not yet
built and a wiki's `$wgLanguageCode` is set to anything other than 'en',
all maintenance scripts will fail during setup.

Forcing `$wgLanguageCode` to 'en' just prior to the maintenance class
execution works around this issue. It was cargo culted from an identical
workaround in `RebuildLocalisationCache`.

Note that this issue may not be exclusively related to maintenance
scripts but of any post-setup script that attempts to run before l10n
caches have been built as failure occurs when `include/Setup.php`
attempts to set the `$wgContLang` global using a direct call to
`MediaWikiServices->getContentLanguage()` which in turn instantiates the
primary and fallback languages and attempts to preload the missing
cache. This root issue may be solved once `$wgContLang` is fully
deprecated using `DeprecatedGlobal` which will defer the call to
`getContentLanguage()` until the first method call on the global object.

For now, however, this workaround is necessary for successful
bootstrapping.

Change-Id: Ie62e4b8f33ad63813f37a59eacb9f47493a2d4ef
2021-03-02 21:41:23 -08:00
Dan Duvall
de5323e218 maintenance: mergeMessageFileList should be DB_NONE
The `mergeMessageFileList` maintenance script does not need database
access and will need to be run in offline environments such as those for
building container images.

Bug: T260827
Bug: T238436
Change-Id: I3b10482e227e2414857d020526f00dc2116ef73e
2021-03-02 21:21:19 -08:00
Ahmon Dancy
4433207f48 mergeMessageFileList.php: Improve error handling
If the call to file_put_contents fails, say something and exit
non-zero instead of silently ignoring the error.

Additionally, don't write a newline to STDERR in quiet mode.

Change-Id: I3b69c6c40fea6f689b6e1a4d550e87fafd200410
2021-02-26 21:29:11 +00: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
2d3692e668 Remove phpcs suppression of ValidGlobalName.wgPrefix
Sniff was renamed, phpcs violations are already
suppressed in phpcs.xml, no longer need these
individual line suppressions

Change-Id: I92ca4c6d576f1f0abada103a218155cc3aae38dd
2020-09-29 21:58:14 +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
Daimona Eaytoy
23daef5c18 Remove dead properties
*LogPage::timestamp was introduced with r4919 back in 2004, and is unused
since then.
*ApiMain::mCommit was introduced in r33133, then removed in r33381 but that
line was forgotten.
*SpecialRecentChangesLinked::mResultEmpty was introduced in r36682, then 
removed at some point with this leftover.
*SpecialStatistics::hook, introduced in r54511 and unused since then.
*MergeMessageFileList::hasError introduced in Id4b16083435ef7f4fce31861c72889e664d07236
and removed in I3d9cf1d614dacaa91fb2092019ccf1d14d61ccab with a leftover

Change-Id: Ie15c148a3217ee8da62874840f3ef7739893f69e
2019-09-07 16:34:55 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
Thiemo Kreuz
b7cd670cb7 maintenance: Remove unused code from several maintenance scripts
The most notable removal is done in the orphans script. This code was
really never used. Brion introduced it in 2005, already disabled.

I have all the respect for what Brion did. I just think it does not make
much sense to keep code around for so long if it does not work anyway,
and must be rewritten from scratch anyway now that we have multi-content
revisions and such.

Change-Id: I4e8050929f90e44a6e6051bf938993a8b0cdf649
2019-03-03 16:57:19 +00:00
Fomafix
204126e7c7 Simplify strings in PHP code
Change-Id: I481810ade68b0c5a5be21d22e2a107646d5813e6
2019-03-01 22:16:26 +01: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
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01: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
Niklas Laxström
96effdf8f3 Fix mergeMessageFileList.php --extensions-dir extensions:skins
Only last directory of multiple was being used.

Follows up e74bc3b32e

Change-Id: I30190a30c387f1c34a41f9bbc033d421be631756
2017-11-07 17:48:06 +00:00
Chad Horohoe
76680021f8 Don't hard fail when we couldn't find an entry point for an extension
It doesn't make a ton of sense, it's just pointing out that we have
a weird extension for which we cannot detect a standard entry point
for. These (unfortunately) exist, but they're easily worked around
using --list-file

Removing the hard failure allows you to use the two options in
tandem... --extension-dir for the initial pass and then --list-file
for the weirdo outstanding ones

Change-Id: I3d9cf1d614dacaa91fb2092019ccf1d14d61ccab
2016-12-02 00:31:11 +00:00
Mukunda Modell
e74bc3b32e Support multiple extension-dir paths to be passed to mergeMessageFileList
If scap is modified to pass the path to both extensions/ and skins/ then
the extension-list file in wmf-config will no longer be needed, eliminating
many headaches. (refs T125678)

Bug: T125678

Change-Id: I4fd0c99d68fa32bf2378691955850a1be2c022df
2016-03-16 15:35:07 -05: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
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Mukunda Modell
7959f93c30 require_once instead of depending on the return value of include_once
return value from include_once is unreliable, it could be the value
of a 'return;' statement in the included file, or it could be false
when the file wasn't readable. This was breaking deployments because
one of the extensions had "return;" which caused include_once to
return a falsy value.

Change-Id: I48b9a55d5f9e85efe515d87b56b60ee71f939842
2015-04-22 17:37:19 -05:00
Kunal Mehta
338de7faac mergeMessageFileList: Support reading extension/skin.json files
No more hacky reading of PHP files!

Bug: T94756
Change-Id: I0a92f8904bbc422d5c893f7c0af2daedf7576cf0
2015-04-05 23:28:17 -07:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
Siebrand Mazeland
cb8a938105 Pass phpcs-strict on maintenance/ (4/8)
Change-Id: Ib9ee255740681f0d32d76b75ef33b369bc87bcc1
2014-04-23 10:26:09 +02:00
Siebrand Mazeland
2f7b68ffde Rename $wgExtensionMessagesDirs to $wgMessagesDirs
This is a better name, as we'll also be adding core and the installer i18n
to this.

Change-Id: Ic4c5849654aef54f3e5aea01a2d68e47d148b9bd
2013-12-20 17:02:18 +01:00
Roan Kattouw
6380e81cd0 Add support for JSON i18n files
Implementation for https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format

Add $wgExtensionMessagesDirs, which tracks the directory
(or directories) where each extension stores it's JSON i18n files.
In this commit only support for messages is implemented, but adding
support for other i18n variables (e.g. magic words) is easy to do later.

To be backwards compatible, an extension can specify both
$wgExtensionMessagesFiles and $wgExtensionMessagesDirs. Older versions
of MediaWiki will just work, and newer versions will use the JSON files
while ignoring the PHP file (except if the PHP file contains non-message
data like magic words).

Misc changes:
* Updated mergeMessageFileList.php to output both
  $wgExtensionMessagesFiles and $wgExtensionMessagesDirs

Change-Id: I8d137e15e1670880a9847263e6ce796c62a4670d
2013-12-20 14:34:06 +01:00
umherirrender
f153998317 Fixed spacing
- Removed double spaces
- Added space after if/switch/foreach
- Removed space on elseif
- Added space around parentheses
- Added newline at end of file
- Removed space before semicolon at end of line

Change-Id: Id40b87e04786c6111e6686d7f7eea1e588bdf37d
2013-11-19 19:03:54 +01:00
Reedy
8da7f5eeff Added $wgExtensionEntryPointListFiles for use with mergeMessageFileList.php
Going to be used to change target file for labs vs production

Change-Id: Id4b16083435ef7f4fce31861c72889e664d07236
2013-10-08 17:21:58 +01:00
umherirrender
24bfde2710 Fix spacing and break some lines
Change-Id: Ia57685d8858e02e399ad5c75ce64d12609d340ac
2013-08-24 17:06:25 +02:00
Ori Livneh
17ad68087c Discard comments in mergeMessageFileList.php's --list-file file
We're currently working around a bug in an extension (bug 51643) by deviating
from lexicographical order in extension-list to ensure that one extension is
loaded before another. It'd be nice to be able to document that in the file
itself, but there is no convention for adding comments to the file;
mergeMessageFileList.php treats every line as a file name. We've previously
talked about including a comment header in the file as part of our reponse to
bug 50347.

This patch adds some minimal syntax-handling to mergeMessageFileList.php which
causes it to treat as a comment any substring starting with '#' and extending
to the end of the line. This change implements part of what aude projected for
Gerrit change 71056, but I don't see the harm in pushing ahead with it here.

Change-Id: I4b296aa69ad77ecb51f1a0e27ce6a698cf09732b
2013-07-23 21:58:30 -07: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
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
Tim Starling
9c5d996773 mergeMessageFileList.php: abort on read error
If there is a parse error or if one of the files in the extension list
doesn't exist, exit with an error. mw-update-l10n has set -e so it will
abort without syncing the new file.

Change-Id: Idaad65783127b075626c102a8dc02e22df1588b7
2013-04-05 12:03:31 +11:00
jenkins-bot
c3e56c9eb4 Merge "Respect --quiet in mergeMessageFileList.php" 2013-02-04 09:31:03 +00:00
Antoine Musso
f6b92231fd style: normalize end of files
By PSR2 PHP Standard, the files should ends with exactly one newline.
Some of our files have 2 or more and some other were missing a newline.

Fix almost all occurences of CodeSniffer sniff:
PSR2.Files.EndFileNewline.TooMany

I have not fixed the selenium files, I believe we will drop them.

Change-Id: I89fca8c1786fee94855b7b77bb0f364001ee84b6
2013-02-03 15:04:39 +01:00
Tim Starling
672caa9c4c Respect --quiet in mergeMessageFileList.php
To go with Ic6db1d8a

Change-Id: I95cbd4c6f47fe741da93c7d3260196cce5f29275
2013-01-31 16:36:06 +11:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
b2a7aafbed Improve documentation of maintenance scripts.
Change-Id: I93e80edcfc3dc2d5630f7514808cafc22daf39f7
2012-07-25 21:35:53 +02:00