Commit graph

280 commits

Author SHA1 Message Date
jenkins-bot
1270ae1bab Merge "Hard-deprecate getBodyValidator" 2024-08-08 16:12:38 +00:00
jenkins-bot
2d3c0375d1 Merge "Drop writeapi userright" 2024-08-01 21:06:33 +00:00
Reedy
b52a8addf5 Drop writeapi userright
Bug: T294397
Depends-On: Ib34228a18917e404517d45e539bd786419d9c401
Change-Id: Ifad2edc782b36d21c8c67fecde7f011dce02c11b
2024-07-31 11:10:50 +00:00
jenkins-bot
1cbafee5de Merge "[ParsoidParser] Remove unneeded code to set render ID" 2024-07-30 16:54:51 +00:00
jenkins-bot
7e5b96ee7d Merge "Tests on forcing multi-value to be an array in JSON" 2024-07-20 03:42:32 +00:00
C. Scott Ananian
16de2c0851 [ParsoidParser] Remove unneeded code to set render ID
Since I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78 it is part of the
contract of ContentRenderer::getParserOutput() that the render ID (and
other cache parameters) will be set when it returns.
(ContentHandler::getParserOutput() can set them even earlier if it has
custom content-based overrides.)  We had a lot of temporary
backward-compatibility code "later" in the parse process to try to close
the barn door if some code path "forgot" to set them, but these are
unnecessary now.

This patch removes that backward-compatibility code in ParsoidParser;
there is similar remaining code in ParserCache etc. which can be
addressed in follow ups.

(For compatibility we do have to temporarily copy the render ID code
inside ParsoidOutputAccess::parseUncachable, but that class is
deprecated and will be removed.)

The HtmlOutputRendererHelper path which used to call
ParsoidParser::parseFakeRevision() is now replaced with a codepath that
goes through RevisionRenderer.  In order to maintain the same behavior
of the ParsoidHandler, we have also added 'useParsoid' handling to the
JsonContentHandler.  This support can perhaps be deprecated eventually.

Bug: T350538
Change-Id: I0853624cf785f72fd956c6c2336f979f4402a68f
2024-07-19 16:09:32 -04:00
C. Scott Ananian
c23420603c Deprecate Html*Helper::init()
Instead of creating a half-initialized helper and later calling ::init,
provide all the information necessary for the helper in the constructor.
This is facilitated by the fact that there already exists a factory
class, PageRestHelperFactory, which holds all the services required.

This affects:
* HtmlOutputRendererHelper::init()
* HtmlMessageOutputHelper::init()
* HtmlInputTransformHelper::init()

Change-Id: I1e1213597c6be012f2bc024c2b370c968ff3b472
2024-07-19 15:03:37 +00:00
frankie
40e4aaa5cc Tests on forcing multi-value to be an array in JSON
Provides mroe tests for I39a8c50a1cb884fee9807096750789837efdb061

Bug: T368132
Change-Id: I9658a827dbaafd442161901c03ef1514cc36d9b7
2024-07-19 08:48:57 +00:00
C. Scott Ananian
1a1ac6a82d [HtmlOutputRendererHelper] Remove use of ParsoidOutputAccess::parseUncacheable
This removes the last use of ParsoidOutputAccess in core, allowing it
to be deprecated and eventually removed.

Bug: T367074
Bug: T317018
Change-Id: Ica2c880e2e7c2b126aaea66a3e4be460b3f2234f
2024-07-19 03:09:32 -04:00
daniel
17d9a53102 REST: avoid crash on non-strings in request body
ParamValidator and TypeDef could so far assume that data coming from the
client was always a string. Since we are now using the same code to
validate fields coming from a JSON request body, we may encounter arrays
and other non-string values in places where strings are expected. In
that case, we should fail gracefully instead of crashing with a type
error.

Change-Id: I8a3f0c3299d36e1e93e0114abc0d1d15bac7b5f8
2024-07-16 17:18:31 +00:00
Translation updater bot
e93d7f0705 Hard-deprecate getBodyValidator
This patch emits deprecation warnings when extensions override
Handler::getBodyValidator() or otherwise use JsonBodyValidator.
Request body validation should be performed based on body parameter
declarations returned from getBodyParamSettings().

