Commit graph

373 commits

Author SHA1 Message Date
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
Umherirrender
503bff0b04 Rest: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: Idf17719c875466810313f0fbbf16bc67f3e40059
2024-09-07 21:49:56 +02:00
C. Scott Ananian
a0503debb0 Provide previous parse results to parser when rendering
This patch lays the groundwork for incremental/selective parsing in
Parsoid by ensuring that we can pass previous cached parses through
the parse pipeline to Parsoid.  We do this by adding a new render
hint type, `previous-output`, and ensuring it is passed along.

Because revisions can contain a ParserOutput which is the combination
of separate ParserOutput objects for each of their slots, RenderedRevision
also contains a method to unsplit the combined ParserOutput to reconstruct
an original ParserOutput for use in incremental parsing.  Currently this
is mostly a stub, but illustrates how slot combination and splitting can
work, assuming those transformations are reversible.

Extra calls to ParserCache::getDirty() are added to some code paths
in order to ensure that any previously-cached ParserOutput is available
for selective update.  In order to mitigate any performance concerns,
these are only done for the Parsoid parser at the moment.  Future
patches will add additional metrics to quantify the cost/benefit ratio
of the additional cache lookups on these paths.

Bug: T363421
Bug: T371713
Change-Id: I440884f1d7e09c1ff9806f848b7b53a636367690
2024-08-23 17:41:55 -04:00
jenkins-bot
aef156e925 Merge "Migrate ParserOutputAccess metrics to statslib" 2024-08-23 21:39:21 +00:00
Yiannis Giannelos
fa3e92db5e Migrate ParserOutputAccess metrics to statslib
Bug: T359372
Change-Id: I5450251dff31d55a9a46b7fe885c27cd6ba083bf
2024-08-23 21:06:34 +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
thiemowmde
ba36bf46a1 tests: Make use of ??= and ?? operators in various tests
The main benefit is that this syntax avoids repeating the variable
name. It does the same as before.

Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
2024-08-15 11:44:46 +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
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00: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
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
C. Scott Ananian
fc0af94d32 Hard deprecate ParsoidOutputAccess
This class was @unstable and should be replaced by ParserOutputAccess.

Bug: T367074
Depends-On: I543a6e9da4fc473a2ac54ac635286453f2aff96a
Change-Id: Ie51b9b7a8b42a6faafeb28378c188347f274a9c5
2024-07-19 03:09:35 -04: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
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
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
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
jenkins-bot
7df99f2dae Merge "REST: Make module definition files more like OpenAPI specs" 2024-06-24 20:36:14 +00: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
Bartosz Dziewoński
279fd16bab tests: Avoid deprecated Status / StatusValue methods
Use more specific and less fragile assertions whenever possible;
most tests don't need to examine the internals of the status so
closely. Use StatusValue::getMessages() when necessary.

Change-Id: Ie4b3ebc03abb0e352e82394ced6ab9e733c83fb4
2024-06-15 10:14:37 +02:00
Umherirrender
f27c2433bb tests: Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
2024-06-13 23:21:02 +02:00
Bartosz Dziewoński
2bd7bc5cc8 Use real type hints for services etc. in includes/Rest/
Mostly used find-and-replace:

Find:
/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|)
Replace with:
\3 \1 \4

More could be done, but to keep this patch reasonably sized, I only
changed the most obvious and unambiguously correct cases.

In some cases, I also removed redundant doc comments on the
constructor, and re-ordered the properties to match the constructor.

Change-Id: Ifa710fdf4d8d44a2d7244798b787a1b2a58c35a7
2024-06-11 22:40:44 +02: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
Arlo Breault
009edac867 Don't ignore offsetType attribute on lint API paths
The default used to be 'ucs2' when linting but
Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80 stopped setting the offsetType
in the environment options, which changed the output to Parsoid's
default, 'byte'.

For the parsing paths, pagebundles are now post-processed and
non-pagebundles were left as a TODO.

However, for the lint paths, it was always ok to continue setting the
environment option because Parsoid is called directly and doesn't go
through the ParserOutputAccess.  The above patch was trying to limit
Parsoid specific options to that.

Bug: T365284
Change-Id: I8389c2f53b399b39a9f1d908a38aecb3abcb15ef
2024-06-03 19:59:28 -04:00
Arlo Breault
80b3b4494d Fix setting offsetType in options passed to HtmlInputTransformHelper
Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80 stopped setting it as an
envOptions so pull it from the attribs when constructing.

