Commit graph

274 commits

Author SHA1 Message Date
Daniel Kinzler
f2e9d5108d REST: collect metrics on endpoint access
This is a modified version of Ie282bc5b5f5df0bbd6a40c8362ba73fcbbf36c2e
which was reverted in 5c7cca8776.

Bug: T321969
Change-Id: I566d54a473aa51c4cdaada21a49d63c0624aab93
2023-01-12 14:50:58 +00:00
daniel
4912fe27a8 Maintenance scripts: show a warning when run directly.
This shows a warning message when maintenance scripts are run directly.
maintenance/run.php should be used instead.

Change-Id: Ibd47e3f29f93238ccd3e607774927e639ba74ace
2023-01-04 20:10:34 +01:00
Umherirrender
9cd9ab0590 tests: Do not hide deprecation in SpecialPageFatalTest
Since 9cc1cd3 a filterDeprecation() call exists to hide MediWiki
deprecations, let php deprecation show up

Depends-On: Id07a55743bdfe04022b7c96acb6c154c7fe33098
Change-Id: Ia51b00399c584671ccf5d9fb8dfed1e94e5d60f9
2022-12-16 13:04:45 +00:00
jenkins-bot
f9f4bdc197 Merge "Make RestStructureTest run in IDE" 2022-11-22 23:48:45 +00:00
daniel
2afb59c96e Make RestStructureTest run in IDE
PHPUnit tests will fail to run in the IDE if they access the service
container.

Note that the structure test will not include routes registered by
extensions when run without the phpunit wrapper: data providers are
executed before config is loaded, so extensions do not have a chance to
register.

Change-Id: If9d408456686b408062204bec4b41c95f60ab775
2022-11-22 22:07:49 +01:00
jenkins-bot
6800fe2b21 Merge "Replace some in_array( array_keys() ) with simple isset()" 2022-11-18 21:21:24 +00:00
daniel
f517783c5f Settings: Introduce SettingsBuilder::getInstance to avoid $wgSettings
While accessing a SettingsBuilder instance via global state should not
be encouraged, we still need it sometimes. So use a static getter
instead of a global variable. That way, we can emit deprecation warnings
when we have proper alternatives available.

Change-Id: I0013bdab474710fd521532dd2653b3789e2ede34
2022-11-17 20:06:39 +00:00
thiemowmde
2574ef4bfd Replace some in_array( array_keys() ) with simple isset()
Usually it doesn't make much of a difference, but potentially can
when the array is big. The extra conversion also makes the code more
complicated, I would argue.

Change-Id: I91b9e82ca801dd64523557d616462b7ea7edc7b0
2022-11-14 17:56:34 +01:00
Máté Szabó
c04cb6f607 Include core PSR-4 classes in the generated classmap
It appears that autoloading classes via MediaWiki's PSR-4 autoloader has
a not insignificant performance penalty, especially when hundreds of
PSR-4 classes like HookRunner's hook interfaces are autoloaded. Using a
classmap autoloader, like we already do for PSR-4 classes from Composer
dependencies, is a potential way to reduce the performance impact
here.[1]

For core classes, this can be done by simply not excluding PSR-4 classes
in AutoloadGenerator, causing it to include appropriate mappings in the
generated autoload.php classmap. I had to exclude one class_alias()
declared in Result.php from the classmap with a NO_AUTOLOAD stanza,
because including it broke AutoLoaderStructureTest's assertion that all
aliases should be defined in the same file as the aliased class.
Assuming this is still an issue, this would already have been a problem
because the test was previously skipping every PSR-4 class. Excluding
this file via NO_AUTOLOAD just restores that status quo.
----
[1] https://phabricator.wikimedia.org/T274041#8358399

Bug: T274041
Change-Id: I0aa62c944d874bf7a9f3a240e72e58fe6a887b28
2022-11-08 12:13:32 +01:00
Amir Sarabadani
719ce204a0 Reorg: Move ForeignResourceManager to ResourceLoader directory
It literally has @ingroup ResourceLoader

Bug: T321882
Change-Id: Ia5c7c56c9235f98754f6d5e602da4626a76ff083
2022-11-08 10:54:17 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
James D. Forrester
2cf45bc934 ResourceLoader: Mark ForeignResourceStructureTest as @group Standalone
Follow-up 3270283abf.

