Extension:Poem

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Poem

Release status: stable

Implementation  Tag
Description adds <poem> tag for poem formatting
Author(s)  Nikola Smolenski
MediaWiki  1.7+
License No license specified
Download Download snapshot

Subversion [Help]
Browse source code

check usage (experimental)

The Poem extension allows for easy inclusion of poems and similar material in MediaWiki pages, by simply putting them between <poem></poem> tags, instead of adding <br> to the end or : to the beginning 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). The extension preserves wikilinks, bolding, etc. if they are present in the poem, as well as indenting lines which start with spaces.

Nikola Smolenski made the extension in order to practice working on extensions, after an idea by Yann Forget[1].

It was activated on Wikisource and tested on 2006-06-23, and on the rest of the project sites on 2007-02-07.

Contents

[edit] Example

Input text Output
<poem>
In [[Wikipedia:Xanadu|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.

[edit] Style

The poem text is wrapped in a div, which has no style by default; but inherits any style or class option passed to the poem.

For example, while indented text can be used for simple examples to prevent filling and draw a nice blue box, it can be hard to read in some cases, since long lines aren't broken. A similar, but somewhat better effect can be obtained with

<poem style="border: 1px dashed #2f6fab; background-color: #f9f9f9; padding: 1em;">

When applied to the above example, the result is as follows:

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.

[edit] "compact" option

Normally, the parser renders each poem in a paragraph. Occasionally this is not desired; using the compact option suppresses newlines in the poem, to allow adjacent compact poems to blend together.

Input Output Input Output
<poem>
One,
Two.
</poem>
<poem>
Three?
Four!
</poem>

One,
Two.

Three?
Four!

<poem compact>
One,
Two.
</poem>
<poem compact>
Three?
Four!
</poem>
One,
Two.
Three?
Four!

[edit] Problems and solutions

  • Variables and ParserFunctions do work inside the <poem> ... </poem> container, but NOT within the <poem ... > tag itself ; this prevents templates with code such as <poem style="{{{1}}}">.
  • One workaround is to use <div style="{{{1}}}"><poem> ... </poem></div> instead.
  • Another is to use the #tag magic word: {{#tag:poem| ... |style="{{{1}}}"}}.
    • NB: this would however seem not to work with the "compact" option.
Input (inside OK, within not OK) Output
<poem style="{{{1|border: 1px solid Black;}}}">
One,
{{{2|Two.}}}
</poem>

One,
Two.

Input (both inside and within OK) Output
<div style="{{{1|border: 1px solid Black;}}}"><poem>
One,
{{{2|Two.}}}
</poem></div>

One,
Two.

{{#tag:poem|
One,
{{{2|Two.}}}
|style="{{{1|border: 1px solid Black;}}}"
}}

One,
Two.

[edit] Installation

Download the source files into your extensions/ directory, then add the following to your LocalSettings.php:

require_once($IP.'/extensions/Poem/Poem.php');

This extension is being used on one or more of Wikimedia's wikis. It means that the extension is stable and works well enough to be used by such high traffic websites. A full list of the extensions installed on a particular wiki is produced by Special:Version on that wiki.