Commit graph

14 commits

Author SHA1 Message Date
C. Scott Ananian
903a5fc052 Parsoid PageConfig: remove unused ::getTitle() and ::getNs() methods
These methods are no longer needed by the Parsoid PageConfig API.

Depends-On: Ie3b8802153e380d25f9fc8a75469ec1c3a1b7015
Change-Id: I1bf9aad24b2bb04592d62e08923c79d8d46a977e
2024-05-14 21:07:36 -04:00
C. Scott Ananian
1a195e6c4c Rename PageConfig::getTitleObj() to PageConfig::getLinkTarget()
This follows the renaming of this interface in Parsoid.

Change-Id: If2c8f240f400750dbdf65bd443509cb1cb0c1961
2023-12-01 20:17:03 +00:00
C. Scott Ananian
eca7454527 Add implementations of new Parsoid config methods using LinkTarget
Change-Id: I30e2df89e5060ce11f1d6c181a2ba4866fecf99b
2023-11-03 18:52:48 -04:00
Subramanya Sastry
17b0ebd3ac includes/parser/Parsoid/*: Use typed class properties
* I had already used this on one property of one file here
  and noticed that Isabelle used this on a newly created
  class in output transform and that prompted me to switch
  over all these files.

* I am about to start adding new files here for new hooks for
  DiscussionTools and updated everything in this namesspace
  to keep usage consistent.

* This exposed initialization and bad typing issues in
  SiteConfig.php and LanguageVariantConverter.php

Change-Id: I35f131a8f584ccc82a915dbfb1b50b3ef1ec6b06
2023-10-23 17:37:14 -05:00
Arlo Breault
56f0baa058 Remove PageConfig::hasLintableContentModel
Depends-On: I04d102c4deb0d72b4c85f41a2e8500d0cb13188b
Change-Id: Iacbf05e1f3f6f8f60669a5abfc8c183c2d471a04
2023-08-15 15:09:36 -04: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
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
C. Scott Ananian
f8d147e736 Mark Parsoid configuration classes @internal
Clarify that the classes used to interface MediaWiki with Parsoid are
not for external use and have no stability guarantees.  External
clients should use forthcoming support in Parser and
ParserOutputAccess to access Parsoid content and not rely on these
internal classes.

Change-Id: I684fa3ef3e25317c114551de3e2f233c7e84ce6f
2023-03-07 17:34:58 -05:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Thiemo Kreuz
e23b070b45 Make use of ?? and ?: operators where it makes sense
Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
2022-08-04 21:43:12 +02:00
C. Scott Ananian
ae5eb71b7c Code style improvements to code moved from Parsoid
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: I3349dcd1c38ca7759fcff3104e990bb6171b610b
2022-03-28 12:36:38 -04:00
C. Scott Ananian
6651334d1b [doc only] Update Parsoid's class documentation; add @since tags
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: Icbf172b51ffc90b51fd738f90d4425c4fc2aa5d7
2022-03-28 12:36:38 -04:00
C. Scott Ananian
c8829e29a8 [doc only] Update copyright date for files moved from Parsoid
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: I618237c4c91a054767516e1fae15a8a421e15371
2022-03-28 12:36:38 -04:00
C. Scott Ananian
2d66ee70a2 Copy over Parsoid's Config and ServiceWiring classes
* This is the first step of migrating Parsoid integration code into
  core and transitioning Parsoid from an extension to a pure library.

* Parsoid already has conditional code to skip loading Parsoid's
  copy of its classes, but it relies on the existence of ParsoidServices.
  Technically ParsoidServices isn't needed once Parsoid is migrated to
  core -- users can just use MediaWikiServices instead -- but we need
  to temporarily add ParsoidServices as a marker class during the
  transition.

This version of Parsoid's ServiceWiring comes from Parsoid commit
898c813fd832b3f2d7b5a37f60bd65e8368ce18f.

Bug: T302118
Change-Id: I0b388d93143a782c2c3b72e46407572e5c586e4a
2022-03-28 12:36:38 -04:00