Commit graph

42 commits

Author SHA1 Message Date
Arlo Breault
449bc91737 Return additional info about files in DataAccess
Bug: T358158
Change-Id: Ie344ef61f947d7c9d1bffe10de10b12b5643f4be
2024-02-21 18:36:04 -05:00
jenkins-bot
a62f5c7911 Merge "[ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()" 2024-02-21 17:11:00 +00:00
C. Scott Ananian
72c4945a72 [ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()
ParserOutput::getText() is not a simple getter, but does
transformations on the "text" of the ParserOutput; the simple getter
is named ::getRawText().

To maintain consistency, rename ParserOutput::setText() to
::setRawText() and the property name ParserOutput::$mText to
::$mRawText so future readers are not confused.

The JSON property name as it appears in the serialized ParserCache
is left as 'Text' so that we don't have any forward- or backward-
rollback issues.

Change-Id: I3ef34814ab9473cc70d0a6806e8c5a4a02b73491
2024-02-20 17:13:28 +00:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
C. Scott Ananian
5d1c43cdb4 Don't use Parsoid\Config\PageConfig::getTitle()
This has been replaced by ::getLinkTarget(), which returns a Parsoid
LinkTarget.  This is identical to the core LinkTarget interface, but
we can't quite alias them for technical reasons (sigh).  In actual
practice, LinkTargets generated by core are usually Title objects, so
Title::newFromLinkTarget() is a no-op that just returns the argument
after a type check.

It appears that newer code uses a TitleFormatter rather than calling
methods on Title, but TitleFormatter currently takes LinkTarget not a
ParsoidLinkTarget.  That would force us to go via
TitleValue::newFromLinkTarget() which isn't a simple type check.

Change-Id: I490bb38108d0202b43ea2a9b391b2e664e7d2d48
2024-01-26 19:29:14 -05:00
jenkins-bot
b6fc2684bf Merge "Use PageConfig::getLinkTarget() in DataAccess" 2023-12-15 21:02:44 +00:00
Isabelle Hurbain-Palatin
a3f51c732d Refactor DefaultOutputTransform into a pipeline of transforms
Bug: T348253
Change-Id: I53551ec6d6471569709c71c1155729e550f64de8
2023-12-08 18:06:19 -05:00
C. Scott Ananian
034a8064a2 Use PageConfig::getLinkTarget() in DataAccess
This follows the deprecation of PageConfig::getTitle() in Parsoid.

Depends-On: Id3c3ff34a0c796ed0956cb9fb73247056e68667b
Change-Id: I9a24e765bfe914c5ba8496d01b0f9e1bac1c6aea
2023-12-01 18:40:20 -05:00
C. Scott Ananian
b22248ebc6 Allow passing LinkTarget in DataAccess:getPageInfo()
This allows Parsoid to broaden the parameter type for this method in a
future version.

Change-Id: I43fc8fd08f431108ae53b158c109d685347e6e15
2023-12-01 18:40:20 -05:00
Subramanya Sastry
8854179593 Parsoid DataAccess: Don't call getText() in parseWikitext
Call getRawText() and extract the body instead of calling getText()
which invokes the full output transform pipeline which is both
unncessary and could potentially introduce subtle bugs by running
output transforms on nested document content (since output stages
could set parser output config vars, extension data, etc.).

Change-Id: I82aaad965d3d0dd0366b9f3a1891e79ed316d29d
2023-11-28 20:09:34 +00:00
jenkins-bot
97f245a8f7 Merge "Revert "Parsoid DataAccess: Stop processing extensions as top-level docs"" 2023-11-28 04:22:26 +00:00
Subramanya Sastry
00d64e4156 Revert "Parsoid DataAccess: Stop processing extensions as top-level docs"
This reverts commit 0791724ead.

Reason for revert: Breaks math rendering in Parsoid (and hence for all clients)

Change-Id: I9abe07060e5d11a9a1a2c953344eb50d4536e8c4
2023-11-28 03:59:19 +00:00
Isabelle Hurbain-Palatin
f1a83b1f57 Make DataAccess::getPageInfo compatible with string
DataAccess::getPageInfo takes a full PageConfig object only to use its
title string. Passing the title string directly allows us to use this
method in other contexts (such as OutputTransform) where PageConfig is
not available.

Change-Id: Ia5c7648caff0818a83df1383d42050e2c68b7799
2023-11-27 21:08:37 -05:00
Subramanya Sastry
0791724ead Parsoid DataAccess: Stop processing extensions as top-level docs
* See T351461 and T303015 for examples where calling top-level doc
  parser hooks during extension processing causes problems further
  downstream.

  The hooks are: ParserAfterTidy and ParserAfterParse

* Since any extension that relies on those two hooks will need a
  Parsoid-equivalent implementation to work properly with Parsoid,
  we don't need to preemptively run those hooks on a sublevel doc.

  We can instead let the Parsoid-compatible implementation process
  the full doc.

* Accordingly, this patch removes the parseExtensionTagAsTopLevelDoc
  method from Parser.php and has DataAccess::parseWikitext simply
  call Parser::recursiveTagParseFully instead.

Change-Id: I58e693499e1a53e0814911dc2ea424aa822b8320
2023-11-26 22:23:35 -06:00
jenkins-bot
3884dd5405 Merge "Parsoid\Config\DataAccess: Fix type of param to BadFileLookup::isBadFile()" 2023-11-12 17:22:19 +00:00
Bartosz Dziewoński
557b017403 Parsoid\Config\DataAccess: Fix type of param to BadFileLookup::isBadFile()
Bug: T350632
Change-Id: Ic0736135e0fd172366fc8e9291407ab858a3323d
2023-11-06 23:29:24 +01: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
jenkins-bot
a1f4fb418a Merge "Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()" 2023-09-29 21:27:27 +00:00
C. Scott Ananian
f47de6ec61 Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()
This nominally takes a string-valued language code conforming to the
BCP-47 standard, but this is often generated from a Bcp47Code object.
Since the MediaWiki Language code implements Bcp47Code, we may have
the case where we have a Language object in hand (but typed as a
Bcp47Code not Language) and call Language::toBcp47Code() only to pass
it to LanguageCode::bcp47ToInternal to convert it back to a
mediawiki-internal code.

We can save steps and be more efficient if allow the parameter to be a
Bcp47Code object, and write a fast path for the special case where
that Bcp47Code happens to be a Language object and we can simply call
Language::getCode() to obtain the internal code.

Change-Id: I24932449b8c40e3a5072748d87667184f4befa67
2023-09-29 15:10:29 -04:00
Umherirrender
04a039e135 parser: Delay Parser creation in ParsoidSiteConfig/ParsoidDataAccess
Remove parser creation from service creation

In ParsoidSiteConfig inject the ParserFactory and call getMainInstance
later, ParsoidSiteConfig is created often without calls to the parser.
For ParsoidDataAccess store the factory and call it when needed.

Bug: T343070
Change-Id: Ib3acadaf190383e4a8b3d266a9fd75c9b20c6649
2023-09-19 22:19:30 +02:00
Amir Sarabadani
623d3dc419 rdbms: Move ReadOnlyMode and ConfiguredReadOnlyMode to rdbms library
The db/ directory does not have an owner and it's a mess in general.
These classes don't depend on anything in core except the rdbms library.
Let's simply move it there. In other words, Krinkle made me do it.

Since the class was moved in I6202e52ba73 merged less than a week ago,
no need to alias anything.

Bug: T321882
Change-Id: I24ceeb8bf765a50f441270136acd612359d50aa2
2023-05-04 23:41:21 +02:00
Amir Sarabadani
d59ffa4202 Reorg: Move ReadOnlyMode classes to db/
They are not suitable to go to rdbms library as they depend on mediawiki
pieces, the second best place is the db/ directory.

Bug: T321882
Change-Id: I6202e52ba7306d74261206c2ba7930c5f1a0a18e
2023-04-28 12:13:01 +02:00
Func
eb065bb6e1 Revert "Display SVGs in page view language for language variants"
This reverts commit 42aa5f9481.

Reason for revert: Caused T334753, the proposed fix may need more time for review. Let's revert for now, before the train cut.

Bug: T310453
Bug: T334753
Change-Id: I790604eef00491b7f2a921fb3423a2f727f6593b
2023-04-17 11:53:37 +00:00
Winston Sung
42aa5f9481 Display SVGs in page view language for language variants
Bug: T310453
Change-Id: I45e495d2c4fc026bdfc54e3219ff7138789d25dd
2023-03-27 19:59:20 +00:00
jenkins-bot
7c92610ada Merge "Fix some typos" 2023-03-23 12:20:11 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
C. Scott Ananian
e2dc509867 Use a Bcp47Code when communicating with Parsoid
Followup-To: I982e0df706a633b05dcc02b5220b737c19adc401
Change-Id: I4900a230c60be7c80f4b7be37d6954a71b9147d8
2023-03-15 00:36: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
Amir Sarabadani
0f13e81a15 Reorg: Move five page-related classes to page/ out of includes/
These classes:
 - MergeHistory
 - MovePage
 - ProtectionForm
 - BadFileLookup (to MediaWiki\Page\File)
 - FileDeleteForm (to MediaWiki\Page\File)

Bug: T321882
Change-Id: Ibeb488ba322c62a34042a0307bbb5562773bcad1
2023-02-23 17:03:49 +01:00
Umherirrender
570abed74b parser: Use LinkBatchFactory to create LinkBatch objects
Bug: T325591
Change-Id: Icae514117907f508ae23ca91c68e6297c33dab67
2023-01-27 18:53:48 +00:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
C. Scott Ananian
1c3216bf92 Create ParserFetchTemplateData hook
This is moved from TemplateData, but the interface isn't quite right.
Filed T304899 to improve it in the future.

Bug: T304740
Change-Id: Iadd1ed70b72fc282bd5addfc1654aa73322ea470
2022-03-28 17:25:34 -04:00
C. Scott Ananian
3cd693aed6 Create ParserLogLinterData hook
This hook was formerly defined by Extension:Linter and invoked by
Parsoid, but as this part of Parsoid is moving into core the hook
should now be defined by core as well.

Bug: T304740
Change-Id: Iffd073e510202e5766632cc01d3585815289b7b4
2022-03-28 17:25:34 -04:00
C. Scott Ananian
3a8f5b748f Use HookRunner to invoke hooks from Parsoid
Bug: T304740
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: I428b07dac127e26b2bc39ca2a5b1a8b7c954820a
2022-03-28 15:38:19 -04:00
C. Scott Ananian
2d60a6e938 Inject ReadOnlyMode service into Parsoid's DataAccess class
Bug: T304741
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: Ib9669fb9724589d1ce15d5a9ecbe229e9e7c0364
2022-03-28 15:38:19 -04:00
C. Scott Ananian
3f1424fa71 Inject SVGMaxSize configuration into Parsoid's DataAccess class
Bug: T304739
Followup-To: I0b388d93143a782c2c3b72e46407572e5c586e4a
Change-Id: I66ddb44c69ae96ecc459983207d90112154f13e8
2022-03-28 14:57:52 -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