Extension:SimpleViewer.php
<?php
- Extension:SimpleViewer
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:RobCategory:Extensions created with Template:Extension
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('SIMPLEVIEWER_VERSION','0.0.1');
$egSimpleViewerMagic = "simpleviewer"; $wgExtensionFunctions[] = 'efSetupSimpleViewer'; $wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'SimpleViewer', 'author' => 'User:Rob', 'description' => 'Mediawiki integration with SimpleViewer from Airtight interactive', 'url' => 'http://www.organicdesign.co.nz/Extension:SimpleViewer.php', 'version' => SIMPLEVIEWER_VERSION );
class SimpleViewer {
# Properties var $prop1 = 'default value'; var $prop2 = 'default value';
# Constructor function __construct() { global $wgHooks,$wgParser,$egSimpleViewerMagic,$egSimpleViewerTag;
# Add the parser-function $wgParser->setFunctionHook($egSimpleViewerMagic,array($this,'magicSimpleviewer'));
# Add the tagHook $wgParser->setHook($egSimpleViewerTag,array($this,'tagSimpleviewer'));
}
# Expand the simpleviewer-magic function magicSimpleviewer(&$parser) { global $egSimpleViewerMagic; # Populate $argv with both named and numeric parameters $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; }
# Build text of expanded result $args = ; foreach ($argv as $k => $v) $args .= "*$k: $v\n"; $args = htmlspecialchars($args);
/* @params src - page containing a bullet list of images :: what follows are taken directly from the SimpleViewer docs maxImageWidth - width of your largest image in pixels. Used to determine the best layout for your gallery. maxImageHeight - height of your largest image in pixels. Used to determine the best layout for your gallery. textColor - Color of title and caption text (hexidecimal color value e.g 0xff00ff). frameColor - Color of image frame, navigation buttons and thumbnail frame (hexidecimal color value e.g 0xff00ff). frameWidth - Width of image frame in pixels. stagePadding - Distance between image and thumbnails and around gallery edge in pixels. thumbnailColumns - number of thumbnail rows. (To disable thumbnails completely set this value to 0.) thumbnailRows - number of thumbnail columns. (To disable thumbnails completely set this value to 0.) navPosition - Position of thumbnails relative to image. Can be "top", "bottom","left" or "right". title - Text to display as gallery Title enableRightClickOpen - Whether to display a 'Open In new Window...' dialog when right-clicking on an image. Can be "true" or "false" backgroundImagePath (optional) - Relative or absolute path to a JPG or SWF to load as the */ global $wgOut;
$wgOut->addScript("<script type=\"text/javascript\">alert('Hello world! I'm s javascript')</script>\n");
# Return result with available parser flags return array( $text, 'noparse' => true, 'isHTML' => true );
}
# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'SimpleViewer'; }
}
- Called from $wgExtensionFunctions array when initialising extensions
function efSetupSimpleViewer() { global $egSimpleViewer; $egSimpleViewer = new SimpleViewer(); }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function efSimpleViewerLanguageGetMagic(&$magicWords,$langCode = 0) { global $egSimpleViewerMagic; $magicWords[$egSimpleViewerMagic] = array(0,$egSimpleViewerMagic); return true; }