From 8f521476a8f3e31506df007f1616bb615dc517ea Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Sun, 5 Oct 2008 20:27:23 +0000 Subject: [PATCH] * integrate Poem extension into core (patch by Nathaniel Herman) --- CREDITS | 1 + RELEASE-NOTES | 1 + includes/parser/Parser.php | 39 +++++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CREDITS b/CREDITS index a36a66c708..2c418e1e9a 100644 --- a/CREDITS +++ b/CREDITS @@ -53,6 +53,7 @@ following names for their contribution to the product. * Michael De La Rue * Mike Horvath * Mormegil +* Nathaniel Herman * RememberTheDot * ST47 diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 672dcb670c..a78271e3ea 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -60,6 +60,7 @@ The following extensions are migrated into MediaWiki 1.14: * RenderHash * NoMoveUserPages * Special:Nuke to mass delete all pages created by a user +* Poem (patch by Nathaniel Herman) === New features in 1.14 === diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9e8ed0cecb..52b86928fa 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -127,7 +127,7 @@ class Parser $this->mTransparentTagHooks = array(); $this->mFunctionHooks = array(); $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); - $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' ); + $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery', 'poem' ); $this->mUrlProtocols = wfUrlProtocols(); $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'. '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S'; @@ -3304,6 +3304,9 @@ class Parser case 'gallery': $output = $this->renderImageGallery( $content, $attributes ); break; + case 'poem': + $output = $this->renderPoem( $content, $attributes ); + break; default: if( isset( $this->mTagHooks[$name] ) ) { # Workaround for PHP bug 35229 and similar @@ -4173,6 +4176,40 @@ class Parser return $ig->toHTML(); } + /** Renders any text in between tags + * based on http://www.mediawiki.org/wiki/Extension:Poem + */ + + function renderPoem( $in, $param=array() ) { + + /* using newlines in the text will cause the parser to add

tags, + * which may not be desired in some cases + */ + $nl = isset( $param['compact'] ) ? '' : "\n"; + + $tag = $this->insertStripItem( "
", $this->mStripState ); + $text = preg_replace( + array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ), + array( "", "", "$tag\n", "str_replace(' ',' ','\\1')" ), + $in ); + $text = $this->recursiveTagParse( $text ); + + // Pass HTML attributes through to the output. + $attribs = Sanitizer::validateTagAttributes( $param, 'div' ); + + // Wrap output in a

with "poem" class. + if( isset( $attribs['class'] ) ) { + $attribs['class'] = 'poem ' . $attribs['class']; + } else { + $attribs['class'] = 'poem'; + } + + return wfOpenElement( 'div', $attribs ) . + $nl . + trim( $text ) . + "$nl
"; + } + function getImageParams( $handler ) { if ( $handler ) { $handlerClass = get_class( $handler ); -- 2.20.1