Skip to content

Conversation

@a-random-lemurian
Copy link

@a-random-lemurian a-random-lemurian commented Jan 31, 2026

The old way, RequestContext::getMain()->getOutput()->parserOptions(), specifically parserOptions(),
was deprecated in MW 1.44

Summary by CodeRabbit

Release Notes

  • Refactor
    • Updated internal formatter initialization to use improved parameter handling and configuration management.

✏️ Tip: You can customize this high-level summary in your review settings.

The old way, `RequestContext::getMain()->getOutput()->parserOptions()`,
specifically `parserOptions()`,
was deprecated in MW 1.44
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

FormatterBuilder is updated to modify how InlineImageFormatter is instantiated. The ParserOptions initialization method changes from using RequestContext output directly to using ParserOptions::newFromContext(). Additionally, a new string caption parameter is added to the InlineImageFormatter constructor, increasing its arity from four to five.

Changes

Cohort / File(s) Summary
FormatterBuilder Update
src/Services/FormatterBuilder.php
Modified InlineImageFormatter constructor call: updated ParserOptions initialization to use ParserOptions::newFromContext(RequestContext::getMain()->getOutput()) and added new string $caption parameter with value 'commons-media-caption'.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: switching from deprecated parserOptions() to newFromContext for obtaining parser options, which is the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🤖 Fix all issues with AI agents
In `@src/Services/FormatterBuilder.php`:
- Around line 29-31: The code calls ParserOptions::newFromContext(...) in the
FormatterBuilder class but does not import ParserOptions, causing PHP to resolve
it to the wrong namespace; add the same use statement for ParserOptions that
InlineImageFormatter uses (or prefix ParserOptions with a leading backslash) so
ParserOptions::newFromContext(RequestContext::getMain()->getOutput()) resolves
correctly; update the imports at the top of the file to include the
ParserOptions class.

Comment on lines 29 to 31
return new InlineImageFormatter(
RequestContext::getMain()->getOutput()->parserOptions(),
ParserOptions::newFromContext(RequestContext::getMain()->getOutput()),
$this->thumbLimits,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, check if there's a local ParserOptions class in the repo
rg -n 'class\s+ParserOptions\b' -S

Repository: ProfessionalWiki/WikibaseLocalMedia

Length of output: 61


🏁 Script executed:

# Check the imports in FormatterBuilder.php and look for ParserOptions
cat -n src/Services/FormatterBuilder.php | head -50

Repository: ProfessionalWiki/WikibaseLocalMedia

Length of output: 1890


🏁 Script executed:

# Search for where ParserOptions is imported from or defined
rg 'ParserOptions' -B 2 -A 2 | head -100

Repository: ProfessionalWiki/WikibaseLocalMedia

Length of output: 1856


Add the missing ParserOptions import (namespace resolution bug).

Line 30 uses ParserOptions::newFromContext(...) without importing it. Without an import or leading backslash, PHP resolves ParserOptions to Wikibase\LocalMedia\Services\ParserOptions, which doesn't exist and will cause a fatal error at runtime. The InlineImageFormatter class correctly imports it; add the same import here.

🛠️ Proposed fix
 use RequestContext;
+use ParserOptions;
 use ValueFormatters\FormatterOptions;
🤖 Prompt for AI Agents
In `@src/Services/FormatterBuilder.php` around lines 29 - 31, The code calls
ParserOptions::newFromContext(...) in the FormatterBuilder class but does not
import ParserOptions, causing PHP to resolve it to the wrong namespace; add the
same use statement for ParserOptions that InlineImageFormatter uses (or prefix
ParserOptions with a leading backslash) so
ParserOptions::newFromContext(RequestContext::getMain()->getOutput()) resolves
correctly; update the imports at the top of the file to include the
ParserOptions class.

@JeroenDeDauw
Copy link
Member

Cannot drop compatibility with 1.43 yet

@a-random-lemurian
Copy link
Author

Ah, got it

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.

2 participants