Commit graph

119 commits

Author SHA1 Message Date
Abijeet
5c113a833a LanguageVariantConverter: Add fallback to core LanguageConverter
If variant conversion is not supported by Parsoid, fallback to using
the old LanguageConverter.

We still call parsoid to perform variant conversion in order to add
metadata that is missing when the core language converter is used.

Bug: T318401
Change-Id: I0499c853b4e301f135339fc137054bd760ee237d
Depends-On: Ie94aaa11963ec1e9e99136af469a05fa4005710d
2022-12-11 12:12:33 +05:30
jenkins-bot
a997ced2ad Merge "Add e2e test for fetching a message via the page endpoint" 2022-12-06 14:35:14 +00:00
jenkins-bot
cca97bcad7 Merge "[Re-apply] ParsoidHandler: use HtmlOutputRendererHelper in wt2html" 2022-12-05 19:21:23 +00:00
Daniel Kinzler
5cb388455b [Re-apply] ParsoidHandler: use HtmlOutputRendererHelper in wt2html
This restores change Ie430acd0753880d88370bb9f22bb40a0f9ded917.
This reverts commit ab6baad1a5.

NOTE: Also needs the patch the fixes the original reason for the
revert: Ief721c23ed9a57d781cfdac625a62113f22f87a5

Change-Id: Ic48db1b5fdff1dfd4f2d2643d64252e5fc721e79
2022-12-05 18:43:51 +00:00
msantos
fb5c29e2c0 Follow redirects for page/{title} formats source/bare
* Share logic previously implemented for html/with formats through
a trait class

* source/bare formats doesn't execute a temporary redirect. the
JSON body will contain a key "redirect_target" instead if a wiki
redirect is found

* Introduce PageRedirectHandlerTest to test redirect logic shared
between multiple handlers

* Move Handler instatiation to HandlerTestTrait

* Update api-testing tests in Update.js

Change-Id: Id66e33e19adabdb3c9621eaea4a5d441f23edafd
2022-12-02 13:22:14 -03:00
Daniel Kinzler
ab6baad1a5 Revert "ParsoidHandler: use HtmlOutputRendererHelper in wt2html"
This reverts commit e82f11c246.

Reason for revert: Breaks parsoid CI

1) Parsoid round-trip e2e testing with MW REST endpoints
     rt-testing e2e:
     AssertionError: expected 1 to equal 0
     + expected - actual
     -1
     +0

     at Context.<anonymous> (tests/api-testing/RoundTrip.js:59:10)
     at processTicksAndRejections (internal/process/task_queues.js:95:5)

Change-Id: Ib94f964c2717885f777c1fe0c9c443cd6a5ed3ae
2022-12-01 21:17:34 +00:00
daniel
e82f11c246 ParsoidHandler: use HtmlOutputRendererHelper in wt2html
NOTE: This causes Parsoid output to be written to the parser cache.
This should be unconditional in the future, but for now it is
controled by wgTemporaryParsoidHandlerParserCacheWriteRatio.

This change affects the following endpoints that use the wt2html method:
* /coredev/v0/transform/wikitext/to/html in core
* /{domain}/v3/transform/wikitext/to/html from parsoid
* /{domain}/v3/page/html/{title} from parsoid

The /v1/page/{title}/html endpoint is not affected, since it
doesn't use wt2html, but has always been using HtmlOutputRendererHelper
directly.

Bug: T322672
Depends-On: Ic37f606bb51504c8164d005af55ca9a65f595041
Change-Id: Ie430acd0753880d88370bb9f22bb40a0f9ded917
2022-12-01 10:14:49 +00:00
daniel
f0a4048332 Add e2e test for fetching a message via the page endpoint
Change-Id: Ib7a018e09439b4b20ada6520f2e3c49983c5687b
2022-11-23 21:02:01 +01:00
jenkins-bot
91a758ab85 Merge "Follow redirects for page/{title} formats html/with_html" 2022-11-17 00:58:46 +00:00
msantos
46071e9c3d Follow redirects for page/{title} formats html/with_html
* Apply Legacy Temporary redirects (302) if page is a redirect in order
to have feature parity with RESTBase

* Check for normalization redirects and execute permanent redirects (301)

* Add/Update mocha tests for the redirects functionality

* Add query parameter 'redirect=no' check to bypass redirect logic

* Unit tests to check status code and location headers

