# (with modified parser callback and attribute additions)
#
# Anyone is allowed to use this code for any purpose.
#
# To install, copy the extension to your extensions directory and add line
# include("extensions/Poem.php");
# to the bottom of your LocalSettings.php
#
# To use, put some text between tags
#
# For more information see its page at
# http://www.mediawiki.org/wiki/Extension:Poem
$wgHooks['ParserFirstCallInit'][] = 'wfPoemExtension';
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Poem',
'author' => array( 'Nikola Smolenski', 'Brion Vibber', 'Steve Sanbeg' ),
'url' => 'http://www.mediawiki.org/wiki/Extension:Poem',
'descriptionmsg' => 'poem-desc',
);
$wgParserTestFiles[] = dirname( __FILE__ ) . "/poemParserTests.txt";
$wgExtensionMessagesFiles['Poem'] = dirname(__FILE__) . '/Poem.i18n.php';
function wfPoemExtension( &$parser ) {
$parser->setHook("poem","PoemExtension");
return true;
}
function PoemExtension( $in, $param=array(), $parser=null, $frame=false ) {
/* 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";
if( method_exists( $parser, 'recursiveTagParse' ) ) {
//new methods in 1.8 allow nesting in .
$tag = $parser->insertStripItem( "
", $parser->mStripState );
$text = preg_replace(
array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ),
array( "", "", "$tag\n", "str_replace(' ',' ','\\1')" ),
$in );
$text = $parser->recursiveTagParse( $text, $frame );
} else {
$text = preg_replace(
array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ),
array( "", "", "
\n", "str_replace(' ',' ','\\1')" ),
$in );
$ret = $parser->parse(
$text,
$parser->getTitle(),
$parser->getOptions(),
// We begin at line start
true,
// Important, otherwise $this->clearState()
// would get run every time [ or
// is called, fucking the whole
// thing up.
false
);
$text = $ret->getText();
}
$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 Xml::openElement( 'div', $attribs ) .
$nl .
trim( $text ) .
"$nl
";
}