Personal tools
Make a donation
$ 




Extension:SimpleViewer.php

From OrganicDesign Wiki

Jump to: navigation, search
<?php
# Extension:SimpleViewer
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: [http://www.organicdesign.co.nz/User:Rob User:Rob]
#
 
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'      => '[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
	);
 
 
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\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();
		$db = $title->getDBkey();
		$urlsafe = $ns.$wgSimpleViewerUrlMagic.$db;
 
        # construct wikitext with 

The GNU Project Debian Linux Ubuntu Linux Wikipedia Affiliate Button MediaWiki

Content under the www.organicdesign.co.nz domain is available under the Creative Commons Attribution-ShareAlike License