[Mediawiki-l] Cloning the parser?

Chad innocentkiller at gmail.com
Thu Sep 9 12:49:48 UTC 2010


On Wed, Sep 8, 2010 at 11:08 PM, Tim Starling <tstarling at wikimedia.org> wrote:
> On 09/09/10 08:42, Chad wrote:
>> On Wed, Sep 8, 2010 at 3:07 PM, Daniel Barrett
>> <danb at vistaprint.com> wrote:
>>> What is the simplest, correct way to create a new Parser object
>>> with the same initialization as the current Parser object (e.g.,
>>> $wgParser)?   An actual code fragment would be great.
>>>
>>
>> $myParser = clone $wgParser;
>>
>> Or am I missing something here?
>
> I'm afraid so. That's basically the same as making a new parser
> object, and then assigning each of the member variables in turn. So
> the object members (preprocessor, link holders, strip state, etc.),
> end up being handles to the same objects, which means that when you
> call the two parsers, they interfere with each other.
>
> Parser::clearState() should be enough to fix this (or calling some
> parser method that calls clearState()), and that's what
> MessageCache::transform() relies on when it clones the parser.
> Parser::clearState() has some special hacks in it to clean up after a
> clone.
>
> Previously I attempted to support extensions which want to clone the
> parser and then call it without calling clearState(), but I eventually
> gave up on that idea on the basis that it's unmaintainable. So now the
> options are clearState() or find some other way to do what it is
> you're doing.
>

Is there a reason __clone() couldn't (shouldn't?) call clearState()?

-Chad



More information about the MediaWiki-l mailing list