Commit graph

11067 commits

Author SHA1 Message Date
daniel
b3b70624c9 Authority: expose user block info
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
2021-06-30 13:42:21 +02:00
jenkins-bot
7afc309346 Merge "Hard-deprecate AbstractBlock::getTargetAndType() and getTarget()" 2021-06-22 14:41:42 +00:00
vladshapik
e991dff925 Hard-deprecate AbstractBlock::getTargetAndType() and getTarget()
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
2021-06-22 16:59:00 +03:00
ZabeMath
4020306bf7 Hard deprecate User::listOptionKinds()
deprecated since 1.35 and unused.

Bug: T274211
Change-Id: I139ef1de149c94148ad07c62a8c024e4cb0ee053
2021-06-22 15:56:25 +02:00
jenkins-bot
4c85648f32 Merge "Remove User from password policy check interfaces" 2021-06-21 18:54:00 +00:00
jenkins-bot
ca8b0559fc Merge "Make RevisionStore::getKnownCurrentRevision work for foreign wikis" 2021-06-21 18:53:11 +00:00
jenkins-bot
970fc15f95 Merge "Move CRSF token generation to CsrfTokenSet" 2021-06-21 15:03:30 +00:00
Petr Pchelko
f312a6bfe8 Make RevisionStore::getKnownCurrentRevision work for foreign wikis
Bug: T274067
Change-Id: Ia4efa113b4f3dda5a0ed77a8acd2276fc8c3b13c
2021-06-21 07:31:35 -07:00
jenkins-bot
cc4c477f0d Merge "Hard deprecate ContentHandler::getForTitle()" 2021-06-21 00:49:42 +00:00
jenkins-bot
c8f699aca3 Merge "Fix various typos in documentation" 2021-06-21 00:43:51 +00:00
Fomafix
ea1b06c150 Fix various typos in documentation
Bug: T201491
Change-Id: Ifa1b84b28ea97dfb4212658b02f24ee6881c1cb0
2021-06-21 00:26:07 +00:00
Alexander Vorwerk
e77ebc1854 Remove AuthManager::$instance and ::resetCache()
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
2021-06-20 14:55:10 +02:00
Alexander Vorwerk
623c9561cc Hard deprecate ContentHandler::getForTitle()
ContentHandler::getForTitle() is deprecated since 1.35.

Depends-On: I52c40084d96e88b2edab46c15a10b83b7decf192
Change-Id: I9b3967a59714e231467a08e5a603f600ff1ab7c2
2021-06-20 12:10:40 +02:00
jenkins-bot
c4becac43c Merge "Remove AuthManager::singleton" 2021-06-19 23:48:34 +00:00
Alexander Vorwerk
dd52c40cd2 Remove AuthManager::singleton
hard deprecated since 1.36 and unused

Bug: T249421
Change-Id: Ibdfc5c7d755678106c36488f9a223b141ea29566
2021-06-18 23:34:33 +02:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… 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
2021-06-18 21:23:56 +00:00
jenkins-bot
f2877a80ba Merge "Add and fix various type hints in PHPDocs" 2021-06-18 21:14:30 +00:00
Petr Pchelko
6260074a8c Move CRSF token generation to CsrfTokenSet
Change-Id: Idf68f1cc63fb2e01e004ff353fcda026fa4ec10f
2021-06-18 12:24:19 -07:00
jenkins-bot
5028fe175d Merge "Remove User::$mEditCount and internal caching" 2021-06-18 17:57:35 +00:00
jenkins-bot
6ddc3cce59 Merge "api: Fix prefixsearch returning the entire database" 2021-06-18 13:38:11 +00:00
Thiemo Kreuz
51777ee8c1 Add and fix various type hints in PHPDocs
Random fixes I collected the past weeks in my local dev
environment.

Change-Id: Ic8a6262fd28e05cb57335f2faf390a47ff97dbaa
2021-06-18 08:19:23 +00:00
DannyS712
2915e0bbbf DefaultPreferencesFactory: inject and use UserOptionsManager
Inject a UserOptionsManager instead of UserOptionsLookup, and
update deprecated calls to user options methods

