Expose info about user blocks from Authority. This allows calling code
to provide more detailed information to the user about why they are
denied some action on the wiki.
Bug: T271494
Change-Id: Ia84e469888866d72752aad355292666c31e12bad
Replace all uses of AbstractBlock::getTarget with
Block ::getTargetName and ::getTargetUserIdentity.
Create AbstractBlockTest and two test cases for
AbstractBlock::getTarget and ::getTargetAndType.
It tests triggering of the deprecation warning.
Bug: T282247
Depends-On: I0543f363af66c57f5763b91320d87a69f23f9466
Change-Id: Iaeca824cac30172178de72f3cf7b7ae4cdd6f880
AuthManager has been converted to a service in 1.35.
AuthManager::$instance is only used in AuthManager::resetCache(),
where it is set to null.
This patch also removes AuthManager::resetCache() because with
removing AuthManager::$instance AuthManager::resetCache() has no
longer any effect.
Change-Id: I8b27f9a2d0d3f7acec6b93f64f9c256084990026
ContentHandler::getForTitle() is deprecated since 1.35.
Depends-On: I52c40084d96e88b2edab46c15a10b83b7decf192
Change-Id: I9b3967a59714e231467a08e5a603f600ff1ab7c2
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.
Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
Inject a UserOptionsManager instead of UserOptionsLookup, and
update deprecated calls to user options methods
Bug: T277600
Bug: T277818
Change-Id: Ifdf491c3fd6b5b16246f33012f1db21f2cbc1f3e
UserEditTracker now returns null for anonymous users
instead of throwing an exception.
Added new UserEditTracker::setCachedUserEditCount()
method (internal) to handle the user_editcount field
in User::loadFromRow()'s row. This now means that
the creation of one User object can set the cached
value for any other object for the same underlying user
- the alternative (just ignoring the value) would mean
that an extra database read might be needed. This is
only used for users created with a row that includes
the user id - we silently discard the value if
the row doesn't have a user id (or the user id is 0)
to avoid issues with UserEditTracker trying to fetch
the user id and potentially triggering another load.
A follow-up will simplify the UserEditCountUpdate class
to remove storing full UserIdentity objects now that
only the id is needed.
Follow-up: Ibf1482bcbcbf4d56fc06531bb3e17e2a6e3e2e6f
Change-Id: Ie3fb4887d9f2d96b32598865030351bf3bf20ce5
As of now, an input like "[" that contains nothing but invalid
characters behaves odd: The prefixsearch API returns the entire
database, alphabetically ordered.
This behavior exists ever since this code was introduced in
Iaffe30a (2014).
While this might be used as a "feature", I really don't think it
is intentional:
* The way the code is arranged executes an SQL query with a
pointless `LIKE '%'` that doesn't do anything but possibly
wasting CPU resources. This doesn't look intentional.
* There are much better APIs when you really want to list all
pages.
* I would expect an input like "*", "%", or "" to return all
pages. But neither of these inputs does this. Only some very
strange inputs like "[" do.
* I would argue that "[" should behave the same as "", i.e. as
if no useful input is given.
* Since I877297f (2020) we normalize e.g. "[[foo]]" to "foo",
for convenience. Since then such an input works as expected,
instead of returning the entire database. This leaves titles
that contain nothing but invalid characters as the only
edge-case.
Change-Id: Ib2cbf315ed7c3736391362be6d69599c58e690db
This can be used to replace calls like this:
$loadBalancer->getLazyConnectionRef( DB_REPLICA )
I’m not adding a corresponding getLazyWriteConnectionRef() method yet,
because I’m not sure it would make sense (you would want to write to the
database, but only later?). That said, if someone else has a use for it,
don’t let me stop you from adding it :)
Bug: T285042
Change-Id: Icdbf5a170f2ae4e0ea4ee144a801fadfda932cd3
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.
When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.
Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.
Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
There is a fallback in Module->getConfig() to the global services
container. This is not meant to be used in practice, but there were
two places where this was missing: WebInstallerOutput, and various
PHPUnit tests.
* Add missing setConfig() to WebInstallerOutput.
* Add missing setConfig() to various tests. Most tests were already
doing this correctly and using the standard mock from
ResourceLoaderTestCase. Upon switching the last few tests as well,
I uncovered various errors due to the mock missing some settings
that the tested code uses, so these have been added now to
ResourceLoaderTestCase.
Bug: T277728
Change-Id: I44f16ec4e00423fb6f641e58fffc1d40e4571f01
This doesn't yet completely eliminate the dependency
on user, because the individual password policy check
functions are still documented to receive User.
Password policy check functions can be defined by
extensions, and configured via $wgPasswordPolicy,
so we still need to unwrap user identity to a User
before passing into the actual check. But, this removes
User from the PassworkPolicyCheck interface.
Change-Id: If813b9b0ebbeb89bc61331c9da8efb86e591bfb9
This reverts commit 9f4a392544.
Reason for revert: This commit introduced a recursive service
instantiation for sessions using the BotPasswordSessionProvider. The
recursion will need to be addressed before re-merging to master.
Bug: T253077
Change-Id: Idcc250eb3b481a6425d200680b56d9d75e781d0d
Following soft deprecation in 1.31, hard deprecation
in 1.35, and removal of remaining deprecated uses,
the entire Revision class, and the tests for it, can
now be removed. This will be followed by a patch to
clean up old references in comments - this is just
dealing with the code.
There were some other tests in RevisionDbTest.php
for Title::getNextRevisionID and Title::getRelativeRevisionID,
which could have been kept, but since those methods are
tested separately in TitleTest, no need to keep these, so
just remove the entire file.
Also remove the RevisionTestModifyableContent and
RevisionTestModifyableContentHandler classes that were
only loaded for use in RevisionDbTest - not sure how
the stable interface policy applies to classes that
are only loaded within tests, so mention that in the
release notes as a breaking change.
Bug: T247143
Change-Id: I05a297d28b85c7413384979f5c908be318098d9d
This patch adds a service as a replacement for MWGrants. This is
done as it allows proper dependency injection of used services
and configuration settings.
Bug: T253077
Change-Id: Iac52dba15fdaf6869da14deebd89fef59b817255
For any other module, the document root would get processed only
once, but for SkinModule the internal paths would be for the skin
directory, and the path for core ends up processed once.
Once in SkinModule::getStyleFiles via extractBasePaths(), which turns
a document root (wgScript=wgResourceBasePath="") empty string into
a slash (as it should). And then again later by FilePath::getRemotePath
when it is time to perform background image remapping.
The hybrid approach of SkinModule hasn't really been supported or
tested for in this case, but it hasn't been an issue for most installs
because the paths naturally don't end up ambiguous, except for
document root installs. This is likely not the last we've seen of
this, but for now it seems feasible to try to make FilePath
responsible for handling this when it is encountered .
Bug: T284391
Change-Id: I6f5f232bd6da6c655246a5e678a5600889cd78aa
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d