Commit graph

24 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
Derick Alangi
d51522dfd3 ParsoidOutputAccess: Mark dummy parser output as non-cacheable
Bug: T311728
Change-Id: I55f153d21f91ef93fe5c788fd054fa481fc2ab10
2023-01-10 12:43:30 +01:00
Derick Alangi
cdd49f7536 ParsoidOutputAccess: Completely handle unsupported content models
Pages with content models not supported by Parsoid before already
had dummy parser output written to PC but we still got an internal
server error because the output didn't have a render key.

This patch fixes the issue and when we try to render page with
unsupported content models, we get the dummy parser outputs.

Bug: T311728
Change-Id: I49ebbfc0475fb296f2a906ce7dce237641fb375b
2023-01-10 08:38:51 +00: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
daniel
5559d2d471 Parsoid: Enable lint data and parser cache together
The previous attempt at restoring call to the ParserLogLinterData hook
had the undesirable effect of bypassing parser cache. This change
optionally enables the call to the lind data hook without disabling
parser cache.

This patch us working under the assumption that we only need to log lint
data for canonical parses.

Follow-Up to I1f69498ef75

Change-ID: I39ab54ca6e9f9a6a58b59cdd6feea07638fc908f
2022-12-12 22:57:07 +01:00
daniel
75d6892134 ParsoidOutputAccess: generate dummy output for unsupported models.
While RESTbase insists on getting Parsoid renderings for any content
model, don't waste CPU cycles trying to render garbage. Just output
dummy content. Nobody should ever see it.

Bug: T324711
Change-Id: I407171a5f515b594603b287a7a9e49f54e837161
2022-12-12 19:57:31 +00:00
daniel
9842811e75 ParsoidOutputAccess: only cache output for wikitext
ChangeProp is currently requesting a parsoid parse for all page updates,
regardless of content model. Parsoid renderings of non-wikitext content are
unusable, so we shouldn't bother the parser cache with them. This is
especially true for wikidata items.

Bug: T324711
Change-Id: I6f6325f2b8581dfcc9a8bcd97281ccf4caa7e8f1
2022-12-08 18:29:24 +00:00
jenkins-bot
1b3d4d17d4 Merge "Throw a 400 when asking parsoid to render an unknown content model." 2022-12-07 22:44:45 +00:00
daniel
a79b73e722 Make parsoid accept all content models.
This allows parsoid render anything, even if the output is garbage.
This is a quick fix pending the real solution (T311728).

Bug: T324711
Change-Id: If4e4eb8582ab8a62f592394820b30c1b28fb1216
2022-12-07 22:23:54 +00:00
daniel
d34e73b0c1 Throw a 400 when asking parsoid to render an unknown content model.
Bug: T324711
Change-Id: I0a78e5c57e2b8449b393bccc86148aee4ad87bc8
2022-12-07 23:09:58 +01:00
daniel
c6a0d433ec HtmlOutputRendererHelper: allow parser cache to be disabled.
This is needed so we can ramp up parser cache writes in a controlled
manner.

Bug: T322672
Change-Id: I7d97c9e2d4009029dc64f9c0a369f68098185520
2022-11-28 09:43:12 +00:00
daniel
860f8ebee8 Make HtmlOutputRendererHelper more flexible
This adds setters to HtmlOutputRendererHelper which allow it to be used
more conveniently in different contexts. This is aimed specifically at
making it easier for DirectParsoidClient in the VisualEditor extension
to re-use this code.

NOTE: HtmlOutputRendererHelper is declared @unstable, but the changes in
this patch need to be backwards compatible at least temporarily, to
allow the VisualEditor extension to be updated in a follow-up.

Change-Id: I18c8bc6f5aa7c204f0faa56919bfe64026761bd4
2022-10-17 10:53:05 +00:00
daniel
994e50d24f Fix passing the wikiId into ParsoidOutputAccess.
It's not clear if Parsoid still need this, but let's err on the side of
caution.

Change-Id: I7cef2827da23af3c3466cb855de5f42e05375515
2022-10-07 17:50:38 +02:00
Derick Alangi
ab7849ed47 ParsoidOutputAccess: Add support for fragment flavor
This is needed by VE when performing Wikitext -> HTML transformation
during editing.

Also, this patch introduces the new flavor: fragment, that is passed in
via $envOptions to activate VisualEditor's body only mode functionality.

NOTE: This patch also fixes a PHPUnit test that broke by correctly
injecting the appropriate parsoid instance for checking error handling.

