Extension:EnableAbbrTags

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
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) Jeff McNeill (Jeffmcneilltalk)
Last version 0.2 (2007-10-31)
MediaWiki 1.7.3, 1.9.3, 1.11
Database changes no
License No license specified
Download see here
Added rights

Released under GPL 3

Check usage and version matrix

Contents

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]

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

Parameters [edit]

Changes to LocalSettings.php [edit]

require_once("extensions/EnableAbbrTags.php");

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>";
        }
}