Commit graph

44 commits

Author SHA1 Message Date
Arlo Breault 2c1989c338 Stop injecting ServiceOptions in VisualEditorParsoidClientFactory
Change-Id: I7a3c5ef6435a38ef136e830b343dc19166659ef0
2023-08-30 17:05:17 +02:00
Arlo Breault de2935928c Remove unused VisualEditorParsoidClientFactory options
Looks like these were introduced in b029fd8 and could have gone out in
f2bb8cf.

Bug: T341614
Change-Id: I4f77a7fabb1016864cafb15848c0199028a7b6bb
2023-08-30 14:58:55 +00:00
Daimona Eaytoy 3d63e08a02 Use getExistingTestPage consistently in DirectParsoidClientTest
testTransformHtml currently passes just because the previous test
(testGetPageHtml) calls getExistingTestPage for the same page, but it
fails when run on its own because the page doesn't exist. Make it use
getExistingTestPage consistently to fix that.

This is also needed by core change Ie2f1809d, after which all tables
will be reset between tests.

Change-Id: Id4cb4803fae0d62c695ff1d1051056062c54da82
2023-08-18 01:04:34 +00:00
jenkins-bot b65e676d80 Merge "Merge SkinTemplateNavigation::Universal hook handlers" 2023-08-16 16:03:20 +00:00
Bartosz Dziewoński ca64e7e407 ApiParsoidTrait/DirectParsoidClient: Simplify error handling
After catching the REST exception, just throw an API exception.
Remove the step inbetween where we built a response array.

Bonus:
* Remove tests that only tested this array building.
* Remove the unused 'code' from successful responses, and update
  documentation of return value shapes.
* Remove impossible check for `$ex instanceof LocalizedException`.
  After moving the code into one place, it's obvious that it can't
  happen, since LocalizedException doesn't inherit from HttpException.

Bug: T341613
Change-Id: I31370efeed9d5283b53eafca102b2f1efc811d27
2023-08-16 17:09:18 +02:00
Umherirrender 9b4c433cd8 Merge SkinTemplateNavigation::Universal hook handlers
- The code in the hook handler is more related to the hook and the
  structure of the $links array as to the special page.
- Loading another class to process the hook is not necessary.
- Allows better migration to new hook handlers (special page classes and
  hook handler should be separated).
- Replace SpecialCollabPad::getSubPage with
  SpecialPageFactory::resolveAlias.
- The local url to Special:CollabPad is now in the content language
  (only relevant for non-english wikis).

Change-Id: I82985a8ba129b4e336cee337af31452e804090b3
2023-08-15 20:39:10 +02:00
Daimona Eaytoy e3a2b537ca Do not assume that UTPage exists in ApiVisualEditorTest
Create a test page explicitly, specifying the expected content as well.

Bug: T342428
Change-Id: I5a6e211fe6d36b6bf0576d1739b7fbc2cf49495b
2023-08-07 16:33:53 +02:00
Derick Alangi 4418b61894 Remove DualParsoidClient::class and related code from VE (p.2)
I've verified that no other extension uses this code apart from VE
and locally tested that with this patch, VE still works and nothing
explodes.

There parent patch takes care of making sure the mode is no longer
injected and we now have just etags with no hacked in modes because
we now use direct mode always.

Bug: T341612
Change-Id: Ib1756bf60104467a3a34be9bbb06d8f63537e550
2023-07-25 09:01:44 +00:00
Derick Alangi daa6861f01
Remove ::injectMode(), prep to remove DualParsoidClient p.1
In order not to break clients who already have VE open with etag
that injects the "mode:direct..." in their etag, let's first stop
injecting the direct mode to subsequent VE sessions (for edits)
and wait for 24hrs+ so that we're sure we've processed all sessions
with the direct mode etag.

After 24hrs of this patch merged and going live, we'll then remove
the DualParsoidClient entirely as the p.2 of this cleanup.

Bug: T341612
Change-Id: Ie4f43089ee6f94f51fc0398e84604a17bc5bebcf
2023-07-17 11:26:47 +03:00
thiemowmde ab2cbb3b70 Change almost all code to use Bcp47Code instead of Language
This patch makes the following assumptions:

1. There is no class outside of this codebase that implements the
ParsoidClient interface. According to CodeSearch this appears to be
correct.

2. It is fine to use the Bcp47Code instead of the internal MediaWiki
language code in the "Accept-Language" HTTP header. As far as I
understand this might even qualify as a bugfix.