Bug: T358560
Depends-On: I8b12c9c9d5a73c620e3c5d035f815d7c951c7b30
Change-Id: I44b3395b8d2489c5e7ec8de0077fd7a7c9f49bfe
2024-07-16 13:06:01 +00:00
jenkins-bot
82d91ed739 Merge "Use MainConfigNames constants in tests where possible" 2024-07-11 12:46:04 +00:00
jenkins-bot
d9f64a6287 Merge "REST: Generate request body specs from param settings." 2024-07-10 19:27:24 +00:00
daniel
e6d0adcc68 REST: Generate request body specs from param settings.
Bug: T323786
Change-Id: I49da2a07efa32759480070c9d93c31d46f211d26
2024-07-10 20:23:56 +02:00
jenkins-bot
aef29a83c3 Merge "param-settings: Remove backward compatibility code from default" 2024-07-10 17:32:21 +00:00
Atieno
2b31f4c46f param-settings: Remove backward compatibility code from default
We no longer have to check for 'body' PARAM_SOURCE from within getParamSettings

Bug: T367394
Change-Id: I16075fde2db6ea47f61d1d2df1e07a4ef46b537b
2024-07-10 19:55:08 +03:00
jenkins-bot
71285104f5 Merge "Add namespace to the root classes of ObjectCache" 2024-07-10 11:58:53 +00:00
thiemowmde
4bd95cd96b Use MainConfigNames constants in tests where possible
I believe this makes the code less brittle, and also makes it a bit
more obvious what these strings are meant to represent.

Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
2024-07-10 10:11:22 +00:00
jenkins-bot
c3f8d61ed0 Merge "Add temporary account case for page history count" 2024-07-10 06:51:07 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
STran
9d1f0813a9 Add temporary account case for page history count
Edits made by temporary accounts could not be counted independently
when accessing `v1/page/Test2/history/counts/{type}`.

- Add a `temporary` case for page history revision counts.

Bug: T365673
Change-Id: Ib5279684e2843c84a56eea04721dc62700c12577
2024-07-09 05:12:11 -07:00
jenkins-bot
b3ecbf29ec Merge "REST: Enable strict type validation in JSON request bodies" 2024-07-08 19:29:52 +00:00
jenkins-bot
b9a9a792d6 Merge "Normalise string params in MW Rest API" 2024-07-08 17:45:39 +00:00
Wendy Quarshie
5c61c65541 Normalise string params in MW Rest API
Bug: T340185
Change-Id: I1b7189d5951dea019897955f8f9749afcc325fe0
2024-07-08 17:20:14 +00:00
daniel
efb9904e6d REST: include field name when reporting extraneous body fields
Bug: T369156
Change-Id: I354e6098661b95317c8163e5299d19c4f981540d
2024-07-05 10:53:37 +02:00
daniel
2b67cdc907 REST: Enable strict type validation in JSON request bodies
This switches from logging warnings when clients use string instead of
numbers in JSON requests.

Bug: T305973
Depends-On: I17f7d0b89cb584eef5a7203a8f26cb5b100e2abb
Change-Id: I2d00d320f59652040ff914005aad58bf3e724689
2024-07-04 15:34:17 +02:00
daniel
47c463cb3b REST: accept empty strings in request body
In JSON request bodies, empty strings should be accepted in required
string fields. So far, empty strings are considered as missing, which is
the default behavior for query parameters.

Bug: T305973
Change-Id: I97a9556bb440b9564e7d3618d189df4ef6f6725c
2024-07-01 13:21:54 +02:00
daniel
89be6e0c9f REST: detect mismatching value types in json request
DEPLOY: watch the api-warning channel for misbehaving clients.

We are now using TypeDef objects for validating fields in JSON
request bodies. Since TypeDef was designed for use in the action API, it
assumes that all client data is originally supplied as strings. These
strings are parsed and converted to the appropriate type.

But for JSON requests, we don't want that. If a field is defined to be a
boolean, it should be required to be a boolean, not the string "yes" or
"0".

This adds an option to TypeDefs that triggers strict type checks for
booleans and numbers. This option is enabled for all request types other
than form data.

For now, the check does not trigger a validation error. It just logs a
warning. This allows us to assess how often clients would trigger this
kind of error. The warning are logged to the "api-warning" channel.

Bug: T305973
Change-Id: I11e9e37af93bc3b9414eb77095e7cc0ce821a462
2024-06-28 11:10:07 +00:00
Jakob Warkotsch
33cfe4efeb REST: Allow other json request types
This changes parseBodyData() to treat request content types ending in
"+json" just like normal application/json requests in order to support
media types such as application/json-patch+json which is used by the
Wikibase REST API for patch endpoints.

