Difference between revisions of "Extension:SimpleViewer.php"
(update: semi working, flash initialises, just need to link in image source article) |
(update semi working) |
||
Line 9: | Line 9: | ||
define('SIMPLEVIEWER_VERSION','0.0.1'); | define('SIMPLEVIEWER_VERSION','0.0.1'); | ||
− | $egSimpleViewerMagic | + | $egSimpleViewerMagic = "simpleviewer"; |
− | $wgExtensionFunctions[] | + | $wgExtensionFunctions[] = 'efSetupSimpleViewer'; |
+ | $wgExtensionFunctions[] = 'wfSetupSpecialSimpleViewer'; | ||
+ | |||
$wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic'; | $wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic'; | ||
Line 20: | Line 22: | ||
'version' => SIMPLEVIEWER_VERSION | 'version' => SIMPLEVIEWER_VERSION | ||
); | ); | ||
− | + | ||
+ | $wgExtensionCredits['specialpage'][] = array( | ||
+ | 'name' => 'Special:SimpleViewer', | ||
+ | 'author' => '[http://www.organicdesign.co.nz/User:Rob User:Rob]', | ||
+ | 'description' => 'Mediawiki integration with SimpleViewer from [http://www.airtightinteractive.com/simpleviewer Airtight interactive].', | ||
+ | 'url' => 'http://www.organicdesign.co.nz/Extension:SimpleViewer.php', | ||
+ | 'version' => SIMPLEVIEWER_VERSION | ||
+ | ); | ||
+ | |||
+ | require_once "$IP/includes/SpecialPage.php"; | ||
+ | |||
class SimpleViewer { | class SimpleViewer { | ||
Line 41: | Line 53: | ||
# Expand the simpleviewer-magic | # Expand the simpleviewer-magic | ||
function magicSimpleviewer(&$parser) { | function magicSimpleviewer(&$parser) { | ||
− | global $egSimpleViewerMagic, $wgOut, $wgScriptPath; | + | global $egSimpleViewerMagic, $wgOut, $wgScriptPath, $wgParser, $wgCanonicalNamespaceNames; |
# Populate $argv with both named and numeric parameters | # Populate $argv with both named and numeric parameters | ||
$argv = array(); | $argv = array(); | ||
Line 47: | Line 59: | ||
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; | if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | |||
/* @params | /* @params | ||
src - page containing a bullet list of images | src - page containing a bullet list of images | ||
Line 69: | Line 76: | ||
enableRightClickOpen - Whether to display a 'Open In new Window...' dialog when right-clicking on an image. Can be "true" or "false" | 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 | backgroundImagePath (optional) - Relative or absolute path to a JPG or SWF to load as the | ||
− | |||
− | |||
− | |||
*/ | */ | ||
+ | $title = Title::newFromText($argv['src']); | ||
+ | $ns = $title->getNsText(); | ||
+ | $db = $title->getDBkey(); | ||
+ | $urlsafe = "$ns:$db"; | ||
+ | |||
# add the javascript and build the embed code | # add the javascript and build the embed code | ||
$wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/SimpleViewer/simpleviewer/swfobject.js\"></script>"); | $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/SimpleViewer/simpleviewer/swfobject.js\"></script>"); | ||
− | $script = "<script type='text/javascript'>var fo = new SWFObject('$wgScriptPath/extensions/SimpleViewer/simpleviewer/viewer.swf?a', 'viewer', '100%', '500px', '7', '#000000'); fo.addVariable('preloaderColor', '0xaaaaaa'); fo.addVariable('xmlDataPath', ' | + | $script = "<div id='flashcontent'>SimpleViewer requires Macromedia Flash. <a href='http://www.macromedia.com/go/getflashplayer/'>Get Macromedia Flash.</a> If you have Flash installed, <a href='index.html?detectflash=false'>click to view gallery</a>.</div> |
+ | <script type='text/javascript'>var fo = new SWFObject('$wgScriptPath/extensions/SimpleViewer/simpleviewer/viewer.swf?a', 'viewer', '100%', '500px', '7', '#000000'); fo.addVariable('preloaderColor', '0xaaaaaa'); fo.addVariable('xmlDataPath', 'http://mintmedia.co.nz/research/index.php/Mint_Media:Test?action=render'); fo.write('flashcontent');</script>"; | ||
+ | |||
+ | # $wgScriptPath/index.php/Special:SpecialSimpleViewer?src=".$urlsafe." | ||
+ | # /research/index.php/Special:SpecialSimpleViewer?src=Mint_Media:Gallery | ||
+ | # $script = $wikitext; | ||
# Return result with available parser flags | # Return result with available parser flags | ||
return array( | return array( | ||
− | + | $script, | |
'noparse' => true, | 'noparse' => true, | ||
'isHTML' => true | 'isHTML' => true | ||
Line 90: | Line 104: | ||
function __toString() { return 'SimpleViewer'; } | function __toString() { return 'SimpleViewer'; } | ||
} | } | ||
+ | |||
+ | class SpecialSpecialSimpleViewer extends SpecialPage { | ||
+ | |||
+ | # Constructor | ||
+ | function __construct() { | ||
+ | SpecialPage::SpecialPage( | ||
+ | 'SpecialSimpleViewer', # name as seen in links etc | ||
+ | '*', # user rights required | ||
+ | false, # listed in special:specialpages | ||
+ | false, # function called by execute() - defaults to wfSpecial{$name} | ||
+ | false, # file included by execute() - defaults to Special{$name}.php, only used if no function | ||
+ | false # includable | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | # Override SpecialPage::execute() | ||
+ | # - $param is from the URL, eg Special:SpecialSimpleViewer/param | ||
+ | function execute($param) { | ||
+ | global $wgOut, $wgCanonicalNamespaceNames, $wgParser, $wgScriptPath; | ||
+ | #$this->setHeaders(); | ||
+ | #$title = Title::makeTitle(NS_SPECIAL,'SpecialSimpleViewer'); | ||
+ | |||
+ | # get article content | ||
+ | $title = Title::newFromText($_REQUEST['src']); | ||
+ | if(!$title) | ||
+ | return; | ||
+ | $article = new Article($title); | ||
+ | $wikitext = $article->getContent(); | ||
+ | $wikitext = $wgParser->preprocess($wikitext,$title,new ParserOptions()); | ||
+ | |||
+ | # $wikitext = <UL><LI>[[:Image:Industrial-design-a-to-z.jpg|Image:Industrial-design-a-to-z.jpg]]</LI><LI> etc | ||
+ | $ns_image = $wgCanonicalNamespaceNames[NS_IMAGE]; | ||
+ | preg_match_all("|".$ns_image.":([a-z-_.]+?)\]|i", $wikitext, $image); | ||
+ | |||
+ | $wgOut->setArticleBodyOnly(true); | ||
+ | print("<?xml version='1.0' encoding='UTF-8'?> | ||
+ | <simpleviewerGallery maxImageWidth='600' maxImageHeight='600' textColor='0x000000' frameColor='0x000000' frameWidth='2' stagePadding='40' thumbnailColumns='3' thumbnailRows='3' navPosition='left' title='Computer Science Christmas party 2007' enableRightClickOpen='true' backgroundImagePath='' imagePath='' thumbPath=''>"); | ||
+ | |||
+ | foreach($image[1] as $i) { | ||
+ | print("<image><filename>$wgScriptPath/thumb.php?f=$i&width=500</filename><caption>Arles old town.</caption></image>\n"); | ||
+ | } | ||
+ | print("</simpleviewerGallery>"); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
Line 96: | Line 156: | ||
$egSimpleViewer = new SimpleViewer(); | $egSimpleViewer = new SimpleViewer(); | ||
} | } | ||
− | + | ||
+ | function wfSetupSpecialSimpleViewer() { | ||
+ | global $wgLanguageCode,$wgMessageCache; | ||
+ | |||
+ | # Add the messages used by the specialpage | ||
+ | if ($wgLanguageCode == 'en') { | ||
+ | $wgMessageCache->addMessages(array( | ||
+ | 'specialsimpleviewer' => 'SimpleGallery', # The friendly page title | ||
+ | 'exampleMessage' => "Example message: <tt>$1</tt>", | ||
+ | )); | ||
+ | } | ||
+ | |||
+ | # Add the specialpage to the environment | ||
+ | SpecialPage::addPage(new SpecialSpecialSimpleViewer()); | ||
+ | } | ||
+ | |||
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly | # Needed in MediaWiki >1.8.0 for magic word hooks to work properly | ||
function efSimpleViewerLanguageGetMagic(&$magicWords,$langCode = 0) { | function efSimpleViewerLanguageGetMagic(&$magicWords,$langCode = 0) { |
Revision as of 04:31, 31 March 2008
<?php
- Extension:SimpleViewer
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:RobCategory:Extensions created with Template:Extension
- Template:Php
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('SIMPLEVIEWER_VERSION','0.0.1');
$egSimpleViewerMagic = "simpleviewer"; $wgExtensionFunctions[] = 'efSetupSimpleViewer'; $wgExtensionFunctions[] = 'wfSetupSpecialSimpleViewer';
$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 );
$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:SimpleViewer', 'author' => 'User:Rob', 'description' => 'Mediawiki integration with SimpleViewer from Airtight interactive.', 'url' => 'http://www.organicdesign.co.nz/Extension:SimpleViewer.php', 'version' => SIMPLEVIEWER_VERSION );
require_once "$IP/includes/SpecialPage.php";
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, $wgOut, $wgScriptPath, $wgParser, $wgCanonicalNamespaceNames; # 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; }
/* @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 */
$title = Title::newFromText($argv['src']); $ns = $title->getNsText(); $db = $title->getDBkey(); $urlsafe = "$ns:$db";
# add the javascript and build the embed code
$wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/SimpleViewer/simpleviewer/swfobject.js\"></script>");
$script = "
<script type='text/javascript'>var fo = new SWFObject('$wgScriptPath/extensions/SimpleViewer/simpleviewer/viewer.swf?a', 'viewer', '100%', '500px', '7', '#000000'); fo.addVariable('preloaderColor', '0xaaaaaa'); fo.addVariable('xmlDataPath', 'http://mintmedia.co.nz/research/index.php/Mint_Media:Test?action=render'); fo.write('flashcontent');</script>";
- $wgScriptPath/index.php/Special:SpecialSimpleViewer?src=".$urlsafe."
- /research/index.php/Special:SpecialSimpleViewer?src=Mint_Media:Gallery
- $script = $wikitext;
# Return result with available parser flags return array( $script, 'noparse' => true, 'isHTML' => true );
}
# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'SimpleViewer'; }
}
class SpecialSpecialSimpleViewer extends SpecialPage {
# Constructor function __construct() { SpecialPage::SpecialPage( 'SpecialSimpleViewer', # name as seen in links etc '*', # user rights required false, # listed in special:specialpages false, # function called by execute() - defaults to wfSpecial{$name} false, # file included by execute() - defaults to Special{$name}.php, only used if no function false # includable ); }
# Override SpecialPage::execute() # - $param is from the URL, eg Special:SpecialSimpleViewer/param function execute($param) { global $wgOut, $wgCanonicalNamespaceNames, $wgParser, $wgScriptPath; #$this->setHeaders(); #$title = Title::makeTitle(NS_SPECIAL,'SpecialSimpleViewer');
# get article content
$title = Title::newFromText($_REQUEST['src']);
if(!$title) return;
$article = new Article($title); $wikitext = $article->getContent();
$wikitext = $wgParser->preprocess($wikitext,$title,new ParserOptions());
# $wikitext =
- Image:Industrial-design-a-to-z.jpg
- etc
$ns_image = $wgCanonicalNamespaceNames[NS_IMAGE]; preg_match_all("|".$ns_image.":([a-z-_.]+?)\]|i", $wikitext, $image);
$wgOut->setArticleBodyOnly(true); print("<?xml version='1.0' encoding='UTF-8'?> <simpleviewerGallery maxImageWidth='600' maxImageHeight='600' textColor='0x000000' frameColor='0x000000' frameWidth='2' stagePadding='40' thumbnailColumns='3' thumbnailRows='3' navPosition='left' title='Computer Science Christmas party 2007' enableRightClickOpen='true' backgroundImagePath= imagePath= thumbPath=>");
foreach($image[1] as $i) { print("<image><filename>$wgScriptPath/thumb.php?f=$i&width=500</filename>Arles old town.</image>\n"); } print("</simpleviewerGallery>"); }
}
- Called from $wgExtensionFunctions array when initialising extensions
function efSetupSimpleViewer() { global $egSimpleViewer; $egSimpleViewer = new SimpleViewer(); }
function wfSetupSpecialSimpleViewer() { global $wgLanguageCode,$wgMessageCache;
# Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'specialsimpleviewer' => 'SimpleGallery', # The friendly page title 'exampleMessage' => "Example message: $1", )); }
# Add the specialpage to the environment SpecialPage::addPage(new SpecialSpecialSimpleViewer()); }
- 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; }