Extension:Wiklets.php

From Organic Design wiki
Revision as of 10:31, 15 May 2007 by Nad (talk | contribs) (general structure)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?php

  1. Extension:Wiklets
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.

{{#Security:*|dev}}{{#Security:view|*}}Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:ExtensionCategory:Wiklets

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('WIKLETS_VERSION','0.0.1, 2007-05-15');

$wgWikletsMagic = "wiklet"; $wgExtensionFunctions[] = 'wfSetupWiklets'; $wgHooks['LanguageGetMagic'][] = 'wfWikletsLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Wiklets', 'author' => 'User:Nad', 'description' => 'Transclude templates into movable floating panels', 'url' => 'http://www.organicdesign.co.nz/Extension:Wiklets', 'version' => WIKLETS_VERSION );

class Wiklets {

# Properties var $id = 0;

# Constructor function Wiklets() { global $wgParser,$wgWikletsMagic; $wgParser->setFunctionHook($wgWikletsMagic,array($this,'magicWiklet')); }

# Expand the wiklet-magic function magicWiklet(&$parser) { $this->addJS(); $id = $this->id++; $argv = array(); $content = ; foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $content = $arg; } return array($text, 'noparse' => true, 'isHTML' => true); }

# Add the javascript to the output object if not added yet and there is at least one tree function addJS() { global $wgOut,$wgJS,$wgJsMimeType; if (isset($wgJS['DisplayFilter'])) return; $wgJS['Wiklets'] = true; $wgOut->addScript('<script type="'.$wgJsMimeType.'"> function wikletCreate(id) { } function wikletDelete(id) { } function wikletSetPosition(id) { } function wikletSetSize(id) { } function wikletToFront(id) { } function wikletToBack(id) { } function wikletSetContent(id) { } </script>'); }

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

	}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupWiklets() { global $wgWiklets; $wgWiklets = new Wiklets(); $wgWiklets->addJS(); # addScript doesn't seem to work from within parser }

  1. Needed in MediaWiki >1.8.0 for magic word hooks to work properly

function wfWikletsLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgWikletsMagic; $magicWords[$wgWikletsMagic] = array(0,$wgWikletsMagic); return true; } ?>