Page MenuHomePhabricator

ParserAfterTidy hook passes only one short line in $text
Closed, InvalidPublic

Description

Author: Bob-wikimedia

Description:
I was trying to write an extension that adds a function to the ParserAfterTidy hook. It appears that the $text argument to this hook contains only a single tiny line from the bottom of the page, rather than the entire text of the page as expected. I wrote a function like this:

function fnSectionIndenter(&$parser, &$text) {

var_dump($text);
die();

}

and when I reloaded the page on my testing wiki, I got this output:

string(45) "

This page has been accessed 49 times.
"

What happened to the rest of the text of the page? Am I misunderstanding how this extension hook is intended to be used?


Version: 1.13.x
Severity: normal

Details

Reference
bz13408

Event Timeline

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

The rest of the text of the page was rendered previously, such as when it was last saved, and the output cached. Since it's not being rendered again, the parser and the parser's hooks are not running for it.

You should never, ever, ever, ever assume that text run through the parser does any of the following:

  • is the article text
  • is the only text to be run through the parser
  • is parsed when it's displayed
  • is displayed when it's parsed

Any and all of the above assumptions are usually false.

Bob-wikimedia wrote:

Ah, thank you for the clarifications.

I dug deeper into the documentation, and I now understand that I can temporarily put $parser->disableCache(); at the beginning of my extension function to force something closer to the behavior I was expecting.