Commit graph

178 commits

Author SHA1 Message Date
daniel
7c2ad4e058 Add tests for wt2html
Porting relevant tests from tests/api-testing/Parsoid.js in the
Parsoid extension.

Change-Id: Ieb4b41375d521893f95e2fcb5f4984e7b5a2364c
2022-11-17 20:44:48 +00: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
jenkins-bot
20a0a891d1 Merge "ParsoidHandler: test that selser will re-parse" 2022-11-15 01:24:56 +00:00
daniel
f7dc7e6045 ParsoidHandler: test that selser will re-parse
When no original HTML and no etag is provided,
selser should still be attempted based on a rendered
version of the old wikitext.

Change-Id: Ic3cc3a598f32cad6122964cb8a7376a56be9129f
2022-11-08 12:22:57 +01: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
Derick Alangi
701cf7ab92 HtmlInputTransformHelper: Capture metrics for SelSer context
Bug: T318399
Change-Id: Iff2439cb281126ef41c445fb86433a561b3981e7
2022-11-04 14:06:36 +05:30
daniel
0457d9fa5b HtmlInputTransformHelper: setters for programmatic use
This patch is intended to allow HtmlInputTransformHelper to be used
without constructing a fake request body. The idea is to make it easier
to use it in action API modules, such as ApiVisualEditorEdit.

Change-Id: I4002342820b19060da30b6fb8622c85c49eec6a0
2022-11-03 22:25:19 +05:30
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
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
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11: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
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
jenkins-bot
79ad263c46 Merge "html2wt: fall back to re-rendering if needed." 2022-10-05 21:49:05 +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
jenkins-bot
05d701a2a4 Merge "ParsoidHandler: use metrics from SiteConfig" 2022-10-04 17:05:27 +00:00
daniel
79cc21beaf ParsoidHandler: use metrics from SiteConfig
ParsoidHandler should pass the metrics object from the
SiteConfig to HtmlInputTransformHelper, instead of using the global
metrics instance. Otherwise, the metricsPrefix defined in the parsoid
settings is ignored.

Change-Id: Ie85f2306e8b0f123b9fdd737faffdd85117015b1
2022-10-04 16:49:36 +00:00
thiemowmde
178d6810f5 Use markTestSkippedIfExtensionNotLoaded() shortcut in tests
Change-Id: Ie7cc7b8c3aad0225f2f2d2d2241046756c03c0d5
2022-10-04 09:39:55 +00:00
Matthias Mullie
c4a36b0023 Introduce SearchResultThumbnailProvider & move hook + NS_FILE thumbs in
What was previously a REST API-only feature (the thumbnails
hook allowing for thumbnails for non-file pages via the
PageImages extension) is now also being adopted in the main
search page.

That hook will now be called with NS_FILE result thumbnails
pre-filled, which was not the case previously. PageImages
essentially duplicated NS_FILE thumbnail logic that was
already present in Special:Search, so that can (and will
in a follow-up patch) then be removed there. Special:Search
will then simply take whatever is produced from the provider
(which will include both NS_FILE thumbs - which it handled
already - as well as whatever else it receives from the hook),
as will the REST API (which already received both)

Since thumbnails can now come in for multiple namespaces &
having some of those results with & others without a thumbnail
can be quite jarring, it was decided that we'd display
placeholder images (for certain namespaces). This is now
controlled by $wgThumbnailNamespaces.

I also split up a few things in FullSearchResultWidget::
generateFileHtml for more clarity.

Meanwhile also updated mediawiki.special.search.styles.less
to use variables for known colors.

Also implemented a 'transform' (required for testing this
change properly) and 'getDisplayWidthHeight' (it became
needed after implementing transform) callback function for
mock Files, and updated some existing tests in response to
these changes.

And some more Rest test files have been updated to allow
passing around a HookContainer instead of only an array of
hooks (from which a new HookContainer would then be created)
to allow the same container to be used across all relevant
objects, who may have it injected as dependency.

