Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/Util/TestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Maps\Tests\Util;

use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title;
use User;

/**
Expand All @@ -25,7 +26,7 @@ public function parse( string $textToParse ): string {
return MediaWikiServices::getInstance()->getParser()
->parse(
$textToParse,
\Title::newMainPage(),
Title::newMainPage(),
new \ParserOptions( User::newSystemUser( 'TestUser' ) )
)->getText();
Comment on lines 26 to 31

Copy link
Copy Markdown

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.

}
Expand Down
Loading