Commit graph

572 commits

Author SHA1 Message Date
Máté Szabó
c4e9f987f1 rest: Return a 400 for invalid render IDs
Why:

- The REST API takes an optional renderid param when converting HTML
  back to source wikitext, which is user-provided and may be invalid.
- Invalid render IDs cause an InvalidArgumentException to be thrown that
  causes a 500 response.

What:

- Introduce a new error message for invalid render IDs in the REST API.
- Return a 400 with this new error message for HTML reverse-parses with
  an invalid render ID.

Bug: T385568
Change-Id: I062419fe8952329a39781a49cdca2e94c3996447
(cherry picked from commit cd1d42a5066e4bcb9b9d4ed9b4f7714fd428fea3)
2025-02-04 14:54:50 +00:00
bpirkle
f5a7e973c7 REST: make http method available during response schema generation
A previous change made it possible to include response schemas in
generated OpenAPI specs. However, it did not provide the http method
to the code that generates/includes these schemas. Because some
handlers support multiple http methods, this is necessary. So add it.

Bug: T375530
Change-Id: Ie681d576cdffc387d78a1686e058903761b749ac
(cherry picked from commit 576b29092d5fd6a8480e02ddc2141b69cf698936)
2024-11-07 19:06:59 +00:00
Andre Klapper
aab00c9530 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead.

Followup to e662614f, using PHPStan.

Bug: T376276
Change-Id: I60d639b042b537bf2f531cc132f1b75a66b85acb
(cherry picked from commit da0a395efa7847916371f9c0a6b271faa022ff59)
2024-10-23 17:20:01 +00:00
jenkins-bot
b60d69a6ac Merge "REST: Add items wrapper for restbase compat to some response bodies" 2024-10-21 18:40:15 +00:00
jenkins-bot
f057afcc4d Merge "Deprecate ::setMetrics() calls with StatsdDataFactoryInterface" 2024-10-21 17:12:19 +00:00
jenkins-bot
cd58285157 Merge "Parsoid: SiteConfig::prefixedStatsFactory() can never return null" 2024-10-21 10:16:12 +00:00
C. Scott Ananian
4d4715326a Deprecate ::setMetrics() calls with StatsdDataFactoryInterface
HtmlInputTransformHelper::setMetrics() and
HtmlToContentTransform::setMetrics() take a StatsFactory now; deprecate
passing a StatsdDataFactoryInterface.

Depends-On: I0d8eb6cacd761fa4959419b10d59046e61c714ff
Change-Id: I2374731f6d37a191fc4a865d2665f2ca18182db1
2024-10-18 18:45:00 -04:00
C. Scott Ananian
c49d9199a5 Parsoid: SiteConfig::prefixedStatsFactory() can never return null
SiteConfig::$statsFactory is non-nullable, and
StatsFactory::withComponent() never returns null.

Change-Id: Ib14a1ee44b81476447717bc6aa00b54de1dca995
2024-10-18 18:45:00 -04:00
jenkins-bot
53bd99f5dc Merge "Use statslib for metrics emitted by HtmlInputTransformHelper, HtmlToContentTransform" 2024-10-17 23:46:56 +00:00
Yiannis Giannelos
331c181598 Use statslib for metrics emitted by HtmlInputTransformHelper, HtmlToContentTransform
Bug: T359475
Change-Id: I7d4ca748c106dfd560dae31294decfb2b181e2db
2024-10-17 21:28:04 +02:00
jenkins-bot
1d0377f1ba Merge "Adding token validation to the edit handler" 2024-10-17 14:51:30 +00:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
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
2024-10-16 20:58:33 +02:00
bpirkle
330e1633c2 REST: Add items wrapper for restbase compat to some response bodies
Bug: T374136
Change-Id: I995916f53eb9408923456cce8b1f3be391fbf942
2024-10-16 12:58:10 -05:00
James D. Forrester
a5387c7c20 Namespace all remaining classes in includes/parser
Bug: T353458
Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
2024-10-15 23:54:32 +01:00
jenkins-bot
deba2439b7 Merge "REST: Allow specifying param descriptions as MessageValue objects" 2024-10-15 15:24:56 +00:00
jenkins-bot
3867124e9b Merge "REST: Allow specifying response body schemas in json files" 2024-10-14 14:46:17 +00:00
bpirkle
08a2e410e6 REST: Allow specifying response body schemas in json files
Previously, response body schemas could be specified by handlers as
php associative arrays, that were included in the final OpenApi spec.
This mixed the schemas with code, and required developers to deal with
specs in multiple formats. Instead, allow specs to be specified in
JSON format, in separate files. In addition to keeping schemas in JSON,
this gives each schame its own git history.