This way the test is only run on commits made to this repo, not on all
skins and extensions, and so saving an awful lot of downloads from
happening in CI unnecessarily.

Bug: T203694
Change-Id: I071be5821711fb8b039ff24293f66a8ff9d70514
2022-10-27 21:24:44 +00:00
Timo Tijhof
3270283abf ResourceLoader: Add structure test for foreign-resources.yaml
Enable the equivalent of running `manageForeignResources.php verify`
as a structure test via PHPUnit.

Related cleanups for this to work well:

* Improve cache key readability before enabling in CI.
* Document how we do caching in CI.
* Change some exceptions to errors so that we don't
  stop on the first error, thus improving the usefulness of the CI
  result by telling the developer all mismatches instead of only
  the first.
* Fix incorrect typehint for nullable $integrity.

Bug: T203694
Change-Id: I8aeffc1f2e81ffcf037977528f94c00995791999
2022-10-26 10:24:15 -04:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
daniel
bb10b7d528 Settings: add support for obsolete config
This allows config variables to be declared obsolete. Obsolete config
will be omitted from the schema, defaults, name constants, etc. The
purpose of keeping a declaration of obsolete config around is to allow
the updater to warn admins that they are using a config variable that no
longer has any effect, and provide them with a remedy.

The idea is that support for deprecated config can be removed after one
release per the stable interface policy, but the declaration of
obsolete config should be kept for as long as we support updates,
that is, at least two LTS releases.

See https://www.mediawiki.org/wiki/Topic:X4bh4nf3pe2ho5jj for
discussion.

Change-Id: Ia7a00742ea7a5311e820a6a43b11135a3f2a825f
2022-10-14 15:00:43 +02:00
Tim Starling
94e20db64b Add some helpers to filter properties out of var_dump()
Dumping many kinds of object with var_dump() leads to dumping the whole
address space, because a chain of references leads to MediaWikiServices.

So, introduce a trait which replaces the problematic properties with a
placeholder, if their doc comment contains @noVarDump.

Bug: T277618
Change-Id: Ifa685c26fbc5317d0359544289ec3f433ec4fedf
2022-10-12 12:42:23 -04: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
Timo Tijhof
f67f0298d1 ResourceLoader: Add structure test to detect incompatible requiresES6
Bug: T316324
Depends-On: I12f8ebb5c6b61fb7dadeca282dab123c85b0a6a3
Depends-On: I15cec4dc86513373e74d401d0ffdc580385dd890
Depends-On: If57518a1ba6ee96dbf9ef2b9b9aff9242a8dc61c
Depends-On: Ie0f36ddda3bca0a5812887374fb6c82982b98013
Depends-On: I2f1ed2b7451b3789498ac15a285b5ec3b0e53f7b
Depends-On: Iaf04c3a5d64d268b582823eb0e1cc855445d776c
Depends-On: Iffaf7186db4bcdf4e169f2f61b556016860e769e
Depends-On: I601c53e7116f8ddeb1411e4a1e1bd452d414330a
Depends-On: I8f10750b2bc53e656eb636883213b04d4c277c4f
Change-Id: Ibb1d480a538a612f14645df2928f7604abde9fce
2022-08-31 18:13:52 +00:00
Umherirrender
6dcb1ebe76 tests: Change multiple calls from overrideConfigValue to overrideConfigValues
Also change loops to multi-value function

Change-Id: I2301cc246b7f8ca3028d44d70756a5e1ba04e82d
2022-08-17 12:08:50 +00:00
daniel
7f4ed4ea11 SettingsTest: check that the current config didn't trigger warnings.
SettingsBuilder collects warnings about issues with the configuration.
The warnings are so far only surfaced by the installer.
This change adds a structure test that ensures that there are no
warnings.

Change-Id: I92f80ceb8e9eda20ad1de35fa22ed1db7ffcb692
2022-07-22 18:01:13 +02:00
daniel
e8cc4c8f91 Fix type declarations in MainConfigSchema
Validating against the live schema on the WMF cluster exposed several
issues with the config schema. Mostly settings declared to be lists
which are actually associative arrays.

This also removes deprecation markers for some settings that are still
in active use, just discouraged or unstable.

