Skip to content

Conversation

JeroenDeDauw
Copy link
Member

@JeroenDeDauw JeroenDeDauw commented Aug 13, 2025

Summary by CodeRabbit

  • Tests

    • Updated test utilities to align with current namespace conventions, improving consistency and maintainability.
    • No changes to test coverage, behavior, or public interfaces.
  • Chores

    • Internal code hygiene improvements in test setup to reduce ambiguity and follow best practices.

No user-facing changes in this release.

@JeroenDeDauw JeroenDeDauw merged commit 9bfb118 into master Aug 13, 2025
10 of 16 checks passed
@JeroenDeDauw JeroenDeDauw deleted the test44 branch August 13, 2025 19:52
Copy link

coderabbitai bot commented Aug 13, 2025

📝 Walkthrough

Walkthrough

Imported MediaWiki\Title\Title in tests/Util/TestFactory.php and replaced a fully qualified \Title::newMainPage() call with Title::newMainPage(). No other logic, signatures, or behavior changed.

Changes

Cohort / File(s) Summary of changes
Namespace and import cleanup
tests/Util/TestFactory.php
Added use MediaWiki\Title\Title; and switched \Title::newMainPage() to Title::newMainPage().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test44

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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1afab38 and 4c73200.

📒 Files selected for processing (1)
  • tests/Util/TestFactory.php (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
tests/Util/TestFactory.php

[error] 31-31: Command 'php tests/phpunit/phpunit.php -c extensions/Maps' failed: Call to undefined method MediaWiki\Parser\ParserOutput::getText()

🔇 Additional comments (2)
tests/Util/TestFactory.php (2)

8-8: Switch to namespaced Title is correct and future-proof

Importing MediaWiki\Title\Title removes reliance on the global alias and aligns with newer MW versions.


29-30: Consistent use of imported Title

Replacing \Title::newMainPage() with Title::newMainPage() is correct given the new import on Line 8.

Comment on lines 26 to 31
return MediaWikiServices::getInstance()->getParser()
->parse(
$textToParse,
\Title::newMainPage(),
Title::newMainPage(),
new \ParserOptions( User::newSystemUser( 'TestUser' ) )
)->getText();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fix CI: ParserOutput::getText() is undefined on MW 1.44; use a version-agnostic accessor

MW 1.44 removed/renamed ParserOutput::getText(), causing the CI failure. Use feature detection to support both older and newer MW versions.

Apply this diff to return HTML in a cross-version way:

-		return MediaWikiServices::getInstance()->getParser()
-			->parse(
-				$textToParse,
-				Title::newMainPage(),
-				new \ParserOptions( User::newSystemUser( 'TestUser' ) )
-			)->getText();
+		$parserOutput = MediaWikiServices::getInstance()->getParser()
+			->parse(
+				$textToParse,
+				Title::newMainPage(),
+				new \ParserOptions( User::newSystemUser( 'TestUser' ) )
+			);
+		// MW compat: ParserOutput accessor changed across versions
+		if ( method_exists( $parserOutput, 'getHtml' ) ) {
+			$html = $parserOutput->getHtml();
+		} elseif ( method_exists( $parserOutput, 'getRawText' ) ) {
+			$html = $parserOutput->getRawText();
+		} elseif ( method_exists( $parserOutput, 'getText' ) ) {
+			$html = $parserOutput->getText();
+		} else {
+			throw new \RuntimeException( 'Unable to extract HTML from ParserOutput on this MediaWiki version' );
+		}
+		return (string)$html;

Run this quick check to ensure there are no other getText() calls on ParserOutput in the codebase:

If you want me to narrow down the exact MW 1.44 replacement (getHtml vs getRawText) from upstream docs and update the patch accordingly, I can do that as well:


🏁 Script executed:

#!/bin/bash
# Find other usages of ->getText() that may need compatibility handling
rg -n --hidden --glob '!*vendor/*' '->getText\(' -A 2

Length of output: 460


🌐 Web query:

In MediaWiki 1.44, what is the correct method to retrieve the HTML string from ParserOutput? What replaced ParserOutput::getText(), and what are the return types of getHtml() and getRawText()?

💡 Result:

In MediaWiki 1.44, the correct method to retrieve the HTML string from a ParserOutput object is getHtml(). This replaces the deprecated ParserOutput::getText() method.

  • ParserOutput::getHtml() returns the fully rendered HTML string for output to users in MediaWiki 1.44[2][3].
  • ParserOutput::getRawText() returns a cacheable text string with <mw:editsection> markers and other non-final elements, not suitable for direct display to users; its return type is string[3].

Details:

  • In versions prior to 1.44, getText() was commonly used to get HTML, but this method has been deprecated and removed in MediaWiki 1.44[3].
  • The new method, getHtml(), is now the standard approach for retrieving sanitized, ready-to-display HTML from a ParserOutput instance[2].
  • getRawText() is primarily for internal use or caching, as it retains edit section markers and other metadata not intended for user viewing[3].

Summary Table:

Method Purpose Return Type Recommendation in 1.44
getHtml() Final rendered display HTML string Use
getRawText() Internal/cacheable with markers string Do not use for display
getText() Deprecated (was HTML for display) string Deprecated

Always use getHtml() to obtain the user-facing HTML in MediaWiki 1.44[2][3]. If you need the raw parser output (cacheable, with internal markers), use getRawText()[3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Search for "->getText(" occurrences excluding vendor and node_modules
rg -n --hidden --glob '!vendor/**' --glob '!node_modules/**' -e '->getText\(' -S -A2 || true

Length of output: 3219


🏁 Script executed:

#!/bin/bash
set -euo pipefail

files=(
  tests/Util/TestFactory.php
  tests/System/SemanticQueryTest.php
  src/Presentation/WikitextParser.php
)

for f in "${files[@]}"; do
  if [ -f "$f" ]; then
    echo "---- $f ----"
    nl -ba "$f" | sed -n '1,240p'
    echo
  else
    echo "Missing: $f"
  fi
done

echo "---- occurrences of getParserOutput( ----"
rg -n --hidden --glob '!vendor/**' --glob '!node_modules/**' -e 'getParserOutput\(' || true
echo
echo "---- occurrences of ->parse( ----"
rg -n --hidden --glob '!vendor/**' --glob '!node_modules/**' -e '->parse\(' -S -n -A2 || true

Length of output: 421


Fix CI: replace removed ParserOutput::getText() with a version-agnostic accessor (prefer getHtml)

MediaWiki 1.44 removed ParserOutput::getText(), causing CI failures. Replace direct ->getText() calls on ParserOutput with feature-detection that prefers getHtml(), falls back to getText() on older MW, and uses getRawText() only as a last resort.

Files that need changes (from repo scan):

  • tests/Util/TestFactory.php (parse(...)->getText())
  • tests/System/SemanticQueryTest.php (getParserOutput(...)->getText())
  • src/Presentation/WikitextParser.php (parse(...)->getText())

Apply this pattern (example diff for TestFactory.php):

-		return MediaWikiServices::getInstance()->getParser()
-			->parse(
-				$textToParse,
-				Title::newMainPage(),
-				new \ParserOptions( User::newSystemUser( 'TestUser' ) )
-			)->getText();
+		$parserOutput = MediaWikiServices::getInstance()->getParser()
+			->parse(
+				$textToParse,
+				Title::newMainPage(),
+				new \ParserOptions( User::newSystemUser( 'TestUser' ) )
+			);
+		// MW compat: prefer getHtml() (1.44+), fall back to older accessors
+		if ( method_exists( $parserOutput, 'getHtml' ) ) {
+			$html = $parserOutput->getHtml();
+		} elseif ( method_exists( $parserOutput, 'getText' ) ) {
+			$html = $parserOutput->getText();
+		} elseif ( method_exists( $parserOutput, 'getRawText' ) ) {
+			$html = $parserOutput->getRawText();
+		} else {
+			throw new \RuntimeException( 'Unable to extract HTML from ParserOutput on this MediaWiki version' );
+		}
+		return (string)$html;

Notes:

  • Update all ParserOutput->getText() usages listed above with the same pattern. Many other getText() calls in the repo are domain methods (not ParserOutput) and don't need changing.
  • After patching, run the test suite / CI to confirm no further ParserOutput access remains.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return MediaWikiServices::getInstance()->getParser()
->parse(
$textToParse,
\Title::newMainPage(),
Title::newMainPage(),
new \ParserOptions( User::newSystemUser( 'TestUser' ) )
)->getText();
$parserOutput = MediaWikiServices::getInstance()->getParser()
->parse(
$textToParse,
Title::newMainPage(),
new \ParserOptions( User::newSystemUser( 'TestUser' ) )
);
// MW compat: prefer getHtml() (1.44+), fall back to older accessors
if ( method_exists( $parserOutput, 'getHtml' ) ) {
$html = $parserOutput->getHtml();
} elseif ( method_exists( $parserOutput, 'getText' ) ) {
$html = $parserOutput->getText();
} elseif ( method_exists( $parserOutput, 'getRawText' ) ) {
$html = $parserOutput->getRawText();
} else {
throw new \RuntimeException( 'Unable to extract HTML from ParserOutput on this MediaWiki version' );
}
return (string)$html;
🧰 Tools
🪛 GitHub Actions: CI

[error] 31-31: Command 'php tests/phpunit/phpunit.php -c extensions/Maps' failed: Call to undefined method MediaWiki\Parser\ParserOutput::getText()

🤖 Prompt for AI Agents
In tests/Util/TestFactory.php around lines 26-31, the code calls ->getText() on
a ParserOutput instance which was removed in MW 1.44; replace that call with
feature-detection that prefers getHtml(), falls back to getText() if available,
and finally to getRawText() as last resort. Change the expression that currently
does parse(...)->getText() so it captures the ParserOutput, checks for
method_exists($parserOutput, 'getHtml') ? $parserOutput->getHtml() :
(method_exists($parserOutput, 'getText') ? $parserOutput->getText() :
$parserOutput->getRawText()), and return that value. Apply the identical pattern
to tests/System/SemanticQueryTest.php and src/Presentation/WikitextParser.php
for their ParserOutput->getText() usages and run the test suite to ensure no
remaining direct ParserOutput::getText() calls.

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.

1 participant