Depends-On: If059674597e261039df7f4613a89cb08120c3262
Change-Id: Icd160da2d5555891b9a91a0cb966bd36a55f6fdd
2023-07-12 09:38:16 +02:00
Derick Alangi f2bb8cf45d Remove VirtualRESTService code from VisualEditor
This follows the event of VE no longer using RESTBase anything. All
actions related to stashing and Parsoid and now handled in MW core.

Bug: T339227
Change-Id: I50b20ed5abb721a6ac8987cac37a6f395a4816dc
2023-07-11 19:38:05 +02:00
Umherirrender 60e3706f09 tests: Make PHPUnit data providers static
Initally used a new sniff with autofix (T333745)

Bug: T332865
Change-Id: Iad05a3579ec60c576c4aa99567eb3e4fa4c30550
2023-05-20 17:02:35 +02:00
Bartosz Dziewoński a88084509d Use edit intro messages and preloaded content from MediaWiki core
Use MediaWiki core helpers to provide intro messages (including edit
notices), initial page content, and CSS classes for the edit area.

The following intro messages were previously unimplemented,
and will be shown now:
* 'sharedupload-desc-create'
* 'sharedupload-desc-edit'

The following intro messages were previously unimplemented,
but they only apply to pages where VE should never be available,
and will be shown now when editing those pages with 2017WTE:
* 'code-editing-intro'
* 'talkpagetext'

The following intro messages were previously unimplemented,
and are now explicitly skipped:
* 'editpage-head-copy-warn'

The following intro messages were previously unimplemented,
but they only apply to pages where neither VE nor 2017WTE should
ever be available:
* 'userinvalidconfigtitle'
* 'usercssyoucanpreview'
* 'userjsonyoucanpreview'
* 'userjsyoucanpreview'

Depends-On: If0b05710cb52a977bf4e85947d72d68683a0a29e
Bug: T201613
Change-Id: If26e39e383b983f7ee834ed6dd73b80e0545b068
2023-05-16 02:34:35 +02:00
Bartosz Dziewoński 37ab4c2a80 Expose automatic temporary user info in the API
Depends-On: I62b4bb630decac92cbb8c7ddf00307df0dadb516
Bug: T332435
Change-Id: I84ce108b4d46b4e19fad032382f8b69a1b0065d5
2023-05-04 00:44:10 +02:00
daniel 96292e770a Don't force the "view" flavor when using stashing!
Bug: T333402
Change-Id: I6fc598cb2309c442a0b5bfe665f6f96c1a6edf85
2023-04-06 12:17:11 +02:00
C. Scott Ananian 10cb01cdd1 Update DirectParsoidClient to match BCP-47 changes in core
We're trying to avoid passing raw strings around, since they can be
ambiguous specifiers of language.  This patch makes VE compatible
with I982e0df706a633b05dcc02b5220b737c19adc401, with a backward
compatibility workaround which can be removed after
I982e0df706a633b05dcc02b5220b737c19adc401 merges.

The new code also uses slightly more methods of the Language object,
which need to be mocked in a unit test.

Change-Id: I830867d58f8962d6a57be16ce3735e8384f9ac1c
2023-03-08 21:19:21 +00:00
Derick Alangi deecb3cdcb Use helper classes from the new namespace
Helper classes have been moved to a dedicated namespace
of their own, this patch references the new namespace.

Depends-On: Ieeb7a0a706a4cb38778f312bfbfe781a1f366d14
Change-Id: I5a2792a3536f6d953905561410f0e4966254ccbe
2023-01-16 14:22:38 +01:00
Umherirrender 31fdf64247 tests: Replace deprecated Language::factory
Bug: T325986
Change-Id: I87e3c799fcb8959d2b31084479b1d15219a10261
2022-12-28 19:38:38 +01:00
daniel 3a50a092d9 Catch HttpException early
Catch HttpException from REST helpers, even when they are triggered
already during initialization. This will happen e.g. when the request is
asking for a render key for which the stashed rendering has expired.

Bug: T325310
Change-Id: I9e622b5bb253f5e40fe2b50ff08471beddac9acf
2022-12-15 18:12:37 +00:00
daniel f36572432b Use PageRestHelperFactory
This isolates this extension from knowledge about the constructor
signature of the helper classes. Constructore signatures are not stable
interfaces.

