On Feb 5, 2014 8:38 AM, "Zachary Harris" zacharyharris@hotmail.com
wrote:
- Is there a way to tell the Parser that you don't want the initial DOM
element wrapped in paragraph tags? (For example, if you are client-side injecting the mw-api contents into already existing content and you don't want a paragraph break there?) It seems this same question was effectively asked at http://www.mediawiki.org/wiki/API_talk:Parsing_wikitext and hasn't been answered yet. If the parser can't be configured in this way and I have to strip possibly undesired openings tags myself do I have any guarantees on what to expect?
Not really. Even innternally in core (in OutputPage and in Message class) we regex out the <p> when its not wanted. (Icky!)
- Why do JSON results come back, for example, in the form of
parse.text['*'] rather than just parse.text? With format=XML the result is just <parse><text>the stuff</text></parse>. Why the "*"? Sorry if this question is dumb.
From what i've heard, historical reasons mostly. I believe its so that the
xml can be mechanically turned into json - the text body of an element is treated like an attribute * so that if that element had attributes they could also be represented.
-bawolff
On 02/05/2014 08:46 AM, bawolff wrote:
Not really. Even innternally in core (in OutputPage and in Message class) we regex out the <p> when its not wanted. (Icky!)
Better late than never, I did want to say thank you for the answer.
$ rgrep "preg_match( '/^<p>" . -A2 ./includes/Message.php: if ( preg_match( '/^<p>(.*)\n?</p>\n?$/sU', $string, $m ) ) { ./includes/Message.php- $string = $m[1]; ./includes/Message.php- } -- ./includes/OutputPage.php: if ( preg_match( '/^<p>(.*)\n?</p>\n?/sU', $parsed, $m ) ) { ./includes/OutputPage.php- $parsed = $m[1]; ./includes/OutputPage.php- } -- ./includes/GlobalFunctions.php: if ( preg_match( '/^<p>(.*)\n?</p>\n?$/sU', $string, $m ) ) { ./includes/GlobalFunctions.php- $string = $m[1]; ./includes/GlobalFunctions.php- }
At the very least, I call [[Rule of three (computer programming]] on that! It would be nice to have an option where the superfluous <p> didn't show up in the first place, but short of such niceness, the common functionality at least needs to be factored out.
Would filing a bug report be the appropriate thing for me to do with this suggestion?
-Zach
On Wed, 19 Feb 2014 03:30:08 +0100, Zachary Harris zacharyharris@hotmail.com wrote:
At the very least, I call [[Rule of three (computer programming]] on that! It would be nice to have an option where the superfluous <p> didn't show up in the first place, but short of such niceness, the common functionality at least needs to be factored out. Would filing a bug report be the appropriate thing for me to do with this suggestion?
Yes. But since you didn't, I just submitted a patch instead :P https://gerrit.wikimedia.org/r/114942
mediawiki-api@lists.wikimedia.org