Change-Id: Ic47f8f115ec403cab0a8fdd7d53edcd18d130537
2024-06-26 14:21:16 +02:00
daniel
41daf4d0d5 REST: Deprecate using "post" as the parameter source
Note that "post" parameters remain accessible through
getValidatedParams(), while "body" parameters have to be
accessed though getValidatedBody().

This adds a number of tests that ensure that this remains to be the case,
while deprecation warnings are triggered when appropriate.

Code search to check that this is unused in prod: https://codesearch.wmcloud.org/things/?q=SOURCE+*%3D%3E+*%27post%27&files=&excludeFiles=&repos=

Previous reverted incarnation of this: Ia0eedb383e69b

Bug: T362850
Bug: T358560
Depends-On: Id94335b3ec8f0549ff7350d31cb7cfee8feaa012
Change-Id: I88accc52c5faab70b453709b02ed88a8af4bc181
2024-06-25 14:57:58 +02:00
daniel
79c61e80dc REST: Make module definition files more like OpenAPI specs
This splits RouteFileModule into two classes, ExtraRoutesModule and
SpecBasedModule.

ExtraRoutesModule has no module prefix and supports
only "flat" route definition files and additional routes from
extension.json.

SpecBasedModule represents a single module defined in a definition
file similar to an OpenAPI spec. The idea is that a full OpenAPI spec
can be generated by filling in any missing information based on
information provided by the Handler implementation. In particular, the
definition of parameters and request body schemas will be generated.

A JSON schema for the new file format is added under docs/rest/.

Support for the intermediate format introduced in Iebcde4645d4 is
removed. It was not included in a release and was not being used outside
core tests.

Bug: T366837
Change-Id: I4ce306b0997f80b78a3d901e38bbfa8445bed604
2024-06-24 16:42:59 +02:00
jenkins-bot
936f4d7808 Merge "Migrate MediaWiki.rest_api to statslib" 2024-06-11 18:49:08 +00:00
Wendy Quarshie
e7fd78aed1 Migrate MediaWiki.rest_api to statslib
Bug: T359364
Change-Id: I3646140ee8e16800c43f37958fc4b6ff00edcad6
2024-06-11 18:13:21 +00:00
C. Scott Ananian
64d343353e [HtmlOutputRendererHelper] Use ParserOutputAccess
One more step in gradually replacing uses of ParsoidOutputAccess with
ParserOutputAccess.  This is mostly just inlining the code from
ParsoidOutputAccess (which already uses ParserOutputAccess internally)
and then removing dead code.

Change-Id: I87d6568d9dc71bc11f406ea3c31ce86e01667e05
2024-06-05 10:37:36 -04:00
jenkins-bot
2c6f062efc Merge "REST: HandlerTestTrait should mock validateBodyParams instead of validateBody." 2024-05-28 20:19:27 +00:00
daniel
44a3221dc9 REST: fix handling for root path
This fixes the handling for the .../rest.php and .../rest.php/ paths.
The handling for the first case (no "/" at the end) is hard-coded to
redirect to the second case (with a "/") at the end. The second case
can then be handled by a regular route definition.

Change-Id: I9782b17e524f96d7dff4a8e2524fce4ed0940379
2024-05-28 10:29:56 +02:00
daniel
3a37e8d71b REST: HandlerTestTrait should mock validateBodyParams instead of validateBody.
The validateBody method in validator is based on BodyValidator.
Returning a non-null value from it triggers b/c behavior in
Handler::validate. That should generally be avoided.

Change-Id: I3047cb0b6fdd8ed623b43910e737d8882f333ff6
2024-05-28 09:44:41 +02:00
jenkins-bot
f3d376dc44 Merge "REST: support rest.php when another RestPath is configured." 2024-05-24 03:47:24 +00:00
daniel
bccbae4345 REST: support rest.php when another RestPath is configured.
When a "pretty" RestPath is configured for outside requests, we still
need the "ugly" path to work for backwards compatibility and internal
requests.

For example, the REST API could be available through /api/ as
well as /w/rest.php. This is equivalent to supporting page views
at /wiki/ as well as /w/index.php.

We can already set RestPath to /api, but then requests to /w/rest.php would fail. We need a way to support both at once.

