Commit graph

1597 commits

Author SHA1 Message Date
Derick Alangi
1afd52e3e4 REST: Move Helper classes to their own namespace
Mixing Handlers with Helpers doesn't look nice for consistency
reasons. Helpers should be in their own place (grouped) in the
Handlers directory as they're really "helpers for the handlers".

Change-Id: Ieeb7a0a706a4cb38778f312bfbfe781a1f366d14
2023-01-16 21:16:09 +01:00
Timo Tijhof
0e3727b23b objectcache: Fix flaky WANObjectCacheTest::testLockTSESlow case
I noticed this in CI during development for Ia893ddb36427eb5e9bff,
however, it is reproducible on latest master as well. Locally, it
happens about 1/30 times:

```
$ php phpunit.php --filter testLockTSESlow unit/includes/libs/objectcache/
Using PHP 8.1.13
PHPUnit 9.5.27 by Sebastian Bergmann and contributors.
There was 1 failure:
1) WANObjectCacheTest::testLockTSESlow with data set #0 (array('hash_tag'), '{')
Callback not used (mutex not acquired, stale value used)
Failed asserting that 3 is identical to 2.
/w/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php:1311
/w/tests/phpunit/MediaWikiUnitTestCase.php:11
```

* Remove randomisation from test. The HashBag is empty at this point,
  and a dedicated instance is created for each test case. Remove doubt
  over conflicts or other uncertainty, and make it easier to debug at
  the same time.

* Increase mocked time gap from 2s to 32s similar to what the
  previous assertion in the same test does already. 2s does not actually
  go past the reduced logical TTL which is 30s at this point.

  It seems to still pass on master in most cases, but it makes sense
  that it can fail. I could not reproduce failures after this change.

Change-Id: I6e491ae3c4f41413e7a952aa0796a787d559ac48
2023-01-13 23:46:51 +00:00
Timo Tijhof
0c42d3313d objectcache: Simpler @covers annotations for WANObjectCacheTest
Loosen up the code coverage a bit so that we can more clearly identity
what logic truly isn't excercised by tests. It also restores some
gaps that were left behind by various refactors when code moved around
or out into various private methods.

Change-Id: I4e65f92ea1eb3f0e781ada4fb2ced0f8ef9d3cc4
2023-01-13 22:48:25 +00:00
Daniel Kinzler
f2e9d5108d REST: collect metrics on endpoint access
This is a modified version of Ie282bc5b5f5df0bbd6a40c8362ba73fcbbf36c2e
which was reverted in 5c7cca8776.

Bug: T321969
Change-Id: I566d54a473aa51c4cdaada21a49d63c0624aab93
2023-01-12 14:50:58 +00:00
Bartosz Dziewoński
84a43f20f0 Simplify callback in HTMLForm tests
The anonymous function was equivalent to just specifying 'wfMessage'.
Same as in I355504984d343a2c7c469759f791612c5b6d6556 in Wikibase.

Change-Id: Ib94b7cceabce25ca95374d944255c7197e6a476a
Follows-Up: Ica0740049f0a3e8ec764903c5b71825e4d628a3f
2023-01-10 21:34:00 +01:00
Brian Wolff
07cdef809c Deprecate creating HTMLFormFields without reference to parent form
Currently it is documented that mParent in HTMLFormField may be null.
This can happen if the form element is constructed manually via
new, instead of the normal way via HTMLForm methods.

As it stands, much of the code assumes that mParent is always set
despite the documentation. Lets mark creating form fields without
parent set as deprecated. The current situation seems like a
recipe for bugs, and after the deprecation period this would allow
us to simplify some of the HTMLFormField code.

Bug: T326456
Change-Id: Ica0740049f0a3e8ec764903c5b71825e4d628a3f
Depends-On: I15a39605e3eec8a5c265c4a331039fa906eda036
2023-01-08 18:20:16 -08:00
jenkins-bot
35822685b5 Merge "tests: Remove assertion of spec in ParamValidatorTest::testGetTypeDef" 2023-01-07 01:32:15 +00:00
jenkins-bot
4ef95bfb4d Merge "tests: Declare GIFMetadataExtractorTest::$mediaPath" 2023-01-07 01:01:08 +00:00
Umherirrender
77792c225d tests: Change assertion in AbstractSecondaryAuthenticationProviderTest
Creation of dynamic property Mock_AuthenticationRequest_4d271de1::$done
is deprecated in php8.2

Bug: T314099
Change-Id: I21e7a257a5e695cc32f183add5ba6785a6898118
2023-01-06 04:06:32 +01:00
Umherirrender
8170da2516 tests: Remove assertion of spec in ParamValidatorTest::testGetTypeDef
Creation of dynamic property Mock_TypeDef_90a9d0fe::$spec is deprecated
in php8.2

Bug: T314099
Change-Id: If7b8a99cf7e7b94d9d2ff857948f874ccf3f1d37
2023-01-06 04:01:09 +01:00
Umherirrender
ea83138dcc tests: Declare GIFMetadataExtractorTest::$mediaPath
Creation of dynamic property GIFMetadataExtractorTest::$mediaPath is
deprecated in php8.2

