Commit graph

262 commits

Author SHA1 Message Date
Lucas Werkmeister
49ba7597a1 phpcs: Exclude some docs/ subdirectories
Based on .eslintignore; docs/html/, in particular, can contain a handful
of PHP files that shouldn’t be linted. (All four directories are
generated, see .gitignore and docs/html/.gitignore.)

Change-Id: I0fb06d4a6c716680850de93096395650afe3802b
2023-07-21 10:57:23 +02:00
Umherirrender
3bbd8e7984 tests: Resolve maintenance phpunit filename deprecation errors
PHPUnit wants the filenames of the tests to match the class name being
tested.

Bug: T337333
Change-Id: I3d568521121f8cd5e15e87a7ee2ba4800139fa41
2023-07-09 22:34:35 +02:00
Nikolas Nyby
e87316c4a4 Resolve GlobalFunctions phpunit filename deprecation errors
PHPUnit wants the filenames of the tests to match the class name being
tested.

Bug: T337333
Change-Id: Icc450c900b6d4589515d86889403043a5e4ef690
2023-07-01 09:30:42 +00:00
Umherirrender
a01256c5b8 build: Cleanup of .phpcs.xml
Use inline suppression for known exception from eval/passthru/query call

Change-Id: Ie85ea5698a615adf07e4e391bf06d102149effd5
2023-04-13 12:57:51 +02:00
Fomafix
3dce04e1a5 Rename PHP classes to match filenames
Also change the letter case in the file names to be consistent to other
files in includes/specials.

The PHPCS exclude-pattern for these files on
MediaWiki.Files.ClassMatchesFilename.NotMatch can now removed.

The old class names are still available as aliases and are deprecated
now.

Change-Id: Id71f5a5ce456caf522c95c477487e14f366c1b40
2023-03-16 12:55:20 -04:00
libraryupgrader
7375f3a5fe build: Updating mediawiki/mediawiki-codesniffer to 41.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Usage.ForbiddenFunctions.eval

Change-Id: I6fd0a9296c88a77c3abec6e5e8d568bb469c2d6e
2023-03-11 19:04:09 +00:00
Kevin Israel
7c07484ade maintenance: Migrate mcc.php from CommandLineInc to Maintenance
This allows methods to be defined instead of global functions, which in
this case, were missing the "wf" prefix.

Change-Id: I2413675f46a29d914cb756071cd6abbcf38b500e
2023-01-14 02:02:59 +00:00
Kevin Israel
f9fb7d6988 tests: Use MW_VERSION instead of deprecated $wgVersion
Change-Id: Ie4d1c7e660535fff9d0513b7ca4e6479f12bd51b
2023-01-05 05:20:00 -05:00
Kevin Israel
31d8dcbc30 phpcs: Remove exclusions for files that were deleted or moved
* maintenance/benchmarks: 4 files were deleted in d814a74b6f.
  1 file was deleted in 4c5de97a9b.
* includes/Stub*.php: 3 files were moved in 0fff5089ba to a
  new subdirectory. phpcs:ignore comments were added in the move.

Change-Id: I8b2c71e0e054f969741691f29dca62adeab757bd
2022-12-20 05:37:47 -05:00
Kevin Israel
dc31aaad74 phpcs: Remove 3 items from PrefixedGlobalFunctions ignore list
Since 096ea23208, these no longer exist as global functions:

* moveToExternal
* resolveStub
* resolveStubs

Change-Id: I1c36ece4d84895647a27aaf7160ac3b66c402f01
2022-12-20 00:23:09 -05:00
Kevin Israel
a70e8fa299 phpcs: Remove comment regarding silence (at-sign) operator in tests
This comment was added in 355a6cd4c3 and quickly became outdated.
While it should still mostly be correct, it is no longer "policy" to use
the at-ease library. The "@" operator is now explicitly permitted where
necessary and is now recommended even outside tests (T253461). As such,
it no longer makes sense to keep this comment around.

Change-Id: I07aa84d46be8c7e5a1c8a3249d382cbbfef80267
2022-12-03 05:05:40 -05:00
Kevin Israel
1937e2a7d6 tests: Fix missing "wf" prefix for global functions
Also:

* In .phpcs.xml, remove "showUsage" from the list; transstat.php was
  removed in e19f4e16a6.
