From: Steve W. <wai...@us...> - 2001-11-16 01:22:30
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv32563 Modified Files: Tag: release-1_2-branch msql.php Log Message: Fixed a bug with InitBackLinkSearch. Although I completely rewrote it, it turned out to be just a scope issue, and an ampersand would probably have fixed the original code. This implemetation is slightly more efficient at the cost of a small amount of memory. Index: msql.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/Attic/msql.php,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -C2 -r1.6.2.4 -r1.6.2.5 *** msql.php 2001/11/07 20:30:47 1.6.2.4 --- msql.php 2001/11/16 01:22:27 1.6.2.5 *************** *** 425,428 **** --- 425,429 ---- $topage = addslashes($pagename); + $res[arr] = array(); // FIXME: this is buggy. If a [multiword link] is split accross *************** *** 430,457 **** // (Probably the best fix is to implement the link table, and use it.) $res['regexp'] = MakeBackLinkSearchRegexp($pagename); ! $res['res'] = msql_query( "SELECT pagename, line FROM $dbi[page_table]" ! . " WHERE line LIKE '%$topage%'" ! . " ORDER BY pagename", ! $dbi["dbc"]); ! $res['lastpage'] = ''; ! return $res; ! } ! // iterating through database ! function BackLinkSearchNextMatch($dbi, $res) { ! while (true) { ! if ( ! ($o = msql_fetch_object($res['res']))) { ! return 0; ! } ! if ( $res['lastpage'] == $o->pagename ) ! continue; ! if ( ! preg_match($res['regexp'], $a->line) ) ! continue; ! $res['lastpage'] = $o->pagename; ! return $o->pagename; } } function IncreaseHitCount($dbi, $pagename) { --- 431,487 ---- // (Probably the best fix is to implement the link table, and use it.) $res['regexp'] = MakeBackLinkSearchRegexp($pagename); ! $query = "SELECT pagename, line FROM $dbi[page_table]" ! . " WHERE line LIKE '%$topage%'" ! . " ORDER BY pagename"; ! //echo "<p>$query<p>\n"; ! $res['res'] = msql_query($query, $dbi["dbc"]); + $count = 0; + $arr = array(); ! // build an array of the results. ! while ($hash = msql_fetch_array($res[res]) ) { ! if ($arr[$count -1 ] == $hash[pagename]) ! continue; ! $arr[$count] = $hash[pagename]; ! $count++; } + + $res[count] = 0; + reset($arr); + $res[arr] = $arr; + + return $res; } + + + // iterating through database + function BackLinkSearchNextMatch($dbi, &$res) { + + if ($res[count] > count($res[arr])) + return 0; + + $retval = $res[arr][$res[count]]; + $res[count]++; + + return $retval; + } + + /* + if ( ($o = msql_fetch_object($res['res'])) == FALSE ) { + echo "returning zero<p>\n"; + echo "it's '$o' <p>\n"; + return 0; + } + if ( $res['lastpage'] == $o->pagename ) + continue; + if ( ! preg_match($res['regexp'], $a->line) ) + continue; + $res['lastpage'] = $o->pagename; + return $o->pagename; + } + */ + function IncreaseHitCount($dbi, $pagename) { |