2006-06-23 21:22:25 +00:00
|
|
|
<?php
|
|
|
|
# MediaWiki Poem extension v1.0cis
|
|
|
|
#
|
|
|
|
# Based on example code from
|
|
|
|
# http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension
|
|
|
|
#
|
|
|
|
# All other code is copyright © 2005 Nikola Smolenski <smolensk@eunet.yu>
|
|
|
|
# (with modified parser callback and attribute additions)
|
|
|
|
#
|
|
|
|
# Anyone is allowed to use this code for any purpose.
|
2007-12-16 18:27:23 +00:00
|
|
|
#
|
2006-06-23 21:22:25 +00:00
|
|
|
# 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 <poem></poem> tags
|
|
|
|
#
|
|
|
|
# For more information see its page at
|
|
|
|
# http://meta.wikimedia.org/wiki/Poem_Extension
|
|
|
|
|
|
|
|
$wgExtensionFunctions[]="wfPoemExtension";
|
2006-10-29 21:41:25 +00:00
|
|
|
$wgExtensionCredits['parserhook'][] = array(
|
2006-11-01 15:29:34 +00:00
|
|
|
'name' => 'Poem',
|
2007-07-16 20:42:31 +00:00
|
|
|
'author' => array( 'Nikola Smolenski', 'Brion Vibber', 'Steve Sanbeg' ),
|
|
|
|
'description' => 'Adds <tt><poem></tt> tag for poem formatting',
|
2007-12-16 18:27:23 +00:00
|
|
|
'url' => 'http://www.mediawiki.org/wiki/Extension:Poem'
|
2006-10-29 21:41:25 +00:00
|
|
|
);
|
2006-12-14 21:40:24 +00:00
|
|
|
$wgParserTestFiles[] = dirname( __FILE__ ) . "/poemParserTests.txt";
|
2006-06-23 21:22:25 +00:00
|
|
|
|
|
|
|
function wfPoemExtension() {
|
|
|
|
$GLOBALS['wgParser']->setHook("poem","PoemExtension");
|
|
|
|
}
|
|
|
|
|
|
|
|
function PoemExtension( $in, $param=array(), $parser=null ) {
|
2006-12-14 21:40:24 +00:00
|
|
|
|
|
|
|
if (method_exists($parser, 'recursiveTagParse')) {
|
|
|
|
//new methods in 1.8 allow nesting <nowiki> in <poem>.
|
|
|
|
$tag = $parser->insertStripItem("<br />", $parser->mStripState);
|
|
|
|
$text = preg_replace(
|
|
|
|
array("/^\n/","/\n$/D","/\n/", "/^( +)/me"),
|
|
|
|
array("", "", "$tag\n","str_replace(' ',' ','\\1')"),
|
|
|
|
$in );
|
|
|
|
$text = $parser->recursiveTagParse($text);
|
|
|
|
} else {
|
2007-12-16 18:27:23 +00:00
|
|
|
|
2006-06-23 21:22:25 +00:00
|
|
|
$text = preg_replace(
|
|
|
|
array("/^\n/","/\n$/D","/\n/", "/^( +)/me"),
|
|
|
|
array("", "", "<br />\n","str_replace(' ',' ','\\1')"),
|
|
|
|
$in );
|
|
|
|
$ret = $parser->parse(
|
|
|
|
$text,
|
2007-01-17 22:57:38 +00:00
|
|
|
$parser->getTitle(),
|
|
|
|
$parser->getOptions(),
|
2006-06-23 22:12:06 +00:00
|
|
|
// We begin at line start
|
|
|
|
true,
|
2006-06-23 21:22:25 +00:00
|
|
|
// Important, otherwise $this->clearState()
|
|
|
|
// would get run every time <ref> or
|
|
|
|
// <references> is called, fucking the whole
|
|
|
|
// thing up.
|
|
|
|
false
|
|
|
|
);
|
2007-12-16 18:27:23 +00:00
|
|
|
|
2006-12-14 21:40:24 +00:00
|
|
|
$text = $ret->getText();
|
|
|
|
}
|
2007-12-16 18:27:23 +00:00
|
|
|
|
2006-06-23 21:22:25 +00:00
|
|
|
global $wgVersion;
|
|
|
|
if( version_compare( $wgVersion, "1.7alpha" ) >= 0 ) {
|
|
|
|
// Pass HTML attributes through to the output.
|
|
|
|
$attribs = Sanitizer::validateTagAttributes( $param, 'div' );
|
|
|
|
} else {
|
|
|
|
// Can't guarantee safety on 1.6 or older.
|
|
|
|
$attribs = array();
|
|
|
|
}
|
2007-12-16 18:27:23 +00:00
|
|
|
|
2006-06-23 21:22:25 +00:00
|
|
|
// Wrap output in a <div> with "poem" class.
|
|
|
|
if( isset( $attribs['class'] ) ) {
|
|
|
|
$attribs['class'] = 'poem ' . $attribs['class'];
|
|
|
|
} else {
|
|
|
|
$attribs['class'] = 'poem';
|
|
|
|
}
|
2007-12-16 18:27:23 +00:00
|
|
|
|
2006-06-23 21:22:25 +00:00
|
|
|
return wfOpenElement( 'div', $attribs ) .
|
2006-06-23 22:12:06 +00:00
|
|
|
"\n" .
|
2006-12-14 21:40:24 +00:00
|
|
|
trim( $text ) .
|
2006-06-23 22:12:06 +00:00
|
|
|
"\n</div>";
|
2006-06-23 21:22:25 +00:00
|
|
|
}
|
2007-12-16 18:27:23 +00:00
|
|
|
|
|
|
|
|