r41978 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41977‎ | r41978 | r41979 >
Date:21:53, 11 October 2008
Author:skizzerz
Status:old
Tags:
Comment:
* fixes for the merged Poem extension, per comments by Tim Starling on CodeReview (r41710)
* adding <poem> tests to the parser tests file
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -7148,7 +7148,121 @@
71497149 </p>
71507150 !! end
71517151
 7152+!!test
 7153+<poem>
 7154+!!input
 7155+<poem>
 7156+this
 7157+is
 7158+a
 7159+test
 7160+</poem>
 7161+!!result
 7162+<div class="poem">
 7163+<p>this<br />
 7164+is<br />
 7165+a<br />
 7166+test
 7167+</p>
 7168+</div>
71527169
 7170+!!end
 7171+
 7172+!!test
 7173+ <poem> with recursive parsing
 7174+!!input
 7175+<poem>
 7176+this ''is'' a '''test'''
 7177+</poem>
 7178+!! result
 7179+<div class="poem">
 7180+<p>this <i>is</i> a <b>test</b>
 7181+</p>
 7182+</div>
 7183+
 7184+!!end
 7185+
 7186+
 7187+!!test
 7188+ <poem> with leading whitespace
 7189+!!input
 7190+<poem>
 7191+
 7192+ test
 7193+
 7194+</poem>
 7195+!!result
 7196+<div class="poem">
 7197+<p><br />
 7198+&nbsp;&nbsp;&nbsp;test<br />
 7199+</p>
 7200+</div>
 7201+
 7202+!!end
 7203+
 7204+!!test
 7205+Horizontal rule
 7206+!!input
 7207+<poem>
 7208+some
 7209+-----
 7210+text
 7211+</poem>
 7212+!!result
 7213+<div class="poem">
 7214+<p>some<br />
 7215+</p>
 7216+<hr /><br />
 7217+<p>text
 7218+</p>
 7219+</div>
 7220+
 7221+!!end
 7222+
 7223+!!test
 7224+ nested <poem><nowiki>
 7225+!!input
 7226+<poem><nowiki>
 7227+this
 7228+is
 7229+a
 7230+test
 7231+</nowiki></poem>
 7232+!!result
 7233+<div class="poem">
 7234+<p><br />
 7235+this<br />
 7236+is<br />
 7237+a<br />
 7238+test<br />
 7239+
 7240+</p>
 7241+</div>
 7242+
 7243+!!end
 7244+
 7245+!!test
 7246+ nested <poem><nowiki> with formatting
 7247+!!input
 7248+<poem><nowiki>
 7249+this
 7250+'''is'''
 7251+a
 7252+test
 7253+</nowiki></poem>
 7254+!!result
 7255+<div class="poem">
 7256+<p><br />
 7257+this<br />
 7258+'''is'''<br />
 7259+a<br />
 7260+test<br />
 7261+
 7262+</p>
 7263+</div>
 7264+
 7265+!! end
 7266+
71537267 #
71547268 #
71557269 #
Index: trunk/phase3/includes/parser/Parser.php
@@ -4183,34 +4183,42 @@
41844184 * based on http://www.mediawiki.org/wiki/Extension:Poem
41854185 */
41864186
4187 - function renderPoem( $in, $param=array() ) {
 4187+ function renderPoem( $in, $param = array() ) {
41884188
41894189 /* using newlines in the text will cause the parser to add <p> tags,
41904190 * which may not be desired in some cases
41914191 */
4192 - $nl = isset( $param['compact'] ) ? '' : "\n";
 4192+ $nl = array_key_exists( 'compact', $param ) ? '' : "\n";
41934193
41944194 $tag = $this->insertStripItem( "<br />", $this->mStripState );
4195 - $text = preg_replace(
4196 - array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ),
4197 - array( "", "", "$tag\n", "str_replace(' ','&nbsp;','\\1')" ),
4198 - $in );
 4195+ // Only strip the very first and very last \n (which trim cannot do)
 4196+ $text = $in;
 4197+ if( substr( $in, 0, 1 ) == "\n" )
 4198+ $text = substr( $in, 1 );
 4199+ if( substr( $text, -1 ) == "\n" )
 4200+ $text = substr( $text, 0, -1 );
 4201+
 4202+ $text = str_replace( "\n", "$tag\n", $text );
 4203+ $text = preg_replace_callback(
 4204+ "/^( +)/m",
 4205+ create_function(
 4206+ '$matches',
 4207+ 'return str_replace(" ", "&nbsp;", "$matches[0]");'
 4208+ ),
 4209+ $text );
41994210 $text = $this->recursiveTagParse( $text );
42004211
42014212 // Pass HTML attributes through to the output.
42024213 $attribs = Sanitizer::validateTagAttributes( $param, 'div' );
42034214
42044215 // Wrap output in a <div> with "poem" class.
4205 - if( isset( $attribs['class'] ) ) {
 4216+ if( array_key_exists( 'class', $attribs ) ) {
42064217 $attribs['class'] = 'poem ' . $attribs['class'];
42074218 } else {
42084219 $attribs['class'] = 'poem';
42094220 }
42104221
4211 - return wfOpenElement( 'div', $attribs ) .
4212 - $nl .
4213 - trim( $text ) .
4214 - "$nl</div>";
 4222+ return XML::openElement( 'div', $attribs ) . $nl . trim( $text ) . $nl . XML::closeElement( 'div' );
42154223 }
42164224
42174225 function getImageParams( $handler ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r43520Revert r41710, r41978, r42012, r42048 (integration of Poem extension to core ...demon01:19, 15 November 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41710* integrate Poem extension into core (patch by Nathaniel Herman)skizzerz20:27, 5 October 2008

Status & tagging log