Last modified: 2014-09-24 00:06:17 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T23844, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 21844 - DOM preprocessor barfs on headings inserted by parser functions
DOM preprocessor barfs on headings inserted by parser functions
Status: NEW
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
1.16.x
All All
: Low minor (vote)
: ---
Assigned To: Nobody - You can work on this!
: parser, patch, patch-reviewed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-14 05:10 UTC by Jani Patokallio
Modified: 2014-09-24 00:06 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Ensure that the title attribute is set before trying to add in the heading index marker (732 bytes, patch)
2009-12-14 05:10 UTC, Jani Patokallio
Details
Proposed fix: Check also for null values of $title in PPFrame_*::newChild() (833 bytes, patch)
2009-12-14 15:12 UTC, P.Copp
Details

Description Jani Patokallio 2009-12-14 05:10:01 UTC
Created attachment 6877 [details]
Ensure that the title attribute is set before trying to add in the heading index marker

If a parser function extension inserts a heading into an article, PPFrame_DOM::expand() chokes on it because its title attribute is not set:

1041 $titleText = $this->title->getPrefixedDBkey();

Since title attributes are only required for inserting heading index markers, and these markers should most probably not be inserted for headings not within the article content, the simple fix is to check that the title attribute is set before trying to add in the heading index marker.  A trivial patch is attached.
Comment 1 P.Copp 2009-12-14 15:12:50 UTC
Created attachment 6879 [details]
Proposed fix: Check also for null values of $title in PPFrame_*::newChild()

The title attribute of a frame should always be set. It's not working in your case, because there is a little bug in PPFrame_DOM::newChild(), checking only for the value false but not null.

It would be helpful if you could try the attached patch with your code and tell us, if it works for you.
Comment 2 Jani Patokallio 2009-12-15 00:32:48 UTC
Thanks for the fast response.  The patch works in the sense of not crashing anymore, but the autogenerated edit links now all point to nonexistent sections of incorrect articles.  Eg. in the article "Main":

==Orientation== [edit] -> http://atlas-mediawiki.local/index.php?title=Main&action=edit&section=1
==Information== [edit] -> http://atlas-mediawiki.local/index.php?title=Orientation&action=edit&section=T-1

Simply disabling section editing entirely and generating my own edit links via the extension is probably an acceptable workaround though.
Comment 3 P.Copp 2009-12-15 00:46:05 UTC
(In reply to comment #2)
> Thanks for the fast response.  The patch works in the sense of not crashing
> anymore, but the autogenerated edit links now all point to nonexistent sections
> of incorrect articles.  Eg. in the article "Main":
> 
> ==Orientation== [edit] ->
> http://atlas-mediawiki.local/index.php?title=Main&action=edit&section=1
> ==Information== [edit] ->
> http://atlas-mediawiki.local/index.php?title=Orientation&action=edit&section=T-1
>
You should be able to specify the correct title in the array returned by your parser function:

  return array( $output, 'noparse' => false, 'title' => $yourTitleObject );

The section indices might be wrong, though, so I'm not sure, if this is what you're actually trying to do.

> 
> Simply disabling section editing entirely and generating my own edit links via
> the extension is probably an acceptable workaround though.
> 
You can generate headings without edit links via

<h2> Section title </h2>
Comment 4 Jani Patokallio 2009-12-16 22:18:23 UTC
Thanks.   On second thought, the edit links are another kettle of fish, and the original issue I raised is fixed by your patch -- please add it to the trunk and close this bug as FIXED.
Comment 5 Tim Starling 2010-01-06 05:54:28 UTC
Please provide sample calling code which allows me to confirm and reproduce this issue.
Comment 6 P.Copp 2010-01-07 19:12:46 UTC
I don't know if he is still around, but I was able to reproduce it with something like:

$wgHooks['ParserFirstCallInit'][] = 'efBug21844_setHook';
$wgHooks['LanguageGetMagic'][] = 'efBug21844_setMagic';
function efBug21844_setHook( $parser ) { $parser->setFunctionHook( 'bug21844', 'efBug21844' ); return true; }
function efBug21844_setMagic( $magicWords ) { $magicWords['bug21844'] = array( 1, 'bug21844' ); return true; }	
function efBug21844() {
	return array( "== Foo ==\n...", 'noparse' => false );
}

and {{#bug21844:}} on any page.
Comment 7 Jani Patokallio 2010-01-08 01:27:00 UTC
Still around, and you beat me to it!
Comment 8 Tim Starling 2010-01-08 02:59:06 UTC
The problem is the fact that at Parser.php line 2900 (r60825), $isChildObj is set without $title being set. This is incorrect, you can't have a child object with no title. This causes line 2995 to create an invalid frame with $title=null, which then throws fatal errors under various circumstances.

This behaviour of $noparse was apparently added to support DPL2 in r34594, although DPL2 has since stopped using it. I'm not sure if it set $title. Theoretically LST could use it (if it set $title correctly) but it doesn't. 

It doesn't really make sense to use $isLocalObj, since that would give you non-functional edit section links for the current page. If you were getting text from another page and including it like a template, then $isChildObj could make sense, since it would give you edit section links to the other page, if you set $title. 

If the text doesn't come from an editable page at all, then we probably need to have a flag which can be sent to expand() to suppress the generation of heading markers. 

So, Jani, can you please explain your application, particularly what sort of text it is that you're trying to expand? And in that text, what do you expect triple-braces to do?
Comment 9 Jani Patokallio 2010-01-22 09:40:37 UTC
I'm not entirely sure why my application has relevance on the actual bug, which is that inserting titles by parser function fails...?

But at any rate, the parser function is called #include and it's used with the format {{#include:Article}}.  Depending on page state it either returns a link to Article:

* [[Article]]

...or it asks the parser to transclude it, with the article name added as a header:

==Article==
{{:Article}}

...and it's the 2nd case here that's failing.
Comment 10 Sumana Harihareswara 2011-11-09 20:08:14 UTC
Adding the "reviewed" keyword since Tim reviewed the author's approach.  P.Copp, Jani, if you would like more feedback, please feel free to replace that keyword with "need-review".  Thanks.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links