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';
|
2009-01-08 19:12:13 +00:00
|
|
|
case 'x86_64-pc-linux-gnu': return 'Linux/x64';
|
2008-05-22 03:09:11 +00:00
|
|
|
case 'i686-apple-darwin': return 'Mac OS X';
|
2009-01-08 19:12:13 +00:00
|
|
|
case 'x86_64-apple-darwin': return 'Mac OS X 64-bit';
|
2008-05-22 03:09:11 +00:00
|
|
|
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';
|
2009-01-08 19:12:13 +00:00
|
|
|
case 'windows_x86_64': return 'Windows/x64';
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-08 19:12:13 +00:00
|
|
|
//
|
2008-05-21 22:33:21 +00:00
|
|
|
function get_platforms($url) {
|
2009-01-13 19:34:04 +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;
|
2009-01-08 19:12:13 +00:00
|
|
|
$list[] = $p;
|
2008-05-21 22:33:21 +00:00
|
|
|
}
|
|
|
|
return array_unique($list);
|
|
|
|
}
|
|
|
|
|
2009-01-13 19:34:04 +00:00
|
|
|
function get_platforms2($url) {
|
|
|
|
$url .= 'apps.php?xml=1';
|
|
|
|
$x = file_get_contents($url);
|
|
|
|
if (!$x) return null;
|
|
|
|
$cursor = 0;
|
|
|
|
$list = null;
|
|
|
|
$tag = '<platform_short>';
|
|
|
|
while (1) {
|
|
|
|
$p = parse_next_element($x, $tag, $cursor);
|
|
|
|
if (!$p) break;
|
|
|
|
$list[] = $p;
|
|
|
|
}
|
|
|
|
return array_unique($list);
|
|
|
|
}
|
|
|
|
|
2009-01-08 19:12:13 +00:00
|
|
|
// convert an array of platform names into a comma-separated
|
|
|
|
// list of human-readable names
|
|
|
|
//
|
|
|
|
function make_friendly_string($l) {
|
|
|
|
if (!count($l)) return "Unknown";
|
2008-05-21 22:33:21 +00:00
|
|
|
$x = "";
|
|
|
|
$first = true;
|
|
|
|
foreach($l as $p) {
|
2009-01-08 19:12:13 +00:00
|
|
|
$p = friendly_name($p);
|
|
|
|
if (!$p) continue;
|
2008-05-21 22:33:21 +00:00
|
|
|
if ($first) {
|
|
|
|
$x .= "$p";
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
$x .= ", $p";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2009-01-08 19:12:13 +00:00
|
|
|
// return platforms as an array of platform names
|
|
|
|
//
|
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);
|
2009-01-13 19:34:04 +00:00
|
|
|
if (!$l) {
|
|
|
|
$l = get_platforms2($url);
|
|
|
|
}
|
2008-05-21 22:33:21 +00:00
|
|
|
if ($l) {
|
|
|
|
file_put_contents($fname, json_encode($l));
|
|
|
|
} else {
|
2008-06-05 18:36:31 +00:00
|
|
|
if (file_exists($fname)) {
|
|
|
|
touch($fname);
|
|
|
|
} else {
|
2008-05-21 22:33:21 +00:00
|
|
|
$l[] = "Unknown";
|
|
|
|
file_put_contents($fname, json_encode($l));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-08 19:12:13 +00:00
|
|
|
return $l;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return platforms as a human-readable string
|
|
|
|
//
|
|
|
|
function get_platforms_string($url) {
|
|
|
|
$l = get_platforms_cached($url);
|
|
|
|
return make_friendly_string($l);
|
2008-05-21 22:33:21 +00:00
|
|
|
}
|
2009-01-08 19:12:13 +00:00
|
|
|
|
2009-01-13 19:34:04 +00:00
|
|
|
//echo get_platforms_string("http://www.worldcommunitygrid.org/");
|
2008-05-21 22:33:21 +00:00
|
|
|
|
|
|
|
function wfPlatforms() {
|
|
|
|
global $wgParser;
|
2009-01-08 19:12:13 +00:00
|
|
|
$wgParser->setHook( "platforms", "get_platforms_string" );
|
2008-05-21 22:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$wgExtensionFunctions[] = "wfPlatforms";
|
|
|
|
|
|
|
|
?>
|