Problem: We want to be able to provide rich context to the parser, which is currently done by providing a RevisionRecord. However, RevisionRecords should only exist on "proper" pages, not special pages (T380536). But wikitext needs to be able to be parsed in the context of special pages (or no page at all) (T381982).
Solution: introduce a ParserInput object, to match parserOptions and ParserOutput. ParserInput should be able to replace all kinds of parser input we currently use, namely strings, Content objects, and RevisionRecords. It's conceptually similar to Parsoid's PageConfig object.
Interface draft:
class ParserInput { public static function newFromWikitext( string $wikitext, PageReference $page ); public static function newFromContent( TextContent $content, PageReference $page ); public static function newFromSlots( RevisionSlots $slots, PageReference $page ); public static function newFromRevision( RevisionRecord $slots ); public function getPage(): PageReference; public function getPageLanguage(): LanguageCode; public function getContent(): TextContent; public function getSlots(): RevisionSlots; public function getRevision(): ?RevisionRecord; }
This approach would also allow us to get rid of currentRevisionRecordCallback in parserOptions. Note that we'd probably need to keep speculativePageIdCallback and speculativeRevIdCallback, since we want to record if and when they are used. Incorrect, per discussion. Instead: This might allow us to get rid of speculativePageIdCallback and speculativeRevIdCallback in ParserOptions, but we would still need to record if and when they are acutally used.