[MediaWiki-l] OpenSeadragon - extension "ZoomableImages" ... working experimental

Dr. Michael Bonert michael at librepathology.org
Thu Nov 3 02:25:47 UTC 2016


Bawolff, Daniel or anyone else out there:

Is there interest in helping create a 'ZoomableImages' extension?

I am have some working code (below)... it would need a security audit  
and bit more polish.

I started a page for the extension on MediaWiki --  
https://www.mediawiki.org/wiki/Extension:ZoomableImages

Previously reported stuff on Phabricator... but I think the account is locked.

Reading about uploading...

Michael



ZoomableImages.php
----------------------------------------------------------------
<?php

/**
  * @extension ZoomableImages
  * @author Michael Bonert (AKA: Nephron)
  * @copyright © 2016 Michael Bonert
  * @licence GNU General Public Licence Version 2.0+
  * @description allow use of deep zoom images (DZI) via OpenSeadragon
  */

// Extension credits that will show up on Special:Version
$wgExtensionCredits['tag'][] = array(
         'name' => "ZoomableImages",
         'author' => "Michael Bonert",
         'description' => "Extension to allow use of zoomable images  
using the OpenSeadragon viewer",
         'version' => "0.1",
         'license-name' => "GPL-2.0+",
);

$wgAutoloadClasses['ZoomableImages'] = $IP .  
'/extensions/ZoomableImages/ZoomableImages_body.php';
$wgHooks['ParserFirstCallInit'][] = 'ZoomableImages::onParserInit';
?>
----------------------------------------------------------------



ZoomableImages_body.php
----------------------------------------------------------------
<?php
class ZoomableImages {
	static function onParserInit( Parser $parser ) {
		$parser->setHook( 'zoomableimage', array( __CLASS__,  
'zoomableimageRender' ) );
		return true;
	}
	static function zoomableimageRender( $input, array $args, Parser  
$parser, PPFrame $frame ) {
		$attr = array();
		// make a list of attributes and their values and dump them along  
with the user input

		// initialize 'width' and 'height'
		$zimage_width = -1;
		$zimage_height = -1;

		foreach( $args as $name => $value )  {
		  $attr[] = '<strong>' . htmlspecialchars( $name ) . '</strong> = '  
. htmlspecialchars( $value );
		  // get 'width', 'height' and 'name'
		  if ( $name == 'name') {
		    $zimage_name= $value;
		    }
		  if ( $name == 'width' ) {
		    $zimage_width = $value;
		    }
		  if ( $name == 'height' ) {
		    $zimage_height = $value;
		    }
		  }

		// if 'width' and 'height' not defined set default values
		if ( $zimage_width == -1 ) {
		  $zimage_width=400;
		  }
		if ( $zimage_height == -1 ) {
		  $zimage_width=300;
		  }

		$ret = '<table>';
		$ret .= '<tr>';
		$ret .= '<!-- OpenSeadragon zoomable image -->';
		$ret .= '<div id="openseadragon1" style="width: ' . $zimage_width .  
'px; height:' . $zimage_height . 'px;"></div>';
		$ret .= '<script  
src="../extensions/ZoomableImages/openseadragon/openseadragon.min.js"></script>';
		$ret .= '<script type="text/javascript"> var viewer =  
OpenSeadragon({ id: "openseadragon1", prefixUrl:  
"../extensions/ZoomableImages/openseadragon/images/", tileSources:  
"../images/zimages/' . $zimage_name . '" });</script>';
		$ret .= '</tr>';
		$ret .= '</table>';
		return $ret;
	}
}
----------------------------------------------------------------



extension.json
----------------------------------------------------------------
{
	"name": "ZoomableImages",
	"author": [
		"Michael Bonert"
	],
	"license-name": "GPL-2.0+",
	"url": "https://www.mediawiki.org/wiki/Extension:ZoomableImages",
	"descriptionmsg": "zoomableimages-desc",
	"type": "parserhook",
	"MessagesDirs": {
		"ZoomableImages": [
		]
	},
	"Hooks": {
		"ParserFirstCallInit": [
			"ZoomableImages::init"
		]
	},
	"manifest_version": 1
}
----------------------------------------------------------------




More information about the MediaWiki-l mailing list