"Roan Kattouw" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Mark Clements (HappyDog) schreef:
>> It doesn't, and it isn't... :-(
>>
>> That said, the PHP_Compat PEAR module contains a PHP4 version of the 
>> clone
>> function (providing you use clone($wgParser)) which I might try.
>>
>> Alternatively, is there any harm in just using $wgParser directly?  Do we
>> have to make a copy?
> I don't know. The only thing I know is that you have to be careful when
> calling Parser members inside a parser hook, because the parser kind of
> goes crazy when code called from Parser::parse() calls Parser::parse()
> with different arguments; Parser::recursiveTagParse() is the function
> you need in that case. I don't know what harm could be caused by using
> $wgParser directly in other cases; I guess you could try.
>

I tried using clone() and it didn't work :-(

I think it might be because the tag that I am manually parsing for in order 
to add its data to the DB is also used when rendering, therefore it is being 
stripped out of the page by the parser before it comes back to me, which is 
not what I want.

Perhaps it would be better if I explained the problem, as I think the issue 
is perhaps a little more complex than I first thought.

Here is the tag I am using:
  <data>
    name=Jim
    age=20
  </data>

When displaying the page, the data tag has a hook attached, which replaces 
the name/value pairs with a nice table.
When saving, or otherwise changing the page in anyway, the page is parsed to 
extract the contents of the data tags, which are written to the DB for later 
querying (via other means, not relevant to this discussion).

I don't do this on page view (in the <data> tag handler), as it is a 
relatively expensive operation to clear out the old entries and reparse the 
data tags, and the data will not have changed, so it is not necessary.

So instead I re-parse it whenever the data changes (save/undelete/etc.).  In 
order to parse it correctly I first need to run it through the pre-parser to 
remove comments/nowiki blocks, to expand templates etc. otherwise the page 
works differently to how it is rendered (e.g. data will be added to the DB 
even though it is in a nowiki block).  However, an issue arises when the 
code is embedded in some other tag.

For example:

  <somecustomtag>
    <data>
      name=Jim
      age=20
    </data>
  </somecustomtag>

If somecustomtag parses it's contents then the data tag should be treated as 
normal, and if the tag does something else which doesn't result in a parse 
(e.g. syntax highlighting) then we should ignore this block.

Currently my code uses a new parser object, which doesn't have any hooks 
defined so all tags are treated in the second way.
Changing it to use clone() as described above means all tags are treated in 
the first way.  This of course includes my own <data> handler, which results 
in the tag being replaced by the output table, so if I use this method then 
no data is found by the save parser at all!
Neither of these is the correct behaviour, as described in the previous 
paragraph.

I hope I've done a decent job of describing the problem!  Does anyone have a 
suggestion that would allow me to do what I want?

- Mark Clements (HappyDog)



_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to