Bug: T301372
Change-Id: I841c21d54a58e118617aaf5e2c604ea22914adaa
2022-11-16 17:50:03 +00:00
Abijeet
ad5b43f8a2 Api Testing: Enable some variant tests in Transform.js
Change-Id: Idf1f736eb958b093eafce4ee1cd138f52cfae986
2022-11-11 13:48:40 +05:30
Abijeet
5220e5e301 Api tests: Simplify variant tests by using pig-latin
Change-Id: Ice2a9b14db4ae280f5317aaaf3c50a1c6ab0fd05
2022-11-08 19:48:12 +05:30
C. Scott Ananian
418896168d api-testing/REST: BCP 47 language tags should be case-insensitive
The test case was too-strictly enforcing a case-sensitive match against
the BCP 47 language tag, which caused a spurious failure with the
latest version of Parsoid.

Change-Id: I2915e3bc288f4293e4ebf11ab68ccd6d020f2b8e
2022-11-04 13:05:11 -04:00
Abijeet
46989b35ac revision/html endpoint: Support variant conversion
Bug: T317019
Change-Id: Ibcd08d20477dab283e29d37b1387a6289b404b70
2022-11-01 19:21:50 +05:30
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
c25380ca37 Parsoid: Fix e2e tests for size limits.
The tests for size limits did not catch an issue introduced by
If09afc4b933e, which caused resource limits to trigger early, since they
were now being compared to the size in bytes, rather than characters.

The reason the tests didn't protect us is threefold:
- They only check the error returned when the resource sizes is one over the limit.
  They don't check that the error is NOT returned when the size is one under the limit.
- They did not test with a multi-byte character.
- They were disabled, because the limits are quite high, and the e2e test can not change them.

This patch is an attempt to fix all three issues.

Depends-On: I40901a1204b3c698895a836bf3b605239878d1fe
Change-Id: I2aead24cb7f47eb1267fdd2954a7c7e45dd4ed51
2022-10-14 13:22:12 +00:00
daniel
68ccdf26f9 html2wt: fall back to re-rendering if needed.
If we don't have a render id given, but we do have a revision id, we can
fall back to the current rendering that revision to provide a baseline for
selser. This is better than no selser. On wikis that do not heavily rely
on templates, or where templates rarely change while an edit is in
progress, this will produce a clean diff.

Bug: T318398
Change-Id: If7612cc6e64d1f1243289b7d6ba96c71f09fe15d
2022-10-05 14:52:03 +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
daniel
d6140952ed HTMLTransform: do not presume wikitext
Parsoid supports other source formats besides wikitext.
This patch improves support for non-wikitext content by removing
assumptions about the source type.

Change-Id: I5480ff200a93026cea7f1542e12834b06ac6f730
2022-09-22 17:41:48 +01:00
daniel
6236b1f2f4 Move knowledge about the attribs array out of TransformContext
This renames TransformContext to HTMLTransformInput. It is becoming a
wrapper around the input HTML, with a bunch of optional context data
attached.

This introduces a factory method for HTMLTransformInput, so we can
extract knowledge about the structure of the $attribs array from
HTMLTransformInput.

This also allows us to inject Document objects and perhaps PageBundle
objects, instead of just arrays.

Change-Id: I66f9c5dbb50c6bf1f582adad7766422216482402
2022-07-22 12:12:55 +00:00
daniel
3f1cf31740 phpunit tests for ParsoidHandler::html2wt
The test cases were mostly ported from tests/api-testing/REST/Transform.js

Change-Id: Ie6b9f28b6e49e44c64f1fa73ca11e21c2b451474
2022-07-18 13:51:49 +02:00
daniel
0cdc7a73eb Transform e2e test: Move data into separate files
Move HTML and other complex input and output data from giant strings into files.
This makes them easier to read, modify, and compare.

Change-Id: Iafe2638e4eda903e1064b05adaa80a39ff5028f9
2022-07-08 20:08:16 +02:00
Derick Alangi
c1c5f3f7f3 Rest: Make transformation endpoints configurable
Page bundles should not be part of the publicly accessible
API and if we really need it, we can expose it and consume
internally. Hence, remove support for this transform from the
endpoint.

This patch falls back to the behavior before for backwards
compatibility before we fully switch over to using the transforms
in core. We still need to support both core & restbase for now.

NOTE: API integration tests have been updated to status code
404 since we're removing support for it now. If we need it,
we'll expose via a different endpoint and introduce tests.

Bug: T311477
Change-Id: I5577f61f7ae7da2a4d3a78d9ce962997466d550c
2022-06-30 13:28:57 +01:00
jenkins-bot
3a66ddbf57 Merge "Parsoid API: emit strong eTags" 2022-06-17 18:57:33 +00:00
daniel
29dd93d04b Parsoid API: emit strong eTags
This patch changes the etag emitted for HTML in GET requests to be
marked as a "strong" (byte-by-byte) eTag. This matches the behavior of
RESTbase.

