Commit graph

464 commits

Author SHA1 Message Date
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
Bartosz Dziewoński ac946cff36 ParsoidClient: Improve return type documentation for Phan
Change-Id: I1aecdc5ab7a21e1ef43ddcec4f4dbea610822493
2022-12-15 00:00:41 +01:00
Bartosz Dziewoński b368d741a1 Don't index VE edit pages
Bug: T319124
Change-Id: Ia738698e93252f884b9045aab5840465d3f0d3d3
2022-12-01 22:26:45 +01: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
jenkins-bot a584e73975 Merge "Remove usage of User::isBlockedGlobally and User::getGlobalBlock" 2022-11-16 15:22:09 +00:00
csimiyu 4bdb4917f0 Remove usage of User::isBlockedGlobally and User::getGlobalBlock
Bug: T318898
Change-Id: I727cda9008866b665395cd0e9969c920dc9c28d6
2022-11-16 17:22:17 +03:00
daniel 7da2df9724 Collect timing metrics for ParsoidClient
We want to be able to measure how backend performance changes
when we switch from RESTbase to calling Parsoid directly.
We expect to see a performance boost, in particular for
html/to/wikitext, since we avoid the network overhead.

Since we will make the switch by wiki, we need to be able to compare
the metric before vs. after for a single wiki. So, this adds the
wiki ID as a prefix to all existing metrics. Once fully rolled out,
we should get rid of the wiki prefix.

We will need to update the dashboard found at this url:
https://grafana.wikimedia.org/d/000000249/edit-stash?orgId=1

Change-Id: Iac9070b27f4b0d25b0e31c9fad38abc08c433a28
2022-11-15 01:15:28 +00:00
daniel ea62ee6b19 Always allow switching to visual when using DirectParsoidClient.
When using DirectParsoidClient, switching should be lossless.

Depends-On: I86c611fa0b717ef619e5ffe550b6c2be49a28c99
Change-Id: Ie30ccbc8c12ce48f481b9f727f28e60d21ee37b9
2022-11-07 21:25:27 +01:00
daniel bb66502100 Use setters to initialize helpers
Use setters instead of constructing fake request data.

Depends-On: I18c8bc6f5aa7c204f0faa56919bfe64026761bd4
Change-Id: I8d778c6e5d0b21f8615e3f330f63675cf51eee94
2022-11-04 13:18:56 +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 4191ac2a20 Merge "Add HtmlTransformFactory as depdendency for HtmlOutputRendererHelper" 2022-11-01 19:48:39 +00:00
Arlo Breault c1afc62040 Bump requested Parsoid HTML version to 2.6.0
Change-Id: I544d31ca6ea6186a4ddaf7ef25fdea899f454c58
2022-10-20 17:01:17 -04: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
jenkins-bot bf1bacfce1 Merge "Remove AutoConfig setting" 2022-10-14 15:59:07 +00:00
jenkins-bot 669cbcea37 Merge "Use RevisionLookup methods instead of ApiParsoidTrait methods" 2022-10-14 14:16:46 +00:00
Abijeet a9a4d9eab0 Add HtmlTransformFactory as depdendency for HtmlOutputRendererHelper
Bug: T317019
Depends-On: I5e11452f1c531a757e8d860f9c727b5810406bce
Change-Id: Ib4262e95cc333d008b083f74c88919441095f446
2022-10-14 15:47:31 +05:30
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 d2e49b16f7 Use RevisionLookup methods instead of ApiParsoidTrait methods
Part of my secret plan to delete ApiParsoidTrait.

* Inject RevisionLookup into ApiVisualEditor
* Use RevisionLookup::getRevisionById instead of ApiParsoidTrait::getValidRevision
* Use RevisionLookup::getRevisionByTitle instead of ApiParsoidTrait::getLatestRevision
* Use standard MediaWiki error messages
* Delete unused ApiParsoidTrait::getValidRevision
* Delete unused ApiParsoidTrait::getLatestRevision

Depends-On: I7244ee4916fb011fad5faa1d9f837e83f6ac2dc1
Change-Id: I8089c0c516d9dba52e931a0a80740c0361216dbd
2022-10-11 14:54:40 +00:00
Daimona Eaytoy 16ae2da19a build: Update mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: Ib527ec60ac7894d28e330b7080f0e3b0a2b3ddfc
2022-10-08 02:45:31 +02:00
Derick Alangi 1746b76129 ApiVisualEditor: Remove parsedoc VE paction
This VE paction was removed in I90d775dd71d5f5a61d651b63d946ab60a27e2ca3
so this code can be deleted per Bartosz, so this patch removes the code.

