Jani Patokallio wrote:
Greetings,
I've got a simple Extension that expands an {{#include}} parser function
into random text. It works well for most things, but if I try to stick in
a new heading, includes/Preprocessor_DOM.php::expand() fails on this...
$titleText = $this->title->getPrefixedDBkey();
because "$this" (a PPFrame_DOM) does not have a title object. As a
temporary band-aid, I inserted this into Preprocessor_DOM.php:
if(! $this->title) $this->title = Title::newFromText("XXX");
But is there a way to fix this from within the extension? Code attached,
it's pretty trivial.
The code is not attached, presumably it was stripped out by Mailman.
Can you provide a link?
In any case, it's likely that you're not entering the parser
correctly. It should only be entered via one of the five entry points
documented at the top of Parser.php: parse(), preSaveTransform(),
preprocess(), cleanSig() and extractSections().
While I'm at it, for extra credit, is there a way
to determine the
equivalent of expand's $expansionDepth (== how deep in the transclusions
we are) from within an extension?
There's no way to determine the expansion depth. Note that it's
heavily dependent on the implementation details, with various tricks
being used to expand certain kinds of trees without recursion. So it
doesn't have much to do with the syntax if that's what you're looking for.
Maybe you just don't get what it is. This has an expansion depth of 3
but a frame depth of 0:
{{#if: {{#if: {{#if: x | y | z }} }} }}
If you had this:
[[Page]]: {{A}}
[[Template:A]]: {{B}}
[[Template:B]]: {{C}}
[[Template:C]]: foo
then expanding [[Page]] would give you an expansion depth of 3 at
"foo", and also a frame depth of 3.
-- Tim Starling