Fix test compat with MW 44 - #820
Conversation
📝 WalkthroughWalkthroughImported 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
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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-proofImporting MediaWiki\Title\Title removes reliance on the global alias and aligns with newer MW versions.
29-30: Consistent use of imported TitleReplacing \Title::newMainPage() with Title::newMainPage() is correct given the new import on Line 8.
| return MediaWikiServices::getInstance()->getParser() | ||
| ->parse( | ||
| $textToParse, | ||
| \Title::newMainPage(), | ||
| Title::newMainPage(), | ||
| new \ParserOptions( User::newSystemUser( 'TestUser' ) ) | ||
| )->getText(); |
There was a problem hiding this comment.
💡 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 2Length 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:
- 1: https://www.mediawiki.org/wiki/Manual:ParserOutput.php
- 2: https://doc.wikimedia.org/mediawiki-core/master/php/classMediaWiki_1_1Parser_1_1ParserOutput.html
- 3: https://github.com/wikimedia/mediawiki/blob/master/includes/parser/ParserOutput.php
- 4: https://www.mediawiki.org/wiki/API:Parsing_wikitext
- 5: https://doc.wikimedia.org/mediawiki-core/master/php/classMediaWiki_1_1Output_1_1OutputPage.html
- 6: https://www.mediawiki.org/wiki/API:Get_the_contents_of_a_page
- 7: https://www.mediawiki.org/wiki/Manual:Parser.php
- 8: https://doc.wikimedia.org/mediawiki-core/1.27.1/php/classParserOutput.html
- 9: https://github.com/wikimedia/mediawiki/blob/master/RELEASE-NOTES-1.44
- 10: https://www.enviro.wiki/api.php?action=help&recursivesubmodules=1
🏁 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 || trueLength 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 || trueLength 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.
| 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.
Summary by CodeRabbit
Tests
Chores
No user-facing changes in this release.