Difference between revisions of "Extension:SimpleViewer.php"

From Organic Design wiki
m (update works)
(mostly working but needs a tidy up)
 
(6 intermediate revisions by 2 users not shown)
Line 10: Line 10:
 
   
 
   
 
$egSimpleViewerMagic            = "simpleviewer";
 
$egSimpleViewerMagic            = "simpleviewer";
#$wgHooks['ParserBeforeStrip'][] = 'efSetupSimpleViewer';
+
$egSimpleViewEnableHook        = true;
 
$wgExtensionFunctions[]        = 'efSetupSimpleViewer';
 
$wgExtensionFunctions[]        = 'efSetupSimpleViewer';
#$wgExtensionFunctions[] = 'wfSetupSpecialSimpleViewer';
+
$wgHooks['ParserBeforeStrip'][] = 'efSimpleViewer';
 +
$wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic';
 +
 
 
$wgSimpleViewerUrlMagic        = "magic_magic";
 
$wgSimpleViewerUrlMagic        = "magic_magic";
 
$wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic';
 
 
   
 
   
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 25: Line 25:
 
);
 
);
  
$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 {
 
# Properties
 
var $prop1 = 'default value';
 
var $prop2 = 'default value';
 
 
   
 
   
 
# Constructor
 
# Constructor
Line 47: Line 34:
 
# Add the parser-function
 
# Add the parser-function
 
$wgParser->setFunctionHook($egSimpleViewerMagic,array($this,'magicSimpleviewer'));
 
$wgParser->setFunctionHook($egSimpleViewerMagic,array($this,'magicSimpleviewer'));
+
 
# Add the tagHook
 
$wgParser->setHook($egSimpleViewerTag,array($this,'tagSimpleviewer'));
 
 
 
}
 
}
 
   
 
   
Line 64: Line 48:
 
         # list of keys that the parser funtion will accept
 
         # list of keys that the parser funtion will accept
 
         # src is not included here because it is not passed on to the javascript
 
         # src is not included here because it is not passed on to the javascript
         $passparams = array('maxImageWidth', 'maxImageHeight', 'textColor', 'textColor',  
+
        # format: key => regexp validation, default value
             'frameWidth', 'stagePadding', 'thumbnailColumns', 'thumbnailRows',  
+
         $passparams = array(
             'navPosition', 'title', 'enableRightClickOpen');
+
            'maxImageWidth'        => array('/(\d+)/', 600 ),
 +
            'maxImageHeight'       => array('/(\d+)/', 600),
 +
            'textColor'            => array('/(0x\d{6})/i', '0xffffff'),
 +
            'frameColor'            => array('/(0x\d{6})/i', '0xaaaaaa'),  
 +
             'frameWidth'           => array('/(\d+)/', 2),
 +
            'stagePadding'          => array('/(\d+)/', 40),
 +
            'thumbnailColumns'     => array('/(\d+)/', 3),
 +
            'thumbnailRows'         => array('/(\d+)/', 3),
 +
             'navPosition'          => array('/(left|right)/', 'left'),
 +
            'title'                 => array('/(.*)/', ''),
 +
            'enableRightClickOpen' => array('/(true|false)/i', 'true')
 +
            );
 
 
 
 
 
/*foreach($argv as $key => $value) {
 
/*foreach($argv as $key => $value) {
  if(in_array($key, $passparams))
+
  if(array_key_exists($key, $passparams)) {
      $variables .= "fo.addVariable('$key', '$value'); ";
+
      if(preg_match($passparams[$key][0], $v, $match) != 0) {
        }
+
          $variables .= "fo.addVariable('$key', '".$match[1][0]."'); ";
         */
