Page MenuHomePhabricator

Cannot Use Parser Inside EditPage::showEditForm:initial Hook
Closed, InvalidPublic

Description

Author: david.sledge

Description:
PHP: 5.2.4
MySQL: 5.0.45

Given the following extension, I keep getting a blank page if I uncomment either of the commented lines:

$wgHooks['EditPage::showEditForm:initial'][] = "wfParserTest";

function wfParserTest( &$editPage )
{
    global $wgParser;

    $localParser = new Parser();
    //$output = $wgParser->parse( '', $this->mTitle );
    //$output = $localParser->parse( '', $this->mTitle );

    return true;
}

This problem occurs if is just try to preprocess any wikitext [using Preprocessor_DOM::preprocessToObj()].


Version: 1.13.x
Severity: normal
OS: Windows XP
Platform: PC

Details

Reference
bz15298

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:22 PM
bzimport set Reference to bz15298.
bzimport added a subscriber: Unknown Object (MLST).

(In reply to comment #0)

PHP: 5.2.4
MySQL: 5.0.45

Given the following extension, I keep getting a blank page if I uncomment
either of the commented lines:

Of course you do, because:

//$output = $wgParser->parse( '', $this->mTitle );
//$output = $localParser->parse( '', $this->mTitle );

you can't use $this inside a global function.

david.sledge wrote:

Ah, yes. I'm always amazed by my ability to overlook the obvious.

Nonetheless, if I substitute $this->mTitle with a valid title object whose page exists, such as:

$wgHooks['EditPage::showEditForm:initial'][] = "wfParserTest";

function wfParserTest( &$editPage )
{
    global $wgParser;

    $output = $wgParser->parse( '', Title::newFromText( 'Main Page' ) );

    return true;
}

I still get a blank page when I follow any page's "edit" link.

This is a bug with your code. Bugzilla is not a support forum. Please request help on one of the support forums such as the IRC channel (MediaWiki-General) or mailing list (mediawiki-l).

Hint: $wgParser->parse( $text, $title, new ParserOptions );

david.sledge wrote:

My mistake. When I found that a simple method call such as

$wgParser->preprocessToDom( '' );

resulted in a blank page, I genuinely though it was a bug. I'll direct my problem to the proper forums.