Extension:MoodleGlossary

Problem Statement
We have a Moodle site and a Mediawiki-powered wiki. People create glossary entries in Moodle and articles in wiki. If the words in those articles are present in Moodle Glossary, it would be nice to highlight them and provide the definition on mouseover.

This extension does that and it's based on the Glossary Extension created by Benjamin Kahn.

Installation
1. Create the file:

extensions/MoodleGlossary.php
<?php
 * 1) MoodleGlossary MediaWiki Extention
 * 2) Created by Jack Eapen based on Benjamin Kahn's Glossary extyension.
 * 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' => 'MoodleGlossary',        'status' => 'beta',        'type' => 'hook',        'author' => 'Jack Eapen based on code by Benjamin Kahn (xkahn@zoned.net)',        'version' => '1.0',        'update' => '18-07-2007',        'description' => 'Display description of a Moodle Glossary word on mouseover, if that word appears in a wiki article', );

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 global $wgMoodleTablePrefix; global $wgMoodleDBServer; global $wgMoodleDBName; global $wgMoodleDBUser; global $wgMoodleDBPassword; // 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 ;

$conn= mysql_connect($wgMoodleDBServer,$wgMoodleDBUser,$wgMoodleDBPassword) ; mysql_select_db($wgMoodleDBName); $sql='select concept,definition from '.$wgMoodleTablePrefix.'glossary_entries where approved=1'; $result=mysql_query($sql); if($result) { while ($currEmoticon=mysql_fetch_row($result)) {                                        // start by trimming the search value $currEmoticon[ 0 ] = trim( $currEmoticon[ 0 ] ); //Jack-to replace the TRUSTTEXT inserted in Moodle $currEmoticon[ 1 ]= str_replace('#####TRUSTTEXT#####','',$currEmoticon[ 1 ]); // trim the replacement value $currEmoticon[ 1 ] = strip_tags( $currEmoticon[ 1 ] ); $currEmoticon[ 1 ] = trim( $currEmoticon[ 1 ] );

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

// $text=mysql_error; }

$text = preg_replace ($acro, $repl, $text); }            mysql_close($conn); } }

?>

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

LocalSettings.php
require_once("$IP/extensions/MoodleGlossary.php"); $wgMoodleTablePrefix='mdl_'; //Your Moodle table prefix. $wgMoodleDBServer='localhost'; //YOUR_DB_SERVER $wgMoodleDBName='YOUR_MOODLE_DATABASE_NAME'; $wgMoodleDBUser='YOUR_DB_USER_NAME'; $wgMoodleDBPassword='YOUR_DB_PASSWORD';

Known issues

 * 1) The code is now not respecting the wiki links. i.e. if you have a wiki word in the Glossary, that will be highlighted and displayed with the brackets as wiki word.


 * 1) This extension defines (unintentionally?) a &lt;tooltip&gt; tag and may conflict with Extension:Tooltip.

Disclaimer
I'm not an expert programmer. So i'm unaware of the security holes in this. So please try at your own risk. I'm using this in a non-threatening intranet environment. So not much bothered about SQL injection vulnerabilities or similar stuff :) . Feel free to modify the code in the spirit of open source.