Commit graph

30 commits

Author SHA1 Message Date
C. Scott Ananian
0de13d7662 Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse).  This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface.  Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.

In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value.  Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538).  The primary location for
setting cache properties is the ContentRenderer.

Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths.  An extra parameter was added to
ContentRenderer::getParserOutput() to support this.

Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.

In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache.  Eventually (T350538) it
should only be necessary in the ContentRenderer.

Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2024-02-07 21:22:06 -05:00
thiemowmde
0ea7599e3e Replace unspecific exceptions with InvalidArgumentException
A LogicException is very generic and doesn't mean much. An
InvalidArgumentException is also a LogicException, but more
specific: A method was called (for whatever reason – bad code,
bad user input – we don't know) with an invalid, unsupported
argument. This is exactly what's going on in these cases.

BadMethodCallException does have a confusing name and is often
misused because of this. It's documented as "thrown if a callback
refers to an undefined method or if some arguments are missing".
That's something else and not what's going on in these cases.

Change-Id: Id446227f578ba701e22acd5e530ffb795e76c147
2024-01-20 21:10:12 +01:00
James D. Forrester
9bfb75ff90 Namespace ParserOutput
Most used non-namespaced class!

Bug: T353458
Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
2023-12-14 14:57:34 -05:00
Daniel Kinzler
32c12be6fe Re-apply "Rest: replace use of deprecated pingLimiter method"
This introduces RestAuthorizeTrait to ensure proper error reporting
after calls to Authorizer methods to avoid misleading error reports,
see T350117 and T350202.

This reverts commit e047668d9f.
This restores change 701ff30193.

Change-Id: I617cb7ba24a1614c39e2b1072888f0ee7b3127e3
2023-11-22 13:57:06 +11:00
Derick Alangi
d674367af4
REST: Inject Authority instead of full User object
Per T310476, it looks like the Authority interface now supports
rate limiting, so we can just use that instead of a heavy full user
object.

Possible followups
==================
More can be done to make all consumers of the HTML helper's `init()`
method to inject Authority instead.

This patch is needed for the work happening in I08ebea5e8a601f161f.

NOTE: This is technically not a breaking change as the Authority
interface is implemented by both UserAuthority and User classes,
so passing either is fine so consumers passing a full user object
should still work even though we changed the signature of a public
method in HtmlOutputRendererHelper.

Change-Id: I025cd83cc81f73ded861fcab943ba3b942d7c390
2023-11-13 13:42:48 +01:00
jenkins-bot
6039684458 Merge "Revert "Rest: replace use of deprecated pingLimiter method"" 2023-11-01 18:18:09 +00:00
Jforrester
e047668d9f Revert "Rest: replace use of deprecated pingLimiter method"
This reverts commit 701ff30193.

Reason for revert: Caused T350117 and T350202.

Bug: T350117
Bug: T350202
Change-Id: I866061e7b7ef8401b8191fd432b50dd2e216b060
2023-11-01 17:59:30 +00:00
Subramanya Sastry
ef30479885 Remove unused param to HtmlOutputRendererHelper::init
No uses in other repositories as far as I can tell from
code search.

Change-Id: I7bb2b5818d9b5d2539ed08fdec8a04c765b2fa4d
2023-10-23 09:33:42 -05:00
Subramanya Sastry
5fc7e1974c For Internal REST API users, make revid handling lenient
* Parsoid REST API which considers both title and revid will soon
  be made internal. The core REST API only has endpoints where either
  the title OR the revid is provided and is not subject to this issue.

* This patch ignores page id mismatches and simply uses the revision
  page id where the mismatch is detected. This is only supported for
  ParsoidHandler which sets the lenient revision handling while fetching
  the HtmlOutputRendererHelper.

  For these API requests, the output is not cached.

* Local testing shows that this fixes the issue.

* Added new phpunit tests to ParsoidHandlerTest to verify expectations.
  Also verified that disabling this fix fails that test.

Bug: T349235
Change-Id: I2f4a4a644710ee1e3894e6dc6a066eb37846bdfd
2023-10-23 09:31:38 -05:00
jenkins-bot
da1364d4c3 Merge "Rest: replace use of deprecated pingLimiter method" 2023-10-19 00:02:57 +00:00
daniel
701ff30193 Rest: replace use of deprecated pingLimiter method
Change-Id: I55de33f8b38dbac628f67009db3506be9cb23aae
2023-10-14 20:56:27 +02:00
Subramanya Sastry
c8d0470f4b Make ParsoidOutputAccess a wrapper over ParserOutputAccess
* Updated ParserOutput to set Parsoid render ids that REST API
  functionality expects in ParserOutput objects.
* CacheThresholdTime functionality no longer exists since it was
  implemented in ParsoidOutputAccess and ParserOutputAccess doesn't
  support it. This is tracked in T346765.
* Enforce the constraint that uncacheable parses are only for fake or
  mutable revisions. Updated tests that violated this constraint to
  use 'getParseOutput' instead of calling the parse method directly.
* Had to make some changes in ParsoidParser around use of preferredVariant
  passed to Parsoid. I also left some TODO comments for future fixes.
  T267067 is also relevant here.

PARSOID-SPECIFIC OPTIONS:
* logLinterData: linter data is always logged by default -- removed
  support to disable it. Linter extension handles stale lints properly
  and it is better to let it handle it rather than add special cases
  to the API.
* offsetType: Moved this support to ParsoidHandler as a post-processing
  of byte-offset output. This eliminates the need to support this
  Parsoid-specific options in the ContentHandler hierarchies.
* body_only / wrapSections: Handled this in HtmlOutputRendererHelper
  as a post-processing of regular output by removing sections and
  returning the body content only. This does result in some useless
  section-wrapping work with Parsoid, but the simplification is probably
  worth it. If in the future, we support Parsoid-specific options in
  the ContentHandler hierarchy, we could re-introduce this. But, in any
  case, this "fragment" flavor options is likely to get moved out of
  core into the VisualEditor extension code.

DEPLOYMENT:
* This patch changes the cache key by setting the useParsoid option
  in ParserOptions. The parent patch handles this to ensure we don't
  encounter a cold cache on deploy.

TESTS:
* Updated tests and mocks to reflect new reality.
* Do we need any new tests?

Bug: T332931
Change-Id: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
2023-10-13 15:03:03 -05:00
Isabelle Hurbain-Palatin
33908cebed Revert "Revert "Remove unused class_alias deprecated in MW 1.40""
This reverts commit cbde6b69de to re-apply
the initial patch. This should only be merged once
I2acfd0b7a1e48aec107ded3bbe4963e2df24f4d3 is deployed.

Change-Id: If12ab65b1d773946fca6c8601ff51290136549c8
2023-09-29 13:08:50 +02:00
Isabelle Hurbain-Palatin
cbde6b69de Revert "Remove unused class_alias deprecated in MW 1.40"
This reverts commit ec22840c4a.

This patch currently creates issues on beta, which still runs with the
latest vendor version of Parsoid. If, for some reason, Parsoid doesn't
get deployed with this patch, I2acfd0b7a1e48aec107ded3bbe4963e2df24f4d3
doesn't get included, and the REST page handler breaks.

Staggered deploy seems safer in this context, hence the proposal for a
temporary revert, and a merge after the next Parsoid vendor patch is
deployed.

Change-Id: I3f859fa807a04892a67323cd4e98be0d3fbb1676
2023-09-29 11:21:49 +02:00
Subramanya Sastry
311e1a9a43 Revert offsetType disabling from 1aa71cf5: Parsoid's rt-testing needs it
* Parsoid's rt-testing script is still a node.js script and hence needs
  ucs2 offests for its syntactic / semantic diff classification.

* So, we cannot let 1aa71cf5 ride the train since it will break
  Parsoid's rt-testing. We'll figure out an alternative way of handling
  it, but for now, I am reverting that part of the patch.

* Document in the ParsoidHandlerTest test that ucs2 offsets are used and
  cannot be changed to 'byte'

Bug: T347426
Change-Id: Ifa833e01ef117d7bcd6da1c7eb542535192662eb
2023-09-28 19:56:43 -05:00
jenkins-bot
0ff0d237b4 Merge "Disable Parsoid support for non-default output versions and offset types" 2023-09-28 21:19:35 +00:00
Fomafix
ec22840c4a Remove unused class_alias deprecated in MW 1.40
The Helper classes are deprecated since 1afd52e3e4.

Depends-On: I2acfd0b7a1e48aec107ded3bbe4963e2df24f4d3
Change-Id: Ie9973c6d6474bb7b4720c0641ca7492dc946d923
2023-09-28 18:47:13 +00:00
Subramanya Sastry
1aa71cf51b Disable Parsoid support for non-default output versions and offset types
* This is in service of a followup patch that merges ParsoidOutputAccess
  and ParserOutputAccess. We want to eliminate all Parsoid-specific options
  that aren't part of ParserOptions and aren't easily supportable via
  html2html transforms.

* offsetType conversion relies on Parsoid code that is a bit entangled
  with env, siteconfig (and extension configs), page source, etc. It
  could all be refactored but once the html2html output transformation
  framework lands, we could potentially use that to call Parsoid to do
  these transforms by exposing such transforms to the framework.

* In this patch, outputContentVersion that isn't the default major HTML
  version is no longer support. It could potentially be supported via the
  downgrade functionality in Parsoid in the future, or we might decide
  to re-enable multiple outputContentVersion selection in the future
  if such a use case arises. But, there are no plans to bump the major
  HTML version in the near future while we work on read views.

* Rather than delete associated tests, I've marked them skipped so that
  they can re-enabled when this support is added back.

Bug: T347426
Change-Id: Ibede4acd68e944512f6d00763d29c6b1605d67eb
2023-09-27 15:03:41 -05:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Subramanya Sastry
83ea46ff65 Reconcile Parsoid opts in ParsoidOutputAccess & ParserOutputAccess
* Explicitly set wrapSections to true. This has have no significant
  impact since it defaults to true within Parsoid.
* 'pageName' and 'prefix' removed from ParsoidOutputAccess since
  they are not needed / used in Parsoid.
* 'logLinterData' need to be set in the ParserOutputAccess paths.
* A bunch of documentation FIXMEs as I was digging through the code.
* Record a FIXME that ParsoidOutputAccess and ParsoidParser (which
  is used in the ParserOutputAccess use page) differ in how they
  handle the language value (whether the default value of the title /
  page or the pageLanguageOverride from the REST API). ParsoidParser
  computes a preferred variant whereas ParsoidOutputAccess right now
  does NOT do that. So, as part of the switchover to ParserOutputAccess,
  we will need to set disableContentConversion in ParserOptions.

  That will happen in a later patch.

Bug: T332931
Change-Id: I7326ae3452a7d496a57f5c4ff2ddeaf0daa7ab70
2023-08-10 23:40:26 +00:00
thiemowmde
82ed8269ec rest: Use more narrow Bcp47Code interface in rest classes
Change-Id: If059674597e261039df7f4613a89cb08120c3262
2023-07-11 21:34:21 +00:00
Arlo Breault
e54da81d44 Set a render reason when forcing a reparse
Bug: T333606
Follows-Up: Ia70f819df79fbb12a5b1dd6a98bfe0b968808d18
Change-Id: Iea2330fbee8866f9e179926fb3db9db13cb41724
2023-06-05 18:52:54 -04:00
Arlo Breault
ca6e56823e Force a reparse if output from cache is not Parsoid's default
Avoids any issue with not respecting the explicit version in accept
headers.  However, it will effectively mean a cache miss on every
request after a Parsoid version bump.

Bug: T333606
Change-Id: Ia70f819df79fbb12a5b1dd6a98bfe0b968808d18
2023-06-01 15:31:30 -04:00
jenkins-bot
818b4b4fe4 Merge "HtmlOutputRendererHelper: Force flavor when stashing" 2023-05-01 13:43:50 +00:00
daniel
8b1c787466 HtmlOutputRendererHelper: avoid splitting parser cache on page language
ParserOptions::setTargetLanguage will split the parser cache.
Only call it if the page language is different from the default.

Bug: T335183
Change-Id: I4cc21d6d83cb28abbd8e94b5448aa81802e0d88c
2023-04-27 17:15:15 +02:00
daniel
e9413c01e6 HtmlOutputRendererHelper: Force flavor when stashing
In "stash" mode, the HTML flavor must always be "stash".

Bug: T333402
Change-Id: Ic2336689b4bc9775ff76856a35e09c2d702d7c74
2023-04-06 12:18:28 +02:00
C. Scott Ananian
5ad8dea80a Use Bcp47Code when interfacing with Parsoid
It is very easy for developers and maintainers to mix up "internal
MediaWiki language codes" and "BCP-47 language codes"; the latter are
standards-compliant and used in web protocols like HTTP, HTML, and
SVG; but much of WMF production is very dependent on historical codes
used by MediaWiki which in some cases predate the IANA standardized
name for the language in question.

Phan and other static checking tools aren't much help distinguishing
BCP-47 from internal codes when both are represented with the PHP
string type, so the wikimedia/bcp-47-code package introduced a very
lightweight wrapper type in order to uniquely identify BCP-47 codes.
Language implements Bcp47Code, and LanguageFactory::getLanguage() is
an easy way to convert (or downcast) between Bcp47Code and Language
objects.

This patch updates the Parsoid integration code and the associated
REST handlers to use Bcp47Code in APIs so that the standalone Parsoid
library does not need to know anything about MediaWiki-internal codes.
The principle has been, first, to try to convert a string to a
Bcp47Code as soon as possible and as close to the original input as
possible, so it is easy to see *why* a given string is a BCP-47 code
(usually, because it is coming from HTTP/HTML/etc) and we're not stuck
deep inside some method trying to figure out where a string we're
given is coming from and therefore what sort of string code it might
be.  Second, we've added explicit compatibility code to accept
MediaWiki internal codes and convert them to Bcp47Code for backward
compatibility with existing clients, using the @internal
LanguageCode::normalizeNonstandardCodeAndWarn() method.  The intention
is to gradually remove these backward compatibility thunks and replace
them with HTTP 400 errors or wfDeprecated messages in order to
identify and repair callers who are incorrectly using
non-standard-compliant language codes in web standards
(HTTP/HTML/SVG/etc).

Finally, maintaining a code as a Bcp47Code and not immediately
converting to Language helps us delay or even avoid full loading of a
Language object in some cases, which is another reason to occasionally
push Bcp47Code (instead of Language) down the call stack.

Bug: T327379
Depends-On: I830867d58f8962d6a57be16ce3735e8384f9ac1c
Change-Id: I982e0df706a633b05dcc02b5220b737c19adc401
2023-03-13 13:25:09 -04:00
daniel
f598760239 Apply variant conversion to page bundles
Bug: T277059
Change-Id: I27348684097cac7f2c4246cd689da3ec41995c27
2023-02-09 14:04:27 +01:00
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
Renamed from includes/Rest/Handler/HtmlOutputRendererHelper.php (Browse further)