fix(mort): PHP Fatal errors and compatibility issues with DokuWiki Mort#83
Open
eduardomozart wants to merge 12 commits into
Open
fix(mort): PHP Fatal errors and compatibility issues with DokuWiki Mort#83eduardomozart wants to merge 12 commits into
eduardomozart wants to merge 12 commits into
Conversation
…nHandle() on false
…fnotes into fix/bibtex-mort
Reinitialize the BibTeX lexer mode stack to the `base` state at the start of parsing. This prevents stale parser state from previous runs in DokuWiki's Mort lexer and ensures each parse begins with a clean, consistent lexer state.
Reinitialize the BibTeX lexer mode stack to the `base` state at the start of parsing. This prevents stale parser state from previous runs in DokuWiki's Mort lexer and ensures each parse begins with a clean, consistent lexer state.
…fnotes into fix/bibtex-mort
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.
Description
This PR resolves multiple compatibility issues with recent versions of DokuWiki ("Mort" and newer) that cause the wiki to crash with PHP Fatal errors or fail to parse references (Closes #82).
Recent DokuWiki updates significantly modified the parser architecture and removed deprecated core files, which impacted both the custom BibTeX parser and the reference rendering logic.
1. BibTeX Parser Abstract Method and Lexer Offset Errors
Recent DokuWiki updates modified the parser architecture in several ways:
abstract public function handle(...)to the\dokuwiki\Parsing\ParserMode\AbstractModebase class. Sincerefnotes_bibtex_modeextends this base class but delegates handling via mapped handlers ($this->Lexer->mapHandler), the method was missing, violating the class contract.Parser::addMode()which strictly expects the parser to use the native DokuWikiModeRegistryandHandler. Becauserefnotesuses a custom handler, this resulted in an uninitialized typed property access error.Lexer::reduce()method signature to explicitly require a string byte$offsetargument instead of relying on string slicing (substr).$offsettopreg_matchwithPREG_OFFSET_CAPTUREinstead of slicing strings, patterns starting with^(caret) incorrectly anchored to the beginning of the entire document rather than the current offset, causing the BibTeX parser to silently fail to match fields (such asTitle,Author, andnamespace).$_mode) with a dedicated\dokuwiki\Parsing\Lexer\StateStackobject. Because therefnotesLexer implementation reuses the same Lexer instance across multiple pages, the failure to reset this new mode stack resulted in catastrophic state leakage. If a previous page contained a typo like an unclosed quote (title = "unfinished string) or an unclosed bracket (author = {missing bracket), the Lexer would reach the end of that page while still stuck insidestring_value_quotedorstring_value_bracedmode. When it parsed the next page, it would start in that broken mode and immediately crash with aCall to a member function addToken() on nullerror as soon as it encountered nested braces (e.g.,author = "Till {Brehm}").Changes Made:
handle()method torefnotes_bibtex_modeinbibtex.phpreturningfalse.Doku_Handlerto leverage DokuWiki's native backward-compatibility alias layer (inc/legacy.php). This ensures the plugin remains compatible with both older DokuWiki releases and modern ones utilizing the newdokuwiki\Parsing\Handlernamespace.addMode()method inrefnotes_bibtex_parserto bypass the core DokuWiki dependency injection entirely, successfully decoupling the custom BibTeX parser from DokuWiki's internal plugin routing mechanisms.parse()loop inrefnotes_bibtex_lexerto correctly track and pass the$offsetparameter toLexer::reduce()andLexer::dispatchTokens(), aligning with the newer parsing performance optimizations without infinite looping.^anchors from the$this->entryPatternstrings insiderefnotes_bibtex_entry_mode,refnotes_bibtex_field_mode, andrefnotes_bibtex_string_value_modeto ensure compatibility with the updated Lexer's non-slicing offset mechanism.^anchor with the PCRE\Ganchor in$this->specialPatterninsiderefnotes_bibtex_integer_value_modeto properly parse unquoted integers (e.g.year = 2026) at the Lexer's current offset.StateStackarchitecture) by explicitly re-initializing$this->modeStackto'base'at the beginning ofrefnotes_bibtex_lexer::parse().2. Missing
inc/indexer.phpErrorDokuWiki Mort completely removed the
inc/indexer.phpfile in favor of the new object-oriented search classes (tracked in dokuwiki/dokuwiki#4646). When running the plugin on a recent installation, it crashes with the following error during the SearchIndex manager's Rebuild index process:Changes Made:
database.phpto conditionally use the new\dokuwiki\Search\Indexerclass to retrieve the index of pages if available on newer DokuWiki versions.file_existscheck before requiringinc/indexer.phpand retained the usage ofidx_getIndexas a fallback, ensuring compatibility with older DokuWiki versions where the legacy system is still used.3. "Attempt to modify property 'calls' on null" and Context Imbalance Errors
DokuWiki Mort changed how parsers are initialized for nested snippets, introducing a
ModeRegistrywith pooled sub-parsers. Becauserefnotescaches theLexerduring initialization but triggers the snippet parse later, the Lexer would attempt to write instruction calls to an unset object reference. Additionally, attempting to use sub-parsers directly caused an imbalance in thePARSER_WIKITEXT_PREPROCESSandPARSER_HANDLER_DONEhooks, leading to an empty parsing context stack and crashing the plugin entirely (Call to a member function canHandle() on false).Changes Made:
refnotes_parser_core::getInstructions()incore.phpto detect newer versions of DokuWiki by checking forgetModeRegistry().p_get_instructions()API when available. This spawns a clean, isolated parser for footnote text and perfectly balances thePARSER_WIKITEXT_PREPROCESSandPARSER_HANDLER_DONEevents, restoring compatibility while remaining backward-compatible with older DokuWiki versions (which still use the legacy fallback).Note for users upgrading:
After applying this update on an existing installation, you may need to:
data/cache/refnotes_database.index(so the BibTeX fields can be re-parsed).