LyricExtension/Source Code

From PeacockWiki

Revision as of 03:27, 1 June 2006; Trevorp (Talk | contribs)
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Jump to: navigation, search
<?php

#
# Simple lyric parser extension for mediawiki.
# Written by Trevor Peacock, 18 May 2006
# version 0.1
# Tested on MediaWiki 1.6devel, PHP 5.0.5 (apache2handler)
#
# developed to support the notation of lyrics in mediawiki.
# see http://lyricwiki.org/User:TrevorP/Notation
#
# Features:
#  * Allows basic lyric notation
#  * Optional CSS styling embedded in every page
#
# To install, copy this file into "extensions" directory, and add
# the following line to the end of LocalSettings.php
# (above the  ? >  )
#
#   require("extensions/lyric.php");
#

################################################################################
# Extension Credits Definition
#
# This section has no configuration, and can be ignored.
#

$wgExtensionCredits["parserhook"][]=array(
  'name' => 'Lyric Extension',
  'version' => '0.1',
  'url' => 'http://wiki.peacocktech.com/wiki/LyricExtension',
  'author' => '[http://about.peacocktech.com/trevorp/ Trevor Peacock]',
  'description' => 'Adds features allowing easy notation of lyrics in mediawiki' );


################################################################################
# Lyric Render Section
#
# This section has no configuration, and can be ignored.
#
# This section renders <lyric> tags. It forces a html break on every line,
# and styles the section with a css id.
# this id can either be in the mediawiki css files, or defined by the extension
#

#Instruct mediawiki to call LyricExtension to initialise new extension
$wgExtensionFunctions[] = "LyricExtension";

#Install extension
function LyricExtension()
{
  #install hook on the element <lyric>
  global $wgParser;
  $wgParser->setHook("lyric", "renderLyric");
}

#render <lyric> text
function renderLyric($input, $argv)
{
  #make new lines in wikitext new lines in html
  $transform=str_replace(array("\r\n", "\r","\n"), "<br/>", trim($input));

  #define css lyric style
  $transform="<div id=\"lyric\">".$transform."</div>";

  #parse embedded wikitext
  global $wgOut;
  return $wgOut->parse($transform, false);
}

################################################################################
# CSS Styling Section
#
# This section may require configuration.
#
# This section adds a css style to all pages to style lyric sections
#

# If you wish to manually define the style in the css templates,
# add a "#" at the start of this line:
$wgHooks['SkinTemplateSetupPageCss'][] = 'LyricCss';

function LyricCss(&$css) {
  $css = "/*<![CDATA[*/\n".
  "#lyric {\n".
  "	padding: 1em;\n".
  "	border: 1px solid silver;\n".
  "	color: black;\n".
  "	background-color: #ffffcc;\n".
  "}\n".
  "\n/*]]>*/";
  return true;
}

?>
Personal tools