The ParserFetchTemplateData hook could use some cleanup.
- It currently takes an array of titles and processes them in a batch, but the actual implementation in TemplateData iterates through the titles one by one, and the Parsoid code which invokes ParserFetchTemplateData only ever passes in a single title. We should simplify the API and just take a single title and return data for that single title.
- It is somewhat unusual that templates have a Title corresponding to them, eg {{Foo}} corresponds to {{Template:Foo}}. This isn't the case for extensions (T204283) or parser functions, though, and we'd like to eventually support TemplateData for them as well. Further, scribunto modules do have a title -- ie, {{#invoke:Foo}} corresponds to Module:Foo -- but the correspondence isn't exact. I think instead of taking a title, the signature should be something like string $type, string $name with the Template:Foo case corresponding to 'template', 'Foo'. This would be extensible to the other types of invocations we'd like to eventually support. (If this takes long enough, the string $type could become an enumeration, but we can't do that until our minimum PHP version is 8.1.) (#invoke:Foo is perhaps a special case, we maybe need to pass 'Foo' as well as 'invoke' for the "parserfunction" $type.)
- Returning an object without a type is quite odd, and we compound it by returning several not-quite-an-object values for missing, no templatedata, or bad data. These should probably be "normal" null returns, with maybe a &$error or something if we need to distiguish the type (it doesn't seem like we use the error type at all). Ideally we'd return a properly typed object, maybe one defined in Parsoid. If we wanted to maintain loose coupling, however, we could simply return an associative array (and document the property names), since the current Parsoid code promptly turns the object into an associative array anyway.
I propose to introduce a new hook named ParserGetTemplateData or maybe ParserGetInvocationData (to accommodate extensions and parser functions?), and deprecate the existing hook and move to using the new hook.