Difference between revisions of "Extension:SimpleViewer.php"

From Organic Design wiki
(add template)
 
(update: semi working, flash initialises, just need to link in image source article)
Line 3: Line 3:
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Author: [http://www.organicdesign.co.nz/User:Rob User:Rob]{{Category:Extensions created with Template:Extension}}
 
# - Author: [http://www.organicdesign.co.nz/User:Rob User:Rob]{{Category:Extensions created with Template:Extension}}
 +
#{{php}}
 
   
 
   
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
Line 40: Line 41:
 
# Expand the simpleviewer-magic
 
# Expand the simpleviewer-magic
 
function magicSimpleviewer(&$parser) {
 
function magicSimpleviewer(&$parser) {
global $egSimpleViewerMagic;
+
global $egSimpleViewerMagic, $wgOut, $wgScriptPath;
 
# Populate $argv with both named and numeric parameters
 
# Populate $argv with both named and numeric parameters
 
$argv = array();
 
$argv = array();
Line 68: Line 69:
 
         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
       
+
 
 +
 
 
          
 
          
 
         */
 
         */
+
       
    global $wgOut;
+
        # add the javascript and build the embed code
$wgOut->addScript("<script type=\"text/javascript\">alert('Hello world! I'm s javascript')</script>\n");
+
$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', '$wgScriptPath/extensions/SimpleViewer/SimpleViewer/gallery.xml'); fo.write('flashcontent');</script>";
 +
 
# Return result with available parser flags
 
# Return result with available parser flags
 
return array(
 
return array(
$text,
+
"<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",
 
'noparse' => true,
 
'noparse' => true,
 
'isHTML'  => true
 
'isHTML'  => true

Revision as of 10:30, 30 March 2008

<?php

  1. Extension:SimpleViewer
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:RobCategory:Extensions created with Template:Extension
  3. Template:Php

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, $wgOut, $wgScriptPath; # 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


       */
       
       # 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', '$wgScriptPath/extensions/SimpleViewer/SimpleViewer/gallery.xml'); fo.write('flashcontent');</script>";

# Return result with available parser flags return array(

"

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>.

$script",

'noparse' => true, 'isHTML' => true );

}

# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'SimpleViewer'; }

	}

  1. Called from $wgExtensionFunctions array when initialising extensions

function efSetupSimpleViewer() { global $egSimpleViewer; $egSimpleViewer = new SimpleViewer(); }

  1. 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; }