Bug: T306883
Change-Id: I2a679b51758020d3e822da01a1bde1ae632b0b0a
2022-10-03 10:52:50 +00: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
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
33706fd187 Merge "TransformHandler: add test for variant conversion" 2022-09-26 16:39:09 +00:00
jenkins-bot
38dd253878 Merge "Introduce HtmlInputTransformHelper" 2022-09-26 14:16:52 +00:00
jenkins-bot
e0e430c049 Merge "Add PageBundleParserOutputConverter" 2022-09-26 13:16:23 +00:00
daniel
4107333069 Introduce HtmlInputTransformHelper
The HtmlInputTransformHelper is intended to provide code sharing
between VisualEditor's DirectParsoidClient and the ParsoidHandler
base class used by TransformHandler.

Bug: T310376
Change-Id: I9c15f075cfc5f198e290758fc23d25990b47a185
2022-09-26 12:58:17 +00:00
jenkins-bot
0cd6876ee4 Merge "Fix parse() and getParserOutput() interfaces" 2022-09-26 11:19:55 +00:00
daniel
654d1d0dd1 TransformHandler: add test for variant conversion
Change-Id: I91acc9b4306a8170be5e4f94377aab764e185807
2022-09-26 12:57:08 +02: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
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
24a26ec25b REST: make ParsoidHandler use HTMLTransformFactory
This also moves the creation of PageConfig from HTMLTransformFactory
into HTMLTransform, to ensure all relevant info, particularly the
page language, is known.

Change-Id: Id354862d6497816e0c007b9cb3b0d183c9d4b719
2022-09-16 18:46:17 +02:00
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
daniel
79746fbd35 ParsoidOutputAccess: support target language.
When parsing content for page creation, we need to be able to pass the
page language explicitly. This patch allows the language to be looped
through from ParsoidHTMLHelper via ParsoidOutputAccess into Parsoid
itself.

Change-Id: I1bbf9c2180de2d91679edbc9d73adfe44075dde3
2022-09-02 14:00:40 +00:00
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
jenkins-bot
246b1f64e5 Merge "ParsoidHandlerTest: Add tests to cover tryToCreatePageConfig()" 2022-08-25 20:12:46 +00:00
Derick Alangi
0859331ba1 ParsoidHandlerTest: Add tests to cover tryToCreatePageConfig()
This patch creates a patch to cover the aforementioned code path for
when it works correctly and when it throws.

Change-Id: I4b3d9f280a0977d3811afb768824da302673e659
2022-08-25 19:42:48 +01:00
daniel
df0744f402 Split setOriginalData( ... ) to more related setters for encapsulation
By splitting the setOriginalData methods into several setters, we remove
any knowledge about the structure of the request body from HTMLTransform.
It also allows us to be specific about which data to operate on.

This also removes the concept of page bundles from the public interface
of HTMLTransform. PageBundle objects are used only internally.

Change-Id: If97a74ce251f281b7d980928a01b764d6ec0d0a4
2022-08-25 18:40:26 +02:00
Subramanya Sastry
86f2b26589 Don't hardcode Parsoid HTML version number in tests
* Without this fix, the test fails vendor patches whenever Parsoid's
  default version number is bumped in the Parsoid repo.

Change-Id: Icce7b61dfbbbbd57b4f1ed76a32d160e92b48b15
2022-08-12 14:29:25 -05:00
Derick Alangi
b078f598f9 Move transformHtmlToWikitext() and getSelserData() to HTMLTransform
This patch moves remaining transformation logic to a renamed (from
HTMLTransformInput -> HTMLTransform) class. Also, the HTMLTransform
class is moved to the correct directory, hence namespace (including
tests).

Some data files have been copied over to it's own sub-directory in
the correct place since HTMLTransformTest needs it. ParsoidHandler
class is fine where it is because its operation is what happens in
the REST land.

NOTE: The 2 remaining methods moved into HTMLTransform are the last
ones we intended to move into this class to make the refactoring of
html2wt() method complete in this context.