Change-Id: I9ff8e7345e88b1a4235b6870ec04a87527ed271f
2024-05-22 08:34:30 +00:00
jenkins-bot
2589519212 Merge "REST: fix metrics keys" 2024-05-21 19:39:40 +00:00
daniel
68dc4845b5 REST: fix metrics keys
In Iebcde4645d472d2 I broke the way we generate metrics keys from
endpoint paths. Instead of using the declared paths with placeholders,
we were recording the actual paths, resulting in an explosion of metrics
keys.

This moves metrics logging from Router into Module, where the declared
path is available. This patch also introduces regression tests for the
issue.

Bug: T365111
Change-Id: I2c9ddfe6e28aaecd313356894f17033e2db59073
2024-05-21 17:34:59 +00:00
daniel
5ac1f785d4 REST: improve body validation testing
- fix test for body validation errors in HandlerTest that was never
  called.
- provide additional test cases for body validation failures
- provide an error key and failure code when encountering extra body
  parameters, for consistency with other validation errors.

Bug: T305973
Change-Id: I3453a37f9b5dd1348890046582fb2d25c00dfa6c
2024-05-21 16:57:27 +03:00
daniel
020c7f5e75 REST: introduce getSupportedRequestTypes()
REST handlers should explicitly list content types they support for
request bodies. This is needed for generating OpenAPI specs.

NOTE: this removes default support for form data requests, unless
there are "post" parameters declared. "body" parameters require JSON.

Bug: T362850
Change-Id: I1339b1a1770719bd4a5d4d414a8e55fcbb498ac1
2024-05-15 15:10:25 +02:00
thiemowmde
52ddf3e8ce Remove all @package comments
I don't think these do anything with the documentation generators
we currently use. Especially not in tests. How are tests part of a
"package" when the code is not?

Note how most of these are simply identical to the namespace. They
are most probably auto-generated by some IDEs but don't actually
mean anything.

Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
2024-05-10 13:53:15 +02:00
daniel
91a1741787 Introduce Modules into the REST framework
Modules group together endpoints by a shared prefix. The idea is that each module has its own version and can generated self-contained self-documentation. This allows clients to have clear expectations about the endpoints of each module, no matter what wiki they are accessing. So far, each wiki may be exposing a different set of endpoints, with no way to provide a spec that describes that set of endpoints in a way that would be consistent across wikis and stable over time.

Bug: T362480
Change-Id: Iebcde4645d472d27eee5a30adb6eee12cc7d046b
2024-05-08 16:12:30 +02:00
jenkins-bot
0f0d228ec3 Merge "REST: introduce getBodyParamSettings" 2024-05-07 18:23:34 +00:00
daniel
97eae33cf5 REST: introduce getBodyParamSettings
Since we introduced support for the "body" PARAM_SOURCE in
getParamSettings, fields in the request body can be defined in the same
way that path and query parameters are defined. However, body fields are
treated separately by the framework, and the value of body fields are
available through getValidatedBody(), rather than getValidatedParams().

Because of that, it makes sense to have a method that returns the param
settings just for the body fields. This also allows handler classes to
override this method separately to specify body fields. That way, it
also becomes possible to have body fields that have the same name as
other parameters.

Bug: T362850
Change-Id: Ia85bf7e46c949a999052d91f1b0d7d579a880108
2024-05-07 17:35:36 +00:00
daniel
b07d4463db REST: Fix body validation errors
- fix type on the "rest-body-validation-error" message key, causing
  the message to remain untranslated.
- fix error meta-data included when reporting body validation failures.

Bug: T358560
Change-Id: I56ef63e3534770c777cb5f938e3032101abae54b
2024-04-29 16:34:17 +00:00
daniel
c5d29b849a Tests: enable non-integration tests to use TitleFactory service.
This change implements two things that can be combined to allow
the usage of services like the TitleFactory in subclasses of
MediaWikiUnitTestCase:

1) This adds getServiceContainer() to the MediaWikiUnitTestCase base
   class, to mirror the method of the same name on
   MediaWikiIntegrationtest case, along with a a setService() method
   for defining service objects for use in tests.

2) This adds makeMockTitleFactory() to the MockTitleTrait, to allow
   tests to esaily define the TitleFactory service.

Making services available through a service container primarily
benefits code that relies on ObjectFactory, like REST handlers.

Needed-By: Iac113a9e766e38b2d19ae99b7e448548a515469e
Change-Id: Ida6c37c7133b9e3887268025daf6e5b7c1340e52
2024-04-25 13:00:14 +00:00
jenkins-bot
6182df7d1b Merge "Disallow optional or empty path parameters" 2024-04-25 10:00:05 +00:00