Difference between revisions of "Extension:Livelets.php"

From Organic Design wiki
m ({{Category:Livelets}})
(start fixing)
Line 6: Line 6:
 
# - Author: http://www.organicdesign.co.nz/nad
 
# - Author: http://www.organicdesign.co.nz/nad
  
define('LIVELETS_VERSION', '0.2.0, 2007-06-19');
+
define('LIVELETS_VERSION', '0.2.1, 2007-07-09');
  
$wgLiveletsMagic = "live"; # the parser-function name for doing live-transclusions
+
$wgLiveletsMagic         = "live"; # the parser-function name for doing live-transclusions
$wgLiveletsMoo   = "";    # the relative URL to mootools ajax.js script (don't set this if it's already been included by another extension)
+
$wgLiveletsMoo           = '';    # Set this to the relative path of Mootools.js unless loaded elsewhere
 +
$wgLiveletsUseSWF        = false;  # Set this to true to use SWF to make livelets fully event-driven (no polling for change)
  
$wgLiveletsSWF                = dirname(__FILE__).'/Livelets.swf';
+
$wgLiveletsPath                = dirname(__FILE__);
 +
$wgLiveletsDefaultContent      = "<div style='text-align:center'><img src='$wgLiveletsPath/wait.gif'/></div>";
 
$wgExtensionFunctions[]        = 'wfSetupLivelets';
 
$wgExtensionFunctions[]        = 'wfSetupLivelets';
 
$wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic';
Line 30: Line 32:
 
# Constructor
 
# Constructor
 
function Livelets() {
 
function Livelets() {
global $wgParser,$wgLiveletsMagic,$wgLiveletsMoo;
+
global $IP,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsMoo,$wgLiveletsUseSWF,$wgLiveletsPort,$wgLiveletsPath;
 +
 
 +
# Activate the #live parser-function
 
$wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));
 
$wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));
 +
 +
# Include Livelets.js
 +
$url = str_replace($wgLiveletsPath,$IP,'').'/Livelets.js';
 +
$wgOut->addScript("<script type=\"text/javascript\" src=\"$url\"></script>");
 +
 +
# Include Mootools.js is set
 
if ($wgLiveletsMoo) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgLiveletsMoo\"></script>");
 
if ($wgLiveletsMoo) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgLiveletsMoo\"></script>");
 +
 +
# 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=\"width\" height=\"$height\">
 +
<param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"#ffffff\"/></object>");
 +
}
 
}
 
}
  
# Remove live container content
+
# Render livelet container
 
function functionHook(&$parser,$title) {
 
function functionHook(&$parser,$title) {
global $wgScript,$wgLiveletsPath;
+
global $wgScript,$wgLiveletsPath,$wgLiveletsDefaultContent;
$id   = 'livelet'.$this->id++; # this should be a GUID
+
$id = 'livelet'.$this->id++; # this should be a GUID
 
unset($argv['type']);
 
unset($argv['type']);
 
$element = 'a';
 
$element = 'a';
Line 51: Line 68:
  
 
$url  = Title::newFromText($title)->getFullURL('action=render');
 
$url  = Title::newFromText($title)->getFullURL('action=render');
$html  = "<div class='livelet' id='$id' url='$url'><div style='text-align:center'><img src='$wgLiveletsPath/wait.gif'/></div></div>";
+
$html  = "<div class='livelet' id='$id' url='$url'>$wgLiveletsDefaultContent</div>";
 
$html .= "<script type='text/javascript'>liveletRequest('$id')</script>";
 
$html .= "<script type='text/javascript'>liveletRequest('$id')</script>";
return array($html,isHTML => true);
+
return array($html,'isHTML' => true,'noparse' => true);
}
 
 
 
function addJSandSWF() {
 
global $wgOut,$wgLiveletsPath,$wgAddJavaScriptFunctions;
 
 
 
# JS SWF recv: function livelets_DoFScommand(cmd,args) { alert(args) }
 
 
 
# Embed livelets.swf into the output page
 
# NOTE: this actually needs to be served by the WikiDaemon, not the PHP
 
#$swf = "$wgLiveletsPath/livelets.swf";
 
#$wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"width\" height=\"$height\">
 
# <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"#ffffff\"/></object>");
 
 
}
 
}
  

Revision as of 10:32, 9 July 2007

<?

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

Scripts and articles related to Extension:Livelets, see also Wiklets

  1. - Allows articles to be transcluded which load after the main page content and can update dynamically with Ajax
  2. - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details
  3. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  4. - Author: http://www.organicdesign.co.nz/nad

define('LIVELETS_VERSION', '0.2.1, 2007-07-09');

$wgLiveletsMagic = "live"; # the parser-function name for doing live-transclusions $wgLiveletsMoo = ; # Set this to the relative path of Mootools.js unless loaded elsewhere $wgLiveletsUseSWF = false; # Set this to true to use SWF to make livelets fully event-driven (no polling for change)

$wgLiveletsPath = dirname(__FILE__);

$wgLiveletsDefaultContent = "

<img src='$wgLiveletsPath/wait.gif'/>

";

$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,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsMoo,$wgLiveletsUseSWF,$wgLiveletsPort,$wgLiveletsPath;

# Activate the #live parser-function $wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));

# Include Livelets.js $url = str_replace($wgLiveletsPath,$IP,).'/Livelets.js'; $wgOut->addScript("<script type=\"text/javascript\" src=\"$url\"></script>");

# Include Mootools.js is set if ($wgLiveletsMoo) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgLiveletsMoo\"></script>");

# 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=\"width\" height=\"$height\"> <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"#ffffff\"/></object>"); } }

# Render livelet container function functionHook(&$parser,$title) { global $wgScript,$wgLiveletsPath,$wgLiveletsDefaultContent; $id = 'livelet'.$this->id++; # this should be a GUID unset($argv['type']); $element = 'a'; $options = "{data:'action=render',update:$('$update')}"; if ($content == ) $content = $link; if (preg_match('/^\\w/',$link)) { $title = Title::newFromText($link); $argv['class'] = $title->exists() ? 'ajax' : 'new ajax'; $link = $title->getLocalURL(); } $argv['href'] = "javascript:var a=new Ajax('$link',$options).request()";

$url = Title::newFromText($title)->getFullURL('action=render');

$html = "

$wgLiveletsDefaultContent

";

$html .= "<script type='text/javascript'>liveletRequest('$id')</script>"; return array($html,'isHTML' => true,'noparse' => true); }

}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupLivelets() { global $wgLivelets,$wgScriptPath,$wgLiveletsPath; $wgLivelets = new Livelets(); if ($wgLiveletsPath == ) $wgLiveletsPath = "$wgScriptPath/extensions/livelets"; }

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