No subject


Fri Mar 14 23:02:16 UTC 2008


there a way to determine whether or not the page being rendered is a
template?

Here's a simple example of about what I'm talking:

  $wgParser->setHook( 'foo', 'fooParse' );

  function fooParse( $input, $args, $parser ) {
    if( WE ARE RENDERING INSIDE A TEMPLATE )
      return 'FOO';
    else
      return 'BAR';
  }

Here's my underlying motivation: I want to be able to label sections
for transclusion from within a template (using either the LST or DPL
extensions).  Currently, this is how it's done:

 //// Article A ////
 <section begin=content />
 This is some text to be transcluded.
 <section end=content />

 //// Article B ////
 %% Transclude the text from labeled section `content' of [[A]] %%

The above code works perfectly, however, here's what I want to be able to do:

 //// Template:BeginConent ////
 <section begin=content />

 //// Template:EndContent ////
 <section end=content />

 //// Article A ////
 {{BeginContent}}
 This is some text to be transcluded.
 {{EndContent}}

That, however, doesn't work (the transcluded text ends up being
empty).  Here's my theory on why it doesn't work from looking at the
LST and DPL extensions' code:

They each do something like this:

  $wgParser->setHook( 'section', array( __CLASS__, 'noop' ) );

where 'noop' is a function that just returns the empty string, which
is what hides the <section ... /> tags from being rendered in the wiki
text.  Then, inside the functions that do the transclusion, it
actually parses the raw DOM of the page to be transcluded looking for
the <section> tags (which are still in the raw DOM even though they
have not been rendered to the wiki text).

Although I admit that I do not fully comprehend the order in which
MediaWiki parses/expands/transcludes templates, my theory is that the
`<section begin=content />' tag inside the `BeginContent' template
above is being rendered inside the template before it is transcluded
into article A, thus, the section tags are not being included in A's
DOM.  My theoretical solution to this problem is to hack the `section'
tag's hook in DPL such that it will only render to an empty string
when inside of the ultimate article.

Is this even possible?  Does anyone have any alternate theories and/or
suggestions?

Thanks!

    - Evan



More information about the MediaWiki-l mailing list