Change-Id: I63e816edd1a561bda6063f8558ccce88c113df3f
2022-07-15 16:11:50 +02:00
Derick Alangi
f00cd03580 tests: Make use of overrideConfig(Value|Values) where needed
As we slowly move away from using globals, overrideConfigValue()
and overrideConfigValues() were introduced as a way to override
test configs between tests.

Under the hood, it just calls setMwGlobals() which resets services,
so take note.

Part 1: Directories covered are: languages/, maintenance/, tests/,
structure/ and includes/Permissions/.

Depends-On: I618b16c6d99c94eb2e7edcf05e888a65f7156754
Change-Id: If56f7d10d79f3a9824a52091a2b544d8653dd7b6
2022-07-11 21:15:26 +01:00
daniel
5e928f39e8 Dynamic defaults: fix $wgLocaltimezone being empty
Apparently, $wgLocaltimezone is set to the empty string in many
existing LocalSettings.php file, presumably because the installer
failed to detect the correct time zone.

The new code for handling automatic defaults will only trigger if
$wgLocaltimezone is null, not when it is otherwise empty.

This adds fallback code in strategic places to ensure that the empty
string is handled correctly.

Bug: T305093
Change-Id: I39226466f2bb6a36823ae9032fc62f981eabc64a
2022-07-09 18:59:32 +02:00
Lucas Werkmeister
c3c5b6c1b4 Remove 'ignoreKeys' from config schema
Unused since change I88754b52c2 (commit 9e95539fc9) – this was only used
for SessionProviders, which is now a map/object instead.

Change-Id: I8da686e6379eb33a63799874fb44f9b0030ab5ba
2022-07-06 10:46:58 +02:00
Tim Starling
8d90307c50 Fix typos
Change-Id: I2c01adb70e179abbeb6c5ae8bee3abcbdbac8edf
2022-06-30 09:44:00 +10:00
daniel
f2df03704e Add support for nested property schemas in MainConfigSchema.
This adds support for JSONSchema style property declarations with nested
schemas. This is a step towards using more nested structured for
configuration, rather than adding to the over 700 keys already defined
in the main config schema.

Defaults from property schemas are aggregated into a default value in
the top level schema. Descriptions are however not yet aggregated.

Change-Id: Iaf46a9ecc83bee3566098c56137a1be66bff2ab9
2022-06-29 16:34:43 +10:00
DannyS712
32e99c3f19 ResourcesTest: fix typo $ilegalDeps
Added by yours truly in I5846f2c19b003989b56b12628b385fd37049483b

Bug: T201491
Follow-up: I5846f2c19b003989b56b12628b385fd37049483b
Change-Id: If2379b3819686ea14bfbd63202ec8e7c22c7bfce
2022-06-22 01:32:55 +00:00
Derick Alangi
d01e3ed739 Replace deprecated calls ParserOptions::newCanonical( 'canonical' )
This is a quick find & replace of calls to the deprecated method
ParserOptions::newCanonical() when the context is the string literal
'canonical'. This can be safely replaced by called newFromAnon().

Change-Id: If7bb68459b11e0c5f5de188f10fdae85ad1a78bf
2022-06-16 14:22:24 +01:00
Lucas Werkmeister (WMDE)
acae1c5107 Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work.

This reverts commit 7238dff532.

Bug: T310255
Bug: T90875
Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
2022-06-09 14:15:54 +00:00
Kosta Harlan
7238dff532 phpunit: Default to vendor/bin/phpunit, remove suites.xml
* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
  * tests/phpunit/phpunit.php is retained but will be removed after CI
    jobs and other references on
    codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
    are removed
* add a default bootstrap.integration.php; unit tests in
  composer.json use the non-MW bootstrap file (bootstrap.php)
  * Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php

Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
2022-06-08 18:31:16 +00:00
daniel
ad11b034ab Settings: Generate schema artefacts using a single maintenance script
Previously, each of the four derived config schema files had to be
regenerated using a separate maintenance script. This change simplifies
regeneration by combining all for scripts into a single command that can
be used to regenerate all relevant files after changing
MainConfigSchema.

Change-Id: I7d38d8a4aede60475c4bdd0053d2e10e298b9843
2022-06-05 19:17:29 +00:00
Kosta Harlan
ff63886b0f
phpunit: Do not access MW services in dataProviders
We cannot access MW services in a data provider, as MW will not have
bootstrapped by this point in plain PHPUnit. And we do not want to
bootstrap MW by the time a dataProvider is executing, because unit tests
should not need (nor be able to access) MW services.

