Skip to content

Conversation

@OAuthority
Copy link

@OAuthority OAuthority commented Aug 10, 2025

This PR is a draft implementation of a ParsoidModule for PortableInfobox; it displays PortableInfoboxes for reads on Parsoid (and also has the benefit of displaying them in the VisualEditor, and they are editable.) It supersedes #165 with a more robust implementation. It closes #132

It's a bit of a draft at present, and could probably be refined. A few of the classes (such as the PortableInfoboxRenderService have been copied and adjusted, and are namespaced under PortableInfobox\Parsoid.

It's still a work in process, and hasn't been tested against complex infoboxes. But it's a MVP that works at present. There are some issues:

  • AccentColor and AccentColorText need a bit of work; it was a bit confusing how these are generated, so I skipped over it.
  • The wiki text is for some reason not currently parsed, and just displays as wikitext, rather than the resultant HTML.

Issue No. 2 is the most problematic. It feels a bit like a catch-22 situation. Doing everything in the ->extTagToDOM is too early, as we don't know the parameters the user passed to the template on the page, so we rely on getting it later in the wtPostProcess, however this seems to return just plain wiki text and there doesn't appear to be any way to re-feed this to Parsoid to get the parsed value back.

I'm PRing what I have for now, and will continue to work on it - but if there are any ideas how we can get this Parsed, I'm all ears. May need to ask on WMF Phabricator if we can't figure it out.

Changes to wider PortableInfoboxes

  • The NodeFactory::newFromSimpleXML and NodeFactory::newFromXML now accept an $externalParser. This should either be the MediaWikiParser or the ParsoidMediaWikiParser this is needed so we can differentiate between whether we are in a Parser.php context, or Parsoid context. Mostly for the <image> and <media> tags, because NodeImage currently calls out to the legacy parser functions which we don't want. It is null by default, so that no change needs to be made for the legacy implementation.
  • Within the Parsoid implementation, we no longer call MediaWikiParserService::addImage to add the image to the HTML output for selection by PageImages. Internally PageImages relies on several Parser.php hooks which are not guaranteed to be supported. Further investigation is needed to whether this can be supported when/if PageImages is made Parsoid-compat.

@coderabbitai
Copy link

coderabbitai bot commented Aug 10, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@OAuthority
Copy link
Author

The latest commit c036061 actually fixes the Parsing issue, such that wikitext is parsed properly to HTML when it is passed to the template for display.

That fixes the most major bugs, and we essentially have PortableInfobox for Parsoid working. One issue that did crop up, however, is that Parsoid automatically inserts

tags whenever it encounters a h2 or h3 and wraps them.

This corresponds to the section the infobox exists on the page (I assume this is to signal to VisualEditor which section on the page the infobox is at, so when a section is edited, it knows to pull the infobox in. This issue did not crop up during development as I - this seems like an idiot move - was using the VisualEditor primarily to see the result from Parsoid.

Obviously, the VisualEditor API does not return these section tags, but they are returned when using the ParsoidMigration extension. I can't figure out a way to disable this behaviour, so I'm going to ask on Phabricator if anyone has any ideas.

@codecov
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 1.79775% with 437 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@14ec93d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../Services/AbstractPortableInfoboxRenderService.php 0.00% 178 Missing ⚠️
...ncludes/Services/Parser/Nodes/ParsoidMediaNode.php 0.00% 96 Missing ⚠️
...es/Parsoid/ParsoidPortableInfoboxRenderService.php 0.00% 71 Missing ⚠️
includes/Parsoid/ParsoidMediaWikiParser.php 0.00% 41 Missing ⚠️
includes/Parsoid/InfoboxTag.php 0.00% 24 Missing ⚠️
includes/Parsoid/PortableInfoboxDOMProcessor.php 0.00% 17 Missing ⚠️
...ncludes/Services/Parser/Nodes/ParsoidImageNode.php 0.00% 6 Missing ⚠️
includes/Services/Parser/Nodes/NodeFactory.php 60.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #166   +/-   ##
=======================================
  Coverage        ?   44.48%           
  Complexity      ?      613           
=======================================
  Files           ?       43           
  Lines           ?     1850           
  Branches        ?        0           
=======================================
  Hits            ?      823           
  Misses          ?     1027           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infobox only shows heading in VisualEditor

1 participant