Commit graph

829 commits

Author SHA1 Message Date
jenkins-bot
0a33bd66e2 Merge "Use namespaced classes (1)" 2024-06-18 19:32:48 +00:00
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02:00
Gergő Tisza
045c5adcf4
AuthManager: Perform auto-creation as target user in Setup.php also
Passing the target user as performer allows taking into account
global permissions. This is in theory more important Setup.php
(autologin) than in AuthManager (login), and in any case it
probably actually works in Setup.php while it doesn't in
AuthManager (there are too many permission checks happening
at other places which ignore global permissions).

Follows up  I2ad825317e900e865fffa39d4ea644f07beb4cf8.

Bug: T316303
Change-Id: I4dd1651702281cd1b68111b8613344cdae3875e9
2024-06-09 17:32:33 +02:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
Timo Tijhof
16f1d0132c Replace trivial UrlUtils use with parse_url()
For precedent see also change I6492f51428, I1e76d2f5ae, I98ea4670e8,
and many other results for "parse_url" in Codesearch (WMF Deployed).

This follows recent commits that clarified dependency on UrlUtils:

* I3f1d7a2da2f67a38a7d7a7b4268a93e01a01bf1e: Setup.php.

  Same as before, no fallback check, because $wgServer must be valid.

* I5e36ee80e5c30e95b79bf45e7b26860cb2668d56: UserMailer.php.

  Fallback to empty string, same as before.

* Id82a9fba6b3cdae3caf169eef5192766b33f0550: ParsoidHandler.php.

Change-Id: I57a8e7ea1b379779f31f562920888acc6656569e
2024-02-13 13:06:51 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Derick Alangi
d8175a6274
Setup.php: Replace use of deprecated wfParseUrl()
At this point in Setup.php, we already have the services container,
so we can use the UrlUtils service and avoid the global function.

Change-Id: I3f1d7a2da2f67a38a7d7a7b4268a93e01a01bf1e
2024-01-24 17:27:38 +03:00
Bartosz Dziewoński
b2c83a0721 Deprecate $wgCommandLineMode
The global variable is now exactly the same as
`MW_ENTRY_POINT === 'cli'`.

Bug: T313841
Change-Id: I254bf4aa426e4834705be351cc9eb06d18a33f79
2024-01-02 22:21:50 +01:00
Bartosz Dziewoński
6876ccf177 Replace $wgCommandLineMode checks with MW_ENTRY_POINT in other places
I'm not sure if there's a good way to split this up into
logical chunks.

Bug: T313841
Change-Id: I3b35a2e475b5143f383d4085fbc6a0ed3bbc32b8
2024-01-02 22:17:14 +01:00
Bartosz Dziewoński
05ed323113 Replace $wgCommandLineMode checks with MW_ENTRY_POINT in developer code (follow-up)
Follow-up to f61827d9e0,
I missed some debug logging.

Bug: T313841
Change-Id: I5000887ddf5a71e30e10808c6614aa3cbc45e2d2
2023-12-19 22:02:52 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Bartosz Dziewoński
9fbfead564 Fix logging Status objects to 'authevents' channel
We can't pass the actual Status objects due to T269676, but
stringifying them is not good either, as the handlers for this
channel expect just a message key.

Bug: T275085
Change-Id: Idfcaf3455c04b8929dc820a43533cf008e9f41e8
2023-10-16 15:37:33 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Daimona Eaytoy
f78fd3710d Add $wgRequest to phan's globals_type_map
The base phan config uses a file_exists check to determine whether to
use the namespaced class name, but it doesn't work when running against
core because MW_INSTALL_PATH isn't set. So specify the type in the local
config, and remove @phan-var annotations added in I6bbdbbe6.

Also use `::class` instead of string literals for classes.

Change-Id: I994a0ed32ea948253ed07ee3cc8868a0eaa6d8b9
2023-09-11 23:22:12 +02:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Amir Sarabadani
82478bd60d Reorg: Move SiteConfiguration to includes/config/
And namespace it to MediaWiki\Config

