诗
天下维客,你可以修改的网络知识库
诗扩展允许条目中的诗句中同时使用MediaWiki语句。
by simply putting them between <poem></poem> tags, instead of adding
to the end of every line, which is common practice now. Though small, it might be useful, especially on Wikisource or similar projects (there are poems with thousands of lines, so obviously current solution isn't practical). If there is interest, possible improvement might be support for indenting of lines. The extension preserves wikilinks, bolding, etc. if they are present in the poem.
I (Nikola Smolenski) made it in order to practice working on extensions, after an idea by Yann Forget[1].
It could be seen in action at Wikimedia SCG's crash wiki Poem test page. Note that it isn't installed here, so you can't test it here! But you can do all the testing you want on the crash wiki.
Example
| Input text | Output |
|---|---|
<poem> In [[Xanadu]] did Kubla Khan A stately pleasure-dome decree: Where Alph, the sacred river, ran Through caverns measureless to man Down to a sunless sea. So twice five miles of fertile ground With walls and towers were girdled round: And there were gardens bright with sinuous rills, Where blossomed many an incense-bearing tree; And here were forests ancient as the hills, Enfolding sunny spots of greenery. </poem> | In Xanadu did Kubla Khan A stately pleasure-dome decree: So twice five miles of fertile ground |
Source
<?php
# MediaWiki Poem extension v1.0
#
# 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>
#
# 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)
{
global $wgOut;
return $wgOut->parse(
preg_replace(
array("/^\n/","/\n$/D","/\n/"),
array("", "", "<br />\n"),
$in)
);
}
?>


