Extension:Fotonotes/FotonotesExt.php

From MediaWiki.org

Jump to: navigation, search
<?php
// Copyright 2006 by Dallan Quass
// Released under the GPL.
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' => 'Dallan Quass',
        '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 to
	$wgHooks['ArticleEditShow'][] = 'renderImageEditFields';
 
	# register the extension with the WikiText parser
	$wgParser->setHook('fotonotes', 'renderImageData');
}
 
/**
 * Callback function for converting notes to HTML output
 */
function renderImageData( $input, $argv, $parser) {
	$image = new Fotonotes($parser->getTitle());
	return $image->renderImageNotes($input);
}
 
/**
 * 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 = stripos($editPage->textbox1, "<fotonotes>");
      if ($start !== false) {
   	   $start += strlen("<fotonotes>");
	  	   $end = stripos($editPage->textbox1, "</fotonotes>", $start);
		   if ($end !== false) {
		      $notes = substr($editPage->textbox1, $start, $end - $start);
		   }
		}
		$wgOut->addHTML($image->renderEditableImage($notes));
	}
	return true;
}
Personal tools