This should be eventually deprecated and removed but this has been
blocking the reorg for long enough.

Bug: T321882
Change-Id: I7a1a073495469623f6f77e6f74b23b7b4c18033a
2023-09-11 18:43:47 +01:00
Amir Sarabadani
d8e542abf9 Reorg: Move three output related classes to includes/Output/
And namesapce them:
 - StreamFile
 - OutputHandler
 - OutputPage

Bug: T321882
Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
2023-09-05 19:36:42 +01:00
Daimona Eaytoy
6dfa6d451f phpunit: Throw exception when MediaWikiServices is accessed too early
Promote the deprecation to an error in the context of PHPUnit tests. The
point of hard deprecations is to make tests fail and this will help with
that, and also with eventually promoting the deprecation to an error
outside of tests.

Adjust code in parser tests that was accessing MediaWikiServices via
Title too early.

Avoid hack of resetting the error handler after loading Setup.php, and
conditionally install MW's hadler instead. This is particularly
important in scenarios where an exception is thrown before the handler
is reset, because MW's exception handler may also access
MediaWikiServices.

Bug: T227900
Bug: T273261
Change-Id: I7c5234046379cf4abd25d65e78c0a99ac9f32600
2023-07-17 12:16:14 +00:00
Timo Tijhof
b7ce2923f9 installer: Move Pingback->run() to Setup, document reason for external check
Follows-up Ib93fb4e0098d32a8e (2dcae8e9b7).

Change-Id: I3f03289ca2a7664b2c08a51045c6b8eb465e5465
2023-06-20 23:49:09 +00:00
Amir Sarabadani
9606086c4c Reorg: Move Pingback to installer/
It shouldn't be in directly in includes/

Bug: T321882
Change-Id: I3c738cf65def049f7a5b128e8957de672f7bd072
2023-06-05 09:42:57 -04:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
daniel
38cf45a747 parserTests: ensure test classes get auto-loaded.
This introduces the MW_AUTOLOAD_TEST_CLASSES switch to tell Setup.php
to enable auto-loading for test classes.

This switch can be set in file scope by core maintenance scripts that
need access to test classes. This is consistent with the mechanism used
by maintenance scripts to control other aspects of Setup.php

This is an alternative solution to the fix proposed in I17ff5867c5f57c524.

Change-Id: I2a0000f6a885c1ce1b28b748e8cc762af5584c2c
2023-03-27 20:38:53 +02:00
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00:00
Arlo Breault
1f5c50462d Fix typo in Setup.php
Unless this isn't a typo and I'm about to learn something.

Introduced in I157abfd9049fb8382da53005a084ab86f47e8d8a

Change-Id: Ic2f77071696a914f4aa388e020d4e7417cd9f898
2023-03-23 15:50:01 -04:00
Tim Starling
89fef0ef93 Fix total breakage of wgCanonicalServer fallback
wgCanonicalServer is false by default. Setup.php tried to set it to the
result of a wfExpandUrl() call, which initialised the UrlUtils
service with the current value of wgCanonicalServer, i.e. false.
UrlUtils had a fallback for null but not false. So subsequent calls to
wfExpandUrl() would always use the empty string for the canonical
server. Probably since 472a914c63.

So, have UrlUtils handle the fallback, and have Setup.php ask UrlUtils
for the final value.

Bug: T325529
Change-Id: I99329e75bd53049ae84a8ae7a2536ad12cfeeb3b
2023-03-17 14:11:16 +00:00
Brian Wolff
67d13660a4 registration: Add a friendly error message for missing extension
Based on Project:Support_desk, this seems to be a very common error.
Many more novice users seem to get confused by the technical message
involving "stat failed". Given that this might be the first user's
first experience with MW, I think its prudent to make it friendly
as possible.

This error message does not do i18n. I didn't do i18n to avoid
dependencies on MW stuff as it is very early in the setup process,
exceptions aren't usually i18n'd, and its entirely possible that
this error happens before a language is even set.

