From MediaWiki.org
<?php
// Copyright 2006 by Dallan Quass
// Released under the GPL.
// Modified 5-Dec-07 by Matt Collinge (www.mattcollinge.co.uk) to allow wiki tags within notes
require_once("Fotonotes.php");
# Register with MediaWiki as an extension
$wgExtensionFunctions[] = "wfFotonotesExtensionSetup";
//Extension credits that show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Fotonotes',
'author' => array('Dallan Quass', 'Matt Collinge'),
'url' => 'http://www.mediawiki.org/wiki/Extension:Fotonotes',
'description' => 'Add annotations to pages in the Image: namespace'
);
/**
* Callback function for $wgExtensionFunctions; sets up extension
*/
function wfFotonotesExtensionSetup() {
global $wgHooks;
global $wgParser;
# Register hook for edit UI - requires modification too
$wgHooks['ArticleEditShow'][] = 'renderImageEditFields';
# register the extension with the WikiText parser
$wgParser->setHook('fotonotes', 'renderImageData');
}
// Added by MattC 5-Dec-07 for use in the renderImageData function
function unhtmlentities ($string) {
$trans_tbl =get_html_translation_table (HTML_ENTITIES );
$trans_tbl =array_flip ($trans_tbl );
return strtr ($string ,$trans_tbl );
}
/**
* Callback function for converting notes to HTML output
*/
function renderImageData( $input, $argv, $parser) {
// MattC 5-Dec-07. Next bit modified to invoke the Wiki parser to convert links etc.
$output = $parser->parse( $input, $parser->mTitle, $parser->mOptions, true, false );
$outputtxt = unhtmlentities($output->getText());
$image = new Fotonotes($parser->getTitle());
return $image->renderImageNotes( $outputtxt );
}
/**
* Callback function for rendering edit fields
* @return bool must return true or other hooks don't get called
*/
function renderImageEditFields( &$editPage ) {
global $wgOut;
$ns = $editPage->mTitle->getNamespace();
if ($ns == NS_IMAGE && !$editPage->section) {
$image = new Fotonotes($editPage->mTitle);
// get notes
$notes = '';
$start = strpos(strtolower($editPage->textbox1), "<fotonotes>");
if ($start !== false) {
$start += strlen("<fotonotes>");
$end = strpos(strtolower($editPage->textbox1), "</fotonotes>", $start);
if ($end !== false) {
$notes = substr($editPage->textbox1, $start, $end - $start);
}
}
$wgOut->addHTML($image->renderEditableImage($notes));
}
return true;
}