Wikid PHP interface

From Organic Design wiki
Revision as of 00:14, 25 September 2013 by Nad (talk | contribs) (Created page with "{{legacy}} <php> <?php # WikiDaemon Extension for MediaWiki # - Wikid2 started 2007-05-01 # - See http://www.organicdesign.co.nz/Extension:WikiDaemon # - Licenced under LGPL (...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

<php> <?php

  1. WikiDaemon Extension for MediaWiki
  2. - Wikid2 started 2007-05-01
  3. - See http://www.organicdesign.co.nz/Extension:WikiDaemon
  4. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  5. - 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 );

  1. Check running peers

system("$wgWikidDir/wikid.pl --name=$wgWikidName --password=$wgWikidPassword --wiki=$wgWikidWikiUrl --port=$wgWikidPort");

  1. Define a singleton for SimpleForms operations

class Wikid {

# Constructor function Wikid() { global $wgHooks; $wgHooks['ArticleSaveComplete'][] = array($this,'onChange');

  1. $wgHooks['ArticleDeleteComplete'][] = array($this,'onChange');
  2. $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; }

}

  1. Define a new class based on the SpecialPage class
  2. - the content of the special page is the tree maintained by the peer (use treeview if installed)
  3. - it can obtain this information by executing the onChange hook
  4. - later this can be a live transclude (if livelets installed and peer updates the specialpage clients onChange)
  5. 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'); }

}

  1. 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>