The tests continued to set the offsetType in the envOptions, despite the
ParsoidHandler no longer doing that, so they failed to catch the error.

HtmlInputTransformHelper still considers it an envOptions though and a
cleanup could happen there too.  Although, offsetType still is an
envOptions to Parsoid, so maybe it's fine as is.

Change-Id: I661a170fbb2c61308e32a43a9f6b0ce8d2ffb797
2024-06-03 19:53:21 -04:00
C. Scott Ananian
1c0089772d [HtmlInputTransformHelper] Use ParserOutputAccess
One 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: I9807149c30f4bfe06fd7ad12f96c13816c22aa9c
2024-05-22 10:58:38 -04:00
C. Scott Ananian
a565e388f9 Move ParsoidOutputAccess::supportsContentModel() into Parsoid SiteConfig
The `supportsContentModel` method is really querying Parsoid for the
set of content models it supports, so it makes sense to put it in the
Parsoid-specific SiteConfig service.

This is part of the work to deprecate and remove ParsoidOutputAccess.

Change-Id: I81eb2df8cef93ede95361a4e03185b3d58e5b84b
2024-05-22 10:57:37 -04:00
jenkins-bot
31a72c9b71 Merge "REST: introduce OpenSearchDescriptionHandler" 2024-05-21 19:54:56 +00:00
Ebrahim Byagowi
16197f7d76 Add namespace and deprecation alias to TextContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I2c72dacf28ee72fb70b15acdd81d0eb717ea949a
2024-05-20 05:34:31 +03:30
Ebrahim Byagowi
97d1202784 Add namespace and deprecation alias to TextContent
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
2024-05-19 23:23:01 +03:30
daniel
879846b29c REST: introduce OpenSearchDescriptionHandler
Move open search description endpoint from /w/opensource_desc.php
to /w/rest.php/v1/search.

Bug: T363984
Change-Id: Idb5b0d21adc6152ef77e6d17846b6acc6a904e01
2024-05-18 17:29:07 +00:00
jenkins-bot
9f24ff65fe Merge "Parsoid PageConfig: remove unused ::getTitle() and ::getNs() methods" 2024-05-18 15:18:43 +00:00
Ebrahim Byagowi
6316a253aa Add namespace and deprecation alias to CssContent
This patch introduces a namespace declaration for the
MediaWiki\Content to CssContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I6ab25787893cb2195f8cd2ba125ed8dd5a60de43
2024-05-18 01:48:53 +03:30
Ebrahim Byagowi
ccde5085de Add namespace and deprecation alias to JavaScriptContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I87c17327911e28a461feaf2ff46242454cff257a
2024-05-17 13:51:18 +03:30
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
C. Scott Ananian
903a5fc052 Parsoid PageConfig: remove unused ::getTitle() and ::getNs() methods
These methods are no longer needed by the Parsoid PageConfig API.

Depends-On: Ie3b8802153e380d25f9fc8a75469ec1c3a1b7015
Change-Id: I1bf9aad24b2bb04592d62e08923c79d8d46a977e
2024-05-14 21:07:36 -04:00
DannyS712
ee75e1c6f9 Tests: remove a bunch of DummyServicesTrait-related comments
Not sure why I added these, it should be clear from the method names

Change-Id: Ie49881e6f31fad52bb65b0d2ac3e9379dbb7bfc5
2024-05-10 04:07:59 +00: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
addshore
c2992e07a8 Remove unused const (and lines) in PageRedirectHandlerTest
Change-Id: I2297f1d0c3dae29658eeb8ed4478e34e017bdae7
2024-05-04 10:23:55 +03:00
jenkins-bot
f4b0b0a347 Merge "Use LocalizedHttpException for remaining errors in REST handlers" 2024-04-30 07:37:31 +00:00
Wendy Quarshie
1741fd54ea Use LocalizedHttpException for remaining errors in REST handlers
Bug: T358745
Change-Id: I4845af0eacab31e6f648bdea9a2ed67d7188782b
2024-04-29 20:24:07 +00:00
jenkins-bot
55e2fd81fd Merge "REST: Fix body validation errors" 2024-04-29 17:33:03 +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
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
jenkins-bot
9d9dac44fd Merge "Move parsoid version cache invalidation to lower level" 2024-04-26 15:28:03 +00:00