Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead
Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a
Break one long line in SpecialPage.php
Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.
Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.
For reference:
https://www.php.net/manual/en/function.get-debug-type.phphttps://www.php.net/manual/en/function.gettype.php
In this commit I'm only changing code where it looks like the result
is used only for some king of debug, log, or test output. This
probably won't break anything important, but I'm not sure whether
anything might depend on the exact values.
Change-Id: I7c1f0a8f669228643e86f8e511c0e26a2edb2948
Changes to the use statements done automatically via script
Addition of missing use statement done manually
Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
Apparently it’s sometimes possible for the DeprecationHelper’s magic
methods to be called while the object is being destructed and has
already had its properties unset; in that case, if we try to access
$this->dynamicPropertiesAccessDeprecated, we’ll get a warning. Fall back
to a simple property access in that case.
Bug: T363492
Change-Id: Idc233f7c65a48b7d8f13fd97e365ef907ec7fc40
This patch introduces a namespace declaration for the
MediaWiki\Debug to DeprecationHelper and establishes a class
alias marked as deprecated since version 1.43.
Bug: T353458
Change-Id: I808c6aa7836445feaa7b401624d79d01f2c70322
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:
"No value was passed, so return null, as per default".
In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.
Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.
In OED, the phrase "by default" is blessed with its own section just
for computing usage:
"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."
There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.
As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.
Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
This class defines convenient shortcuts for common commands, like
creating a User object. To use on shell.php and similar tools.
Change-Id: I7982d163521e7ae8f2be22613ac6a6fb6af1d7cd
When the logging system is Monolog and when $wgShowDebug
or $wgDebugToolbar is true, the LegacyLogger should be
added as a PsrHandler to display the debug data.
Bug: T114532
Change-Id: I7548201ca33e475e894f92ab1022bdae2a7daecc
This makes it much easier for IDEs and tools like Phan to understand
what's going on. Note this syntax is perfectly valid even if a class
is undefined. Language features like `use`, `instanceof`, and
`class_exists` work perfectly fine. We do this a lot in existing
code.
Change-Id: I4d397621ebcc6a7e842150f7641c1b23d082b730
Store the deprecation info in a static property instead of an
instance property. This was causing noticeable memory use for
the Title class.
Because the deprecated properties are defined in the constructor,
we now have to ignore repeated calls.
Bug: T351732
Change-Id: If9504321c66d9033e4090088cbf21d4dd2bd463f
The WikiProcessor::__invoke() method was using the deprecated
WebRequest::getRequestId() to obtain the request ID. This patch
updates the method to use Telemetry::getInstance()->getRequestId()
instead, as per the deprecation notice in MediaWiki 1.41.
Change-Id: I542d76af00613023db219e55ab57ac9bd807c6c3
Why:
- Developers could reasonably expect that `composer serve` would provide
logs in the terminal used for serving the app
What:
- Set an environment variable, MW_LOG_STDERR, and check this in
LegacyLogger which is already loaded in DevelopmentSettings for
installs using the local development quickstart guidelines. If the env
variable is set, and LegacyLogger is already in use for writing to log
files, then use error_log() to also write to stderr
Bug: T347347
Change-Id: I7ff8ec1664d5ee9ca0487b3ed363b43fe235b738
This code should only be executed in development environments, never
in production, so it should be safe to mess with it.
Bug: T313841
Change-Id: I8cab7704b244db1432f4266b2e06e03452ffc98f
When an included file has since been deleted, filesize will raise a PHP
warning and return false, thus causing logspam (possibly) and test
failures (surely).
Add a check for deleted files and report their size as 0 (in case
anything expects the value to be numeric), but keep including them in
the generated debug information in case this turns out to be useful.
Bug: T351986
Change-Id: Ie91c9f2882f12fd8ea822529528dd1dd9efe89db
For readability, and as reassurance since I kept seeing "0s" and
wondering if it was rounding to the nearest second.
Change-Id: If19f2c2155a1f94b38f80154aef497738c654d75
== Change ==
Remove integration from MWDebug methods in favour of capturing
messages from the 'error' channel. This way we fix the following
that we were all blind to:
* PHP built-in errors for native notices and deprecation warnings.
* trigger_error calls from our own code such as in standolone libs,
where we can't use wfLogWarning or wfDeprecated, and instead use
E_USER_WARNING and E_USER_DEPRECATED instead.
* trigger_error calls from third-party Composer libraries, which
similarly can't and don't know about these at all.
I removed support for including a backtrace. XDebug does a better job
of this nowadays, and the information is also available in
mw-error.log already in a more readable manner. Cramming it into a
100px scrollable area made the "Console" tab much less readable in
my opinion. To make it work, we'd need to duplicate the pretty
string formatting code of wfBacktrace() and make it re-usable when
given only a trace array (rather than capture a new backtrace). I
considered re-using MWExceptionHandler::prettyPrintTrace but that is
far more verbose than the string format in wfBacktrace. Creating yet
another untested error pretty print function seemed not worthwhile
as imho in the majority of cases the $caller suffices, and when not,
the toolbar suffices as a nudge to take a look in mw-debug.log, or
check XDebug display_errors, or engage an IDE.
== Test plan ==
1. Add the following to MediaWiki.php#main() as example:
```
wfLogWarning('Hello');
wfDeprecated('Something');
trigger_error('Goodbye');
$x = []; $a = $x['a'];
```
2. Before this change, your native display_errors=1 or XDebug shows
all four. With $wgDebugToolbar enabled, the "Console" tab
showed only the wfLogWarning and wfDeprecated entry.
3. After this change, all four are included
Change-Id: I62d864823ec8ab9b940aae0e0f47b47a728ba861
Remove the need for wmf-config to perform dynamic 'calls'. It
currently uses this to make createLogger() call setTimezone().
The reasons for this are not WMF-specific, and thus can be done here.
In addition, Monolog\Logger supports a timezome argument so that we
don't need to construct two objects for every logger (one in
Monolog\Logger::__construct, and then another to replace it when
calling setTimezone), and also remove the setTimezone call and
skip the dynamic call for it.
The same call overhead can also be removed for the processors
and handlers array. Instead of calling push on each item, we can
pass these to the constructor directly. This does mean the order
will now be reversed but this is imho less surprising than before
(i.e. call from first to last, instead of reversed), and to my
knowledge none of our processors or handlers depend on side-effect
from previous ones.
Bug: T99581
Bug: T116550
Change-Id: Ib300c01c886dc8916413db65078a8356fd40a5c1
* Remove redundant file-level description and ensure the class desc
and ingroup tag are on the class block instead.
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+message:ingroup
* Widen `@covers` annotations in unit tests.
Ref https://gerrit.wikimedia.org/r/q/owner:krinkle+is:merged+message:covers
* Create "Debug" documentation group, covering the debug/ directory.
This will show up on doc.wikimedia.org under "Modules", where
each class is listed, and the class page will also link back to
the group as part of its breadcrumb navigation.
Test with `php maintenance/mwdocgen.php --file docs/,includes/debug/`
and then view /w/docs/html/
* Improve docs of various classes and explain relationships better.
In particular, reformat to ensure each class has a oneline
description that captures its essential function.
Change-Id: I5d1143a9244b7fd888e1dc31f0fd7965272aa900
* Remove conditional test since monolog is, at least as a library,
unconditionally available in both test and production context.
* Reduce direct usage of Monolog by preferring the PSR interface
where possible.
Change-Id: Id529cfd54e98697cf3254d2a0b8b1e247fe1b7f3
The "nonce" CSP feature has been never been properly tested and is not
on track to be enabled at WMF or in MW by default. The use of
nonce-protected eval is not particularly meaningful. It is trivially
bypassed by mw.loader.implement, mw.loader.store, or importScript();
all of which allow any code to be executed directly, or to be stored
and loaded from a first-party origin.
The "nonce" feature is not required for the T208188 roadmap, and with
change I51b8535b2b21a3 there is now also a (small) performance reason
to keep this disabled long-term.
Until and unless there is a plan for enabling this particular aspect
of CSP, we might as well remove it so that we don't waste time our
time building abstraction layers and satisfying dependency injection
through many years for something that might never be used.
Note that this does not remove CSP support from ResourceLoader, and
does not take away from the future of enabling CSP in MediaWiki to
e.g. strictly block third-party scripts, or to require domains to
opt-in by site config or user pref (T208188).
Change-Id: I5a176c41a06a484a11e64bdacdc42b40811fe72e
"BadMethodCallException" sounds like it would fit, but it does
have a very different meaning, described as "exception thrown if
a callback refers to an undefined method or if some arguments are
missing". This is not what's going on here. These are methods that
should only be called from unit tests.
This appears to be a common mistake, often copy-pasted.
Change-Id: Ib39e28f596a883481d5f526460a5c871c75f5313
* Extend ConsoleLogger to support filtering by log level and
forwarding to another logger.
* Extend ConsoleSpi to support filtering by channel/level and
forwarding to another provider.
* Allow configuring which channels shell.php should log to STDERR
and at what levels.
* Deprecate shell.php -d, use more meaningful parameter names.
* Change logging behavior so that logging to STDERR doesn't
prevent normal logging, which seemed like confusing behavior
(either we should always disable normal logging for shell.php
or never, it shouldn't depend on whether we log to console).
Keep old behavior for -d, just in case.
Change-Id: I5d29c95995bf83784c96dd40df9c96e22b9ec73e
Notable changes:
* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
injected. The rest implicitly got a NullLogger due to being absent.
These are now effectively unsilenced.
* Database::__construct() required almost all parameters, even the
loggers. I've wanted to move some of DatabaseFactory into the ctor
here for a while. In order to make this change not a breaking
change, the new 'logger' parameter is optional with NullLogger as
default. This allowed some of the test cases, which were simply
passing NullLogger, to be fixed by passing nothing instead of
passing the new option name.
The Database class is behind a dozen layers of indirection for
real use, so this will still be injected just fine (DBF, LB, LBF,
MWLBF, etc.).
* In LegacyLogger, the handling for $wgDBerrorLog was previously
limited to DBConnection and DBQuery. This now includes errors
from other (generally, newer) parts of Rdbms as well, which were
previously missing.
This only affects sites (typically CI and dev setup) where
$wgDBerrorLog is used, as opposed to the more common
$wgDebugLogGroups by-channel configuration.
* TransactionProfiler gets its logger injected in a rather odd way,
via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
as opposed to service wiring. This is kept as-is for now.
* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
there are cases that intentionally produce failures of which
the result is then observed. In CI we assert that dberror.log is
empty so instead of adding the missing logger fields to that
LBFactory instance, the only one set (replLogger) is removed.
The alternative is to set 'logger' now, which would naturally
cause CI failures due to unexpected entries coming through to
non-mocked error log.
Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
* ForkController, OrderedStreamingForkController: indeed pcntl_fork()
can't return false.
* RL\Image: Specify type instead of using suppression, since the issue
name changes.
* VueComponentParser: Accept complaint about nullable nodeValue.
* Disable PHP 8.0 polyfill stubs when running on PHP 8.0+ to avoid
duplicate interface errors.
* Add Socket stub and use it in LegacyHandler instead of multiple
existing suppressions.
* MemcachedPeclBagOStuff: accept complaint recommending !$result over
$result === false when the type is boolean.
* MemcachedPeclBagOStuff: fix probable bug, ignoring errors from
Memcached::getMulti(). Phan noticed that $res=false was unreachable,
but it should probably be reachable.
* DatabaseMysqli: accept complaint that $this->conn->errno is already
known to be an int. It was probably a hack for some previous version
of Phan.
* BcryptPassword, MWOldPassword, MWSaltedPassword: accept complaint that
the !is_string() checks are unnecessary, after code review of PHP.
* Pbkdf2PasswordUsingHashExtension: note that contrary to Phan's
suggestion, this check is necessary.
* DefaultPreferencesFactory: remove an existing hack for
array_diff_key(), no longer necessary on 7.4 and causes an error on
8.1. Use coalesce instead of cast for the remaining
array_intersect_key() hack since it better shows that we are casting
away null.
* FullSearchResultWidget: fix likely bug involving strict comparison
between a float and an int.
* SpecialWatchlist: accept complaint that $selectedHours is
unconditionally a float, being the return value of round(), and thus
the cast is unnecessary.
* Add stub for AllowDynamicProperties, resolving an error in User.php.
* Xml: accept complaint that $encMonth is already known to be an int.
Six errors remain. These need suppressions or otherwise conflict with
PHP 7.4 support.
Bug: T322278
Change-Id: Ie375bbc8ccf22330b9a169e8da98f2bbe26ec8b9
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
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