Wikid PHP interface
<php> <?php
- WikiDaemon Extension for MediaWiki
- - Wikid2 started 2007-05-01
- - See http://www.organicdesign.co.nz/Extension:WikiDaemon
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('WIKID_VERSION','0.0.0, 2007-05-24');
$wgWikidName = $wgSitename.'Bot'; # The daemon's username for shell and wiki login's $wgWikidPassword = 'password' # The daemon's password for shell and wiki login's $wgWikidPort = 0; # Set this to a valid TCP port number if your daemon needs to accept incoming external requests
$wgWikidWikiUrl = $_SERVER['SERVER_NAME'].'/$wgScriptPath'; # URL of the daemon's wiki $wgWikidDir = dirname(__FILE__);
$wgExtensionFunctions[] = 'wfSetupWikid';
$wgExtensionCredits['specialpage'][] = array( 'name' => 'WikiDaemon', 'author' => 'User:Nad', 'description' => 'Loads an instance of wikid.pl for this wiki if not already running', 'url' => 'http://www.organicdesign.co.nz/Extension:WikiDaemon', 'version' => WIKID_VERSION );
- Check running peers
system("$wgWikidDir/wikid.pl --name=$wgWikidName --password=$wgWikidPassword --wiki=$wgWikidWikiUrl --port=$wgWikidPort");
- Define a singleton for SimpleForms operations
class Wikid {
# Constructor function Wikid() { global $wgHooks; $wgHooks['ArticleSaveComplete'][] = array($this,'onChange');
- $wgHooks['ArticleDeleteComplete'][] = array($this,'onChange');
- $wgHooks['TitleMoveComplete'][] = array($this,'onChange');
}
# Send a request to the wiki-daemon for the current tree when an event occurs in the wiki which may invalidate some of its entries function onChange() { global $wgWikidPort;
# Send a GET request to the wiki-daemon for /tree # - format is a.b.c...:content $response = file("http://127.0.0.1:$wgWikidPort/tree"); $tree = array(); foreach ($response as $item) if (preg_match("/^[a-z_0-9-.]+:(.*)$/i",$item,$match)) eval("\$tree['".preg_replace('/\\.+/',"']['",$match[1])."'] = \$match[2];");
# Check if any of the modified dates are invalid $changes = array(); if (is_array($tree['titles'])) foreach ($tree['titles'] as $title => $data) { $a = new Article(Title::newFromText($title)); if ($data['ts'] != $a->getTimestamp()) $changes[$title] = $data; }
# if so, construct as a query and send to wikid (will change to a POST later) if (count($changes)>0) { $qs = ; foreach ($changes as $k => $v) $qs .= ($qs?'&':'?')."$k=$v"; $response = file("http://127.0.0.1:$wgWikidPort/update$qs"); }
return true; }
}
- Define a new class based on the SpecialPage class
- - the content of the special page is the tree maintained by the peer (use treeview if installed)
- - it can obtain this information by executing the onChange hook
- - later this can be a live transclude (if livelets installed and peer updates the specialpage clients onChange)
- if title is special require_once "$IP/includes/SpecialPage.php";
class SpecialWikid extends SpecialPage {
# Constructor function SpecialSearchLog() { SpecialPage::SpecialPage('Wikid'); }
# Override SpecialPage::execute() execute($param) { global $wgOut; $title = Title::makeTitle(NS_SPECIAL,'Wikid'); }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikid() { global $wgWikid,$wgLanguageCode,$wgMessageCache;
# Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'wikid' => 'Example Specialpage', # The friendly page title 'exampleMessage' => "Example message: $1", )); }
# Add the specialpage to the environment SpecialPage::addPage(new SpecialWikid());
# Instantiate a singleton for the extension $wgWikid = new Wikid(); } </php>