Commit graph

28 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
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
jenkins-bot
630925a09d Merge "HtmlOutputRendererHelper: test that parser cache is used." 2022-12-15 18:22:11 +00:00
daniel
91c1380d1e HtmlOutputRendererHelper: test that parser cache is used.
This protected against the performance regression that was addressed in
abec307409.

Change-Id: Ie5f7c2c713a10eec19bc19e0ba709f36599fb291
2022-12-15 17:56:14 +00:00
daniel
6decc0ba09 Parsoid: return 404 when page is deleted.
If HtmlOutputRendererHelper can't produce output because the page
doesn't exist, don't crash. Return a 404 instead.

Bug: T325205
Change-Id: I6a713025e2eb447ed61de8949c820bd9cda7594e
2022-12-15 12:13:57 +01:00
daniel
4f22f967c5 Parsoid: implicitly enable linting in API endpoints
Logging linter data should be enabled automatically by
HtmlOutputRendererHelper.

This change enables linting data for requests coming in via the
v1/page/{title}/html endpoint.

Change-Id: Idafd29784ec712547e36fea88a8c159784b97f2b
2022-12-13 13:35:06 +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
9ff8edfa1e HtmlOutputRendererHelper: fix semantics of getRevisionId
getRevisionId is documented to return 0 for fake revisions, but it was
returning 0 for the current revision as well. This patch makes a clear
distinction, with 0 meaning current (like elsewhere in the code), and
null meaning a fake revision.

This patch includes a fix for redirect handling in ParsoidHandler::wt2html.
This fix is needed here because it previously relied on getRevisionId()
to return the actual revision ID; this would fail, since getRevisionId()
will return 0 when the current revision of a page is requested.

Change-Id: I33d1ab54023c6ac96c6bb5e4750b980e381cb464
2022-12-06 23:06:25 +01:00
jenkins-bot
f253617b73 Merge "HtmlOutputRendererHelper: fix etag tests" 2022-12-06 14:07:45 +00:00
daniel
42e55bcd6f HtmlOutputRendererHelper: fix etag tests
The test cases getETag and getLastModified where checking the method's
return values against themselves.

Change-Id: I13c5abfdd07373795ca9b661d812ec0eed11f766
2022-12-06 13:23:44 +00:00
Daniel Kinzler
f36a28ff21 [Fix] ParsoidHandler: use HtmlOutputRendererHelper in wt2html
Fixes the reason for reverting Ie430acd0753880d88370bb9f22bb40a0f9ded917:

The issue was that with my patch, the transform/wikitext/to/html started
ignoring the offsetType field in the body. So the offsetType used in the
response (or stashed data) would always be 'byte'.
But the roundtrip-test.js scripts requests 'ucs2'.

This causes an error when sending the HTML and data-parsoid back to
transform/html/to/wikitext, again with offsetType:'ucs2': the offsetType
embededed in data-parsoid will be byte, and the mismatch causes a 400
to be returned. This broke the roundtrip-test.js script.

The fix is to no ignore the offsetType specified in the request body.

Change-Id: Ief721c23ed9a57d781cfdac625a62113f22f87a5
2022-12-05 18:49:30 +00:00
daniel
c6b4a18573 HtmlOutputRendererHelper: Add edit flavor
This adds support for an "edit" flavor to HtmlOutputRendererhelper,
which causes data-parsoid attributes to be present in the HTML output.

In addition, this adds the ability to request HTML output using a
specific profile versionThis adds support for an "edit" flavor to
HtmlOutputRendererhelper, which causes data-parsoid attributes to be
present in the HTML output.

In addition, this adds the ability to request HTML output using a
specific profile version..

Change-Id: I5c21e0358da6a8915ddfe574fb2d13e469f625c5
2022-11-28 12:12:15 +01:00
daniel
93015579a1 HtmlOutputRendererHelper: add more convenient setters
REST helper objects should be geared towards accepting input directly
from an HTTP request. As such, they should offer setters that take
string values. And native representation of things like page titles,
languages, or content objects should be done implicitly by the helper.

Change-Id: I9b81cad4d5cc575e7c5283035e385ac0457e8059
2022-11-28 12:07:17 +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
6fd3a7b0b0 Stash original wikitext when rendering unsaved content.
When visual editor switches from source mode to visual mode, we need to
stash the wikitext. Otherwise, we later lack the proper context to
convert the modified HTML back to wikitext.

Bug: T321862
Change-Id: Id611e6e022bf8d9d774ca1a3a214220ada713285
2022-11-04 17:17:32 +01:00
daniel
f545d5efeb Rename HTMLTransform to HtmlToContentTransform
* We will have several kinds of HTML transformations.
Rename HTMLTransform to indicate that its for converting HTML to Content
objects.

* Using Naming Convention 'Html' instead of 'HTML'

Change-Id: I506f3303ae8f9e4db17299211366bef1558f142c
2022-11-03 16:47:36 +01:00
Abijeet
1b53f15e7f page/html endpoint: Support variant conversion
Variant conversion is based on the Accept-Language header. Updated
the HtmlOutputRendererHelper to set the HTTP headers related to
variant conversion.

Bug: T317019
Change-Id: I5e11452f1c531a757e8d860f9c727b5810406bce
2022-11-01 19:21:42 +05:30
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
jenkins-bot
46c8bb05bf Merge "Use markTestSkippedIfExtensionNotLoaded() shortcut in tests" 2022-10-14 15:43:13 +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
thiemowmde
178d6810f5 Use markTestSkippedIfExtensionNotLoaded() shortcut in tests
Change-Id: Ie7cc7b8c3aad0225f2f2d2d2241046756c03c0d5
2022-10-04 09:39:55 +00:00
Derick Alangi
9397a235c9 Loop in more relevant data to parsoid's parser outputs
We need the output content language when fetching HTML in VE
so this needs to match whatever parsoid gives us. In order for
this to happen, we need to loop in more data to the parser output
after parsing. This patch adds that more relevant data and
exposes it via a public method: `getHtmlOutputContentLanguage()`

In addition, this patch fixes a bug that was introduced in the
PageBundleParserOutputConverterTest when setting extension data
on parser output (L#64).
Follow-up: I33076c359ee45719c1c4ef63f77c1f1285951d0c (test fix)

Change-Id: I06bf9f575ed5a2521cf4b2c42fc6e0e7faab6bc0
2022-09-27 13:04:25 +01: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
Derick Alangi
ebc3f41399 Rest: Rename ParsoidHTMLHelper -> HtmlOutputRendererHelper
NOTE: stats key has been updated to reflect this change so we'll
  no longer get data on the "parsoidhtmlhelper..." key after this
  is deployed.
Change-Id: I599b1fd22c2d962b57e80beb84fe6f3a335f488c
2022-09-06 10:30:55 +01:00
Renamed from tests/phpunit/integration/includes/Rest/Handler/ParsoidHTMLHelperTest.php (Browse further)