Fix: SimpleBlogPage paginator TypeError - #11
Merged
Conversation
Comment on lines
360
to
370
| */ | ||
| public function onBeforePageDisplay( $out, $skin ): void { | ||
| if ( \MediaWiki\MediaWikiServices::getInstance() | ||
| ->getExtensionRegistry() | ||
| ->isLoaded( 'SimpleBlogPage' ) | ||
| ) { | ||
| $out->addModules( [ 'ext.wikioasismagic.simpleBlogPageFix' ] ); | ||
| } | ||
| } | ||
|
|
||
| 'CentralAutoLogin', |
Contributor
Author
There was a problem hiding this comment.
Bug: The onBeforePageDisplay method is defined inside the $specialsArray array literal, which is invalid PHP syntax and will cause a fatal parse error.
Severity: CRITICAL
Suggested Fix
Move the onBeforePageDisplay method definition outside of the $specialsArray array literal. The method should be defined as a class method within the Main class, but after the closing bracket ] of the array.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: includes/HookHandlers/Main.php#L348-L370
Potential issue: The `onBeforePageDisplay` method and its docblock have been inserted
directly inside the `$specialsArray` array literal in `includes/HookHandlers/Main.php`.
Defining a method within an array literal is not permitted by PHP's language
specification. This will cause a fatal `Parse error` as soon as the file is loaded by
PHP's autoloader. Because the extension is loaded on every page request, this syntax
error will prevent the `WikiOasisMagic` extension from loading entirely, leading to
application failure on any page that relies on it.
Did we get this right? 👍 / 👎 to inform future reviews.
onBeforePageDisplay was accidentally nested inside the $specialsArray array literal in Main::onTitleReadWhitelist, which is invalid PHP and crashes the file on load. Moved it out as a proper standalone method. Co-authored-by: Claude <noreply@anthropic.com>
Sort use statements alphabetically and use tab indentation for the class implements list, resolving the CI composer test failure. Claude-Session: https://claude.ai/code/session_01U4vgWaeoQRxSTZyaSDnLrH Co-authored-by: Claude <noreply@anthropic.com>
…rror (#14) The CI's native php-ast extension misreports "Main.php:9 PhanSyntaxError syntax error, unexpected token \"<<\", expecting end of file" against a file that php -l, ast\parse_code() (all supported AST versions), and Phan's own tolerant-php-parser polyfill all accept without error - confirmed by rerunning the exact same commit's CI job and reproducing locally against the pinned phan/phan and mediawiki-phan-config versions. Forcing use_polyfill_parser sidesteps the broken native parser in that environment. Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a
TypeError: this.paginator.init is not a functionoccurring in theext.simpleBlogPage.ui.panel.BlogListcomponent when viewing user blog pages (e.g.,/wiki/User_blog:BlossomVicky218).Root Cause:
The error stems from a version mismatch between the
SimpleBlogPageextension and theOOJSPluslibrary. TheBlogListpanel inSimpleBlogPageexpectsOOJSPlus.ui.data.pagination.Paginatorobjects to have aninit()method, which it calls after the data store loads. However, theOOJSPlusversion deployed on the server does not expose thisinit()method, leading to theTypeErrorwhenSimpleBlogPageattempts to call it.Solution:
This fix introduces a JavaScript compatibility shim (
ext.wikioasismagic.simpleBlogPageFix) that dynamically adds a no-operationinit()method toOOJSPlus.ui.data.pagination.Paginator.prototypeif it is not already defined. This ensures that the call fromSimpleBlogPage'sBlogListcomponent succeeds without error, while allowing newerOOJSPlusversions (which might natively includeinit()) to function as intended.Changes Made:
modules/ext.wikioasismagic.simpleBlogPageFix.js(new file): Contains the JavaScript shim to patch thePaginator.prototype.extension.json:ext.wikioasismagic.simpleBlogPageFixResourceModule, with a dependency onext.OOJSPlus.data.BeforePageDisplayhook to load this module.includes/HookHandlers/Main.php:onBeforePageDisplayhook to conditionally add theext.wikioasismagic.simpleBlogPageFixmodule to the output, but only when theSimpleBlogPageextension is active. This ensures the shim is only loaded when necessary.Fixes MEDIAWIKI-2J4