Last modified: 2014-02-04 10:57:25 UTC
I'd like to have access to templates and other transcluded pages, pre-transclusion (and before subtransclusions take place), so that I may do some rendering modifications on the wikitext in a context sensitive manner. There is currently no way to do this as far as I know. I relate this to the ParserAfterStrip hook that is called on source documents before templates and other variables are expanded. I'm sure such a hook could also be useful to the community at large for other purposes. Poking at the code, I've found that I can insert a hook near the end of the braceSubstitution function in Parser.php and have it work as intended (though I haven't done any exhaustive testing).
I'm fairly sure that braceSubstitution is the best function for this hook. I'm beginning to think that the proper location is just before this line: wfProfileOut( __METHOD__ . '-loadtpl' ); I'm still undecided on what exactly should get passed to the hook other than the text. Also, I need to check to see if the text there is in DOM format or not. I'll see what I can hammer out this weekend if no one has a better suggestion.
Created attachment 5732 [details] Transclude Hooks I'm sure this patch is wrong in some way, but I'd appreciate some hints on how to improve it. Right now, it attempts to cover both local and interwiki transcludes.
Also, I'm currently using the ParserAfterStrip hook. I'm not sure if I want to make a new hook or use this one. It's open to debate.
Setting this to need-review
Hi Kinsey, thank you for the patch! As you may already know, MediaWiki is currently revamping its PHP-based parser into a "Parsoid" prototype component, to support the rich-text Visual Editor project: https://www.mediawiki.org/wiki/Parsoid https://www.mediawiki.org/wiki/Visual_editor Folks interested in enhancing the parser's capabilities are very much welcome to join the Parsoid project, and contribute patches as Git branches: https://www.mediawiki.org/wiki/Git/Tutorial#How_to_submit_a_patch Compared to .diff attachments in Bugzilla tickets, Git branches are much easier for us to review, refine and merge features together. Each change set has a distinct URL generated by the "git review" tool, which can be referenced in Bugzilla by pasting its gerrit.wikimedia.org URL as a comment. If you run into any issues with the patch process, please feel free to ask on irc.freenode.net #wikimedia-dev and the wikitext-l mailing list. Thank you!
Change 103238 had a related patch set uploaded by Cptanu: Included a hook to have access to templates and other transcluded pages. https://gerrit.wikimedia.org/r/103238