function port1_0RenderHash($dbi, $dbmh, $pagename) { $pagehash = unserialize(dbmfetch($dbmh, $pagename)); // array fields for pagehash 1.0 // 'version', 'date' as string, 'author', 'text' echo "{$pagename}<br>\n"; $newhash['version'] = isset($pagehash['version']) ? $pagehash['version'] : 1; $newhash['author'] = isset($pagehash['author']) ? $pagehash['author'] : '1.0 wiki setup page'; $newhash['created'] = time(); $newhash['lastmodified'] = time(); $newhash['flags'] = 0; $newhash['pagename'] = $pagename; $newhash['refs'] = array(); for ($i = 1; $i <= 4; $i++) { if (isset($pagehash['r$i'])) { $newhash['refs'][$i] = $pagehash['r$i']; } } $content = implode("\n", $pagehash['text']); $content = str_replace("[", "[[", $content); $newhash['content'] = explode("\n", $content); InsertPage($dbi, $pagename, $newhash); }
function dba_fetch($key, $handle) { return dbmfetch($handle, $key); }
function GetWikiPageLinks($dbi, $pagename) { $linkinfo = RetrievePage($dbi, $pagename, 'wikilinks'); if (is_array($linkinfo)) { // page exists? $tolinks = $linkinfo['tolinks']; // outgoing links $fromlinks = $linkinfo['fromlinks']; // incoming links } else { // new page, but pages may already point to it // create info for page $tolinks = array(); $fromlinks = array(); // look up pages that link to $pagename $pname = dbmfirstkey($dbi['wikilinks']); while ($pname) { $linkinfo = RetrievePage($dbi, $pname, 'wikilinks'); if ($linkinfo['tolinks'][$pagename]) { // $pname links to $pagename? $fromlinks[$pname] = 1; } $pname = dbmnextkey($dbi['wikilinks'], $pname); } } // get and sort the outgoing links $outlinks = array(); reset($tolinks); // look up scores for tolinks while (list($tolink, $dummy) = each($tolinks)) { $toPage = RetrievePage($dbi, $tolink, 'wikilinks'); if (is_array($toPage)) { // link to internal page? $outlinks[$tolink] = count($toPage['fromlinks']); } } arsort($outlinks); // sort on score $links['out'] = array(); reset($outlinks); // convert to right format while (list($link, $score) = each($outlinks)) { $links['out'][] = array($link, $score); } // get and sort the incoming links $inlinks = array(); reset($fromlinks); // look up scores for fromlinks while (list($fromlink, $dummy) = each($fromlinks)) { $fromPage = RetrievePage($dbi, $fromlink, 'wikilinks'); $inlinks[$fromlink] = count($fromPage['fromlinks']); } arsort($inlinks); // sort on score $links['in'] = array(); reset($inlinks); // convert to right format while (list($link, $score) = each($inlinks)) { $links['in'][] = array($link, $score); } // sort all the incoming and outgoing links $allLinks = $outlinks; // copy the outlinks reset($inlinks); // add the inlinks while (list($key, $value) = each($inlinks)) { $allLinks[$key] = $value; } reset($allLinks); // lookup hits while (list($key, $value) = each($allLinks)) { $allLinks[$key] = (int) dbmfetch($dbi['hitcount'], $key); } arsort($allLinks); // sort on hits $links['popular'] = array(); reset($allLinks); // convert to right format while (list($link, $hits) = each($allLinks)) { $links['popular'][] = array($link, $hits); } return $links; }
function InitMostPopular($dbi, $limit) { return; $pagename = dbmfirstkey($dbi['hitcount']); $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); while ($pagename = dbmnextkey($dbi['hitcount'], $pagename)) { $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); echo "got {$pagename} with value " . $res[$pagename] . "<br>\n"; } rsort($res); reset($res); return $res; }