Bug: T277600
Bug: T277818
Change-Id: Ifdf491c3fd6b5b16246f33012f1db21f2cbc1f3e
2021-06-17 17:27:40 -07:00
DannyS712
b82cf00983 Remove User::$mEditCount and internal caching
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
2021-06-18 00:25:47 +00:00
jenkins-bot
52cc0ce6ba Merge "DefaultPreferencesFactory: inject all services needed" 2021-06-18 00:04:19 +00:00
Thiemo Kreuz
26bd5ff256 api: Fix prefixsearch returning the entire database
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
2021-06-17 16:25:43 +02:00
Lucas Werkmeister
85846c442c Add getLazyReadConnectionRef() to ConnectionManager
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
2021-06-16 15:57:05 +02:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
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
2021-06-15 00:11:10 +00:00
jenkins-bot
0ce5956898 Merge "resourceloader: Add missing Module->setConfig() calls in tests and installer" 2021-06-14 00:44:54 +00:00
Timo Tijhof
b7c70526a9 resourceloader: Add missing Module->setConfig() calls in tests and installer
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
2021-06-13 21:20:58 +00:00
jenkins-bot
2b3aca6820 Merge "Revert "GrantsInfo service to replace MWGrants"" 2021-06-11 17:40:00 +00:00
Petr Pchelko
48402ba83a Remove User from password policy check interfaces
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
2021-06-11 10:21:14 -07:00
Ebernhardson
7c353e47a7 Revert "GrantsInfo service to replace MWGrants"
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
2021-06-11 17:17:01 +00:00
jenkins-bot
3d487a3b89 Merge "Replace easy usages of User for UserIdentity/Authority" 2021-06-11 11:56:46 +00:00
jenkins-bot
87f10b99a6 Merge "GrantsInfo service to replace MWGrants" 2021-06-11 06:24:29 +00:00
DannyS712
983984d5d4 EPIC: Remove the Revision class entirely
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
2021-06-10 15:57:44 +00:00
Petr Pchelko
6a8a786599 Replace easy usages of User for UserIdentity/Authority
Change-Id: Id176ee0fab64707020ac6c47a087ef00f8bed4e3
2021-06-09 07:53:52 -07:00
Alexander Vorwerk
9f4a392544 GrantsInfo service to replace MWGrants
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
2021-06-09 16:48:46 +02:00
Petr Pchelko
92564edc7c Use Message::page instead of Message::title
Also modified new APIs added to ApiErrorFormatter to
use PageReference instead of Title.

Change-Id: I093c89f8e1e6d383603f887358be6ece70f23a02
2021-06-09 13:18:22 +00:00
Petr Pchelko
bdecf516b9 Replace Title in Message/MessageCache
Change-Id: Ib0e36d767788edcdd8fa9ebc5de6bbde4cf50f12
2021-06-09 06:16:56 -07:00
jenkins-bot
e8ca8b4be2 Merge "resourceloader: Fix remote bash path at document root passed into SkinModule" 2021-06-09 06:44:09 +00:00
jenkins-bot
f14a28d092 Merge "tests: Remove unused composer.json sample data" 2021-06-09 06:30:33 +00:00
Timo Tijhof
526c6a4172 resourceloader: Fix remote bash path at document root passed into SkinModule
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
2021-06-08 23:18:22 -07:00
jenkins-bot
f448d93a0f Merge "Use the unserialized form of image metadata internally" 2021-06-09 02:33:55 +00:00
Timo Tijhof
3371e4031c tests: Remove unused composer.json sample data
Follows-up c351c4f06e.

Change-Id: I842690849590f2ee57eb951099b9131728ecb7d7
2021-06-08 23:56:01 +00:00
jenkins-bot
b9941fd10d Merge "Contributions: when ip_changes is the "target table", put it first" 2021-06-08 21:25:45 +00:00
jenkins-bot
170f5c21a6 Merge "Rename change_tag indexes to have ct_ prefix" 2021-06-08 17:50:09 +00:00
Ammar Abdulhamid
1adaca51c3 Rename change_tag indexes to have ct_ prefix
Bug: T270033
Change-Id: I8a429726c99f6cadea0d671fd871f66b5611c856
2021-06-08 17:57:15 +01:00
jenkins-bot
cd14aa0806 Merge "Accept UserIdentity in code to manage edit counts" 2021-06-08 13:30:25 +00:00
jenkins-bot
ed1d2a9b9c Merge "Allow passing mock Authority in API integration tests" 2021-06-08 12:20:07 +00:00
Tim Starling
b4849e03b7 Use the unserialized form of image metadata internally
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
2021-06-08 17:04:01 +10:00