Change-Id: I8929931e1b0acf247abe9d826eef57f3e0d4e132
2022-08-11 07:50:53 +01:00
jenkins-bot
e1ff495a45 Merge "ParsoidHandler: fix page bundle input with no orig HTML." 2022-08-02 19:55:25 +00:00
daniel
311f5450a1 ParsoidHandler: fix page bundle input with no orig HTML.
When refactoring, we were assuming that if the input is a page bundle,
it will always contain original HTML. That is not the case. We need to
make use of the supplied data-parsoid array even if there is no original
HTML given.

Change-Id: Ida8cbfcaac059af8902db9560a3ad6884e8b1790
2022-08-02 19:07:52 +02:00
daniel
6fd1561658 ParsoidHandler: add test for pagebundle input without original HTML
This is a regression test for an issue that broke parsoid's roundtrip
tests. The issue itself was already fixed on the master branch.

Change-Id: Ia7edb26a149231fbfc43f4edb8185304341b19ca
2022-08-02 14:46:39 +00:00
jenkins-bot
9af6aa5d86 Merge "Fix $validateXMLNames flag when parsing HTML" 2022-08-01 17:05:56 +00:00
daniel
00c4f11ab6 Fix $validateXMLNames flag when parsing HTML
Change-Id: I6cbd2e8a7096b96814e9e0afe0193e1ca781af45
2022-08-01 17:23:03 +02:00
daniel
891c06816d ParsoidHandler: measure input size in characters
In If09afc4b933 we made ParsoidHandler measure input size in bytes
consistently, rather than using sometimes bytes, and sometimes
characters.

However, that was going to cause input limits to trigger early for
languages that use a lot of multibyte characters. So now we are switching
everything to measuring in characters.

NOTE: this may cause the html2wt.timePerInputKB to report worse values.
It also makes the name slightly misleading, since it's no longer in KB,
it's in kilo-chars.

Change-Id: I41872db6d1f5d96776fef54624428cc3ee5f21b3
2022-07-31 01:04:02 +02:00
daniel
d50218c84f Move DOM transformations into HTMLTransformInput getters.
This moved the logic for applying page bundle data into the getters that
return DOM elements. It also makes the application of version
downgrades implicit.

NOTE: This patch changes the expected value of one of the phpunit tests
to a version that has no closing </div> tags. This appears to be the
original and expected behavior, per the corresponding test in the
parsoid extension's Parsoid.js test suite.

Change-Id: If2d7b06d8ba92fb63e6955ec7587ed4aea557251
2022-07-28 19:07:40 +02:00
jenkins-bot
5e82dca25f Merge "Fix ParsoidHandler html2wt unit tests" 2022-07-27 19:42:32 +00:00
Subramanya Sastry
d443dfa395 Fix ParsoidHandler html2wt unit tests
* Several unit tests had lost information about the input format
  being a pagebundle format.

* Fix the input format for a number of tests and a test expectation
  in one case.

  I removed a number of spurious comments which were misinterpreting
  why the pagebundle format was being used. If the input payload is
  in pagebundle format, the specified format should match that.

  In integration tests, the API endpoint implicitly provides this
  format information. But, in unit tests, this should be done explicitly
  which would also be the case for internal service object callers.

Change-Id: If3d3c0ad2ee1fe19f4c1590caa43bea4340cc08c
2022-07-27 11:43:49 -05:00
daniel
f1f5d470c9 Move dowgrade logic into HTMLTransformInput
Moving lazy initialization logic into HTMLTransformInput to clarify flow
of information.

DEPLOY: Mention that we've fixed $htmlSize and it will affect metrics
  graphs when this roles out.

Change-Id: If09afc4b933ec99561ac9e4d53383bd42a856eaa
2022-07-27 16:15:32 +01:00
daniel
eaa7e31b9d Add test for offset type check
We were only testing the offset type mismatch case with a non-standard
offset type in the 'original' data structure. This cause us to miss a
bug. This adds a test that has a non-standard offset type coming from
the request attributes.

Change-Id: Icac28b3f8c85bc594e1cae42a4ee407f0d54a19b
2022-07-26 16:51:47 +02:00
Derick Alangi
f331834754 Rest: offsetType is not in the options sub-array
This patch fixes an issue that happened when the assumption was
made that offsetType is in the opts sub-array but it's really not
part of it. It's directly in attributes, copied from envOptions,
which causes the offset type to always be byte.

