1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?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.
#
# 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";
function wfPoemExtension() {
$GLOBALS['wgParser']->setHook("poem","PoemExtension");
}
function PoemExtension( $in, $param=array(), $parser=null ) {
$text = preg_replace(
array("/^\n/","/\n$/D","/\n/", "/^( +)/me"),
array("", "", "<br />\n","str_replace(' ',' ','\\1')"),
$in );
$ret = $parser->parse(
$text,
$parser->mTitle,
$parser->mOptions,
// We begin at line start
true,
// Important, otherwise $this->clearState()
// would get run every time <ref> or
// <references> is called, fucking the whole
// thing up.
false
);
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();
}
// Wrap output in a <div> with "poem" class.
if( isset( $attribs['class'] ) ) {
$attribs['class'] = 'poem ' . $attribs['class'];
} else {
$attribs['class'] = 'poem';
}
return wfOpenElement( 'div', $attribs ) .
"\n" .
$ret->getText() .
"\n</div>";
}
?>
|