From c504be76677fa970ae062a54f520fc3cc67e7b5b Mon Sep 17 00:00:00 2001 From: wainstead Date: Tue, 9 Jan 2001 19:02:52 +0000 Subject: [PATCH] Reverted to version 1.4; there is a bug in Jan Hidders' patch for dbmlib. It causes a stack overflow in stdlib.php line 318. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@368 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/dbmlib.php | 292 ++++++------------------------------------------- 1 file changed, 33 insertions(+), 259 deletions(-) diff --git a/lib/dbmlib.php b/lib/dbmlib.php index de0db38dc..d3773c4c9 100644 --- a/lib/dbmlib.php +++ b/lib/dbmlib.php @@ -1,24 +1,28 @@ \n"; $count = 1; dbminsert($dbi['hitcount'], $pagename, $count); } } - function GetHitCount($dbi, $pagename) { if (dbmexists($dbi['hitcount'], $pagename)) { @@ -243,66 +206,40 @@ // sort the results highest to lowest, and return // n..$limit results - // Because sorting all the pages may be a lot of work - // we only get the top $limit. A page is only added if it's score is - // higher than the lowest score in the list. If the list is full then - // one of the pages with the lowest scores is removed. - $pagename = dbmfirstkey($dbi['hitcount']); - $score = dbmfetch($dbi['hitcount'], $pagename); - $res = array($pagename => (int) $score); - $lowest = $score; + $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); while ($pagename = dbmnextkey($dbi['hitcount'], $pagename)) { - $score = dbmfetch($dbi['hitcount'], $pagename); - if (count($res) < $limit) { // room left in $res? - if ($score < $lowest) - $lowest = $score; - $res[$pagename] = (int) $score; // add page to $res - } elseif ($score > $lowest) { - $oldres = $res; // save old result - $res = array(); - $removed = 0; // nothing removed yet - $newlowest = $score; // new lowest score - $res[$pagename] = (int) $score; // add page to $res - reset($oldres); - while(list($pname, $pscore) = each($oldres)) { - if (!$removed and ($pscore = $lowest)) - $removed = 1; // don't copy this entry - else { - $res[$pname] = (int) $pscore; - if ($pscore < $newlowest) - $newlowest = $pscore; - } - } - $lowest = $newlowest; - } + $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); + //echo "got $pagename with value " . $res[$pagename] . "
\n"; } - - arsort($res); // sort - reset($res); - + + arsort($res); return($res); } - function MostPopularNextMatch($dbi, &$res) { // the return result is a two element array with 'hits' // and 'pagename' as the keys + if (count($res) == 0) + return 0; + if (list($pagename, $hits) = each($res)) { + //echo "most popular next match called
\n"; + //echo "got $pagename, $hits back
\n"; $nextpage = array( "hits" => $hits, "pagename" => $pagename ); + // $dbm_mostpopular_cntr++; return $nextpage; } else { return 0; } } - function GetAllWikiPagenames($dbi) { $namelist = array(); $ctr = 0; @@ -317,167 +254,4 @@ return $namelist; } - - //////////////////////////////////////////// - // functionality for the wikilinks DBM file - - // format of the 'wikilinks' DBM file : - // pagename => - // { tolinks => ( pagename => 1}, fromlinks => { pagename => 1 } } - - // takes a page name, returns array of scored incoming and outgoing links - 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; - } - - - // takes page name, list of links it contains - // the $linklist is an array where the keys are the page names - function SetWikiPageLinks($dbi, $pagename, $linklist) { - - $cache = array(); - - // Phase 1: fetch the relevant pairs from 'wikilinks' into $cache - // --------------------------------------------------------------- - - // first the info for $pagename - $linkinfo = RetrievePage($dbi, $pagename, 'wikilinks'); - if (is_array($linkinfo)) // page exists? - $cache[$pagename] = $linkinfo; - else { - // create info for page - $cache[$pagename] = array( 'fromlinks' => array(), - 'tolinks' => array() - ); - // look up pages that link to $pagename - $pname = dbmfirstkey($dbi['wikilinks']); - while ($pname) { - $linkinfo = RetrievePage($dbi, $pname, 'wikilinks'); - if ($linkinfo['tolinks'][$pagename]) - $cache[$pagename]['fromlinks'][$pname] = 1; - $pname = dbmnextkey($dbi['wikilinks'], $pname); - } - } - - // then the info for the pages that $pagename used to point to - $oldTolinks = $cache[$pagename]['tolinks']; - reset($oldTolinks); - while (list($link, $dummy) = each($oldTolinks)) { - $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); - if (is_array($linkinfo)) - $cache[$link] = $linkinfo; - } - - // finally the info for the pages that $pagename will point to - reset($linklist); - while (list($link, $dummy) = each($linklist)) { - $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); - if (is_array($linkinfo)) - $cache[$link] = $linkinfo; - } - - // Phase 2: delete the old links - // --------------------------------------------------------------- - - // delete the old tolinks for $pagename - // $cache[$pagename]['tolinks'] = array(); - // (overwritten anyway in Phase 3) - - // remove $pagename from the fromlinks of pages in $oldTolinks - - reset($oldTolinks); - while (list($oldTolink, $dummy) = each($oldTolinks)) { - if ($cache[$oldTolink]) { // links to existing page? - $oldFromlinks = $cache[$oldTolink]['fromlinks']; - $cache[$oldTolink]['fromlinks'] = array(); // erase fromlinks - reset($oldFromlinks); // comp. new fr.links - while (list($fromlink, $dummy) = each($oldFromlinks)) { - if ($fromlink != $pagename) - $cache[$oldTolink]['fromlinks'][$fromlink] = 1; - } - } - } - - // Phase 3: add the new links - // --------------------------------------------------------------- - - // set the new tolinks for $pagename - $cache[$pagename]['tolinks'] = $linklist; - - // add $pagename to the fromlinks of pages in $linklist - reset($linklist); - while (list($link, $dummy) = each($linklist)) { - if ($cache[$link]) // existing page? - $cache[$link]['fromlinks'][$pagename] = 1; - } - - // Phase 4: write $cache back to 'wikilinks' - // --------------------------------------------------------------- - - reset($cache); - while (list($link,$fromAndTolinks) = each($cache)) - InsertPage($dbi, $link, $fromAndTolinks, 'wikilinks'); - - } - ?> -- 2.45.0