Bug: T308743
Change-Id: I838a3b05d7d8523a469236cf112158349063283c
2022-10-06 20:41:48 +01:00
daniel
a02be0b3f8 HtmlInputTransformHelper: Fall back to ParserCache
If a render ID is given via the use-cache parameter, but the key is not
found in the parsoid stash, look at the most recent known rendering of
the revision, and use it if it matches the render ID.

This patch moves the responsibility for looking up RevisionRecords and
PageRecords into ParsoidOutputAccess. This way, callers only need to
have a PageIdentity, and optionally a revision ID.

Bug: T318395
Change-Id: I1aa5b0fd9fb1acaa2544d5a58125fa3810a0eb39
2022-09-30 15:56:23 +00:00
daniel
f31cd9f1d3 REST: HtmlInputTransformHelper: Load original data from stash
Parsoid needs the original rendering in order to apply
selective serialization (selser). The page/{title}/html endpoint
can stash the rendering, and now the transform endpoint can make use
of the stashed rendering.

Bug: T310464
Change-Id: Ia58043ed3aa1eb12731d82aa87606c82ec63f663
2022-09-29 19:52:27 +02:00
jenkins-bot
e0e430c049 Merge "Add PageBundleParserOutputConverter" 2022-09-26 13:16:23 +00:00
msantos
d3a86cfc6f Fix parse() and getParserOutput() interfaces
In Ie87f823e721ed5ae9d49cf7ead8e77cbef254cd7, we changed the signature
of `parse()` to accept a PageIdentity instead of PageRecord and it broke
some tests in other places, specifically: HtmlOutputRendererHelperTest,
so this patch fixes the interfaces.

Change-Id: I35685412c52f7d4ae9e63960695e686fb2bb9b21
2022-09-26 11:40:19 +01:00
Abijeet
7400456b1a Add PageBundleParserOutputConverter
Move code to create ParserOutput from PageBundle and vice versa to a
separate final class. An final class was used instead of a trait
because traits do not support constants for PHP version < 8.2.

The plan is to use this final class in various interfaces in order
to avoid exposing them to Parsoid concepts.

Bug: T317019
Change-Id: I33076c359ee45719c1c4ef63f77c1f1285951d0c
2022-09-26 15:11:47 +05:30
msantos
f29803e2d9 Support access to outputs of non-existent pages
* Introduce a method in ParsoidOutputAccess that parses and returns
  a parse output directly without caring about cache.

* Parse a non-existent page with the new method when the page object
  is not a PageRecord, but a PageIdentity

Change-Id: Ie87f823e721ed5ae9d49cf7ead8e77cbef254cd7
2022-08-31 20:52:41 +01:00
daniel
2ba27ab06e Protect against passing unsupported content models to Parsoid.
Parsoid currently only supports wikitext (and JSON), so don't give it anything else.

NOTE: ParsoidOutputAccess will fail on content that is unsupported by parsoid.
This will however not affect the /transform and /page endpoints in the
parsoid extension, since they use the ParsoidHandler base class, which doesn't
rely on ParsoidOutputAccess.

Bug: T301371
Change-Id: I6bc9b978947b31455a4bce6385b7bdf64ed4043c
2022-06-30 14:54:42 +00:00
daniel
8ce08c0cbc Move knowledge about HTTP status out of ParsoidOutputAccess
This removes a cyclic dependency:
ParsoidHTML helper in the REST component uses ParsoidOutputAccess in the
parser component. So ParsoidOutputAccess cannot use LocalizedHttpException
from the REST component.

This also improves separation of concerns: the parsing component should
not be concerned with HTTP status codes.

Bug: T301371
Change-Id: I2e661fe3ce0824dbfd7579650972f9019c92ed59
2022-06-28 12:30:44 +02:00
daniel
1271faa381 Move access to the page bundle into ParsoidOutputAccess
This isolates ParsoidHTMLHelper from the internal of
ParsoidOutputAccess. The corresponding test cases were changed to use a
mock ParsoidOutputAccess, and to not test the behavior of
ParsoidOutputAccess.

Bug: T301371
Change-Id: Id693fae2264f15e5d35f28acc5adc4239b2ae24f
2022-06-28 11:49:36 +02:00
Derick Alangi
1854fb02d9 Storage: Warm parsoid parser cache with parsoid outputs
This patch introduces a ParsoidOutputAccess service for
getting parsoid outputs and warms the cache with pregenerated
outputs.

It also introduces a config variable in ParsoidCacheConfig that
is turned off by default for controlling the cache warming.

Bug: T301371
Change-Id: I6152c42ea765d94093d8d62598b1b4278314adec
2022-06-28 09:05:41 +00:00