Change-Id: I5d1a8a7cdfe13c22a2afa70128203050a4b5f98a
2022-07-26 11:33:42 +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
Derick Alangi
01c16063ad Rest: Refactor the ParsoidHandler::html2wt() method
In preparation to making the logic into a service object.

Bug: T310376
Change-Id: I4e272fbfa27814c027f7ffc31627c59f63de5bf4
2022-07-20 18:48:17 +01: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
Tim Starling
8de63ae485 Make RateLimiter use WRStats
Bug: T261744
Change-Id: Ib947340cbac19fb26176257e1707e51426c7f76e
2022-07-16 11:00:22 +00:00
Derick Alangi
f88eab53a6 tests: Use overrideConfig(Value|Values) where needed
This continues the work in the child patch to replace callers
of setMwGlobals() with the appropriate method. Directory this
patch covers is `tests/phpunit/integration/`.

Change-Id: I0a9abf0d2a43587f2ffa029b68024a1ba5165fc7
2022-07-12 14:40:46 +01:00
daniel
bf092744c9 PHPUnit: introduce setMainCache
The main object cache is disabled during testing. Some integration tests
need it though. This provides a clean way to enable it, to replace the hacks
that were used so far.

Note that we may want to enable the main cache during testing soon. When
that happens, this method is still useful to disable the cache in certain
tests, and to set a specific cache instance.

Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
2022-07-07 16:25:59 +10: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
Derick Alangi
270699ec34 Configure caching parsoid output per wiki based on threshold
Cache the parsoid outputs only if a certain time is exceeded on
parse and consider the parse operation within this time limit as
not expensive per that wiki and not cache the parsoid output at all.

Bug: T308588
Change-Id: I7793b77feab13400ccd04343e7878ad701f5e6a7
2022-06-16 11:42:06 +01:00
daniel
6955380fbe Add rate limiting to ParsoidHTMLHelper
Bug: T267991
Change-Id: I52a83e7d3bdb0bcde59160e2d193f06908fda3d4
2022-06-15 13:40:56 +02:00
daniel
4dd7bd16b5 ParsoidOutputStash: make storage backend configurable.
This introduces the ParsoidOutputStash config setting, which defines the
storage backend and cache duration. The storage backend name refers to
an entry in the ObjectCache setting, and defaults to the main stash.

Bug: T267990
Bug: T309016
Change-Id: Ic67dc43ed9843810e4b180127f9a3bb7608f7608
2022-06-14 14:11:37 +01:00
jenkins-bot
b494330aa7 Merge "ParserCache: always use JSON" 2022-06-07 14:12:29 +00:00
daniel
697f28df32 ParserCache: always use JSON
When JSON support was introduced into ParserCache in 1.36, it was
controlled by a feature flag, $wgParserCacheUseJson. The feature flag
was "born deprecated" in 1.36. It can now be removed.

This means that ParserCache will always store entries as JSON.
Support for reading old non-JSON entries remains intact.
This is needed when updating wikis from a version older than 1.36
to the current version.

Change-Id: Id04e42bfb458d98414bac50e0d6c505e8878e5c0
2022-06-07 15:19:45 +02:00
Subramanya Sastry
d3c3abcd22 Unbreak ParsoidHTMLHelperTest: Fix call to ParsoidHTMLHelper constructor
Change-Id: I17af4240ac81c6234c213c7a92465354a9942201
2022-06-02 17:26:24 -05:00
Derick Alangi
141b42c7ca Rest: Collect stats on Cache & Stash usage
As a means of understanding the usage of the stash FEAT for
/page/html & /revision/html endpoints used by VE extension,
this patch introduces the collection of stats using the
StatsDataFactory.

Bug: T309017
Change-Id: I4e17d50e79da263637bdd55ab62e993df441fe38
2022-05-30 09:51:55 +01:00
Derick Alangi
d62f97d5e0 Rest: Return different eTags for different output modes
This patch enables the response from PageHTMLHandler and
RevisionHTMLHandler to have different eTags for different
output modes and varying flavors.