This also adds checks for strong ETags to the e2e tests for the v1/page
and v1/revision endpoints. This is done for completeness. These endpoints
do not use the code changed here, the tests would have passed without
the change to ParsoidHandler.

NOTE: This addresses the issue of weak ETags coming from parsoid
endpoints only for setups that do NOT use RESTbase and/or Varnish.
RESTbase never had the issue. Varnish apparently weakens any ETag when
applying compression.

Context: The eTags returned in response to GET requests to parsoid endpoints
are later used in an If-Match header in requests to the transform endpoint,
when transforming HTML to wikitext. The intent is for the request to
fail if the server doesn't have the "stash" entry identified by the
etag, which would be needed to get a clean conversion using SelSer.

For this to work, the etag must be "strong", that ism they must not have
the W/ prefix that indicates a weak prefix. The HTTP spec mandates that
If-Match headers using a weak etag must always cause the request to
fail.

Bug: T310710
Change-Id: I075b20f0937b51b7fcde2e9fa9ac1cec8c7eec87
2022-06-17 14:22:30 +02:00
Arlo Breault
2dbef8d9f0 Transform.js tests: soften one more schema version check.
Follow up to I6d7db6a05c48de8a57f83e4c8af38ab50271297a

Change-Id: I317ce587e62f9e94bbafbdabac64156237c4f1e3
2022-06-14 15:09:47 -04:00
jenkins-bot
65572907d2 Merge "Transform.js tests: soften schema version check." 2022-06-14 16:31:48 +00:00
daniel
dbd5506a4a Transform.js tests: soften schema version check.
This changes the Transform.js e2e test to not break when the parsoid
schema version is getting higher. We are only guaranteeing stability
according to the semver caret semantics to clients, so that is what
the e2e test should assert.

This allows tests to pass when raising the version of the parsoid lib in
composer.json. This also allows core tests to pass when run against the
development branch of the parsoid repo.

Change-Id: I6d7db6a05c48de8a57f83e4c8af38ab50271297a
2022-06-14 17:38:41 +02:00
Derick Alangi
b0d08dcbfc Rest: Remove {domain} param from TransformHandler
RESTBase used this to check if the domain sent by the client
matches the domain in the restbase config under the hood. Since
this code is moving to core, this assertion is no longer needed.

Bug: T301370
Change-Id: I01a4f35b81c31d106671e5c829d317a41687fd7a
2022-06-02 19:37:51 +01:00
jenkins-bot
ed6bec04df Merge "Add end-to-end tests for fetching HTML" 2022-06-02 17:13:27 +00:00
Derick Alangi
80ce1fe28f Rest: Move TransformHandler to core (part 1)
Begin moving the transform endpoints and handler class to
MediaWiki core.

Bug: T301370
Change-Id: I94e9d2e8d497c1992c542001afe333fa7537e553
2022-06-02 15:55:06 +01:00
daniel
643c89677e Add end-to-end tests for fetching HTML
This adds Mocha end-to-end tests for the following endpoints:
* /page/{title}/html
* /page/{title}/with_html
* /revision/{id}/html
* /revision/{id}/with_html

Bug: T309549
Change-Id: Ib7c6f1371ef1dbc8dd68708a5bd8f7566ace14f3
2022-06-01 11:47:31 +00:00
Klein Muçi
803b873beb docs: Fix 'the the' typo
Bug: T201491
Change-Id: Idd776953dcf7dadc136e57d586c09b24363005a6
2022-05-05 15:40:26 +00:00
Bill Pirkle
fc7acbee64 Promote experimental revision rest endpoints to official
These three endpoints have been experimental for many months:
  revision/{id}
  revision/{id}/html
  revision/{id}/with_html
Promote them to officially released. This completes the
basic "revision" endpoint support, and helps clear out
the coreDevelopmentRoutes.json file for unrelated
experiments.

This also modifies the existing revision/{id}/bare endpoint
response, which previously pointed callers to the experimental
endpoint for html. It now points callers to the official one.

Bug: T305506
Change-Id: Iee8d1723e98dd3e3e389a0514dde28799914b2fd
2022-04-13 11:30:53 -05:00
Nikki Nikkhoui
f16c46dcb0 api-testing: Remove 'matched_title' check
Sqlite and MySQL are returning results in different
orders for the REST Search handler, which affects how it handles
de-duplicating results with redirects.

If the Redirect Target is processed first, the matched_title
field is not populated because that page is not a redirect.
If the Redirect Source is processed first, the matched_title
field IS populated because that page is a redirect.