NOTE: A merged API test that uses this is also removed along side.

Change-Id: I4ff75df57fd58f508ef7212486e52cb11a7cfb57
2022-10-03 14:12:35 +01:00
Bartosz Dziewoński 8418686893 ApiParsoidTrait: Remove unused abstract method dieStatus
No longer needed after 1177e677e6.

Change-Id: Ie77ff40c6c98208e99efe151ec18544644a3c9b4
2022-09-28 16:00:24 +00: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 0d833c3de1 ParsoidClient: rename language parameter
The language parameter in the ParsoidClient is always the desired output
language.

Change-Id: I10bec964b16fb041d5acfc63f38511e545adafc4
2022-09-26 22:46:22 +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
Alexander Vorwerk 87ff7a5fec Only die when error string is not empty
Bug: T318083
Change-Id: I21c7a2b2541061a858a9791a2cb12866acd38dc5
2022-09-19 13:25:37 +00:00
daniel 1177e677e6 Remove redundant ParsoidHelper class from VE
All code that used to live in ParsoidHelper has been moved to
VisualEditorParsoidClientFactory and VRSParsoidClient.
ParsoidHelper is no longer needed.

Change-Id: I21c4a8cd86f8d085e75a601ed6d2509dedd75d42
2022-09-15 19:23:05 +00: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
jenkins-bot 47cba98037 Merge "Improve some API param docs and validation" 2022-09-06 22:40:13 +00:00
Derick Alangi 8bfe88b8b1 ParsoidHelper: Make VisualEditorParsoidClientFactory required
In order to make this interface cleaner and not promote the
use of optional parameters when not needed, make the factory
required so that callers should worry about it and not overwork
the helper.

In this case, DiscussionTools extension is already using this
interface and has the factory injected appropriately.

Depends-On: If682af406c0fc7a9eca106eb3ebd95e6c14baddd
Change-Id: I836c0ad73687d8b99d1e067a5c3a3e512b4bd37a
2022-09-06 21:44:29 +01:00
Derick Alangi 8c458e78b4 ParsoidHelper: Remove unnecessary $config
Getting the correct client is now done via the VisualEditorParsoidClientFactory
so this is no longer needed. Follow-up of: I787c0afb227308aab56770d.

Depends-On: I4b9e7362a1bf1b4f224c8c652d40851a18c19824
Change-Id: I175aef2326a0d784fb8211542a3fe90cbf6c6d08
2022-09-06 12:05:39 +00: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
Bartosz Dziewoński 0ade4be5b6 Restore the $oldid condition for funny ETag logging
Follow-up to 951348dbbf. When creating a
new page on a RESTBase wiki, ETag is actually expected, but it will be
in a different format; the code comment was wrong.

Bug: T316969
Change-Id: Ia36488616ced70b900d2e67ce8e28993cc2c7514
2022-09-03 05:06:44 +02:00
Bartosz Dziewoński 6f3de6d7f0 Improve some API param docs and validation
Change-Id: Ic1319f82e581b1a3c2108ab32449ce75aa187831
2022-09-02 04:20:41 +02:00
jenkins-bot ce37169a51 Merge "Don't send missing $wgVisualEditorTabMessages to the browser" 2022-08-26 18:57:07 +00:00
Bartosz Dziewoński 951348dbbf ParsoidHelper: Stop logging missing etags
While a missing etag on a RESTBase wiki still indicates a problem,
we worked around these problems long ago in T233320 and we don't
really care about the logs any more, and the logging is now dominated
by requests on private wikis where etags are not expected.

Bug: T316234
Change-Id: I4cc29847524863af2c5642cb60371893533a9df8
2022-08-25 21:23:35 +02:00
Bartosz Dziewoński f2df5dc7b9 Improve error messages for RESTBase errors
For error responses, the response body should be JSON containing a
'detail' key with a human-readable error message.

Remove old debug logging for T233320, it's no longer needed and it
stopped working on WMF wikis anyway (again, previously it was broken
due to T234564).