Needed-By: Ie430acd0753880d88370bb9f22bb40a0f9ded917
Depends-On: I10af85b2da96568cfffd03867d1cb299645fb371
Change-Id: If1914dbfbefc3501b4d4cef4beb1fae307c36455
2022-11-19 21:21:11 +00:00
msantos 72b4f8cdbb Rename HTMLTransform related classes
* Rename imported classes in VE that will be renamed in core
* Re-enable tests that would fail when the core patch is merged

Depends-On: I506f3303ae8f9e4db17299211366bef1558f142c
Change-Id: I59ebeb24fa0de5f10d1501cc0830c7e4805e1003
2022-11-04 11:43:36 +00:00
jenkins-bot 2972e744cc Merge "Skip tests while renaming HTMLTransform" 2022-11-02 16:34:34 +00:00
msantos 1647a0ae89 Skip tests while renaming HTMLTransform
HTMLTransform is being renamed at I506f3303ae8f9e4db17299211366bef1558f142c.
This is a temporary measure to allow CI to succeed in the core patch

Change-Id: Id11068e34d4b3ed6ccc210c91e449656e74138a2
2022-10-22 19:55:55 +00:00
daniel adc017f73f Pick ParsoidClient implementation based on etag.
When receiving HTML from a VE session, process it with the same kind of
ParsoidClient that was originally used to generate the HTML. If we were
to use a different implementation, the ETag wouldn't match, so we would
fail to find the stashed data-parsoid map, and the edit would fail.

Bug: T320704
Change-Id: I3b73431fccacecb4ad88b82f8f5675b1042e03ce
2022-10-20 08:52:20 +00:00
daniel 92e52d0bad Remove AutoConfig setting
AutoConfig was used to set VE to call internal REST API endpoints exposed by the parsoid extension.
With DirectParsoidClient available, this is no longer needed.

NOTE: this causes all wikis that do not have a RESTbase backend
configured to start using DirectParsoidClient. This is true in
particular for officewiki and labswiki.

Bug: T320704
Change-Id: Ia4c6184dd75a653c3202ea160b6605335f36f6eb
2022-10-14 10:55:53 +02:00
daniel 07afdba500 Don't try to contact RESTbase directly when in PHP direct mode.
If VE is configured to call parsoid directly in PHP, the client
should not try to fetch HTML from restbase. Doing so will
lead to inconsistencies, and may cause edits to fail.

Bug: T320704
Bug: T320703
Change-Id: I98bfdd305dcd188d91db6a8fe5885156cdeca7db
2022-10-13 11:22:52 +00:00
daniel 35cb550747 Local implementation of ParsoidClient (DirectParsoidClient)
* DirectParsoidClient makes use of parsoid directly for performing
transformations on both wikitext and/or HTML contents.

* Also, it's used to fetch HTML from parsoid's parser cache. Before,
this operation was done via RESTBase but now it's being fetched in
core's parsoid parser cache.

* This patch also enables VE clients to transform HTML to
Wikitext when switching from HTML to source mode on. It
makes use of the HtmlInputTransformHelper to perform this
transformation.

* Now, VE client can make use of core code for switching
between HTML to source mode and back without RESTBase.

Change-Id: I5c7cfcc4086d8da7905897194d8601aa07418b59
2022-10-11 18:34:06 +01:00
Bartosz Dziewoński 209aaf6943 ParsoidClient: Fix getPageHtml() $targetLanguage param inconsistencies
* DirectParsoidClient: Actually allow null to be provided.
  Previously we tried to call methods on it unconditionally.

* VRSParsoidClient: Require the param to be provided (even if null).
  No reason to diverge from the interface, which requires it.

Change-Id: Id9a450dc8b8eb3e82cf87718b96975e5a3c6180c
2022-09-26 22:52:31 +02:00
daniel 4c1ec8fc40 ParsoidClient: error should be array or null
This follows up the initial fix with additional sanitation and a
regression test. See I21c7a2b2541061a858a9791a2cb12866acd38dc5.

Bug: T318083
Change-Id: I4e433e711c068336a888f4aafa243455764fd710
2022-09-20 21:05:51 +02:00
daniel 0cd6c90d5a Extract RESTbase client code into VRSParsoidClient.
This makes the "direct" client and the VRS based client
implement the same interface, so the caller doesn't have to know
which one it is using.

It looks like ParsoidHelper will not be needed if we use this approach.

Change-Id: Ib1c1d7355951fc0765227dd01a9edfc554fc448d
2022-09-14 18:20:36 +01:00
Derick Alangi b029fd8ede Introduce VisualEditorParsoidClientFactory
This patch introduces a factory service for creating VE Parsoid
clients.