This does not respect $wgShowExceptionDetails. I think that can
be justified because this error happens during setup and not during
normal operation and there would be no user controlled values in
the backtrace just paths.

Bug: T321363
Change-Id: I4ed0d333d57626d05c361d08f1bf4a919115d550
2023-03-15 08:00:22 -07:00
daniel
db729e46f6 Treat $wgHooks as a regular setting
$wgHooks should be treated like a regular setting, which cannot be
manipulated after bootstrapping is complete. This will allow us to
greatly simplify the logic in HookContainer.

Replacing $wgHooks with a fake array after bootstrapping allows us to
detect any remaining live access to $wgHooks without breaking
functionality.

The plan is to have the fake array emit deprecation warnings in the 1.40
release, and make it throw exceptions in later releases.
See Iddcb760cf8961316d6527e81b9aa968657d8354c for the deprecation
warnings.

Bug: T331602
Change-Id: I0ebba9a29f81b0d86ad8fd84d478fb244f9e9c15
2023-03-09 10:20:44 +01:00
jenkins-bot
a04e191f42 Merge "Reorg: Namespace the Title class" 2023-03-02 18:40:46 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
daniel
0a54ca1526 Remove support for MW_USE_LEGACY_DEFAULT_SETTINGS
The purpose of MW_USE_LEGACY_DEFAULT_SETTINGS was to allow Setup.php to
load default values from DefaultSettings.php, instead of using
MainConfigSchema. It was put into place for the benefit of third-party
installations that encounter issues with using MainConfigSchema. No such
issues have been reported, so we can remove the compatibility switch in
1.40.

The use of DefaultSettings.php as been deprecated since 1.39, but there
are still several extensions that rely on loading it. It remains a stub
for MainConfigSchema::listDefaultValues() for now.

Change-Id: I280f80e5be15fbcd809596087b299add5f83af1f
2023-03-02 13:39:17 +00:00
daniel
180f0a6468 Introduce run.php for running maintenance scripts
Maintenance scripts can now be run like this:

    maintenance/run.php <class>

NOTE: This introduces a new callback into Setup.php,
MW_FINAL_SETUP_CALLBACK. In contrast to MW_SETUP_CALLBACK, it is
called after extensions have been initialized.

Bug: T99268
Change-Id: Ia221f72d6b7d23df74623d60ade7fe3e5d913074
2022-12-21 06:52:04 +00:00
daniel
455e7686bf SettingsBuilder: introduce a "registration" stage
Previously, SettingsBuilder would allow configuration to be loaded
and modified until it was "finalized", at which point configuration
became read only. This patch introduces an intermediate stage where
registration dynamic manipulation of config values can be performed,
after all extensions have been loaded and all config schemas are known.

Motivation:
Extension registration callbacks are typically used to dynamically set
config variables, often based on other configuration. This should be
done using SettingsBuilder rather than global variables. But previously,
we could only be sure that all extensions are known after SettingsBuilder
was "finalized", at which point it would be impossible to change config
values.

Change-Id: I6f8f9f3f7252f0024282d7b005671f28a5b3acc3
2022-12-16 15:47:05 +00:00
jenkins-bot
22e62b9fda Merge "Miscellaneous PHP version related cleanups" 2022-11-20 23:59:47 +00:00
Tim Starling
28750729bd Miscellaneous PHP version related cleanups
MediaWikiTitleCodec: I removed the comment about dbkey being
"conveniently nullified" since that is no longer correct. The first
preg_replace() can return null, and that is guarded. The second
preg_replace() hopefully can't return null, because if it does, trim()
will generate a deprecation notice on PHP 8.1.

Some other self-explanatory changes.

Change-Id: Iad0ace821eba782c3033ec8abfeac461ac4e8ace
2022-11-21 10:11:53 +11: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
Timo Tijhof
41333fa512 profiler: Inject $wgProfiler from Setup.php to Profiler
Follows-up I58ff3c193190d78a. Small step toward not run-time reading
the global (and using Config here is non-trivial/unsafe).

