2008-05-21 22:33:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Mediawiki extension to show a project's platforms.
|
|
|
|
// The platforms for a given project are stored in a file platforms/URL
|
|
|
|
//
|
|
|
|
function parse_next_element($xml, $tag, &$cursor) {
|
|
|
|
$element = null;
|
|
|
|
$closetag = "</" . substr($tag,1);
|
|
|
|
$pos = substr($xml,$cursor);
|
|
|
|
$x = strstr($pos, $tag);
|
|
|
|
if ($x) {
|
|
|
|
if (strstr($tag, "/>")) return $tag;
|
|
|
|
$y = substr($x, strlen($tag));
|
|
|
|
$n = strpos($y, $closetag);
|
|
|
|
if ($n) {
|
|
|
|
$element = substr($y, 0, $n);
|
|
|
|
}
|
|
|
|
$cursor = (strlen($xml) - strlen($x)) + strlen($tag) + strlen($closetag) + strlen($element);
|
|
|
|
}
|
|
|
|
return trim($element);
|
|
|
|
}
|
|
|
|
|
|
|
|
function friendly_name($p) {
|
|
|
|
switch ($p) {
|
|
|
|
case 'i686-pc-linux-gnu': return 'Linux/x86';
|
|
|
|
case 'windows_intelx86': return 'Windows';
|
|
|
|
case 'x86_64-pc-linux-gnu': return 'Linux/x86_64';
|
2008-05-22 03:09:11 +00:00
|
|
|
case 'i686-apple-darwin': return 'Mac OS X';
|
|
|
|
case 'powerpc-apple-darwin': return 'Mac OS X (PowerPC)';
|
2008-05-21 22:33:21 +00:00
|
|
|
case 'sparc-sun-solaris2.7': return 'SPARC Solaris 2.7';
|
|
|
|
case 'sparc-sun-solaris': return 'SPARC Solaris';
|
|
|
|
case 'powerpc64-unknown-linux-gnu': return 'Linux/PowerPC64';
|
|
|
|
case 'windows_x86_64': return 'Windows/x86_64';
|
2008-05-22 03:09:11 +00:00
|
|
|
case 'powerpc64-ps3-linux-gnu': return 'Playstation3/Linux';
|
2008-05-23 19:24:20 +00:00
|
|
|
case 'x86_64-unknown-linux-gnu': return null;
|
2008-05-21 22:33:21 +00:00
|
|
|
}
|
2008-05-22 03:09:11 +00:00
|
|
|
if (strstr($p, "fubar")) return null;
|
2008-05-21 22:33:21 +00:00
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_platforms($url) {
|
2008-05-22 03:09:11 +00:00
|
|
|
$url .= '/get_project_config.php';
|
2008-05-21 22:33:21 +00:00
|
|
|
$x = file_get_contents($url);
|
|
|
|
if (!$x) return null;
|
|
|
|
$cursor = 0;
|
|
|
|
$list = null;
|
|
|
|
$tag = '<platform_name>';
|
|
|
|
if (!strstr($x, "<platform_name>")) $tag = '<platform>';
|
|
|
|
while (1) {
|
|
|
|
$p = parse_next_element($x, $tag, $cursor);
|
|
|
|
if (!$p) break;
|
|
|
|
$list[] = friendly_name($p);
|
|
|
|
}
|
|
|
|
return array_unique($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_list($l) {
|
|
|
|
$x = "";
|
|
|
|
$first = true;
|
|
|
|
foreach($l as $p) {
|
|
|
|
if ($first) {
|
|
|
|
$x .= "$p";
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
$x .= ", $p";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2008-05-22 03:09:11 +00:00
|
|
|
function get_platforms_cached($url) {
|
2008-05-21 22:33:21 +00:00
|
|
|
$u = urlencode($url);
|
|
|
|
$fname = "/home/boincadm/boinc/doc/platforms/$u";
|
|
|
|
$t = @filemtime($fname);
|
|
|
|
if ($t && $t > time() - 86400) {
|
|
|
|
$l = json_decode(file_get_contents($fname));
|
|
|
|
} else {
|
|
|
|
$l = get_platforms($url);
|
|
|
|
if ($l) {
|
|
|
|
file_put_contents($fname, json_encode($l));
|
|
|
|
} else {
|
|
|
|
if (!file_exists($fname)) {
|
|
|
|
$l[] = "Unknown";
|
|
|
|
file_put_contents($fname, json_encode($l));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return show_list($l);
|
|
|
|
}
|
2008-05-22 03:09:11 +00:00
|
|
|
//echo get_platforms_cached("http://www.malariacontrol.net/");
|
2008-05-21 22:33:21 +00:00
|
|
|
|
|
|
|
function wfPlatforms() {
|
|
|
|
global $wgParser;
|
|
|
|
$wgParser->setHook( "platforms", "get_platforms_cached" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgExtensionFunctions[] = "wfPlatforms";
|
|
|
|
|
|
|
|
?>
|