NOTE: This patch also injects a GlobalIdGenerator to the client
 and avoids usage of deprecated UIDGenerator class.

Change-Id: I787c0afb227308aab56770d14d62e08eb0084a6c
2022-09-06 12:47:43 +01:00
Kosta Harlan 21de9f4728 ApiVisualEditorTest: Set Database annotation and $tablesUsed
Bug: T312849
Change-Id: Iacb1e7f3b66f93d54c2512718ea00f46a0b55c89
2022-07-12 13:07:31 +00:00
Bartosz Dziewoński 37bb0075db Add tests for the expected properties in API result and auto-save
The goal is to have some tests fail if a new property is added to the
API result, but it's not stored in auto-save data.

Bug: T305225
Change-Id: I9ac328c71c616a8f33e1cfb39431cd9a665adafc
2022-04-08 01:02:53 +02:00
Kosta Harlan 9241add01e Allow hook implementations to modify params
This is needed because the $params array is then passed on to
ApiEditPage, so if the hook implementer wants to alter the data used
with the edit, it needs to be able to modify the $params.

See I494d72a42d9103c28c4d44077cfe0f1269fc7b00 for an example where
GrowthExperiments would like to modify the 'tags' parameter for an
edit.

Depends-On: Idd052281898f99e4f13f241d5633294b59b29329
Bug: T304747
Change-Id: Ia4842a1593028f5fa145de167ccf9b72efa81351
2022-03-29 11:31:30 +00:00
Reedy 239fbb64e4 Namespace rest of the extension
Change-Id: I4f3e2793099d81401035ea282f268a3afaa03067
2022-03-14 22:27:15 +00:00
Ed Sanders 131d940d99 ApiVisualEditorTest: Assert properties in result
Change-Id: Ibc63ec4c2fc9d3b002b016d01417f61f68b9dc54
2022-03-01 15:09:58 +00:00
Thalia b0c0917f19 ApiVisualEditor: Support Special:MyLanguage for preload param
This allows nonexistent translated pages to fall back to the
corresponding page in a suitable language.

Bug: T299544
Change-Id: I43f461e9f595c364ecdaf2faccbd580fc0df6799
2022-02-25 12:23:16 +00:00
Thalia 0c5ed2e772 ApiVisualEditorTest: Avoid using VirtualRESTServiceClient
Use paction 'metadata' instead of 'parse' by default, to avoid
accidentally using VirtualRESTServiceClient when testing cases
that don't require it.

Change-Id: I02492a2dc444cf531a5c8767b0dcfe0d20ac7339
2022-02-25 12:15:37 +00:00
Thalia 8807b07d37 Add basic test for ApiVisualEditor::execute
Bug: T299791
Change-Id: I1217f065572565f076ecb24271c3b5af34e74121
2022-01-24 12:28:49 +00:00
Thiemo Kreuz a3a738b4f9 Rewrite ApiVisualEditor::getAvailableNamespaceIds()
For readability. The current implementation is a sequence of
7 (!) array_…() function calls. It is also not free from bugs.
If one of the two inputs (ExtensionRegistry and Config) specifies
namespaces by e.g. canonical name, but the other by number,
the two are not properly merged. It should be possible to use
configuration to disable a namespace that would otherwise be
enabled. This currently works only if both use the same array
keys.

Bug: T291727
Change-Id: I2671f391cdc510da21eda8a1dc5ed4d2513a378a
2021-10-01 14:10:08 +02:00
DannyS712 492fcfbd9f Don't include null in the namespaces where VE can be enabled
Bug: T291728
Change-Id: I2cb168a21c559e61bf2c9e881d46f7f23110e826
2021-09-29 16:23:48 +00:00
Thiemo Kreuz 3484f1927d Add unit tests for static ApiVisualEditor methods
Done for I2cb168a.

Change-Id: I29f8c127ea19abd3449ee0e2742c3ddcc4db23ba
2021-09-28 10:49:47 +02:00
Thiemo Kreuz 61fac2fb44 Add a first PHPUnit test for SpecialCollabPad
Change-Id: I871f3d9616a40300ee306f58b4bae5a58b57b53f
2021-08-26 12:09:59 +02:00
Thiemo Kreuz d78af2c0e9 Add a first trivial PHPUnit test
This is more a proof of concept. The PHP code in this codebase
is rather small, but not trivial, and worth being covered by
tests.

Change-Id: I20c713c3c3be5d289947a343cd4fbf5256234a4a
2021-08-20 15:20:35 +00:00