Page MenuHomePhabricator

Feature Request: Transclusion Preprocessing Hook
Open, LowPublicFeature

Description

Author: nyphbl8d

Description:
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).


Version: unspecified
Severity: enhancement

Details

Reference
bz17131

Related Objects

StatusSubtypeAssignedTask
OpenFeatureNone
OpenFeatureNone

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:25 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz17131.
bzimport added a subscriber: Unknown Object (MLST).

nyphbl8d wrote:

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.

nyphbl8d wrote:

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.

Attached:

nyphbl8d wrote:

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.

nyphbl8d wrote:

Setting this to need-review

audreyt wrote:

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

Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:01 AM