Bug: T314099
Change-Id: I3247925a548586713d4363fc9e11625bc4c9ad46
2023-01-06 03:53:31 +01:00
jenkins-bot
26df447672 Merge "rdbms: Consolidate logger channels into one" 2023-01-03 23:39:38 +00:00
Timo Tijhof
4ef0891994 rdbms: Consolidate logger channels into one
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
2023-01-03 22:46:38 +00:00
Umherirrender
e59cf6c133 Use SlotRecord::MAIN instead of hard coded value
Makes it clear what about the value is (slot role name)

Change-Id: I0dc195aa24c0e699a32d3b07e62d58e90cfac84d
2023-01-03 16:24:42 +01:00
DannyS712
1f8e5bcefe DummyServicesTrait: add content handler factory
Simplify mocking common cases of the content handler factory
only support specific content models.

Change-Id: Ib7f4099a2b1655b1bfb4d90f03105c27d17042ed
2023-01-02 01:09:42 +00:00
Umherirrender
c0794e1b6e Hard-deprecate User/PermissionManager group permissions lookup functions
- User::getGroupPermissions
- User::getGroupsWithPermission
- User::groupHasPermission
- PermissionManager::getGroupPermissions
- PermissionManager::getGroupsWithPermission
- PermissionManager::groupHasPermission

Bug: T325680
Change-Id: If9ae610037f049050c21ad0eab7bcb4d6e596f29
2022-12-21 21:15:00 +01:00
jenkins-bot
95347830fc Merge "SettingsBuilder: introduce a "registration" stage" 2022-12-19 00:25:33 +00:00
jenkins-bot
4fde3b96de Merge "ParsoidOutputAccess should support all models that serialize to wikitext." 2022-12-16 19:36:18 +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
Amir Sarabadani
cb18d1007e Reorg: Move ActorMigration and ActorMigrationBase to user/
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
2022-12-16 13:44:33 +01:00
daniel
e1c3af9177 ParsoidOutputAccess should support all models that serialize to wikitext.
The motivation is to restore parsoid support for the content models
defined in the Proofread extension.

Bug: T246403
Change-Id: I33d269e42fede28139f7c923504326a77d11ee13
2022-12-16 12:20:10 +01:00
Derick Alangi
ce8e5f1549 Introduce HtmlMessageOutputHelper for system messages
This introduces an interface HtmlOutputHelper that is implemented
by both HtmlMessageOutputHelper or HtmlOutputRendererHelper based
on the page we're dealing with.

Bug: T323558
Change-Id: I1fb8dcc5cc05ce3f32f3c1862b88045f1c8e612b
2022-12-16 11:49:56 +01:00
jenkins-bot
f3b5f09e4c Merge "Make use of the ?? and ??= operators where it makes sense" 2022-12-16 01:06:50 +00:00
jenkins-bot
dba0bf3877 Merge "add redirects to page/history and link endpoints" 2022-12-15 11:37:43 +00:00
jenkins-bot
bb20303cb6 Merge "Fix whitespaces after comma" 2022-12-15 00:56:34 +00:00
jenkins-bot
c913145a86 Merge "rdbms: Moving replication-related code to its own component" 2022-12-15 00:54:24 +00:00
Amir Sarabadani
9b078129d2 rdbms: Moving replication-related code to its own component
Remove 'insertSelectIsSafe' option, unused.

Remove 'topologicalPrimaryConnRef' option, no longer used as of two
months ago with I41a57247503 (8c9398f7f9).

Remove unneeded DatabaseSqlite::getTopologyBasedServerId
implementation which can inherit null instead of overriding with string
of "0". Only caller is SqlBagOStuff::makeTimestampedModificationToken
which can be used as MainStash DB, where its important that a given
server always has the same unique name within a set of db hosts that
may replicate to each other. By inheriting null as topology server ID,
it SqlBagOStuff will use IDatabase::getServerName instead. That in turn
uses the 'host' connection parameter, which defaults to null in
DatabaseFactory, and then falls back to the string "unknown" which is
as good as "0" for this purpose.

Bug: T299691
Change-Id: Iceb65c28cdd3c4a89b3c8b34c3f95d3285718ec0
2022-12-15 00:37:02 +00:00
Umherirrender
fd516a98e1 Fix whitespaces after comma
Change-Id: Ide6de0a53661e6f650099d7b1f274a02699441df
2022-12-15 01:24:14 +01:00
jenkins-bot
0fb254ffa5 Merge "cache: Inject HookContainer into BacklinkCache" 2022-12-14 22:03:37 +00:00
jenkins-bot
f59e8aca77 Merge "site\MediaWikiPageNameNormalizer: Replace deprecated Http::get" 2022-12-14 21:35:35 +00:00
Umherirrender
1e62e1af8f site\MediaWikiPageNameNormalizer: Replace deprecated Http::get
Bug: T305813
Change-Id: I138aecd6275b7e9b2a852565e67e083460b8286d
2022-12-14 21:12:30 +00:00
jenkins-bot
81ee9e8ca8 Merge "Revert "REST: collect metrics on endpoint access"" 2022-12-12 22:16:02 +00:00
Daniel Kinzler
5c7cca8776 Revert "REST: collect metrics on endpoint access"
This reverts commit d32c260ed0.