Before, the only difference we got was when the stashing
option is set or not, but we need more flavors.

Bug: T308744
Change-Id: I2e9679e46a31955a2106a52af4eb612b32799c8c
2022-05-25 11:15:47 +00:00
Derick Alangi
13f6ec9e1b Rest: Migrate parsoid stashing logic from RESTbase
Add stash option to /page/html & /revision/html endpoints.
When this option is set, the PageBundle returned by Parsoid is
stashed and an etag is returned that can later be used to
make use of the stashed PageBundle.

The stash is for now backed by the BagOStuff returned by
ObjectCache::getLocalClusterInstance().

This patch adds additional data to the ParserOutput stored in ParserCache.
Old entries lacking that data will be ignored.

Bug: T267990
Co-Authored-by: Nikki <nnikkhoui@wikimedia.org>
Change-Id: Id35f1423a69e3ff63e4f9883b3f7e3f9521d81d5
2022-05-23 17:28:29 +01:00
jenkins-bot
6411cc09c5 Merge "Allow REST API handlers to require csrf-safe session providers" 2022-05-23 10:06:52 +00:00
Bill Pirkle
7295100773 Allow REST API handlers to require csrf-safe session providers
Bug: T305043
Depends-On: Ic7c1b19b86e8a151e2d42aaec00ef0e89db77f08
Change-Id: Ic6bd48b400ecd839ef99b518ef955781470cd05c
2022-05-20 16:52:54 +00:00
Derick Alangi
1618bbd671 Add data-parsoid data to ParserOutput for caching
NOTE: This changes the HTML returned by the endpoint!
It will now include the id="mwXYZ" attributes needed to
later map to data-parsoid entries.

Bug: T268205
Change-Id: I0a29434b996cc289eb67083e62bd6f1ad750cb4d
2022-05-16 15:06:15 +00:00
Umherirrender
2909d06a08 Use new namespace for revision related classes
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.

Bug: T305784
Change-Id: I34e492d84d9fc4bc78481667202716d93b3c43cb
2022-04-14 23:03:43 +02: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
Alexander Vorwerk
62a70ec7c7 Use new namespace for revision related classes
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.

Bug: T305784
Change-Id: Ia0030814ce2176d06e2898acffe533d31633fccb
2022-04-09 20:22:36 +02:00
Subramanya Sastry
8aae1a0b21 Fix error message in test assertion
Change-Id: Id7604d9af623ffdb77b16960e8b9ca893d368963
2022-03-09 16:29:25 -06:00
Kosta Harlan
c9da85abb5 UpdateHandlerTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: I22777f933e2351cc11735ff75861174c80d81bd4
2021-12-08 15:54:13 +01:00
Kosta Harlan
ce10edfbc4 CreationHandlerTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: I2e7d4fa7e9fd0861ecb4eaf0687c9dc1cbe144f7
2021-12-08 15:25:20 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Derick Alangi
e894dc75fa tests: Use service container in integration tests cases
Since MediaWiki 1.36, this method is provisioned to replace creating
new instances of the services object. If one is already created and
seen by the service locator, just use it.

Change-Id: I9509497a8380194aa93310343b1896521070fc31
2021-09-05 22:14:36 +01:00
Petr Pchelko
339fd93f67 Make MovePageTest actually test valid moves
Before MovePageTest was skipped if the move was valid,
claiming we can't test actual moves. Now we can.

Additionally, use MediaTestTrait for file and repo
mocking.

Change-Id: Ie8a1edbdb2f22432919f03a60c2dacc5d4528615
2021-07-28 09:18:59 -07:00
Petr Pchelko
4ca16e8d08 Eliminate use of Title object in REST infrastructure
Change-Id: I585f0f23cac5f6dc2a4879f69f7b83828fda3dd3
2021-05-05 18:54:58 -07:00
DannyS712
41287e87d8 Add MediaWikiTitleCodec and NamespaceInfo to DummyServicesTrait
Move MockTitleTrait::makeMockTitleCodec to DummyServicesTrait, and
replace the two existing uses, which are in core. Add some new
uses instead of mocking each time.