+
          }
    /* @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).
 
        textColor - 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']);
 
$title = Title::newFromText($argv['src']);
 +
if(!$title->exists())
 +
return array("==SimpleViewer==\n\n''src'' parameter: No such article exists\n\nCreate it: [[".$argv['src']."]]",
 +
'found' => true,
 +
'nowiki' => false,
 +
'noparse' => false,
 +
'noargs' => false,
 +
'isHTML' => false );
 +
 
$ns = $title->getNsText();
 
$ns = $title->getNsText();
 
$db = $title->getDBkey();
 
$db = $title->getDBkey();
 
$urlsafe = $ns.$wgSimpleViewerUrlMagic.$db;
 
$urlsafe = $ns.$wgSimpleViewerUrlMagic.$db;
+
       
    #$wgParser->disableCache();
+
        # construct wikitext with <gallery> tags for use where flash is not available
         #$wgOut->setHeaders();
+
         # get title
 
+
        # get article
 +
        /* eg html gallery
 +
        <gallery widths="250px" heights="250px" perrow="3">
 +
Image:Speak,-memory,-an-autobiography.jpg|{{Image:Speak,-memory,-an-autobiography.jpg}}
 +
        */
  
 
         # 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>");
+
$script = "<div id='flashcontent'>There was a problem. Please <a href='mailto:rob@mintmedia.co.nz?subject=problem with content'>tell me about it.</a></div>\n<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/index.php/SpecialSimpleViewer/$urlsafe'); ".$variables."fo.write('flashcontent');</script>";
$script = "<div id='flashcontent'>There was a problem. Please <a href='mailto:rob@mintmedia.co.nz?subject=problem with content'>tell me about it.</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', '$wgScriptPath/index.php/SpecialSimpleViewer/$urlsafe'); ".$variables."fo.write('flashcontent');</script>";
 
  
# /research/extensions/SimpleViewer/simpleviewer/Special:Test.xml
 
 
# /research/index.php/Special:SpecialSimpleViewer/Mint_Media:Gallery
 
 
# $wgScriptPath/index.php/Special:SpecialSimpleViewer/$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(
Line 126: Line 110:
 
  }
 
  }
  
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) {
 
 
}
 
 
}
 
 
 
# Called from $wgExtensionFunctions array when initialising extensions
 
 
function efSetupSimpleViewer() {
 
function efSetupSimpleViewer() {
global $egSimpleViewer, $wgSimpleViewerUrlMagic, $wgOut, $wgCanonicalNamespaceNames, $wgParser, $wgScriptPath;
+
    global $wgOut, $wgScriptPath;
 +
  $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/SimpleViewer/simpleviewer/swfobject.js\"></script>");
 +
  }
  
 +