Reason for revert: Timo has reservations, I'll submit an updated version later.

Change-Id: I71d4d61a879fda4dccfc105127446cfedde75a7b
2022-12-12 20:05:06 +00:00
jenkins-bot
be2ff28b48 Merge "Reorg: Move MagicWord related files to under parser/" 2022-12-11 18:15:48 +00:00
Amir Sarabadani
a1b4699fea Reorg: Move MagicWord related files to under parser/
This is approved as part of T166010 RFC.

Bug: T321882
Change-Id: Ia4498c0a20e38a6a288dc14065ea8242c84fbc49
2022-12-09 13:48:35 +01:00
msantos
63deedc94c add redirects to page/history and link endpoints
* Add normalization redirects for page/history, page/history/counts
and links/language endpoints

Bug: T301372
Change-Id: I731fbfdcfb538c3e8a5dd32349ebaa0e642bf338
2022-12-09 12:17:38 +00:00
thiemowmde
3d65c37ba4 Fix remaining link numeric ids in LinkHolderArrayTest
These specific placeholders are meant to stay untouched in the test.
Because of this it technically doesn't matter if the namespace numbers
and link ids (from Parser::nextLinkID) are numeric. Still I find it
less confusing when the test setup reflects how the code actually
behaves. An IWLINK is identified by a single numeric id, and a LINK by
a namespace:numeric id pair.

This is split from Ie994059 to make it easier to review.

Change-Id: I1141de06eb3235d199a3dc02ef0a24d0d4fe1416
2022-12-09 12:04:40 +01:00
thiemowmde
c05e0183ad Fix bogus test setup in LinkHolderArrayTest
These array keys are all meant to come from Parser::nextLinkID(). That
returns a positive integer. Let's please make the tests reflect what
the code actually does to reduce confusion.

I tried my best to come up with a mapping that still (possibly even
better) makes it obvious what's happening.

Change-Id: Ib5d5f6f48ddc8c066961ea0f36a922ae9f0c6f6c
2022-12-09 12:01:18 +01:00
thiemowmde
f846177e33 Fix bogus non-numeric namespaces in LinkHolderArrayTest
The first level in LinkHolderArray::$internals is indexed by numeric
namespace id. This must be a number. Let's please make the test
reflect what the code actually does.

Note the same mistake was already fixed before in I7e71ffc.

Change-Id: I14f717510a71adf8ea3f75e61ba844d93838f945
2022-12-09 11:46:26 +01:00
jenkins-bot
81ab58ed82 Merge "Protect HistoryBlob storage against malicious class injection" 2022-12-07 20:54:34 +00:00
jenkins-bot
ca84394a1d Merge "Use services in WikitextContentHandler" 2022-12-07 11:43:18 +00:00
jenkins-bot
d9eca3447e Merge "REST: collect metrics on endpoint access" 2022-12-06 21:03:41 +00:00
daniel
090ec5777d Use services in WikitextContentHandler
Change-Id: I626b5ee9a070ad3a97ab9ac9f44cb7003d68bf13
2022-12-06 15:44:40 -05:00
daniel
d32c260ed0 REST: collect metrics on endpoint access
This collects metrics on how often each endpoint is hit, and with which
code it responds.

Change-Id: Ie282bc5b5f5df0bbd6a40c8362ba73fcbbf36c2e
2022-12-06 12:46:01 +01:00
Tim Starling
540bddfb1f When content is marked bad, show an error, don't pretend it is empty
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
2022-12-05 22:03:45 +00:00
jenkins-bot
4380291b40 Merge "Fix casing of class and function name usages" 2022-12-05 07:34:42 +00:00
jenkins-bot
d36136b1b0 Merge "Follow redirects for page/{title} formats source/bare" 2022-12-04 22:45:55 +00:00
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
msantos
fb5c29e2c0 Follow redirects for page/{title} formats source/bare
* Share logic previously implemented for html/with formats through
a trait class

* source/bare formats doesn't execute a temporary redirect. the
JSON body will contain a key "redirect_target" instead if a wiki
redirect is found

* Introduce PageRedirectHandlerTest to test redirect logic shared
between multiple handlers

* Move Handler instatiation to HandlerTestTrait

* Update api-testing tests in Update.js

Change-Id: Id66e33e19adabdb3c9621eaea4a5d441f23edafd
2022-12-02 13:22:14 -03:00
jenkins-bot
b287441ec0 Merge "Replace some more mock builders with createMock() shortcut" 2022-12-02 00:29:35 +00:00