Unfortunately, we cannot use an actual MediaWikiTitleCodec
for the tests in BadFileLookup, because those tests are unit tests
and a MalformedTitleException cannot be created in the context
of a unit test. BadFileLookupTest gets around this by using
a mock that throws a mock exception - add a comment inline
explaining why we cannot use a real MediaWikiTitleCodec.

Paired with adding of NamespaceInfo to make mocking the language
methods related to namespaces easier by matching the real
logic in the Language class to the extend possible. Update a few
tests to use the DummyServicesTrait for their NamespaceInfo services.

Change-Id: Ibd691ccf0e632e1bf0bc1f7e9ddc0c660d5cad32
2021-05-04 19:10:23 +00:00
Petr Pchelko
f642215aed Convert ParserCache to PageRecord
ParserOptions not updated cause they depend on Title::getLanguage
implementation.

Tests converted to not require a DB anymore. Can't be proper unit
tests yet due to globals in ParserOptions and fake time hacks,
but exec time does go down from 70 seconds to 9 seconds.

Page content model is still emitted in the metrics since
it was considered useful. Should be removed when we get
something like a page type concept.

Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
2021-04-02 21:14:54 -06:00
daniel
91dc627c85 UpdateHandler: fix response for null edits
The response from a null-edit should contain the current revision's
revision ID and timestamp, not the info from the edit's base revision.

Bug: T277601
Change-Id: I9d353cdc4cb9e3c1435c93ffe63ef4fef173ec4d
2021-03-26 16:53:43 +00:00
daniel
b38e0e8e32 REST edit: handle null edits correctly
For null-edits, the new revision is the same as the old revision.

Bug: T277601
Change-Id: I73f902f7ef890470ff6ee3e4500095adbb00938a
2021-03-19 14:10:25 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Petr Pchelko
10de1d3472 Introduce MockAuthorityTrait for Authority test helpers
Change-Id: I152f2cbe8a7000eedc237fb46b4e4c6d2f9730d4
2021-01-21 20:19:12 -06:00
Petr Pchelko
3a2e8883b4 Rest: use Authority in all core handlers
Bug: T239753
Change-Id: Idf2229255f49514dd8b68bf63573c5b619b4f2f1
2021-01-21 18:22:33 -06:00
Petr Pchelko
816e02ae51 Convert RevisionRecord to Authority and PageIdentity
As we convert the RevisionRecord to using Authority,
we no longer need Title instances, so we can convert
that to PageIdentity.

Ideally, we'd part away from using Title at all, but:
1. For foreign wikis PageIdentity has stronger validation,
so calling PageIdentity getId() on Title will break things.
There's still a lot of code depending on lax Title guarantees,
so we keep it.
2. A lot of code still depends on Title, so we try to pass it
through even if we don't nesessarily need to, to save cost
on recreating it later on.

Bug: T271458
Depends-On: I287400b967b467ea18bebbb579e881a785a19158
Change-Id: I63d9807264d7e2295afef51fc9d982447f92fcbd
2021-01-21 13:37:01 -06:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Petr Pchelko
7854dd5fc9 Split title mocking methods out of HandlerTestTrait.
The functionality of creating title mocks is generally useful
and this will also allow to make HandlerTestTrait more narrow.

Bug: T264058
Change-Id: I76eca48dfcff65a6203fccde5366912a2d66c495
2021-01-13 12:46:10 -06:00
C. Scott Ananian
df1ddd6f9c LanguageLinksHandlerTest: use wgInterwikiCache instead of mutating database
Mutating the interwiki table invalidates the Title codec and in
general leads to a bunch of complications.  Easier to just use the
`wgInterwikiCache` mechanism, as a lot of other phpunit tests do.

Bug: T271287
Change-Id: Id1899a89ae6b55e7032befe73990d215370828d8
2021-01-06 17:07:47 -05:00
daniel
637f630fe9 Implement caching for old revision HTML endpoint
Bug: T269663
Change-Id: I2d17ec37d25f3a6e1c4836c05576bf0fabb7d429
2020-12-15 23:40:08 +01:00