function efSimpleViewer( &$parser ) {
 +
global $egSimpleViewer, $wgSimpleViewerUrlMagic, $wgOut, $wgCanonicalNamespaceNames, $wgScriptPath, $wgServer, $egSimpleViewEnableHook;
 +
if (!$egSimpleViewEnableHook) return true;
 +
# add script in all cases,client caches external js file so not too bad for efficiency
  
 
$egSimpleViewer = new SimpleViewer();
 
$egSimpleViewer = new SimpleViewer();
Line 160: Line 126:
 
     if(preg_match("#^SpecialSimpleViewer/#", $_REQUEST['title'])) {
 
     if(preg_match("#^SpecialSimpleViewer/#", $_REQUEST['title'])) {
 
      
 
      
    # is this an image request?
+
header('Content-Type: text/xml');
    $m = preg_match_all("#SpecialSimpleViewer/images/(\d+)/(.+)#i", $_REQUEST['title'], $matches, PREG_SET_ORDER);
+
    $size = $matches[0][1];
+
$wgOut->disable();
    $file = $matches[0][2];
+
wfResetOutputBuffers();
  
    # if the url is of the form Special:SpecialSimpleViewer/images/200/foo.jpg
+
# is this an image request?
    # then send a redirect to get thumb.php to do the resizing
+
$m = preg_match_all("#SpecialSimpleViewer/images/(\d+)/(.+)#i", $_REQUEST['title'], $matches, PREG_SET_ORDER);
    if($m > 0) {
+
$size = $matches[0][1];
      header("Location: $wgScriptPath/thumb.php?f=$file&width=$size");
+
$file = $matches[0][2];
      exit;
 
      }
 
  
    # Redirect can make things a bit slower so may provide the image directly in future
+
# if the url is of the form Special:SpecialSimpleViewer/images/200/foo.jpg
   
+
# then send a redirect to get thumb.php to do the resizing
    # if we got this far it's not an image and we should output an XML file
+
if($m > 0) {
 +
  header("Location: $wgScriptPath/thumb.php?f=$file&width=$size");
 +
  return false;
 +
  }
  
    $wgParser->disableCache();
+
    $wgOut->setHeaders();
+
# if we got this far it's not an image and we should output an XML file
  
    header('Content-Type: text/xml');
+
# params:
    # params:
+
# src = article name containing a list of images for the gallery, article may also contain a DPL query
    # src = article name containing a list of images for the gallery, article may also contain a DPL query
+
   
+
preg_match_all("#SpecialSimpleViewer/(.+)$#", $_REQUEST['title'], $matches, PREG_SET_ORDER);
    preg_match_all("#SpecialSimpleViewer/(.+)$#", $_REQUEST['title'], $matches, PREG_SET_ORDER);
+
#print_r($matches);
    #print_r($matches);
+
$t = str_replace($wgSimpleViewerUrlMagic, ':', $matches[0][1]);
    $t = str_replace($wgSimpleViewerUrlMagic, ':', $matches[0][1]);
+
#print($t);
    #print($t);
 
  
    # get article content
+
# get article content
    $title    = Title::newFromText($t);
+
$title    = Title::newFromText($t);
    # if the image article does not exist exit
+
# if the image article does not exist exit
    if(!$title) {
+
if(!$title) {
    print "does not exist";
+
print "title not valid";
        $wgOut->disable();
+
return false;
        wfResetOutputBuffers();
+
}
        return;
+
    }
+
$article  = new Article($title);
 +
$content = $article->getContent();
 +
$egSimpleViewEnableHook = false;
  
 +
$wikitext = $parser->preprocess( $content, $title, $parser->getOptions() );
 +
 +
# make a list of image names excluding the namespace (Image:)
 +
$ns_image = $wgCanonicalNamespaceNames[NS_IMAGE];
 +
#print_r($wikitext);
  
    $article  = new Article($title);
+
preg_match_all("/\[\[:?".$ns_image.":(.+?)(\||\]\])/mi", $wikitext, $image);
    $wikitext = $article->getContent();
+
if(count($image[1]) == 0 )
   
+
    preg_match_all("/\*\s*".$ns_image.":(.+?)\s*$/mi", $wikitext, $image);
    # parse the wikitext to expand templates and parser functions
+
    #$wgParser = new Parser();
+
# standard header, other options to add later
   
+
print("<?xml version='1.0' encoding='UTF-8'?>
    #$wikitext = $wgParser->preprocess($wikitext, $title,new ParserOptions());
+
<simpleviewerGallery maxImageWidth='600' maxImageHeight='600' textColor='0xffffff' frameColor='0xaaaaaa' frameWidth='2' stagePadding='40' thumbnailColumns='3' thumbnailRows='3' navPosition='left' title='' enableRightClickOpen='true' backgroundImagePath='' imagePath='$wgScriptPath/index.php/SpecialSimpleViewer/images/500/' thumbPath='$wgScriptPath/index.php/SpecialSimpleViewer/images/100/'>");
 +
# simpleviewer requires a TRAILING / on the imagePath and thumbPath params
  
    #print($wikitext);
 
   
 
    # need some heiristics here to handle a few reasonable image-article-list formats
 
    # we accept the default output format of DPL for now
 
   
 
    # $wikitext = <UL><LI>[[:Image:Industrial-design-a-to-z.jpg|Image:Industrial-design-a-to-z.jpg]]</LI><LI> etc
 
   
 
    # make a list of image names excluding the namespace (Image:)
 
    $ns_image = $wgCanonicalNamespaceNames[NS_IMAGE];
 
    preg_match_all("|".$ns_image.":(.+?)$|mi", $wikitext, $image);
 
    #print_r($image);
 
  
   
+
# loop and generate <image> containers
    # standard header, other options to add later
+
foreach($image[1] as $i) {
    print("<?xml version='1.0' encoding='UTF-8'?>
+
#$html = htmlentities(file_get_contents("$wgServer$wgScriptPath/index.php/$ns_image:$i?action=render"));
<simpleviewerGallery maxImageWidth='600' maxImageHeight='600' textColor='0xffffff' frameColor='0xaaaaaa' frameWidth='2' stagePadding='40' thumbnailColumns='3' thumbnailRows='3' navPosition='left' title='' enableRightClickOpen='true' backgroundImagePath='' imagePath='$wgScriptPath/index.php/SpecialSimpleViewer/images/500/' thumbPath='$wgScriptPath/index.php/SpecialSimpleViewer/images/100/'>");
+
$title    = Title::newFromText($i, NS_IMAGE);
    # simpleviewer requires a TRAILING / on the imagePath and thumbPath params
+
$article  = new Article($title);
 +
$html = htmlentities($parser->parse($article->getContent(), $title, $parser->getOptions(),true,false )->getText());
 +
 
 +
print("<image><filename>$i</filename><caption>$html</caption></image>\n");
 +
}
 +
$egSimpleViewEnableHook = true;
  
 
+
# close document         
    # loop and generate <image> containers
+
print("</simpleviewerGallery>");
    foreach($image[1] as $i) {
+
return false;
        $html = htmlentities(file_get_contents("http://mintmedia.co.nz/$wgScriptPath/index.php/$ns_image:$i?action=render"));
 
        #$title    = Title::newFromText($i, NS_IMAGE);
 
        #$article  = new Article($title);
 
        #$wikitext = htmlentities($article->getContent());
 
        /*$replace =
 
            array("/\[\[\.+?|(.+?)\]\]/" => "$1",
 
           
 
            );
 
        foreach($replace as $key => $value)
 
            $wikitext = preg_replace($key, $value, $wikitext);*/
 
           
 
        print("<image><filename>$i</filename><caption>$html</caption></image>\n");
 
    }
 
 
 
    # close document         
 
    print("</simpleviewerGallery>");
 
    die();
 
 
     }
 
     }
  
 +
return true;
 
}
 
}
 
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

Latest revision as of 03:27, 17 April 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"; $egSimpleViewEnableHook = true; $wgExtensionFunctions[] = 'efSetupSimpleViewer'; $wgHooks['ParserBeforeStrip'][] = 'efSimpleViewer'; $wgHooks['LanguageGetMagic'][] = 'efSimpleViewerLanguageGetMagic';

$wgSimpleViewerUrlMagic = "magic_magic";

$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 {

# Constructor function __construct() { global $wgHooks,$wgParser,$egSimpleViewerMagic,$egSimpleViewerTag;

# Add the parser-function $wgParser->setFunctionHook($egSimpleViewerMagic,array($this,'magicSimpleviewer'));

}

# Expand the simpleviewer-magic function magicSimpleviewer(&$parser) { global $egSimpleViewerMagic, $wgOut, $wgScriptPath, $wgParser, $wgCanonicalNamespaceNames, $wgSimpleViewerUrlMagic; # 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; }

       # list of keys that the parser funtion will accept
       # src is not included here because it is not passed on to the javascript
       # format: key => regexp validation, default value
       $passparams = array(
           'maxImageWidth'         => array('/(\d+)/', 600 ),
           'maxImageHeight'        => array('/(\d+)/', 600),
           'textColor'             => array('/(0x\d{6})/i', '0xffffff'),
           'frameColor'            => array('/(0x\d{6})/i', '0xaaaaaa'), 
           'frameWidth'            => array('/(\d+)/', 2),
           'stagePadding'          => array('/(\d+)/', 40),
           'thumbnailColumns'      => array('/(\d+)/', 3),
           'thumbnailRows'         => array('/(\d+)/', 3),
           'navPosition'           => array('/(left|right)/', 'left'),
           'title'                 => array('/(.*)/', ),
           'enableRightClickOpen'  => array('/(true|false)/i', 'true')
           );


/*foreach($argv as $key => $value) { if(array_key_exists($key, $passparams)) { if(preg_match($passparams[$key][0], $v, $match) != 0) {

   		      $variables .= "fo.addVariable('$key', '".$match[1][0]."'); ";

} }

       }*/


$title = Title::newFromText($argv['src']); if(!$title->exists()) return array("==SimpleViewer==\n\nsrc parameter: No such article exists\n\nCreate it: [[".$argv['src']."]]", 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false );

$ns = $title->getNsText(); $db = $title->getDBkey(); $urlsafe = $ns.$wgSimpleViewerUrlMagic.$db;

       # construct wikitext with <gallery> tags for use where flash is not available
       # get title
       # get article
       /* eg html gallery
       <gallery widths="250px" heights="250px" perrow="3">

Image:Speak,-memory,-an-autobiography.jpg|File:Speak,-memory,-an-autobiography.jpg

       */
       # add the javascript and build the embed code

$script = "

There was a problem. Please <a href='mailto:rob@mintmedia.co.nz?subject=problem with content'>tell me about it.</a>

\n<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/index.php/SpecialSimpleViewer/$urlsafe'); ".$variables."fo.write('flashcontent');</script>";

# 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'; }

	}

