Commit graph

52 commits

Author SHA1 Message Date
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
Antoine Musso
ad1609059f merge msg script now detects extensions main files
maintenance/mergeMessageFileList.php is used by `scap` to establish a
list of message files to load. To do that, it read extensions paths from
a manually maintained list: wmf-config/extension-list.

This patch adds an optional automatic detection system to add extension
messages. That will reduce the risk of forgetting to update the
extension-list file and will be of good use on labs.

The new parameter is named --extensions-dir and takes a path holding
MediaWiki extensions. The script will take the directory names there and
attempt to load a file named `Foobar/Foobar.php`. --list-file is still
required, you can skip it using /dev/null.

Synopsis:

php maintenance/mergeMessageFileList.php \
 --list-file /dev/null \
 --extensions-dir /srv/mw-trunk/extensions

Script will bail out whenever an expected PHP file is not found and will
list all of those "missing" files.

Change-Id: I8ab15f899f0333428fd8b2a98c58c07c2fce2962
2012-07-06 20:16:01 +02:00
Catrope
e69afa4340 Fix https://gerrit.wikimedia.org/r/4830 , I botched the conflict
resolution there

Change-Id: I7d563851e8b89c249105e91ceed71f747732084f
2012-04-12 17:48:03 -07:00
Catrope
d242205f72 Revert "Bit more refactoring"
This reverts commit 5586e73fac.

This broke mergeMessageFileList.php by no longer running the extension
setup files in the global scope.

Change-Id: I8f22d0b3e938ba617f4297802edfc2012d78cc9b
2012-04-12 17:20:00 -07:00
Siebrand Mazeland
a63b207fff Bye, bye $wgExtensionAliasesFiles (deprecated in 1.16). 2011-12-25 23:09:26 +00:00
Sam Reed
5586e73fac Bit more refactoring 2011-10-11 21:34:53 +00:00
Sam Reed
c2884b8bd1 Don't reinvent the wheel to do parameter existence checking
Stops running the code outside the class when there's no point attempting it
2011-10-11 21:28:31 +00:00
Roan Kattouw
86a5b6c87f Merge r81725 from 1.17wmf1: add parent constructor call so $IP is set properly 2011-02-08 12:19:59 +00:00
Chad Horohoe
26505b170a Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.
Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
2011-01-13 22:58:55 +00:00
Alexandre Emsenhuber
9f5d06527c Part of bug 26280: added license headers to PHP files in maintenance 2010-12-16 19:15:12 +00:00
Sam Reed
b6f2713294 Remove unused variable
Remove 1 unused global
2010-07-24 21:11:29 +00:00
Sam Reed
659778619c Stylize maintenance folder.. 2010-05-22 16:50:39 +00:00
Tim Starling
0956ad88ed Don't include the old ExtensionMessages.php when you're building a new one. Otherwise renames break. 2009-11-27 00:18:59 +00:00
Tim Starling
1d8d173ecc Assorted tweaks. 2009-09-18 05:23:10 +00:00