allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

天下维客,你可以修改的网络知识库

Jump to: navigation, search

诗扩展允许条目中的诗句中同时使用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 textOutput
<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:
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.

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)
	);
}
?>
Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币