Difference between revisions of "Extension:Livelets.php"
(action=live) |
(Return naked if live action requested) |
||
Line 10: | Line 10: | ||
$wgExtensionFunctions[] = 'wfSetupLivelets'; | $wgExtensionFunctions[] = 'wfSetupLivelets'; | ||
$wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic'; | $wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic'; | ||
+ | $wgHooks['UnknownAction'][] = 'wfLiveletsActionHandler'; | ||
class Livelets { | class Livelets { | ||
Line 62: | Line 63: | ||
$magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); | $magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); | ||
return true; | return true; | ||
+ | } | ||
+ | |||
+ | # Return naked if live action requested | ||
+ | function wfLiveletsActionHandler($action,$title) { | ||
+ | global $wgHooks; | ||
+ | if ($action == 'live') $wgHooks['ParserAfterTidy'][] = 'wfLiveletsNakedArticle'; | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | # Output the naked page and die | ||
+ | function wfLiveletsNakedArticle(&$parser,&$text) { | ||
+ | while(@ob_end_clean()); | ||
+ | echo($text); | ||
+ | die; | ||
} | } | ||
?> | ?> |
Revision as of 12:04, 1 April 2007
<?
- Extension:Livelets
- - Allows live articles to be transcluded which update automatically on change in a non-polling, fully event-driven way
- - Version 0.1 (2007-03-30)
- - 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
$wgLiveletsMagic = "live"; # the parser-function name for doing live-transclusions $wgExtensionFunctions[] = 'wfSetupLivelets'; $wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic'; $wgHooks['UnknownAction'][] = 'wfLiveletsActionHandler';
class Livelets {
var $version = '0.1, 2007-03-30'; var $magic; var $args; var $id = 0;
# Constructor function Livelets($magic) { global $wgParser,$wgHooks,$wgOut; $this->magic = $magic; $this->args = array(); $wgParser->setFunctionHook($magic,array($this,'functionHook')); $wgParser->setHook($magic,array($this,'tagHook')); $wgOut->addScript('<script type="text/javascript" src="http://www.organicdesign.co.nz/livelets.js"></script>'); }
# Remove live container content, store its parameters and convert it to $magic tags function functionHook(&$parser) { $magic = $this->magic; $id = $this->id++; $args = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)=(.+)$/',$arg,$match)) $args[$match[1]] = $match[2]; else $args[] = $arg; } $this->args[$id] = $args; return "<$magic>$id</$magic>"; }
# Convert the $magic tags to client-side javascript request code from its stored parameters function tagHook($id,$argv,&$parser) { global $wgScript; $args = $this->args[$id]; $title = $args[0];
return "
";
}
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupLivelets() { global $wgLivelets,$wgLiveletsMagic; $wgLivelets = new Livelets($wgLiveletsMagic); }
- 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; }
- Return naked if live action requested
function wfLiveletsActionHandler($action,$title) { global $wgHooks; if ($action == 'live') $wgHooks['ParserAfterTidy'][] = 'wfLiveletsNakedArticle'; return true; }
- Output the naked page and die
function wfLiveletsNakedArticle(&$parser,&$text) { while(@ob_end_clean()); echo($text); die; } ?>