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
> Given all called same-class methods are de-facto and liberally claimed,
> and that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class as a whole instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors, especially private functions (or worse,
> forget to update it).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
Change-Id: If90fc5285a067ec8f706d87b2ba1ae85020e2ba0
And deprecated aliases for the the no namespaced classes.
ReplicatedBagOStuff that already is deprecated isn't moved.
Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContentHandler and establishes a class
alias marked as deprecated since version 1.43.
Bug: T353458
Change-Id: I2c72dacf28ee72fb70b15acdd81d0eb717ea949a
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContent and establishes a class
alias marked as deprecated since version 1.43.
Bug: T353458
Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
TestCase::expectDeprecation() is deprecated in PHPUnit 10,
use mediawiki own MediaWikiTestCaseTrait::expectDeprecationAndContinue()
for this case. This avoids the trigger_error call and isolate the
deprecation check into MWDebug class.
The continue part is also helpful in StubGlobalUserTest, where after the
first deprecation access more code exists, that was not executed as
PhpUnit 9 converts deprecations to exceptions.
In RCFeedTest the exception needs to be catched as the code proceed
after the deprecation notice is emitted.
Bug: T342110
Change-Id: Iecf827bec0d5215fd21bbb20b84caf928ee108a0
It is part of the global teardown in
MediaWikiTestCaseTrait::mwDebugTearDown which is annotated with @after
Change-Id: I25df03370e4efbbd08c2833ab72e449f3797e3d1
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way
Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.
Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.
Do the same with the corresponding TitleFactory methods.
Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).
Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.
Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.
Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
Simplify mocking common cases of the content handler factory
only support specific content models.
Change-Id: Ib7f4099a2b1655b1bfb4d90f03105c27d17042ed
This may seem a bit weird but anything else related to actor is already
under user/ including ActorCache, ActorNormalization, ActorStore and
ActorStoreFactory.
Bug: T321882
Change-Id: I7072b374bba7a0cd9d905e399c822bf30bd5c0d8
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
These three classes:
- TitleArray
- TitleArrayFromResult
- TitleFactory
We need to move these and the rest of files under title/ to Title/ (and
namespace them) but the patch will become way too big given that Title class is
also one of them.
Bug: T321882
Change-Id: Iac1688172ee457348a08a470c86e047571feb8e0
createMock() does the same, but is much easier to read.
A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.
Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.
Bug: T305784
Change-Id: I34e492d84d9fc4bc78481667202716d93b3c43cb
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.
Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:
1. It requires any/all statements to be explicitly marked. The
suppressWarnings/restoreWarnings sections encourage developers to
be "lazy" and thus encapsulate more than needed if there are multiple
ones near each other, which would ignore potentially important
warnings in a test case, which is generally exactly the time when
it is really useful to get warnings etc.
2. It avoids leaking state, for example in LBFactoryTest the
assertFalse call would throw a PHPUnit assertion error (not meant
to be caught by the local catch), and thus won't reach
AtEase::restoreWarnings. This then causes later code to end up
in a mismatching state and creates a confusing error_reporting
state.
See .phpcs.xml, where the at operator is allowed for all test code.
Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
Note: this contains a b/c incompatible change to
SlotRoleHandler, but it's never used in any extensions
and never was used.
Change-Id: I898ab18467f7f8c605a579cc6236859b9d86c7f5
Combine single use private methods, simplify mocks,
use a mock ActorMigration to allow making a unit test
Change-Id: I50e18b7727ca78a0ce0504d2b6c978e14d142b6a
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.
Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.
Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
Since there is the testGetIdDeprecated() test case which tests that the deprecated functionality still works in RevisionRecordTests trait. So the new testGetIdTriggerDeprecatedWarning test case was added in order to check triggering of the warning in RevisionRecord::getId() method.
Bug: T273314
Change-Id: I7248bfa5ed8b485ea79929a3bd5f8db0156c3201
TextContent/WikiTextContent can actually get to initializing
the global service container, which is not good.
Change-Id: I418d0a839fc3cd154d6d02af865e53564e2805ed