http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89638

Revision: 89638
Author:   ialex
Date:     2011-06-07 09:45:41 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
Use preg_replace_callback() instead of preg_repace() with /e, also some style 
fixes

Modified Paths:
--------------
    trunk/extensions/Poem/Poem.php

Modified: trunk/extensions/Poem/Poem.php
===================================================================
--- trunk/extensions/Poem/Poem.php      2011-06-07 09:20:13 UTC (rev 89637)
+++ trunk/extensions/Poem/Poem.php      2011-06-07 09:45:41 UTC (rev 89638)
@@ -30,7 +30,7 @@
 $wgExtensionMessagesFiles['Poem'] =  dirname(__FILE__) . '/Poem.i18n.php';
 
 function wfPoemExtension( &$parser ) {
-       $parser->setHook("poem","PoemExtension");
+       $parser->setHook( 'poem', 'wfRenderPoemTag' );
        return true;
 }
 
@@ -41,19 +41,21 @@
  * @param bool $frame
  * @return string
  */
-function PoemExtension( $in, $param=array(), $parser=null, $frame=false ) {
+function wfRenderPoemTag( $in, $param=array(), $parser=null, $frame=false ) {
 
        /* using newlines in the text will cause the parser to add <p> tags,
-        * which may not be desired in some cases
+        * which may not be desired in some cases
         */
        $nl = isset( $param['compact'] ) ? '' : "\n";
-  
+
        $tag = $parser->insertStripItem( "<br />", $parser->mStripState );
+
        $text = preg_replace(
-               array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ),
-               array( "", "", "$tag\n", "str_replace(' ','&#160;','\\1')" ),
+               array( "/^\n/", "/\n$/D", "/\n/" ),
+               array( "", "", "$tag\n" ),
                $in );
-               $text = $parser->recursiveTagParse( $text, $frame );
+       $text = preg_replace_callback( '/^( +)/m', 'wfPoemReplaceSpaces', $text 
);
+       $text = $parser->recursiveTagParse( $text, $frame );
 
        $attribs = Sanitizer::validateTagAttributes( $param, 'div' );
 
@@ -64,8 +66,15 @@
                $attribs['class'] = 'poem';
        }
 
-       return Xml::openElement( 'div', $attribs ) .
-               $nl .
-               trim( $text ) .
-               "$nl</div>";
+       return array(
+               Html::rawElement( 'div', $attribs, $nl . trim( $text ) . $nl ),
+               'markerType' => 'none',
+       );
 }
+
+/**
+ * Callback for preg_replace_callback()
+ */
+function wfPoemReplaceSpaces( $m ) {
+       return str_replace( ' ', '&#160;', $m[1] );
+}


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to