Revision [859]
This is an old revision of WikiPing made by JsnX on 2004-08-02 11:28:11.
the whole wikiping-specification is still beta and any suggestion how to improve this idea is welcomed!
to get in touch with the wikiping-server you need to implement a little xml-rpc-engine which is called at the end of the $wakka->SavePage()-function just after saving a page to the database:
<? $this->WikiPing($this->config["wikiping_server"], $tag, $user, $note); ?>
this function-call will stay inactive unless you have defined one or more wikiping-servers in your configs.
<? "wikiping_server" => "http://recentchanges.net/rpc/wikiping.php", ?>
and here is the ping-mechanism itself, which has to be added to the wakka-class:
<?
function HTTPpost($host, $data, $contenttype="application/x-www-form-urlencoded", $maxAttempt = 5) {
$attempt =0; $status = 300; $result = "";
//repeat the ping if a http 3xx response has redirected the request to another url
while ($status >= 300 && $status < 400 && $attempt++ <= $maxAttempt) {
$url = parse_url($host);
if (isset($url["path"]) == false) $url["path"] = "/";
if (isset($url["port"]) == false) $url["port"] = 80;
if ($url["host"] && $socket = fsockopen ($url["host"], $url["port"], $errno, $errstr, 15)) {
$strQuery = "POST ".$url["path"]." HTTP/1.1\n";
$strQuery .= "Host: ".$url["host"]."\n";
$strQuery .= "Content-Length: ".strlen($data)."\n";
$strQuery .= "Content-Type: ".$contenttype."\n";
$strQuery .= "Connection: close\n\n";
$strQuery .= $data;
// send request & get response
fputs($socket, $strQuery);
$bHeader = true;
while (!feof($socket)) {
$strLine = trim(fgets($socket, 512));
if (strlen($strLine) == 0) $bHeader = false; // first empty line ends header-info
if ($bHeader) {
if (!$status) $status = $strLine;
if (preg_match("/^Location:\s(.*)/", $strLine, $matches)) $location = $matches[1];
} else $result .= trim($strLine)."\n";
}
fclose ($socket);
} else $status = "999 timeout";
if ($status) {
if(preg_match("/(\d){3}/", $status, $matches)) $status = $matches[1];
} else $status = 999;
$host = $location;
}
return $result;
}
function WikiPing($servers, $tag, $user, $changelog = "") {
if ($servers) {
if ($this->LoadPage($user)) $hp = $this->href("", $user); //get the user's personal page
$taglink = $this->href("", $tag); // make an url out of the wikiword $tag
$revision = $this->href("revisions", $tag); // url to the page-history
$wiki = $this->config["mind_name"]; // site name of your wiki
$rpcRequest .= "<methodCall>\n";
$rpcRequest .= "<methodName>wiki.ping</methodName>\n";
$rpcRequest .= "<params>\n";
$rpcRequest .= "<param>\n<value>\n<struct>\n";
$rpcRequest .= "<member>\n<name>tag</name>\n<value>".$tag."</value>\n</member>\n";
$rpcRequest .= "<member>\n<name>url</name>\n<value>".$taglink."</value>\n</member>\n";
$rpcRequest .= "<member>\n<name>wiki</name>\n<value>".$wiki."</value>\n</member>\n";
if ($user) {
$rpcRequest .= "<member>\n<name>author</name>\n<value>".$user."</value>\n</member>\n";
if ($hp) $rpcRequest .= "<member>\n<name>authorpage</name>\n<value>".$hp."</value>\n</member>\n";
}
$rpcRequest .= "<member>\n<name>history</name>\n<value>".$revision."</value>\n</member>\n";
if ($changelog) $rpcRequest .= "<member>\n<name>changelog</name>\n<value>".$changelog."</value>\n</member>\n";
$rpcRequest .= "</struct>\n<value>\n</param>\n";
$rpcRequest .= "</params>\n";
$rpcRequest .= "</methodCall>\n";
foreach (explode(" ", $servers) as $server) $response = $this->HTTPpost($server, $rpcRequest, "text/xml");
}
}
?>
function HTTPpost($host, $data, $contenttype="application/x-www-form-urlencoded", $maxAttempt = 5) {
$attempt =0; $status = 300; $result = "";
//repeat the ping if a http 3xx response has redirected the request to another url
while ($status >= 300 && $status < 400 && $attempt++ <= $maxAttempt) {
$url = parse_url($host);
if (isset($url["path"]) == false) $url["path"] = "/";
if (isset($url["port"]) == false) $url["port"] = 80;
if ($url["host"] && $socket = fsockopen ($url["host"], $url["port"], $errno, $errstr, 15)) {
$strQuery = "POST ".$url["path"]." HTTP/1.1\n";
$strQuery .= "Host: ".$url["host"]."\n";
$strQuery .= "Content-Length: ".strlen($data)."\n";
$strQuery .= "Content-Type: ".$contenttype."\n";
$strQuery .= "Connection: close\n\n";
$strQuery .= $data;
// send request & get response
fputs($socket, $strQuery);
$bHeader = true;
while (!feof($socket)) {
$strLine = trim(fgets($socket, 512));
if (strlen($strLine) == 0) $bHeader = false; // first empty line ends header-info
if ($bHeader) {
if (!$status) $status = $strLine;
if (preg_match("/^Location:\s(.*)/", $strLine, $matches)) $location = $matches[1];
} else $result .= trim($strLine)."\n";
}
fclose ($socket);
} else $status = "999 timeout";
if ($status) {
if(preg_match("/(\d){3}/", $status, $matches)) $status = $matches[1];
} else $status = 999;
$host = $location;
}
return $result;
}
function WikiPing($servers, $tag, $user, $changelog = "") {
if ($servers) {
if ($this->LoadPage($user)) $hp = $this->href("", $user); //get the user's personal page
$taglink = $this->href("", $tag); // make an url out of the wikiword $tag
$revision = $this->href("revisions", $tag); // url to the page-history
$wiki = $this->config["mind_name"]; // site name of your wiki
$rpcRequest .= "<methodCall>\n";
$rpcRequest .= "<methodName>wiki.ping</methodName>\n";
$rpcRequest .= "<params>\n";
$rpcRequest .= "<param>\n<value>\n<struct>\n";
$rpcRequest .= "<member>\n<name>tag</name>\n<value>".$tag."</value>\n</member>\n";
$rpcRequest .= "<member>\n<name>url</name>\n<value>".$taglink."</value>\n</member>\n";
$rpcRequest .= "<member>\n<name>wiki</name>\n<value>".$wiki."</value>\n</member>\n";
if ($user) {
$rpcRequest .= "<member>\n<name>author</name>\n<value>".$user."</value>\n</member>\n";
if ($hp) $rpcRequest .= "<member>\n<name>authorpage</name>\n<value>".$hp."</value>\n</member>\n";
}
$rpcRequest .= "<member>\n<name>history</name>\n<value>".$revision."</value>\n</member>\n";
if ($changelog) $rpcRequest .= "<member>\n<name>changelog</name>\n<value>".$changelog."</value>\n</member>\n";
$rpcRequest .= "</struct>\n<value>\n</param>\n";
$rpcRequest .= "</params>\n";
$rpcRequest .= "</methodCall>\n";
foreach (explode(" ", $servers) as $server) $response = $this->HTTPpost($server, $rpcRequest, "text/xml");
}
}
?>
Testing WikiPing .... nice idea! -- JsnX
Nope.... I implemented as described above, and it didn't work. I'll have to check into it tonight when I have more time.