Change-Id: I64d0b934c90c7e9582e5433ae7a1b9ed2bc0c9a2
2022-08-19 21:13:35 +00:00
Timo Tijhof 3901a8a4f1 ApiVisualEditorEdit: Switch to non-global FlaggablePageView::newFromTitle
Introduced in FlaggedRevs with Idbdab9a7396 (6bfd276e64), and I've
migrated consumers away from the singleton in I192b962147 (5ee96e5ca7)
and I04fdbd497b8 (bbdfc4c024).

The one thing that remains global by default is the context, but
VE already avoids that with setContext, and (correctly) restores this
afterward since the FlaggablePageView object is re-used by title.
That's exactly as terrible as it sounds, but at least it's a bit more
visible after my refactor.

Bug: T314008
Change-Id: I0008818ec821c35c570d9db9c82f737783e6729b
2022-08-15 18:02:24 +00:00
Bartosz Dziewoński 84433157aa Migrate usage of Database::select to SelectQueryBuilder
We can simplify the code in Hooks.php to use revision.rev_actor
unconditionally, reverting 391c30da67
(the migration is done: T275246).

Bug: T312472
Change-Id: Iaab268409ec4ad0a8d3a835057321aa3c01a2cc7
2022-08-12 22:35:30 +00:00
jenkins-bot efdde38f85 Merge "Create Parsoid helper for use outside of action API" 2022-08-11 13:39:29 +00:00
Bartosz Dziewoński 8d735bbd9e Create Parsoid helper for use outside of action API
ApiParsoidTrait depends on some ApiBase methods, which is inconvenient
when one wishes to access Parsoid HTML outside of the action API. Move
the bulk of the code into a new class ParsoidHelper, which doesn't.

Replace the uses of methods:
* dieWithError: throw a different kind of exception where it makes
  sense, or change the method to return a StatusValue instead of
  throwing where it doesn't
* getPageLanguage: use Title::getPageLanguage() or pass as parameter
* getConfig: pass to constructor
* getLogger: pass to constructor
* getRequest: pass the only required part to constructor,
  leave some other API-specific code using it in ApiParsoidTrait

Bug: T314565
Change-Id: I90656cc74bb1cb1f2f3c82ad51cfb164cb8a4a4b
2022-08-10 23:20:59 +00:00
jenkins-bot 484dcffaab Merge "ApiParsoidTrait: Mark private methods and properties" 2022-08-10 17:12:03 +00:00
jenkins-bot ebef91b210 Merge "Update code for setting user preferences" 2022-08-10 16:44:42 +00:00
Bartosz Dziewoński 6980c966cd ApiParsoidTrait: Mark private methods and properties
They are not accessed outside this trait.

Change-Id: Ib238c0d5507f717ab0d4af2b6e452c255d260fd0
2022-08-09 23:42:35 +02:00
jenkins-bot dbecc84755 Merge "ApiVisualEditorEdit: Re-order FlaggedRevs logic to avoid breakage" 2022-08-08 09:17:47 +00:00
Subramanya Sastry 5319c49df0 Update call to PageConfigFactory::create to use new signature
* Followup to 43231df9

Bug: T314523
Change-Id: I9a299321344c7bbd481f96132393c45b31a93e52
2022-08-03 15:06:52 -05:00
Timo Tijhof f43dfea1b5 ApiVisualEditorEdit: Re-order FlaggedRevs logic to avoid breakage
Needed for Idbdab9a73964efa5 and I09eb8c3a38c0d4.

Bug: T314008
Change-Id: I8575bb40d0a9d24d481b6f58cd9ba500fe0f0f13
2022-08-01 16:23:10 -07:00
C. Scott Ananian d668492e58 ApiVisualEditorEdit: Transition from 'hidetoc' to 'showtoc' in API result
Bug: T314000
Depends-On: I1644a74370b42b04d0db167879f7de2207ebfcf5
Change-Id: I823f26652b9770ea577daee32bff05864a7498bb
2022-07-28 14:55:27 +00:00
Thiemo Kreuz f09f704364 Don't send missing $wgVisualEditorTabMessages to the browser
This is send as an associative array. Instead of adding elements that
are null we can just not add them.

Bug: T291729
Change-Id: I28d847941eec865cb255779534eca14ec88f588f
2022-07-27 09:13:48 +02:00