On 11/29/07, Roan Kattouw roan.kattouw@home.nl wrote:
- Add all requested titles to a LinkBatch [1]
- Return a marker like marker-ifexist-0 and store the ifTrue and ifFalse
values in an array
- In a ParserAfterTidy hook, run LinkBatch::execute() (checks for
existence) and str_replace() all markers
Of course, it can't be ParserAfterTidy: the branches can contain arbitrary wikicode. Instead, the parser must
1) (in preprocessor stage) Add each title to a LinkBatch and replace with a marker,
2) (after preprocessor stage) Resolve the LinkBatch to figure out which path to follow for each,
3) (still just after preprocessor stage) Reinvoke the preprocessor on the path that was followed to produce wikitext for the main parsing pass.
Or alternatively,
1) (in preprocessor stage) Add each title to a LinkBatch and replace with a marker,
2) (still in preprocessor stage) Preprocess *both* paths,
3) (after preprocessor stage) Resolve the LinkBatch to figure out which path to follow for each,
4) (still after preprocessor stage) Insert the already-preprocessed wikitext for that path while discarding the other one,
whichever is more efficient. Nested {{#ifexist:}} have to be considered: they'd probably work a lot better with my second plan, with steps (1) and (2) being executed together and recursively, and step (4) being executed recursively later.