Extension:EnableAbbrTags

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
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) Jeff McNeill (Jeffmcneilltalk)
Latest version 0.2 (2007-10-31)
MediaWiki 1.7.3, 1.9.3, 1.11
Database changes No
License GNU General Public License 3.0
Download see here
Translate the EnableAbbrTags extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?[edit]

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.

Usage[edit]

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.

Installation[edit]

  • Download and place the file(s) in a directory called EnableAbbrTags in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/EnableAbbrTags/EnableAbbrTags.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit]

<?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 https://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>";
	}
}