Difference between revisions of "Extension:Livelets.php"

From Organic Design wiki
(1.2.0 changing this over to the mooer too)
(moved to wikimedia)
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
<?
+
{{svn|http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Livelets}}
# Extension:Livelets{{php}}{{Category:Extensions|Livelets}}
 
# - 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.0, 2007-06-19');
+
== Notes ==
 
+
Add dev notes here, e.g. regarding the SWF live updates
$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)
 
 
 
$wgLiveletsSWF                = dirname(__FILE__).'/Livelets.swf';
 
$wgExtensionFunctions[]        = 'wfSetupLivelets';
 
$wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic';
 
 
 
$wgExtensionCredits['parserhook'][] = array(
 
'name'        => 'Livelets',
 
'author'      => '[http://www.organicdesign.co.nz/User:Nad 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 $wgParser,$wgLiveletsMagic,$wgLiveletsMoo;
 
$wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));
 
if ($wgLiveletsMoo) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgLiveletsMoo\"></script>");
 
}
 
 
 
# Remove live container content
 
function functionHook(&$parser,$title) {
 
global $wgScript,$wgLiveletsPath;
 
$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  = "<div class='livelet' id='$id' url='$url'><div style='text-align:center'><img src='$wgLiveletsPath/wait.gif'/></div></div>";
 
$html .= "<script type='text/javascript'>liveletRequest('$id')</script>";
 
return array($html,isHTML => 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>");
 
}
 
 
 
}
 
 
 
# Called from $wgExtensionFunctions array when initialising extensions
 
function wfSetupLivelets() {
 
global $wgLivelets,$wgScriptPath,$wgLiveletsPath;
 
$wgLivelets = new Livelets();
 
if ($wgLiveletsPath == '') $wgLiveletsPath = "$wgScriptPath/extensions/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;
 
}
 
?>
 

Latest revision as of 02:55, 4 September 2010

Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.

Notes

Add dev notes here, e.g. regarding the SWF live updates