To do so, we move the relevant parts to a separate include file that's
included both by Setup and the test.
The --color-moved option is highly recommended when reviewing this patch
to verify correctness.
More tests to come.
Bug: T305093
Change-Id: I931b92357ec48db4665891c8546f86264885e881
Use name constants instead of string literals in calls to Config::get
and ServiceOptions::get, when referring to core configuration variables.
This protects against typos and makes the decumentation and schema
declaration of the config settings discoverable.
This is the first batch, only touching files directly under /includes/
Change-Id: I7252e636c7c86d950d9257b33491af492c6dd5eb
Instead of loading global variabls from DefaultSettings.php, load the schema from config-schema.php.
For 1.38, keep a DefaultSettings.php and use it if MW_USE_LEGACY_DEFAULT_SETTINGS is set.
Additional changes:
* Removes timing stats collection. This was temporary, to make sure
performance is OK in production.
* Removes loop to pull in config globals, when Setup is included in
bootstrap.php. This is only the case when invoking phpunit tests
with IDE integration. The code in Setup.php is buggy and redundant
while bootstrap.php still pulls in DefaultSettings.php.
This code will be put back in I7b2c0ca95a78990be.
Bug: T305176
Change-Id: I399df9e1ee678e525e37c172d0fd8e1e634436e5
The default value for GitInfoCacheDirectory doesn't seem to be necessary
outside of GitInfo.php, so move it from Setup to there. Theoretically
this could break third-party code that uses this setting and was relying
on Setup.php to set a default value, but it doesn't seem very likely.
I didn't find any other dynamic configuration that could be moved out of
Setup so easily:
* MainWANCache isn't accessed outside of ServiceWiring, but Setup
still needs to check it to initialize WANObjectCaches.
* ForeignFileRepos is only read in FileBackendGroup, but various tests
(including in extensions) reset it and their behavior will be affected
if they no longer override the various related settings like
UseInstantCommons.
* ShortPagesNamespaceBlacklist handling could be moved to
SpecialShortPages.php, but that would require re-adding it as a
recognized configuration setting, which doesn't seem worth the tiny
code simplification.
Bug: T305093
Change-Id: Iec8c391fec8396846216a9708d75df57f7d799a2
Added support for an easy to configure multi-tenant ("wiki farm") mode:
Settings for each site can be placed in a directory specified by
$wgWikiFarmSettingsDirectory. Site detection is controlled by
$wgWikiFarmSiteDetector and defaults to the requested host name.
Instructions for manual testing: https://etherpad.wikimedia.org/p/T221535
Bug: T221535
Change-Id: I7581921b7d99ba1fe7e25523fde691d76b67a99c
This adds an experimental mode that loads LocalSettings.php in a
function, rather than in top level global scope. This is controlled
using the MW_USE_LOCAL_SETTINGS_LOADER environment variable.
This is not intended for use in production as this time.
The experimental mode should be available in the 1.38 release,
so people can try it out with different setups.
Bug: T304183
Depends-On: Ie6245ff8cd2bc7bab2af3b1450070185dbc2d824
Change-Id: I0f20024803336064ecb07b51fa56581af7b67a85
This allows MW_USE_CONFIG_SCHEMA to be defined as a constant instead of
an environment variable. This is useful if we want to set it in
multiversion. We could use putenv, but its interaction with getenv is a
mess, see the warning on
<https://www.php.net/manual/en/function.getenv.php>.
Bug: T304460
Change-Id: I0bd87e2ddde70ba9fede65b8d607eec01b39aed5
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together
Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
Application logic should use the BaseDirectory config variable.
Framework code should use MW_INSTALL_PATH to locate files should.
NOTE: Update https://www.mediawiki.org/wiki/Manual:$IP
Bug: T300301
Depends-On: I7142af16d692f26e90673b058029f572c1ea3991
Change-Id: Ib4caa80bb7007c4c7960a2fd370cf5da7d9ba344
$wgStyleSheetPath has been a deprecated alias for $wgStylePath since 1.3 (2004).
Time to get rid of it.
Change-Id: I78a6394003b9aefab7aa8559b8e2b22bc50154fc
In order to safely transition Setup.php to load config-schema.yaml
rather than DefaultSettings.php, we need to be able to test the new
setup mechanism selectively, on only a few hosts.
This patch makes Setup.php use config-schema.yaml if the
MW_USE_CONFIG_SCHEMA variable is set.
The condition could be patched in production to be based on the host
name or a request parameter for further experimentation in the live
environment.
Bug: T300129
Change-Id: Idc12b8e6ee2a3cc41cf5ab8d1eb755e6fab0213d
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
We are already passing SettingsBuilder into callbacks registered with
MW_SETUP_CALLBACK. Do the same for MW_CONFIG_CALLBACK.
This will allow us to avoid messing with global variabls in more places.
Bug: T294739
Change-Id: Ic6296907139912351b53dc80672ef950c0aefeb3
This allows a file other than LocalSettings.php to be used as the primary
settings file by setting the MW_CONFIG_FILE environment variable.
This also allows the primary settings file to use YAML or JSON format.
Using static configuration files should be the default in the future.
However, YAML files in the document root could easily be exposed to the
public. Better not to encourage that, and require them to be enabled
explicitly and loaded from a different place.
Bug: T294750
Change-Id: I7747f83481cb05a6d05f819be652259951183819
In order to allow configuration default to come from JsonSchema,
and dynamic defaults need to be initialized in Setup.php.
This movesd the initialialization of $wgExtensionDirectory and $wgStyleDirectory
to Setup.php
Bug: T294788
Change-Id: I11f5723aa299caa210cf6a1f5b7436f191b1ffc2
This was originally added in changes linked to T77093 without
coordination with maintainers and took various shortcuts and lacked
proper integration.
* Rather than reading a global variable from LocalRepo::getInfo,
inject this option from Setup.php, the same as for other local
settings.
* Apply the wfExpandUrl() call in the base class getInfo() method.
This is done so that $wgForeignFileRepos and $wgLocalFileRepo
settings via LocalSettings.php or wmf-config get the same treatment
and benefit (support for paths) as $wgFavicon, which one would
generally expect.
Other reasons to do this at run-time are 1) We can't safely call
wfExpandUrl() during Setup.php as it is too early, and 2) We generally
avoid doing computational work during Setup.php given it's not
needed for most web requests to most entry points (T189966, etc.).
* Document the option in DefaultSettings.php.
* Fix bad doc in FileRepo.php, to reflect that it is optional
and may be null.
* Remove now-redundant hack in ForeignDBRepo::getInfo,
which had to jump over its parent class previously to avoid
inheriting the other hack in LocalRepo::getInfo, which is now
gone as well.
Bug: T77093
Change-Id: I9102b5a246ff81a3435748a3fd1c759a4b884a51
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
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
This is a minimal baseline implementation that allows skins and
extensions to be loaded from settings files.
This should be improved by closely integrating SettingsBuilder with
ExtensionRegistry. They should probably end up being the same thing
eventually. Loading extension.json is essentially the same as loading
settings files.
Change-Id: I02a1d9b517815463f150b53c0602927609ff9eeb
When we're done applying settings and we call `finalize()`, any further
attempt to apply settings too late should throw.
This is a defensive mechanism for us to track the state of settings applied
in during setup process and will guide us to bring all settings to be applied
in the appropriate place so unexpected things don't happen.
Bug: T296684
Change-Id: Id58654c8265bc8310e1fe464ff5a480aad8a8666
This feature enables the SettingsBuilder to be able to set php-ini
environment variables at run-time.
We just do so by specifying the various key/value pairs to the `php-ini`
key like below:
```
"php-ini": {
"key": "value",
...
}
```
This will allow us to set things like `display_errors`, `memory_limits` etc.
Bug: T294752
Change-Id: I2ff0e7abc010342537bbaf1e1b71fb84d02a153b
The config file path can be overridden, so we should use the defined
constant rather than hardcoding a path. The intention of this logic
is to purge cache with the active config changes, so it's more correct
to check the mtime of the file in use.
Change-Id: Iac5fa2af4021ab8c1a0532b46b3bbc02641c682a
I tried doing this in Id9a6cf9ee2520db9d405e17eaf34b10bd72897f3 but
the error message modified in that patch was specific to the PSR-3
logging library, not for missing composer dependencies. This patch
modifies the error message for the latter as well.
Change-Id: I713a9037b8c5dc71bf03fb2ec791b3ce63e5f1be
It wasn't obvious to me that the mediawiki.org link actually pointed
to specific instructions for resolving the error, as opposed to
just telling the user to search on mediawiki.org. Try to make this
a bit more obvious.
Change-Id: Id9a6cf9ee2520db9d405e17eaf34b10bd72897f3
$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
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
As part of our wider work on modernising and making more welcoming the
language we use within and around MediaWiki, now is a good time for us
to rename these configuration variables:
- $wgFileBlacklist is now $wgProhibitedFileExtensions
- $wgMimeTypeBlacklist is now $wgMimeTypeExclusions
- $wgEnableUserEmailBlacklist is now $wgEnableUserEmailMuteList
- $wgShortPagesNamespaceBlacklist is now $wgShortPagesNamespaceExclusions
Bug: T277987
Depends-On: I91e065c58fda144a722a41cf532e717f962d7a64
Change-Id: I558a8b20d67d48edccce0d065aec2d22992e9dda
Follows-up 1c9230d9fd.
* Move the $wgServer check back where it was, to after installing
MWExceptionHandler. This is not strictly required as one can always
throw, and it'd end up in the logs, and if display_errors is
on also on-screen. But the use of FatalError page specifically,
results in a cleaner plain text error page, which only works if
MWExceptionHandler is installed first. Restore this and document it.
To test, change the conditional to `if ( true )`.
* Update the outdated explaination around date_default_timezone_get().
My patch removed the warning suppression, but left behind the comment
talking all about warning suppression.
Change-Id: I3da96e35d9bc253db2cfc6cc99180e5669320964
This is as useless on load.php as it already was on api.php, and for
things like thumb.php, rest.php, and opensearch.php it's probably not
helping, either.
Change-Id: I86745ad244ae9d969d4d33bfd5e37f1e7eea39f6
* Document the divide between trivial and complex expansion.
* Move more trivial statements from below to the trivial section,
thus making it easier to spot and reduce more of the complex stuff
such as in T233886, and T189966 etc.
Change-Id: Iad8cfd6b377b9ec706e9212892461c71cea55877