Bug: T376290
Change-Id: Ic27f422df0ab12a3a0b1cbce79eb0be30f7b7815
2024-10-10 20:42:14 -05:00
jenkins-bot
ae3afe014b Merge "Remove meaningless @var documentation from constants" 2024-10-09 22:03:23 +00:00
C. Scott Ananian
79896b6e0d Ensure HtmlOutputRendererHelper::setPageLanguage() splits the cache
HtmlOutputRendererHelper sets ParserOptions::setTargetLanguage(),
but this isn't actually included in ParserOptions::$cacheVaryingOptionsHash
so even though this setting changes the ParserOutput it wasn't
being included in the cache key.

Bug: T376783
Change-Id: Ie76020dc4fa3545f827e1674051530b479f01f31
2024-10-09 10:55:22 -04:00
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
bpirkle
27b5faf93b REST: Allow specifying param descriptions as MessageValue objects
Previously, parameter descriptions could only be specified as
strings. We want OpenAPI specs generated from parameter
definitions to be internationalizable, so allow specifying
descriptions as MessageValue objects, which can be translated
using normal MediaWiki mechanisms.

Associated improvements to ResponseFactory.

Bug: T376493
Change-Id: If1cbe4f7bfd5c375e64b802b666c0247d65b1ee0
2024-10-08 16:42:52 -05:00
Yiannis Giannelos
fec9daae4e Use statslib for metrics emitted by HtmlOutputRendererHelper
Bug: T359476
Change-Id: If8bc5a7f7383dcb67dadf1f4c02d1b69d7c8fa53
2024-10-04 14:52:30 -04:00
James D. Forrester
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
Wendy Quarshie
0c22b25b31 Adding token validation to the edit handler
Change-Id: I86fa7d613aa79e07ce20ea7936becf02f25832ac
2024-09-26 15:08:57 +00:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
C. Scott Ananian
137f228edd parsoid: use real ParserOutput, not StubMetadataCollector in wikitext2lint
Bug: T374149
Bug: T331084
Depends-On: Iec2ab2a831a56b6bed0615df8a437e84ec63e799
Change-Id: I7a43df32cf0cc0c062374f404edb468a4e59f386
2024-09-24 15:35:38 +00:00
daniel
84fe1b9ccd REST: Introduce discovery endpoint
The discovery endpoint provides basic information about accessing the
wiki's APIs, as well as a directory of available modules.

Bug: T365753
Change-Id: I161aa68566da91867b650e13c8aadc87cd0c428c
2024-09-20 17:02:59 +00:00
bpirkle
90494183bb REST: add restbase compat error handling mode
In order to replace certain /api/rest_v1 endpoints, we
need to have something in MediaWiki that generates a compatible
responser. The MediaWiki REST API error format does not match
RESTbase. So the easiest approach seemed to be to
add a compatibility mode, triggered using the x-restbase-compat
header. This can be set via the gateway when rerouting the request.

Bug: T374136
Change-Id: I73934940d367be52941bd27861c248ab5bcfb5d2
2024-09-16 18:09:12 -05:00
jenkins-bot
634373a3cf Merge "REST: add restbase compat mode for some endpoints" 2024-09-16 19:21:57 +00:00
daniel
602f0ab595 REST: add restbase compat mode for some endpoints
In order to replace the /api/rest_v1/page/title/{title} endpoints, we
need to have something in MediaWiki that generates a compatible
responser. The v1/page/{title}/bare and v1/revision/{id}/bare endpoints
are functionally equivalent, so the easiest approach seemed to be to
add a compatibility mode to them. The compatibility mode is triggered
using the x-restbase-compat header, which can be set via the gateway
when routing the request from /api/rest_v1/page/title/.