Either way, we don't have duplicate results (which is the most
important part). Until the logic is consistent, remove the
matched_title check.

Bug: T302706
Change-Id: Ic3977655565aa9f6d6c184749706273b0315b7be
2022-02-28 19:45:18 +00:00
Kosta Harlan
dc828c4aae
api-testing: Run all jobs in a few more tests
Follows-Up: I126d14d552eb060aba6c91764ea54092da7aff21
Change-Id: I4f9a2f16ed0472c27cced2235473837d4499ec8c
2022-02-22 09:26:37 +01:00
jenkins-bot
85e2a07fe6 Merge "Revert "api-testing: Skip flaky bot edit revert test"" 2022-02-21 15:19:44 +00:00
Kosta Harlan
03c070d467
api-testing: Disable failing contributions count tests
Partial revert of I0e30fdb6acba85cec4bb1499f7063ba6bfb0ffb2;
re-application of I3e1fe5e8112e3b1d487c46bc7fd8f924d65ce7fa and
I8f7b5e9257c7f283ded1a61e41d9e344f5cea67d

Bug: T301100
Change-Id: I90bea3fda48efdc7e915908d00535df220c4cc69
2022-02-16 16:30:56 +01:00
daniel
0ebf7786b1 DeferredUpdates: Introduce $wgForceDeferredUpdatesPreSend
Enabling this setting will cause post-send deferred updates to be run
before a response is sent to the client, so the client can observe all
effects of their last request immediately.

This resolves a problem with some end-to-end tests that were failing
because the updates caused by one request had not landed in the database
by the time the subsequent request was made.

This patch re-enabled some e2e tests that were disabled because of this
problem. If $wgForceDeferredUpdatesPreSend works as intended, the tests
should again pass reliably.

Bug: T230211
Bug: T301100
Change-Id: I0e30fdb6acba85cec4bb1499f7063ba6bfb0ffb2
2022-02-15 19:49:14 +01:00
jenkins-bot
a9658e06b5 Merge "api-testing: Run all jobs after edit in Watchlist.js" 2022-02-15 09:15:45 +00:00
Kosta Harlan
8197a4e5f6
api-testing: Run all jobs after edit in Search.js
Change-Id: I126d14d552eb060aba6c91764ea54092da7aff21
2022-02-11 10:59:41 +01:00
Kosta Harlan
d01950a57d
api-testing: Run all jobs after edit in Watchlist.js
See
https://integration.wikimedia.org/ci/job/mediawiki-quibble-apitests-vendor-php72-docker/28585/console
for a build failure where the watchlist query didn't return a result.

Change-Id: I891668e9daf92286d2cf8f98b9aab72f56c57d78
2022-02-10 14:03:57 +01:00
Ed Sanders
9e234e6a37 eslint: Only apply client rules to client files
Change-Id: I757b9616ce69b6020e9f0e556e006d39de59eb01
2022-02-09 02:40:11 +00:00
jenkins-bot
730b6ee3a7 Merge "api-testing: Skip flaky contributions count test" 2022-02-08 17:57:58 +00:00
jenkins-bot
07a36a3ca8 Merge "Add matched_title field to /search/page results" 2022-02-08 15:56:50 +00:00
Nikki Nikkhoui
9805798a21 Add matched_title field to /search/page results
Add a field to the response object of the REST
endpoint /search/page to display the title of the page
that the given page is a redirect to, or null if
the page is not a redirect.

Bug: T296671
Change-Id: I6673d50e8eae822455972403c82ec33e6ffce5dd
2022-02-08 10:18:46 -05:00
Kosta Harlan
9858e67baa
api-testing: Skip flaky contributions count test
Follows-Up: I8f7b5e9257c7f283ded1a61e41d9e344f5cea67d
Bug: T301100
Change-Id: I3e1fe5e8112e3b1d487c46bc7fd8f924d65ce7fa
2022-02-08 15:29:03 +01:00
Kosta Harlan
4075ed5ee5
api-testing: Skip flaky test
Bug: T301100
Change-Id: I8f7b5e9257c7f283ded1a61e41d9e344f5cea67d
2022-02-07 09:37:50 +01:00
Kosta Harlan
c5ba14f8cf api-testing: Disable flaky test
Bug: T285649
Change-Id: Ib13f81715c3bfcc4232d6a17da86a9e6d7e7f347
2022-02-02 13:52:07 +01:00
Kosta Harlan
b3fb341423 api-testing: Add wiki.runAllJobs() for two more tests
Bug: T285649
Change-Id: I4b770577b711c368541f4e7e53fe6e25bf26aa78
2022-02-02 13:50:39 +01:00