Change-Id: Ic527e493baabe700c50f75fadaa5b51615a5e597
2022-11-09 02:58:19 +00:00
Amir Sarabadani
7690ab4e33 Reorg: Move HeaderCallback to Request directory
Cleaning root of includes/

Bug: T321882
Change-Id: I1844da95d4fd79824646fdf4b6063cb771ca3000
2022-11-08 10:53:27 +01:00
Amir Sarabadani
0fff5089ba Reorg: Move StubObject classes in includes to its own directory
Bug: T166010
Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
2022-10-25 16:04:48 -04:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
TheSandDoctor
da38639658 Remove deprecated $wgParser
$wgParser, deprecated in 1.32, has been removed.

Bug: T160811
Change-Id: Iaf09d3e158e1fee8c0f541695b6d9b4233033c81
2022-08-03 14:40:16 +02:00
daniel
cf39a40f16 SettingsBuilder: report warnings
This adds functionality to SettingsBuilder for collecting warnings to be
logged later, when the logging mechanism has been set up.

This also adds a validation step to update.php that aborts the update
if any warnings have been registered in SettingsBuilder, or the settings
fail to validate against the settings schema.

Change-Id: I387905289fb93591f79b96bf4c6cb5ec692b2aff
2022-07-15 12:24:20 +02: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
Aryeh Gregor
b72b9a8c43 Move dynamic defaults into MainConfigSchema
The goal is to keep the actual default values for settings in the same
place as the setting is declared, and applied using the regular means
for loading the settings -- not in a separate piece of code that needs
to be loaded through some entirely different mechanism.

SetupDynamicConfig.php now contains a few categories of things:

* Post-processing of configuration settings, where already-set settings
  are altered. This could be moved to MainConfigSchema too as a separate
  set of methods.
* Processing of old aliases of settings (blacklist, slave) that are not
  registered as settings anymore and therefore are not available to
  MainConfigSchema. This could perhaps be moved to LocalSettings
  processing somehow?
* Setting $wgUseEnotif, which is also not registered as a setting.
  Easiest would be just to declare it as a setting and have it set
  unconditionally.
* Setting the actual timezone to $wgLocaltimezone. This is not related
  to configuration and should just be in Setup.php.

Bug: T305093
Change-Id: Ia5c23b52dbbfcb3d07ffcf5d3b7f2d7befba2a26
2022-07-07 09:55:48 +10:00
Timo Tijhof
30fe871e82 exception: Inject wgShowExceptionDetails from Setup.php
Follows-up I8520d8cb16 and Ib941c22d6b7ec5f1b9, and adds an internal
setter for use by Setup.php, and for wmf-config:rpc/RunSingleJob.php
which is a use case for setting it after Setup.php but before most
code execution. Interact with a component owner instead of directly
maintaining state and providing a shared API through the Config object.

Change-Id: I5c3d4b11f4e0eb3906ccb5b5fe3979e026459859
2022-05-22 19:46:18 +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
jenkins-bot
5029306c80 Merge "Remove access to config globals from includes/exception" 2022-05-16 01:47:20 +00:00
Timo Tijhof
4f4f283d1d Setup.php: Remove internal use of $IP
Follows-up bedd996fe6 (I157abfd9049fb838).

Change-Id: Ib7a7e26f564ca996f1de3edd37b2359c5abec9d2
2022-05-13 16:32:09 +00:00
daniel
05b0937bdf Remove access to config globals from includes/exception
Allow callers of MWExceptionHandler::getStructuredExceptionData() and
jsonSerializeException() to explicitly control whether a backtrace is
included in the return value. This avoids the need to rely on the
LogExceptionBacktrace setting in static methods.

Bug: T294739
Change-Id: Ib941c22d6b7ec5f1b984bf5ded90652e42ad7b67
2022-05-12 20:33:15 +02:00
jenkins-bot
6308d67121 Merge "Setup.php: allow loading config schema from MainConfigSchema." 2022-05-04 23:41:13 +00:00
jenkins-bot
654ccb3a4c Merge "Setup.php: clarify the use of $IP." 2022-05-04 18:10:39 +00:00