Bug: T374136
Change-Id: I4af7ff5325660ae30faebb24753b9dc1c3acb2b3
2024-09-15 16:41:21 -05:00
bpirkle
c308465d52 Clean up a few comments in HtmlOutputRendererHelper (typos, etc.)
Change-Id: I26a23dd3d7f858cd28a12ff9f0dd739e746829f0
2024-09-09 21:38:30 -05:00
thiemowmde
dca4931b42 Make use of the ??= and ?? operators where it makes sense
This touches various production classes and maintenance scripts.
The code should do the exact same as before. The main benefit is that
the syntax avoids any repetition.

Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
2024-08-26 09:26:36 +02:00
Bartosz Dziewoński
d46fdf645b Replace a few more uses of deprecated Status / StatusValue methods
Change-Id: I017bcaffe6945d633d7387f9391803845369bfed
2024-08-22 19:34:51 +00:00
daniel
057dda8588 REST: include version in generated OpenAPI spec
The generated OpenAPI spec should contain information from the info
section of module spec files.

Bug: T366834
Change-Id: I488f550adbf32205bdcdcb59b1e7f5273643bf69
2024-08-19 20:47:40 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
jenkins-bot
22163e47a7 Merge "Add MediaWiki\Registration namespace to registration classes" 2024-08-10 11:33:27 +00:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
James D. Forrester
f7ce0a0976 Move remaining four classes in includes/content into Content namespace
Bug: T353458
Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
2024-08-10 10:40:53 +02:00
jenkins-bot
fb5f6862c0 Merge "Add content.v1 REST module with relevant content endpoints" 2024-08-09 17:01:15 +00:00
bpirkle
3f614a0898 Add content.v1 REST module with relevant content endpoints
T366837 added the ability to group REST endpoints into modules.
This change now introduces the first use of a REST module.
The existing endpoints remain accessible at their original paths,
and mocha tests are run against both old and new paths.

Bug: T370430
Change-Id: I83a5cdbdd359e4d3e5f70dd3930783616b556738
2024-08-07 16:51:09 -05:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
jenkins-bot
1cbafee5de Merge "[ParsoidParser] Remove unneeded code to set render ID" 2024-07-30 16:54:51 +00:00
jenkins-bot
5b56564da4 Merge "Use expression builder instead of raw sql" 2024-07-26 21:06:34 +00:00
jenkins-bot
3956a0de3b Merge "REST: showcase usage of ArrayDef convenience functions" 2024-07-25 17:42:32 +00:00
daniel
d0f4e4514f REST: showcase usage of ArrayDef convenience functions
This demonstrates how to use ArrayDef::makeObjectSchema to define a
schema for a complex body field.

The "latest" field in the request body for page PUT requests identifies
the base revision. To allow the base revision info to be looped through
from an earlier GET request, it's nice to allow the "timestamp" field
to be present, even though we don't use it.

I changed the relevant part of Update.js to test that use case specifically.

Bug: T368131
Change-Id: I166396e0dbfc995e5346252ee438c9afe2c808e2
2024-07-25 16:54:18 +00:00
Umherirrender
9a107e6b03 Use expression builder instead of raw sql
Bug: T361023
Change-Id: Ibf1c93ddbf8f680e8fb9442816f6fed94a069c0a
2024-07-23 23:30:45 +02: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
e334f8cd78 Deprecation warnings for includes/Rest/Handler/Helper
The ::init() methods were deprecated in
I1e1213597c6be012f2bc024c2b370c968ff3b472; this adds deprecation warnings.

Followup-To: I1e1213597c6be012f2bc024c2b370c968ff3b472
Depends-On: Ie762dc34523eed79bc537143394b04e64f004b53
Depends-On: I4a8fc5f69d0704099bea52900d0595d56c7266f1
Depends-On: I304d79095a2dfa0702cc4dba9c2e76f6d033548e
Change-Id: I52140518d9e903e9750d4f616bb1ca75160d91b1
2024-07-19 11:54:30 -04:00