Extension:Glossary

What can this extension do?
Ever been reading a technical article with lots and lots of acronyms? Unless you know all the terminology they are using, it can be really frustrating trying to understand what the author means.

This extension allows wiki authors to define a list of acronyms and their definitions on a special page. Whenever that acronym is found, it will be highlighted and mousing over it will reveal the definition in a tooltip.

As a side benefit, it also adds a new tag called 'tooltip' which can be used to make arbitrary tooltips on phrases.

This extension is based on the Extension:Emoticons extension.

Usage
By default, the page "Glossary" without a namespace will be used as the source of acronyms and their definitions. It's also possible to modify the extension to put the definitions in a protected namespace.

To make a tooltip by hand, use this form: This should be the text|This is the tooltip text

Installation
1. Create the file:

extensions/glossary.php
<?php


 * 1) Glossary MediaWiki Extention
 * 2) Created by Benjamin Kahn (xkahn@zoned.net)
 * 3) Based on the Emoticon MediaWiki Extension written by Alex Wollangk (alex@wollangk.com)
 * 1) Based on the Emoticon MediaWiki Extension written by Alex Wollangk (alex@wollangk.com)

if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); }

global $wgHooks; global $wgExtensionCredits;

$wgExtensionFunctions[] = "wfTooltip";

$wgExtensionCredits['parserhook'][] = array(       'name' => 'Glossary',        'status' => 'stable',        'type' => 'hook',        'author' => 'Benjamin Kahn (xkahn@zoned.net) based on code by Alex Wollangk (alex@wollangk.com)',        'version' => '1.0',        'update' => '6-05-2007',        'description' => 'Enable a Glossary within MediaWiki using tooltips.', );

function wfTooltip { global $wgParser; $wgParser->setHook( "tooltip", "tooltip" ); }

$wgHooks['ParserBeforeStrip'][] = 'fnTooltips';

function tooltip ( $input ) { $input = preg_replace ('/XQX/', '', $input); $split = explode("|", $input, 2); return "". $split[0]. " "; }

// The callback function for replacing acronyms with tooltip tags function fnTooltips( &$parser, &$text, &$strip_state ) { global $action; // Access the global "action" variable // Only do the replacement if the action is not edit or history

if(               $action !== 'edit'                && $action !== 'history'                && $action !== 'delete'                && $action !== 'watch'                && $parser->mTitle->getNamespace != NS_SPECIAL                && $parser->mTitle->mNamespace !== 8        ) {

$acro = array ; $repl = array ;

// Get the list of emoticons from the "MediaWiki:Glossary" article. $title = Title::makeTitle( null, 'Glossary' ); $emoticonListArticle = new Article( $title ); $emoticonListArticle->getContent;

// If the content successfully loaded, do the replacement if( $emoticonListArticle->mContentLoaded ) {                       $emoticonList = explode( "\n", $emoticonListArticle->mContent ); foreach( $emoticonList as $index => $emoticon ) {                               $currEmoticon = explode( "//", $emoticon, 2 ); if( count($currEmoticon) == 2 ) {                                       // start by trimming the search value $currEmoticon[ 0 ] = trim( $currEmoticon[ 0 ] ); // if the string begins with, lop it off if( substr( $currEmoticon[ 0 ], 0, 6 ) == ' ' ) {                                               $currEmoticon[ 0 ] = trim( substr( $currEmoticon[ 0 ], 6 ) ); }                                       // trim the replacement value $currEmoticon[ 1 ] = trim( $currEmoticon[ 1 ] );

array_push ($acro, '/(\b)' . $currEmoticon[ 0 ]. '(\b)/'); array_push ($repl, ' XQX' . $currEmoticon[ 0 ] . "XQX|XQX" . $currEmoticon[ 1 ] . 'XQX '); }			}

// and finally perform the replacement $text = preg_replace ($acro, $repl, $text); }       } }

?>

2. Add the following to the end of: (right above the "?>" at the end)

LocalSettings.php
require_once( "extensions/glossary.php" );

3. Create the page "Glossary"

4. Add one line to this page for each acronym. Each line contains the text to be replaced followed by "//" followed by the text to replace it with. See discussion for alternative glossary formats.

Sample Glossary
FTP//File Transport Protocol AAAAA//American Association Against Acronym Abuse ACK//Acknowledge AFAIK//As Far As I Know AWGTHTGTATA//Are We Going To Have To Go Through All This Again HTTP//HyperText Transfer Protocol

Parameters
To lock down the glossary, modify the glossary.php file.

Find the line:

$title = Title::makeTitle( null, 'Glossary' );

and change it to:

$title = Title::makeTitle( 8, 'Glossary' );

The Glossary will now be located at:

MediaWiki:Glossary

Changes to LocalSettings.php
require_once("$IP/extensions/glossary.php");