* In styleTest.css.php, check the type of the $_GET value as part of the
  "basic sanitization".

Change-Id: Icb82d8a42dd6cd062f41a04696f092b43b04f54f
2022-11-28 07:28:55 -05:00
Umherirrender
c6fecd5ab0 tests: Replace assertEmpty with assertSame
assertSame avoids use of loose comparisons and
allows to check the expected type

Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
2022-11-25 00:42:53 +01:00
Fomafix
7a9f03b20a Remove PHPCS exclude-pattern for */languages/*
Since 863a1d5bdd the converter classes are in own files.
therefor the exclude for the rule
Generic.Files.OneObjectStructurePerFile.MultipleFound is not needed
anymore.

Change-Id: Id10ba77fc4caf9065a8f0e3480f42aad492275e4
2022-10-19 06:09:17 +00:00
Fomafix
330c0c0b41 Remove PHPCS exclude-pattern */languages/*
The Language converter classes are not in this folder anymore and don't
use the pattern of two classes in one file anymore.

Change-Id: Ie25bc2fe4ad860c218145615caefbfee2200d1c6
2022-10-15 12:34:37 +00:00
libraryupgrader
b70581e4ca
build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 38.0.0 → 39.0.0
  The following sniffs are failing and were disabled:
  * MediaWiki.PHPUnit.AssertEmpty.AssertEmptyUsed

* php-parallel-lint/php-console-highlighter: 0.5 → 1.0.0
* php-parallel-lint/php-parallel-lint: 1.3.1 → 1.3.2

npm:
* grunt-banana-checker: 0.9.0 → 0.10.0
* grunt: 1.5.2 → 1.5.3
* karma: 6.3.15 → 6.4.1
* async: 2.6.3 → 2.6.4
  * https://github.com/advisories/GHSA-fwr7-v2mv-hh25
* got: 11.8.3 → 11.8.5
  * https://github.com/advisories/GHSA-pfrx-2q88-qq97

Change-Id: I1d7bc9c9599b48d2bd837617cad409a31adb362a
2022-10-07 21:09:37 +03:00
Daimona Eaytoy
1c60cafab4 Add @coversNothing to all structure tests
With PHPUnit 9, tests without @covers tags are considered risky and emit
warnings. Not having @covers is bad practice anyway, so use
@coversNothing instead to make the intention clear, and re-enable the
phpcs rule.

Also rewrite an assertion in ResourcesTest that was bothering me.

Bug: T243600
Change-Id: I6dd683f93b6b2faed5f107be2ca7860602277fbc
2022-10-07 03:21:54 +02:00
Amir Sarabadani
2b9fd5176d Drop support for doctrine/dbal < 3.0.0
Removes various hacks and back compat support

Bug: T270740
Change-Id: I17d74705cdd5a2e1af0bda66bfa466067b8387a8
2022-09-29 10:49:17 -04:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Timo Tijhof
f745292c69 maintenance: Move MWTerm classes to /tests/parser/
This further removes files that are not maintenance scripts from this
directory. It isn't used outside of tests, either.

While at it, rename this to a PSR-4 namespace consistent with some of
the other test-only classes.

Change-Id: Ibc49617631f17a5e9489789a90a7b8537340ead3
2022-03-24 21:01:14 +00:00
Timo Tijhof
8d406bbcd6 phpcs: Disable Generic.Files.LineLength for test files
There is a common and reasonable need for longer lines in tests.
The nudge for shorter lines doesn't seem valuable here. The natural
breaks will likely still fall in 80-100 given the enforced practice
for non-test code, e.g. whether through habit, or 80-100 column markers
in text editors, or the finite width of diff and code review
interfaces.

Change-Id: I879479e13551789a67624ce66f0946d2f185e6ee
2022-02-18 18:32:05 +00:00
Tim Starling
54c735354f Stop using is_resource() where possible
* Enforce the ban on is_resource in phpcs
* In OrderedStreamingForkController, the comment was incorrect. I
  confirmed using a small test script that if the child closes one end
  of a socket pair, the other end will still be open, and is_resource()
  will still return true, and fclose() will not fail. The issue was
  introduced in c82d30d19c, it was not present in the
  CirrusSearch copy of the class.
* Allow is_resource() for debug logging.
* Allow is_resource() for parameter validation where a stream may be
  passed to a function, since there is no alternative.

Bug: T260735
Change-Id: I59a752f7bb4b043ddfb2434b52a02f9221bf54db
2022-01-26 10:03:23 +11:00
Alexander Vorwerk
e73e07e85b Use inject Config in api modules and special pages
Replacing the usage of global vars with the usage of the injected
Config instance.

Change-Id: I90612b4dde9b76afb1bac4855274c03dcaf23044
2021-12-01 13:01:02 +00:00
Tim Starling
65b1b6b56a Remove $wgShellLocale, always use C
$wgShellLocale was a flawed solution to the problem of locale
dependence. MediaWiki has its own concept of locale (the Language
hierarchy) and any kind of dependence on the server's libc locale is
incorrect and harmful, leading to bugs. Developers have an expectation
that functions like strtolower() will work in a certain way, and
respecting the locale set in the environment at install time violates
this expectation.

The problems with using C as a locale, which led to $wgShellLocale, are:

* escapeshellarg() will strip non-ASCII characters. This can be worked
  around by not using it. The security vulnerability it was trying to
  fix can be prevented in another way.
* Shell commands like rsvg will fail to correctly interpret UTF-8
  arguments. This is the reason for the putenv(). On Linux, this can
  be fixed by using C.UTF-8, which we didn't know at the time. On
  Windows, the problem is not relevant (there are unrelated issues
  with UTF-8 arguments).

Bug: T291234
Change-Id: Ib5ac0e7bc720dcc094303a358ee1c7bbdcfc6447
2021-09-24 17:25:01 -07:00
Alexander Vorwerk
1a22c1c1d7 Remove global function mimeTypeMatch()
This is done without a deprecation process since the function is
@internal and completely unused outside of core.

Bug: T291341
Change-Id: I4b074f83f9be67b5b5bc2d33b2a6a55bb109a2b3
2021-09-19 19:03:46 +00:00
DannyS712
a2b20b63d7 Emit deprecation warnings reading from $wgUser
With this patch deprecation warnings will be emitted
if $wgUser is accessed or written into. The only pattern
of usage still allowed is

$oldUser = $wgUser;
$wgUser = $newUser;
// Do something
$wgUser = $oldUser;

Once there is no deprecation warnings, we know that nothing
legitimately depends on $wgUser being set, so we can safely
remove the code that's still allowed as well.

Bug: T267861
Change-Id: Ia1c42b3a32acd0e2bb9b0e93f1dc3c82640dcb22
2021-09-15 20:17:04 -07:00
Fomafix
12f9cba673 Rename PHP class RandomPage to SpecialRandomPage
This change is for consistency to the file name and to other classes.

The old class name RandomPage is kept as alias for compatibility and is
now deprecated.

Also change the letter case in the class names and file names:
* SpecialRandompage     -> SpecialRandomPage
* SpecialRandomredirect -> SpecialRandomRedirect
* SpecialRandomrootpage -> SpecialRandomRootPage

The change of the letter case of file names may cause problems on
Windows operating systems.

Change-Id: If4dd23126e0d032f42a86aff7d09414edcb1ade2
2021-09-03 09:26:06 -07:00
DannyS712
57139640c5 phpcs: remove class name exclusion for invalidateUserSessions
Follow-up: I0c0f5c94a7ee0aa3f0aeb8b7f84857022810f17a
Change-Id: I0e24cf641ad16330ee152e80dbcad6a2f71a7001
2021-08-24 11:40:09 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Umherirrender
7f684ed81c build: Cleanup and improve .phpcs.xml
Use /* at the end of exclude-pattern when excluding the whole folder,
see Id95236edbd3d87f57719d235c7c9cee366180099 for explaination

Remove the file extension when excluding the whole folder,
because it process php files only by the extensions argument set to php

Change-Id: Icaad23ab4b1708a5ce17930f77067ac9224169b5
2021-04-29 20:51:09 +00:00
James D. Forrester
623f80ff04 Follow-up dcdec1a2b: Also update path to file in .phpcs.xml exclusions
Change-Id: I21597266131aca1d0190f4eee4a42fc8335da74b
2021-04-29 13:00:15 -07:00
Reedy
2b40657a36 .phpcs.xml: Replace useage of whitelist in comments
Bug: T277987
Change-Id: I7735279b4dceceb0c9620bb0983ca4839245f194
2021-04-18 16:22:58 +01:00
DannyS712
7aba39a718 Update .phpcs.xml to remove deleted maintenance scripts
Scripts that were removed:
* maintenance/archives/upgradeLogging.php
* maintenance/benchmarks/bench_wfIsWindows.php
* maintenance/minify.php

Change-Id: I05c198e7f1bf8e8f57ba82cce4223fe73c6af3f9
2021-04-14 00:38:20 +00:00
libraryupgrader
649d0cb4f2 build: Updating eslint-config-wikimedia to 0.19.0
Additional changes:
* Dropped .php5 and .inc files from .phpcs.xml (T200956).

Change-Id: I66c9980d3ef6f6604c3145ad0b7f308257dff046
2021-03-12 10:55:29 +00:00
James D. Forrester
bdddfb92ba Drop wgContLang, deprecated in 1.32
Bug: T245940
Depends-On: Ib7fe7318100c0aadc3aa759416bf787913a9b788
Change-Id: I75c3b6715abd5eaf3619337cab8b1844e9a8349a
2021-03-08 13:27:28 -06:00
Umherirrender
393b6fb508 Add missing @param tags in tests
And exclude the rest inline to remove global exclude

Bug: T238572
Change-Id: Ib4c207177dd73702c113e6233f59be6e571a0f6a
2021-02-01 20:38:05 +01:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Reedy
d4a5632307 PHPVersionCheck: Enable Generic.Arrays.DisallowShortArraySyntax
Bug: T273340
Change-Id: Ic24e16897b90b92467a270b5ef64b1a0d7694eb5
2021-01-30 01:30:35 +00:00
C. Scott Ananian
f99a79cef9 phpcs: Ignore LocalSettings-installer.php
The quibble test infrastructure generates LocalSettings-installer.php
during continuous integration testing, and (depending on the exact
set of extensions installed) it could end up violating various sniffs
relating to excess white space.  Easiest just to ignore it.

Change-Id: I34c5783a1bc8c5646fbabafaf442e20c91de41ed
2021-01-12 16:42:02 -05:00
Reedy
b16a862d43 Upgrade doctrine/dbal from 2.10.4 to 3.0.0 for PHP 8.0 support
Some irritating breaking changes, including dropping PHP 7.2 support
and renaming the classes we care about. For now, hack in via || and
some back-compatibility class aliases.

Bug: T270732
Change-Id: I685f099584d2f0e5fa17f1f4275eab5289c7bfee
2020-12-23 02:24:31 +00:00
Umherirrender
49efbfe2fb Improve documentation about object to be stdClass or specific type
Some classes still needs exclude for the sniff

Change-Id: I9536c2ee84f6fb4c83cf862a152cf6b00344cb97
2020-11-20 14:47:56 +00:00
Daimona Eaytoy
4f2692a056 Kill tests/phan
As per comments on phabricator, the Suppressor was used when phan still
didn't have per-line suppression, which is no longer the case. The phan
script was also outdated and broken, so just remove everything.

Bug: T267859
Change-Id: Ic4a68dd30a4481656a5c44b2446cf851ea638c1c
2020-11-17 16:04:33 +01:00
Umherirrender
d53f786a80 build: Updating mediawiki/mediawiki-codesniffer to 33.0.0
Change-Id: I4dbe8ce6f130fe6631e6329ba972d1569741e072
2020-11-02 02:05:02 +01:00
jenkins-bot
3c262bffdf Merge "Make unit tests assertion about assertNotEquals more strict" 2020-11-02 00:37:36 +00:00
Umherirrender
bdf8cefaf8 Make unit tests assertion about assertNotEquals more strict
Originally an autofix of PHPUnitAssertEquals sniff, but manually
updated.

Change-Id: I78efc6f7997f0b7227b40d7eab1495cc7a1d7da5
2020-11-01 23:12:06 +00:00
jenkins-bot
0ea13bb963 Merge "Improve class property documentation" 2020-10-30 17:12:33 +00:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +01:00
Umherirrender
448d2f4d51 Avoid local variable with wg prefix
Change-Id: Ib32cc0db07636238aa0b4f8ea7f8c1ae37084889
2020-10-28 22:21:24 +01:00