function efSetupSimpleViewer() {

   global $wgOut, $wgScriptPath;
  	$wgOut->addScript("<script type=\"text/javascript\" src=\"$wgScriptPath/extensions/SimpleViewer/simpleviewer/swfobject.js\"></script>");
  	}

function efSimpleViewer( &$parser ) { global $egSimpleViewer, $wgSimpleViewerUrlMagic, $wgOut, $wgCanonicalNamespaceNames, $wgScriptPath, $wgServer, $egSimpleViewEnableHook; if (!$egSimpleViewEnableHook) return true; # add script in all cases,client caches external js file so not too bad for efficiency

$egSimpleViewer = new SimpleViewer();

   #print($_REQUEST['title']);
   
   if(preg_match("#^SpecialSimpleViewer/#", $_REQUEST['title'])) {
   

header('Content-Type: text/xml');

$wgOut->disable(); wfResetOutputBuffers();

# is this an image request? $m = preg_match_all("#SpecialSimpleViewer/images/(\d+)/(.+)#i", $_REQUEST['title'], $matches, PREG_SET_ORDER); $size = $matches[0][1]; $file = $matches[0][2];

# if the url is of the form Special:SpecialSimpleViewer/images/200/foo.jpg # then send a redirect to get thumb.php to do the resizing if($m > 0) { header("Location: $wgScriptPath/thumb.php?f=$file&width=$size"); return false; }


# if we got this far it's not an image and we should output an XML file

# params: # src = article name containing a list of images for the gallery, article may also contain a DPL query

preg_match_all("#SpecialSimpleViewer/(.+)$#", $_REQUEST['title'], $matches, PREG_SET_ORDER); #print_r($matches); $t = str_replace($wgSimpleViewerUrlMagic, ':', $matches[0][1]); #print($t);

# get article content $title = Title::newFromText($t); # if the image article does not exist exit if(!$title) { print "title not valid"; return false; }

$article = new Article($title); $content = $article->getContent(); $egSimpleViewEnableHook = false;

$wikitext = $parser->preprocess( $content, $title, $parser->getOptions() );

# make a list of image names excluding the namespace (Image:) $ns_image = $wgCanonicalNamespaceNames[NS_IMAGE]; #print_r($wikitext);

preg_match_all("/\[\[:?".$ns_image.":(.+?)(\||\]\])/mi", $wikitext, $image); if(count($image[1]) == 0 )

   		preg_match_all("/\*\s*".$ns_image.":(.+?)\s*$/mi", $wikitext, $image);

# standard header, other options to add later print("<?xml version='1.0' encoding='UTF-8'?> <simpleviewerGallery maxImageWidth='600' maxImageHeight='600' textColor='0xffffff' frameColor='0xaaaaaa' frameWidth='2' stagePadding='40' thumbnailColumns='3' thumbnailRows='3' navPosition='left' title= enableRightClickOpen='true' backgroundImagePath= imagePath='$wgScriptPath/index.php/SpecialSimpleViewer/images/500/' thumbPath='$wgScriptPath/index.php/SpecialSimpleViewer/images/100/'>"); # simpleviewer requires a TRAILING / on the imagePath and thumbPath params


# loop and generate <image> containers foreach($image[1] as $i) { #$html = htmlentities(file_get_contents("$wgServer$wgScriptPath/index.php/$ns_image:$i?action=render")); $title = Title::newFromText($i, NS_IMAGE); $article = new Article($title); $html = htmlentities($parser->parse($article->getContent(), $title, $parser->getOptions(),true,false )->getText());

print("<image><filename>$i</filename>$html</image>\n"); } $egSimpleViewEnableHook = true;

# close document print("</simpleviewerGallery>"); return false;

   }

return true; }

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