Change-Id: I21a5993f91b8fbe3fa476a8244b8911cf81e1d5f
2022-05-30 23:16:06 +02:00
Umherirrender
de47d93928 Get the MainConfig from MediaWikiServices instead of RequestContext
The getConfig of a ContextSource should only be used, if the
ContextSource is available. Getting the global context just for the
config looks harder to fix/inject as using the MainConfig from
MediaWikiServices

Change-Id: Iaf14bfc7bd68cc315672e1c256887faf87e22542
2022-05-24 21:54:21 +00: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
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
jenkins-bot
df7b81e0e5 Merge "Settings: Add remaining schema info to config-schema.php" 2022-05-18 21:28:20 +00:00
daniel
e72b9d1ad6 Settings: Add remaining schema info to config-schema.php
By optimizing the structure of config-schema.php for fast loading,
some information needed for schema validation was lost. This patch
ensures that all schema information is retained in config-schema.php.

The code for consuming this field already existed, as written for
what we already output to the generated config.schema.yaml file.

Bug: T307769
Change-Id: I8adcdfd2b8fb5f5b96308eea74c07d8cc7a4d6ba
2022-05-17 22:16:29 +00:00
daniel
237bbf089f Turn DefaultSettings.php into a deprecated stub
DefaultSettings.php has been replaced by MainConfigSchema.
Loading DefaultSettings.php is deprecated.

Code that needs to have access to configuration defaults should use the
ConfigSchema service object.

Bug: T300129
Change-Id: I7b2c0ca95a78990be1cdb9dd9ace92f6dcf1af15
2022-05-17 16:50:56 +02: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
jenkins-bot
783a763bd2 Merge "AutoLoader: provide methods for registering classes" 2022-05-10 06:05:52 +00:00
daniel
37af531721 AutoLoader: provide methods for registering classes
This introduces static methods for registering classes and namespaces,
so we don't have to mess with global variables and static members
fields.

Bug: T240535
Change-Id: I1abb27bd70898d04c9253e0b7467447fa96d15a4
2022-05-10 13:55:53 +10:00
Aaron Schulz
774abe3ba6 Split out slow ScopeStructureTest for easier paratest parallelization
Change-Id: I677f27847e635003c932102b3876fcf81d270c88
2022-05-10 11:18:24 +10:00
Lucas Werkmeister
2e9fa547a1 Skip failing structure test in SettingsTest
This is blocking merges in several important extensions.

Bug: T307769
Change-Id: Ib33989dc38fe3a0dec59fbac949d4c732fa5d5d7
2022-05-06 16:09:56 +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
lens0021
7798f184e8 phpunit: Support setting skin context in BundleSizeTest subclasses
BundleSizeTest is mainly used by skins to test the size of the modules
of the skin. Using default skin may cause unexpected results.

Bug: T305779
Change-Id: Id77c6124c9b1fd20633cda47bbca89f9b6724a63
2022-04-11 23:50:45 +00:00
Lucas Werkmeister (WMDE)
1aca74e298 Revert "Add SpecialPageFatalTest to @group Database"
This reverts commit be7565e3e1.

Reason for revert: Needed for a revert of CentralAuth change I3baf207711.

Change-Id: I847086a8ea2be8931b9f3fc092467445c47644a0
2022-03-31 12:37:57 +00:00
Taavi Väänänen
be7565e3e1
Add SpecialPageFatalTest to @group Database
This causes this test case to be run with sql_mode set to
STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY, instead of the default TRADITIONAL
set in DevelopmentSettings. Many database pages (such as those including
a pager) make database connections when loaded without parameters.

If this can be merged without problems it would let us un-revert
Ic2729428297162763a772e6a16549ded8de06c01 too.

Bug: T304762
Change-Id: I3bb424ddcbd7d3d6c03ad23d071a69a94b7f5749
2022-03-26 15:43:46 +02:00
daniel
1137a357db phpunit: Revert "testConfigGeneration" structure test to simpler version
This was changed to support in-place updates of files,
but the idea which was since abandoned. So we can go back to
using stdout.

Change-Id: I825a00258c4f50244679fc47c81b6920dd241647
2022-03-24 14:57:47 +00:00