Commit graph

28 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
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Umherirrender
d0786734e8 maintenance: Check return of preg_match_all in generateJsonI18n.php
Help phan to understand the values in $matches

Bug: T304887
Change-Id: Ie9610a6e83731468311edb3ed17f80fc509de385
2022-03-29 00:32:10 +00:00
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
Thiemo Kreuz
bb786be640 Add /** @var SplFileInfo $fileInfo */ docs where needed
Change-Id: Ia844af3347db52f9f004892578ba4aefac7dd875
2019-03-14 15:04:05 +01:00
Thiemo Kreuz
cc329a5b06 Update PHPDoc types in several maintenance scripts and related
There is like a billion of these in our core codebase. I would love to
update them all. But I don't have the time, at least not to do them all
at once.

TL;DR: It's an improvement. :-)

Change-Id: I0a9c51bdcf0f261f971586bb8703f418324b0f98
2019-03-07 17:54:26 +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
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
Erik Bernhardson
e5b8bf4942 Un-blacklist PhanUndeclaredVariable
Undeclared variables are a very common error type that we want to catch
as often as possible. To avoid needing to refactor a variety of global
level code (mostly in old-style maintenance scripts) this ignores
undeclared variables in global scope. This is still a good improvement
over what was happening previously.

Change-Id: I50b41d571724244552074b9408abbdf6160aca59
2017-01-18 13:07:39 -08: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
Kevin Israel
5f6fdaab77 generateJsonI18n.php: Remove features that should no longer be needed
* Removed --langcode, which was for converting core messages files.
* Do not generate backward compatibility shims. MediaWiki 1.19 will
  enter end-of-life status in May 2015.
* Print a special error message for shims, which is different from
  the one that used to refer to --langcode.
* Removed extra newlines from error messages.

Change-Id: Ic8498fbdd7c2bd6e30ddbd96da85b2b8b23d706b
2015-04-30 15:59:13 -04:00
umherirrender
d15f1cc5e1 Break some long lines in maintenance, skins, tests
Change-Id: I5d86ad3e0c90e09440268a670f5af3e2bf080612
2014-07-24 19:03:17 +02:00
Adam Roses Wight
0b655e4810 Add --supplementary flag to generateJsonI18n
Recursively searches the DonationInterface extension for i18n files and
performs default conversion on the lot.

Usage:
	php maintenance/generateJsonI18n.php \
		--extension DonationInterface --supplementary

Change-Id: I8e61c3d0f34394c0d766cf9532df9ac221ce7405
2014-05-10 15:40:27 +01:00
Adam Roses Wight
68bdc4f7f4 Adds an --extension option to generateJsonI18n
Usage:
	php maintenance/generateJsonI18n.php --extension WikiLove
Performs the default conversions in $IP/extensions/WikiLove/, replacing
the WikiLove.i18n.php file with a backwards-compatibility shim and porting
messages to the WikiLove/i18n/ directory.

This patch has the side-effect of making the second cmdline argument in
the ordinary usage optional.  When omitted, we will make the default guess
as to $jsondir, that it should live in the same directory as the .i18n.php file.

Change-Id: I6246d2c4eb7327d6dcc503421b71ffdcaf01769c
2014-05-10 15:38:23 +01:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
jenkins-bot
ba8a835dcb Merge "JSON i18n shim: Only register LocalisationCacheRecache handler once" 2014-04-22 10:11:33 +00:00
Kevin Israel
cdf358807c generateJsonI18n.php: Use tabs for indentation
Bug: 63444
Change-Id: Iaaf6b1a08c316f29c18fd5c9494decee401a43f1
2014-04-21 16:54:31 -04: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
Kevin Israel
e0736bd1cd JSON i18n shim: Only register LocalisationCacheRecache handler once
Because LocalisationCache::recache() includes PHP shims each time it is
called (e.g. for a different language), in such cases as automated testing,
the shims could end up registering handlers many times instead of only
once, leading to a rather significant, progressively worse slowdown.

Checking whether the shim has already been loaded, and if so, not
registering the handler again, avoids this performance problem.

I also made the shim compatible with PHP 5.2 (minimum PHP version for
MW 1.17 - 1.19) by avoiding closures and __DIR__, and I added a
--shim-only option to generateJsonI18n.php to allow regenerating
existing shims.

Bug: 63928
Change-Id: I3bb39e7d2bb094873061b3b2adf7066bf26c1b71
2014-04-17 08:59:07 -04:00
Niklas Laxström
3e05447e38 Add newline at the end of converted json files
1) Some text editors add missing newline at the end of the file
automatically.
2) It's generally a nice thing to do to avoid messing up display
for example when cat'ing a file

Change-Id: Icf636721c4edcf4ae706c9a346fe36233928cae8
2014-04-01 10:45:39 +00:00
Adam Roses Wight
8594eba70b Comment generated code to explain the i18n JSON migration.
Change-Id: I4d41be5a70eab5ceeec3be0bd544e4a87504572a
2014-03-26 10:32:18 -07:00
umherirrender
2000672ac3 Fixed spacing
- Added spaces after if/foreach/catch
- Added new line before end of file
- Added or removed spaces before/after parenthesis, comma
- Added spaces around string concat

Change-Id: I0590070f1b3542108e242730e8d9a3ba9831e94f
2014-03-20 20:37:30 +00:00
Alexandre Emsenhuber
d0ddc9208e Use "elseif" instead of "else if" in PHP
Per https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#C_borrowings

Change-Id: I5e3a301c2f3c5ec6b965500c43d16022b8b82e59
2014-03-15 13:59:15 +01:00
Siebrand Mazeland
d32179aff9 Do not suggest to use unused local vars
Change-Id: I4c2ab60054304593a9fd873b28e160b9d07442f0
2014-01-08 19:27:10 +01:00
Hydriz
20934e595a Fix missing apostrophe in maintenance/generateJsonI18n.php
Change-Id: I3f678df09853bfdb6295985c81d4469024aecfbb
2014-01-08 20:52:43 +08:00
Niklas Laxström
2d01b8be9f generateJsonI18n.php: replace i18n.php with a shim
Change-Id: I4b8f1d9c0b13fca3aae0bec5c614218e917691ef
2013-12-23 08:28:25 +01:00
Roan Kattouw
5e6c3b17ce Script to convert PHP i18n to JSON
Change-Id: I769d5a106bf6214127cee2056cd64c18ca4182c6
2013-12-20 13:40:30 +00:00