twikiName = $twikiName; $this->mediawikiLocation = $mediawikiLocation; $this->mediawikiSpecialLocation = $mediawikiSpecialLocation; } } $electricMini = new TWiki('ElectricMini', 'http://carrott.org/emini', 'http://carrott.org/_emini'); $electricSaker = new TWiki('ElectricSaker', 'http://wiki.greenstage.co.nz/saker', 'http://wiki.greenstage.co.nz/_saker'); $twikis = array($electricMini, $electricSaker); $path = $_SERVER['REQUEST_URI']; $parts = explode("/", $path); foreach ($parts as $index => $value) { if (strlen($value) == 0) { unset($parts[$index]); } } $parts = array_values($parts); if (count($parts) == 4) { // we probably have the main page $parts[4] = 'WebHome'; } if (count($parts) != 5) { header('Status: 404'); // todo encode print 'Expected 5 parts found ' . count($parts) . ' in ' . $path; return; } if ($parts[1] == "pub") { // this is an image $web = $parts[2]; $img = $parts[4]; } else { $web = $parts[3]; $page = $parts[4]; } ///cgi-bin/twiki/viewfile/ElectricSaker/HighVoltageSticker?rev=1;filename=high_voltage.ai if ($parts[2] == "viewfile") { $web = $parts[3]; if(array_key_exists("rev", $_GET)) { $imgParts = 'rev=' . $_GET["rev"]; } else if (array_key_exists("filename", $_GET)) { $imgParts = 'filename=' . $_GET["filename"]; } if (!$imgParts) { print 'could not find filename in ' . $_GET; return; } foreach (explode(";", $imgParts) as $index => $value) { if (substr($value, 0, 8) == "filename") { $img = explode("=", $value); $img = $img[1]; break; } } } $twiki = null; foreach ($twikis as $t) { if ($web == $t->twikiName) { $twiki = $t; break; } } if ($twiki == null) { header('Status: 404'); print 'Not Found'; return; } if (isset($img)) { //print "
" . $web . " " . $img . "
"; header('Status: 301'); $hash = md5($img); $a = substr($hash, 0, 1); $b = substr($hash, 0, 2); // todo encode header('Location: ' . $twiki->mediawikiSpecialLocation . '/img_auth.php/' . $a . '/' . $b . '/' . $img); return; } if ($parts[4] == 'WebRss') { header('Status: 301'); // todo encode header('Location: ' . $twiki->mediawikiSpecialLocation . '/index.php?title=Special:RecentChanges&feed=rss'); return; } if ($parts[4] == 'WebAtom') { header('Status: 301'); // todo encode header('Location: ' . $twiki->mediawikiSpecialLocation . '/index.php?title=Special:RecentChanges&feed=atom'); return; } print "
" . " " . htmlspecialchars($web) . " " . htmlspecialchars($page) . "
"; $nameMapping = array( "WebHome" => "Main_Page", "NZSmartGrid" => "NZ_Smart_Grid", "LATASwitch" => "LATA_Switch", "NZSCSeries" => "NZSC_Series", "DoneARunner" => "Done_A_Runner", "USB-CAN" => "USB-CAN", "DC-DCConverter" => "DC-DC_Converter", "LinuxConf2010Abstract" => "Linux_Conf_2010_Abstract", "KillacycleDownUnder2010" => "KillaCycle_Down_Under_2010", ); $newPage = $nameMapping[$page]; if (!$newPage) { $newPage = ""; $lastIsUpper = True; for ($i = 0; $i < strlen($page); $i++) { $c = substr($page, $i, 1); if (ctype_upper($c) and !$lastIsUpper) { $newPage = $newPage . "_" . $c; } else { $newPage = $newPage . $c; } $lastIsUpper = ctype_upper($c) or $c == "#"; } } header('Status: 301'); // how do we make this safe? $destination = $twiki->mediawikiLocation . '/' . $newPage; // print $destination; header('Location: ' . $destination); ?>