Extension:EnableAbbrTags

From MediaWiki.org

Jump to: navigation, search

           

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Enable Abbr Tags

Release status: experimental

Implementation  Tag
Description Adds <xabbr></xabbr> tags and parses them to <a class(es) href=''></a> tags.
Author(s)  jeffmcneill
Last Version  0.2
MediaWiki  1.7.3, 1.9.3, 1.11
License No license specified
Download no link

check usage (experimental)

Contents

[edit] What can this extension do?

The purpose is to allow abbr tag to be handled to support POSH and microformats. Builds on the AllowAnchorTags extension. Adds support for <xabbr></xabbr> tags and parses them to tags.

[edit] Usage

The URL must be specified in the following format: <xabbr class='some class(es)' title='some title(s)'>Some Text</xabbr>.

  • Both class and title are optional, but including one or the other is sort of the point of this extension.

[edit] Installation

To install/test the extension kindly add it to the end of your LocalSettings.php file in your MediaWiki installation folder.

[edit] Parameters

[edit] Changes to LocalSettings.php

require_once("extensions/EnableAbbrTags.php");

[edit] Code

<?php
/**
 * EnableAbbrTags.php
 * v.0.2 added return codes to run under 1.11
 * This extension enables <abbr></abbr>
 * written by Jeff McNeill http://jeffmcneill.com/
 * building on the work of AllowAnchorTags http://www.mediawiki.org/wiki/Extension:AllowAnchorTags
 * To activate the functionality of this extension include the following in LocalSettings.php file:
 * require_once('extensions/EnableAbbrTags.php');
 */
 
#Defines the main function to be executed for this extension.
$wgExtensionFunctions[] = 'EnableAbbrTag';
 
# Sets the hook to be executed once the parser has stripped HTML tags.
$wgHooks['ParserAfterStrip'][] = 'EnableAbbrTag';
 
# This function initiates the hook for the parser to convert <xabbr></xabbr>
# tags to <abbr></abbr> tags.
function EnableAbbrTag() {
	// Declaring the global parser..
	global $wgParser;
 
	// Setting the hook to parse <xabbr></xabbr> tags from the parser output..
	$wgParser->setHook( 'xabbr', 'startEnableAbbr' );
return(true);
}
 
# This function extracts the parameters from the <xabbr></xabbr> tags and
# the text between the <xabbr> and </xabbr> tags and formats them as "<abbr></abbr>"
# tags and writes them in the document.

function startEnableAbbr( $input, $argv ) {
	// Fetching the 'class' parameter..
	if(isset($argv['class'])) {
		$class = $argv['class'];
	} else {
		$class = '';
	}
 
	// Fetching the 'input' parameter..
	$body = $input;
 
	// Fetching the 'title' parameter.. 
	if(isset($argv['title'])) {
		$title = $argv['title'];
	} else {
		$title = '';
	}
 
	if ($body != '' && $class != '' && $title != '' ) {
		// all three
		return "<abbr" . " class=\"" . $class . "\"" . " title=\"" . $title . "\">" . $body . "</abbr>";
	} else if ($body != '' && $class != '' ) {
		// body and class
		return "<abbr" . " class=\"" . $class . "\">" . $body . "</abbr>";
	} else if ($body != '' && $title != '' ) {
		// body and title
		return "<abbr" . " title=\"" . $title . "\">" . $body . "</abbr>";
	} else if ($body != '' ) {
		// body
		return "<abbr>" . $body . "</abbr>";
	} else {
		// none
		return "<abbr" . " class=\"" . $class . "\"" . " title=\"" . $title . "\">" . $body . "</abbr>";
	}
}
?>

[edit] To-do