Difference between revisions of "Extension:Livelets.php"
m (cat) |
(formatting) |
||
Line 26: | Line 26: | ||
'url' => 'http://www.mediawiki.org/wiki/Extension:Livelets', | 'url' => 'http://www.mediawiki.org/wiki/Extension:Livelets', | ||
'version' => LIVELETS_VERSION | 'version' => LIVELETS_VERSION | ||
− | + | ); | |
class Livelets { | class Livelets { | ||
Line 45: | Line 45: | ||
$wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"1\" height=\"1\"> | $wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"1\" height=\"1\"> | ||
<param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"$wgLiveletsSwfBg\"/></object>"); | <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"$wgLiveletsSwfBg\"/></object>"); | ||
− | |||
} | } | ||
+ | } | ||
# Render livelet container | # Render livelet container | ||
Line 57: | Line 57: | ||
if (preg_match('/^([a-z0-9_]+?)\\s*=(.+)$/is',$arg,$match)) $argv[trim($match[1])] = trim($match[2]); | if (preg_match('/^([a-z0-9_]+?)\\s*=(.+)$/is',$arg,$match)) $argv[trim($match[1])] = trim($match[2]); | ||
else $argv['title'] = trim($arg); | else $argv['title'] = trim($arg); | ||
− | + | } | |
$title = $argv['title']; | $title = $argv['title']; | ||
$update = isset($argv['update']) ? $argv['update'] : 0; | $update = isset($argv['update']) ? $argv['update'] : 0; | ||
Line 72: | Line 72: | ||
return array($html,'isHTML' => true,'noparse' => true); | return array($html,'isHTML' => true,'noparse' => true); | ||
− | + | } | |
− | + | } | |
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
Line 80: | Line 80: | ||
global $wgLivelets; | global $wgLivelets; | ||
$wgLivelets = new Livelets(); | $wgLivelets = new Livelets(); | ||
− | + | } | |
# 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 | ||
Line 87: | Line 87: | ||
$magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); | $magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); | ||
return true; | return true; | ||
− | + | } | |
− |
Revision as of 01:42, 18 August 2008
<?
- Extension:LiveletsTemplate:Php
Scripts and articles related to Extension:Livelets, see also WikletsCategory:Extensions in progress
- - Allows articles to be transcluded which load after the main page content and can update dynamically with Ajax
- - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
define('LIVELETS_VERSION', '0.2.6, 2007-11-05');
$wgLiveletsMagic = 'live'; # the parser-function name for doing live-transclusions
$wgLiveletsUseSWF = false; # Set this to true to use SWF to make livelets fully event-driven (no polling for change) $wgLiveletsSwfBg = '#ffffff'; # The background colour of the embedded SWF $wgLiveletsPort = '1729'; # The port that Livelets.pl can be reached on (using $wgServer:$wgLiveletsPort)
$wgLiveletsPath = dirname(__FILE__); $wgLiveletsBaseUrl = preg_replace('|^.+(?=/extensions)|',$wgScriptPath,$wgLiveletsPath);
$wgLiveletsDefaultContent = "
";
$wgExtensionFunctions[] = 'wfSetupLivelets'; $wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'Livelets', 'author' => 'User:Nad', 'description' => 'Allows articles to be transcluded which load after the main page content and can update dynamically with Ajax', 'url' => 'http://www.mediawiki.org/wiki/Extension:Livelets', 'version' => LIVELETS_VERSION );
class Livelets {
var $version = LIVELETS_VERSION; var $id = 0;
# Constructor function Livelets() { global $IP,$wgOut,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsUseSwf,$wgLiveletsSwfBg,$wgLiveletsPort;
# Activate the #live parser-function $wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));
# Embed the SWF if enabled (SWF must be requested from Livelets.pl) if ($wgLiveletsUseSwf) { $swf = "$wgServer:$wgLiveletsPort/Livelets.swf"; $wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"1\" height=\"1\"> <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"$wgLiveletsSwfBg\"/></object>"); } }
# Render livelet container function functionHook(&$parser) { global $wgScript,$wgTitle,$wgLiveletsPath,$wgLiveletsDefaultContent;
# Process parameters $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^([a-z0-9_]+?)\\s*=(.+)$/is',$arg,$match)) $argv[trim($match[1])] = trim($match[2]); else $argv['title'] = trim($arg); } $title = $argv['title']; $update = isset($argv['update']) ? $argv['update'] : 0; unset($argv['update']); if (isset($argv['type'])) $type = $argv['type']; unset($argv['type']);
# Render container $args = ; foreach ($argv as $k => $v) $args .= " $k=\"$v\""; $id = 'livelet'.$this->id++;
$html = "<div$args id='$id'>$wgLiveletsDefaultContent";
if ($update >= 0) $html .= "<script type='text/javascript'>x = sajax_do_call('wfSimpleFormsAjax',['title=$title','pagename={$wgTitle->getFullText()}'],document.getElementById('$id'))</script>";
return array($html,'isHTML' => true,'noparse' => true); }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupLivelets() { global $wgLivelets; $wgLivelets = new Livelets(); }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfLiveletsLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgLiveletsMagic; $magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); return true; }