3 require_once 'lib/WikiDB/backend.php';
5 // FIXME:padding of data? Is it needed? dba_optimize() seems to do a good
6 // job at packing 'gdbm' (and 'db2') databases.
12 * Index: 'p' + pagename
13 * Values: latestversion . ':' . flags . ':' serialized hash of page meta data
14 * Currently flags = 1 if latest version has empty content.
17 * Index: 'v' + version:pagename
18 * Value: serialized hash of revision meta data, including:
19 * + quasi-meta-data %content
22 * index: 'o' + pagename
23 * value: serialized list of pages (names) which pagename links to.
24 * index: 'i' + pagename
25 * value: serialized list of pages which link to pagename
28 * Don't keep tables locked the whole time.
31 * - Yes - RecentChanges support. Lists of most recent edits (major, minor, either).
32 * 't' + mtime => 'a|i' + version+':'+pagename ('a': major, 'i': minor)
33 * Cost: Currently we have to get_all_pages and sort it by mtime.
34 * With a separate t table we have to update this table on every version change.
35 * - No - list of pagenames for get_all_pages (very cheap: iterate page table)
36 * - Maybe - mostpopular list? 'h' + pagename => hits
38 * Separate hit table, so we don't have to update the whole page entry
39 * each time we get a hit. Maybe not so important though.
42 require_once 'lib/DbaPartition.php';
44 class WikiDB_backend_dbaBase
45 extends WikiDB_backend
47 function __construct(&$dba)
50 // TODO: page and version tables should be in their own files, probably.
51 // We'll pack them all in one for now (testing).
52 // 2004-07-09 10:07:30 rurban: It's fast enough this way.
53 $this->_pagedb = new DbaPartition($dba, 'p');
54 $this->_versiondb = new DbaPartition($dba, 'v');
55 $linkdbpart = new DbaPartition($dba, 'l');
56 $this->_linkdb = new WikiDB_backend_dbaBase_linktable($linkdbpart);
57 $this->_dbdb = new DbaPartition($dba, 'd');
60 function sortable_columns()
62 return array('pagename', 'mtime' /*,'author_id','author'*/);
72 $this->_db->optimize();
80 function rebuild($args = false)
82 if (!empty($args['all'])) {
85 // rebuild backlink table
86 $this->_linkdb->rebuild();
90 function check($args = false)
92 // cleanup v?Pagename UNKNOWN0x0
94 $pagedb = &$this->_pagedb;
95 for ($page = $pagedb->firstkey();
97 $page = $pagedb->nextkey()) {
99 $errs[] = "empty page $page";
100 trigger_error("empty page $page deleted", E_USER_WARNING);
101 $this->purge_page($page);
104 if (!($data = $pagedb->get($page))) continue;
105 list($version, $flags,) = explode(':', $data, 3);
106 $vdata = $this->_versiondb->get($version . ":" . $page);
107 if ($vdata === false)
108 continue; // linkrelations
109 // we also had for some internal version vdata is serialized strings,
110 // need to unserialize it twice. We rather purge it.
111 if (!is_string($vdata)
112 or $vdata == 'UNKNOWN
\0'
113 or !is_array(unserialize($vdata))
115 $errs[] = "empty revision $version for $page";
116 trigger_error("empty revision $version for $page deleted", E_USER_WARNING);
117 $this->delete_versiondata($page, $version);
120 // check links per default
121 return array_merge($errs, $this->_linkdb->check());
124 function get_pagedata($pagename)
126 $result = $this->_pagedb->get($pagename);
129 list(, , $packed) = explode(':', $result, 3);
130 $data = unserialize($packed);
134 function update_pagedata($pagename, $newdata)
136 $result = $this->_pagedb->get($pagename);
138 list($latestversion, $flags, $data) = explode(':', $result, 3);
139 $data = unserialize($data);
141 $latestversion = $flags = 0;
145 foreach ($newdata as $key => $val) {
151 $this->_pagedb->set($pagename,
152 (int)$latestversion . ':'
157 function get_latest_version($pagename)
159 return (int)$this->_pagedb->get($pagename);
162 function get_previous_version($pagename, $version)
164 $versdb = &$this->_versiondb;
166 while (--$version > 0) {
167 if ($versdb->exists($version . ":$pagename"))
173 //check $want_content
174 function get_versiondata($pagename, $version, $want_content = false)
176 $data = $this->_versiondb->get((int)$version . ":$pagename");
177 if (empty($data) or $data == 'UNKNOWN
\0') return false;
179 $vdata = unserialize($data);
180 if (DEBUG and empty($vdata)) { // requires ->check
181 trigger_error("Delete empty revision: $pagename: " . $data, E_USER_WARNING);
182 $this->delete_versiondata($pagename, (int)$version);
185 $vdata['%content'] = !empty($vdata['%content']);
191 * Can be undone and is seen in RecentChanges.
194 function delete_page($pagename)
196 $version = $this->get_latest_version($pagename);
197 $data = $this->_versiondb->get((int)$version . ":$pagename");
198 // returns serialized string
199 if (!is_array($data) or empty($data)) {
200 if (is_string($data) and ($vdata = @unserialize($data))) {
203 } else // already empty page
206 assert(is_array($data) and !empty($data)); // mtime
207 $data['%content'] = '';
208 $data['mtime'] = time();
209 $data['summary'] = "removed by " . $GLOBALS["request"]->_deduceUsername();
210 $this->set_versiondata($pagename, $version + 1, $data);
211 $this->set_links($pagename, false);
215 * Completely delete all page revisions from the database.
217 function purge_page($pagename)
219 $pagedb = &$this->_pagedb;
220 $versdb = &$this->_versiondb;
222 $version = $this->get_latest_version($pagename);
223 while ($version > 0) {
224 $versdb->set($version-- . ":$pagename", false);
226 $pagedb->set($pagename, false);
228 $this->set_links($pagename, false);
231 function rename_page($pagename, $to)
233 $result = $this->_pagedb->get($pagename);
235 list($version, $flags, $data) = explode(':', $result, 3);
236 $data = unserialize($data);
240 $links = $this->_linkdb->get_links($pagename, false, false);
241 $data['pagename'] = $to;
242 $this->_pagedb->set($to,
246 // move over the latest version only
247 $pvdata = $this->get_versiondata($pagename, $version, true);
248 $data['mtime'] = time();
249 $data['summary'] = "renamed from " . $pagename
250 . " by " . $GLOBALS["request"]->_deduceUsername();
251 $this->set_versiondata($to, $version, $pvdata);
253 // update links and backlinks
254 $this->_linkdb->set_links($to, $links);
255 // better: update all back-/inlinks for all outlinks.
257 $this->_pagedb->delete($pagename);
262 * Delete an old revision of a page.
264 function delete_versiondata($pagename, $version)
266 $versdb = &$this->_versiondb;
268 $latest = $this->get_latest_version($pagename);
270 assert($version > 0);
271 assert($version <= $latest);
273 $versdb->set((int)$version . ":$pagename", false);
275 if ($version == $latest) {
276 $previous = $this->get_previous_version($pagename, $version);
278 $pvdata = $this->get_versiondata($pagename, $previous);
279 $is_empty = empty($pvdata['%content']);
282 $this->_update_latest_version($pagename, $previous, $is_empty);
287 * Create a new revision of a page.
289 function set_versiondata($pagename, $version, $data)
291 $versdb = &$this->_versiondb;
293 if (!is_array($data) or empty($data)) {
294 if (is_string($data) and ($vdata = @unserialize($data))) {
295 trigger_error("broken page version $pagename. Run Check WikiDB",
301 assert(is_array($data) and !empty($data)); // mtime
302 $versdb->set((int)$version . ":$pagename", serialize($data));
303 if ($version > $this->get_latest_version($pagename))
304 $this->_update_latest_version($pagename, $version, empty($data['%content']));
307 function _update_latest_version($pagename, $latest, $flags)
309 $pagedb = &$this->_pagedb;
311 $pdata = $pagedb->get($pagename);
313 list(, , $pagedata) = explode(':', $pdata, 3);
315 $pagedata = serialize(array());
317 $pagedb->set($pagename, (int)$latest . ':' . (int)$flags . ":$pagedata");
320 function numPages($include_empty = false, $exclude = '')
322 $pagedb = &$this->_pagedb;
324 for ($page = $pagedb->firstkey(); $page !== false; $page = $pagedb->nextkey()) {
326 assert(!empty($page));
329 if ($exclude and in_array($page, $exclude)) continue;
330 if (!$include_empty) {
331 if (!($data = $pagedb->get($page))) continue;
332 list($latestversion, $flags,) = explode(':', $data, 3);
334 if ($latestversion == 0 || $flags != 0)
335 continue; // current content is empty
342 function get_all_pages($include_empty = false, $sortby = '', $limit = '', $exclude = '')
344 $pagedb = &$this->_pagedb;
349 if ($limit) { // extract from,count from limit
350 list($from, $count) = $this->limit($limit);
352 for ($page = $pagedb->firstkey(); $page !== false; $page = $pagedb->nextkey()) {
354 assert(!empty($page));
357 if ($exclude and in_array($page, $exclude)) continue;
358 if ($limit and $from) {
360 if ($i < $from) continue;
362 if ($limit and count($pages) >= $count) break;
363 if (!$include_empty) {
364 if (!($data = $pagedb->get($page))) continue;
365 list($latestversion, $flags,) = explode(':', $data, 3);
367 if ($latestversion == 0 || $flags != 0)
368 continue; // current content is empty
372 return new WikiDB_backend_dbaBase_pageiter
374 array('sortby' => $sortby)); // already limited
377 function set_links($pagename, $links)
379 $this->_linkdb->set_links($pagename, $links);
382 function get_links($pagename, $reversed = true, $include_empty = false,
383 $sortby = '', $limit = '', $exclude = '',
384 $want_relations = false)
386 // optimization: if no relation at all is found, mark it in the iterator.
387 $links = $this->_linkdb->get_links($pagename, $reversed, $want_relations);
389 return new WikiDB_backend_dbaBase_pageiter
391 array('sortby' => $sortby,
393 'exclude' => $exclude,
394 'want_relations' => $want_relations,
395 'found_relations' => $want_relations
396 ? $this->_linkdb->found_relations : 0
401 * @return array of all linkrelations
402 * Faster than the dumb WikiDB method.
404 public function list_relations($also_attributes = false,
405 $only_attributes = false,
408 $linkdb = &$this->_linkdb;
409 $relations = array();
410 for ($link = $linkdb->_db->firstkey();
412 $link = $linkdb->_db->nextkey()) {
413 if ($link[0] != 'o') continue;
414 $links = $linkdb->_get_links('o', substr($link, 1));
415 foreach ($links as $link) { // linkto => page, linkrelation => page
417 and $link['relation']
418 and !in_array($link['relation'], $relations)
420 $is_attribute = empty($link['linkto']); // a relation has both
422 if ($only_attributes or $also_attributes)
423 $relations[] = $link['relation'];
424 } elseif (!$only_attributes) {
425 $relations[] = $link['relation'];
438 * WikiDB_backend_dumb_LinkSearchIter searches over all
439 * pages and then all its links. Since there are less
440 * links than pages, and we easily get the pagename from
441 * the link key, we iterate here directly over the
442 * linkdb and check the pagematch there.
444 * @param $pages object A TextSearchQuery object for the pagename filter.
445 * @param $query object A SearchQuery object (Text or Numeric) for the linkvalues,
446 * linkto, linkfrom (=backlink), relation or attribute values.
447 * @param $linktype string One of the 4 linktypes "linkto",
448 * "linkfrom" (=backlink), "relation" or "attribute".
449 * Maybe also "relation+attribute" for the advanced search.
450 * @param $relation object A TextSearchQuery for the linkname or false.
451 * @param $options array Currently ignored. hash of sortby, limit, exclude.
452 * @return object A WikiDB_backend_iterator.
453 * @see WikiDB::linkSearch
455 function link_search($pages, $query, $linktype,
456 $relation = false, $options = array())
458 $linkdb = &$this->_linkdb;
461 $want_relations = false;
462 if ($linktype == 'relation') {
463 $want_relations = true;
464 $field = 'linkrelation';
466 if ($linktype == 'attribute') {
467 $want_relations = true;
468 $field = 'attribute';
470 if ($linktype == 'linkfrom') {
474 for ($link = $linkdb->_db->firstkey();
476 $link = $linkdb->_db->nextkey()) {
477 $type = $reverse ? 'i' : 'o';
478 if ($link[0] != $type) continue;
479 $pagename = substr($link, 1);
480 if (!$pages->match($pagename)) continue;
481 if ($linktype == 'attribute') {
482 $page = $GLOBALS['request']->_dbi->getPage($pagename);
483 $attribs = $page->get('attributes');
485 /* Optimization on expressive searches:
486 for queries with multiple attributes.
487 Just take the defined placeholders from the query(ies)
488 if there are more attributes than query variables.
490 if ($query->getType() != 'text'
492 and ((count($vars = $query->getVars()) > 1)
493 or (count($attribs) > count($vars)))
495 // names must strictly match. no * allowed
496 if (!$query->can_match($attribs)) continue;
497 if (!($result = $query->match($attribs))) continue;
498 foreach ($result as $r) {
499 $r['pagename'] = $pagename;
503 // textsearch or simple value. no strict bind by name needed
504 foreach ($attribs as $attribute => $value) {
505 if ($relation and !$relation->match($attribute)) continue;
506 if (!$query->match($value)) continue;
507 $links[] = array('pagename' => $pagename,
508 'linkname' => $attribute,
509 'linkvalue' => $value);
514 // TODO: honor limits. this can get large.
515 if ($want_relations) {
516 // MAP linkrelation : pagename => thispagename : linkname : linkvalue
517 $_links = $linkdb->_get_links('o', $pagename);
518 foreach ($_links as $link) { // linkto => page, linkrelation => page
519 if (!isset($link['relation']) or !$link['relation']) continue;
520 if ($relation and !$relation->match($link['relation'])) continue;
521 if (!$query->match($link['linkto'])) continue;
522 $links[] = array('pagename' => $pagename,
523 'linkname' => $link['relation'],
524 'linkvalue' => $link['linkto']);
527 $_links = $linkdb->_get_links($reverse ? 'i' : 'o', $pagename);
528 foreach ($_links as $link) { // linkto => page
530 $link = $link['linkto'];
531 if (!$query->match($link)) continue;
532 $links[] = array('pagename' => $pagename,
534 'linkvalue' => $link);
539 $options['want_relations'] = true; // Iter hack to force return of the whole hash
540 return new WikiDB_backend_dbaBase_pageiter($this, $links, $options);
544 * Handle multi-searches for many relations and attributes in one expression.
545 * Bind all required attributes and relations per page together and pass it
547 * (is_a::city and population < 20000) and (*::city and area > 1000000)
548 * (is_a::city or linkto::CategoryCountry) and population < 20000 and area > 1000000
549 * Note that the 'linkto' and 'linkfrom' links are relations, containing an array.
551 * @param $pages object A TextSearchQuery object for the pagename filter.
552 * @param $query object A SemanticSearchQuery object for the links.
553 * @param $options array Currently ignored. hash of sortby, limit, exclude
555 * @return object A WikiDB_backend_iterator.
556 * @see WikiDB::linkSearch
558 function relation_search($pages, $query, $options = array())
560 $linkdb = &$this->_linkdb;
562 // We need to detect which attributes and relation names we should look for. NYI
563 $want_attributes = $query->hasAttributes();
564 $want_relation = $query->hasRelations();
565 $linknames = $query->getLinkNames();
566 // create a hash for faster checks
567 $linkcheck = array();
568 foreach ($linknames as $l) $linkcheck[$l] = 1;
570 for ($link = $linkdb->_db->firstkey();
572 $link = $linkdb->_db->nextkey()) {
573 $type = $reverse ? 'i' : 'o';
574 if ($link[0] != $type) continue;
575 $pagename = substr($link, 1);
576 if (!$pages->match($pagename)) continue;
577 $pagelinks = array();
578 if ($want_attributes) {
579 $page = $GLOBALS['request']->_dbi->getPage($pagename);
580 $attribs = $page->get('attributes');
581 $pagelinks = $attribs;
583 if ($want_relations) {
584 // all links contain arrays of pagenames, just the attributes
585 // are guaranteed to be singular
586 if (isset($linkcheck['linkfrom'])) {
587 $pagelinks['linkfrom'] = $linkdb->_get_links('i', $pagename);
589 $outlinks = $linkdb->_get_links('o', $pagename);
590 $want_to = isset($linkcheck['linkto']);
591 foreach ($outlinks as $link) { // linkto => page, relation => page
593 if ((isset($link['relation'])) and $link['relation']
594 and isset($linkcheck[$link['relation']])
596 $pagelinks[$link['relation']][] = $link['linkto'];
598 $pagelinks['linkto'][] = is_array($link) ? $link['linkto'] : $link;
601 if ($result = $query->match($pagelinks)) {
602 $links = array_merge($links, $result);
605 $options['want_relations'] = true; // Iter hack to force return of the whole hash
606 return new WikiDB_backend_dbaBase_pageiter($this, $links, $options);
610 function WikiDB_backend_dbaBase_sortby_pagename_ASC($a, $b)
612 return strcasecmp($a, $b);
615 function WikiDB_backend_dbaBase_sortby_pagename_DESC($a, $b)
617 return strcasecmp($b, $a);
620 function WikiDB_backend_dbaBase_sortby_mtime_ASC($a, $b)
622 return WikiDB_backend_dbaBase_sortby_num($a, $b, 'mtime');
625 function WikiDB_backend_dbaBase_sortby_mtime_DESC($a, $b)
627 return WikiDB_backend_dbaBase_sortby_num($b, $a, 'mtime');
631 function WikiDB_backend_dbaBase_sortby_hits_ASC ($a, $b) {
632 return WikiDB_backend_dbaBase_sortby_num($a, $b, 'hits');
634 function WikiDB_backend_dbaBase_sortby_hits_DESC ($a, $b) {
635 return WikiDB_backend_dbaBase_sortby_num($b, $a, 'hits');
638 function WikiDB_backend_dbaBase_sortby_num($aname, $bname, $field)
641 $dbi = $request->getDbh();
642 // fields are stored in versiondata
643 $av = $dbi->_backend->get_latest_version($aname);
644 $bv = $dbi->_backend->get_latest_version($bname);
645 $a = $dbi->_backend->get_versiondata($aname, $av, false);
647 $b = $dbi->_backend->get_versiondata($bname, $bv, false);
648 if (!$b or !isset($b[$field])) return 0;
649 if (empty($a[$field])) return -1;
650 if ((!isset($a[$field]) and !isset($b[$field])) or ($a[$field] === $b[$field])) {
653 return ($a[$field] < $b[$field]) ? -1 : 1;
657 class WikiDB_backend_dbaBase_pageiter
658 extends WikiDB_backend_iterator
660 // fixed for linkrelations
661 function __construct(&$backend, &$pages, $options = false)
663 $this->_backend = $backend;
664 $this->_options = $options;
666 if (!empty($options['sortby'])) {
667 $sortby = WikiDB_backend::sortby($options['sortby'], 'db',
668 array('pagename', 'mtime'));
669 // check for which column to sortby
670 if ($sortby and !strstr($sortby, "hits ")) {
671 usort($pages, 'WikiDB_backend_dbaBase_sortby_'
672 . str_replace(' ', '_', $sortby));
675 if (!empty($options['limit'])) {
676 list($offset, $limit) = WikiDB_backend::limit($options['limit']);
677 $pages = array_slice($pages, $offset, $limit);
679 $this->_pages = $pages;
681 $this->_pages = array();
684 // fixed for relations
687 if (!($page = array_shift($this->_pages)))
689 if (!empty($this->_options['want_relations'])) {
690 // $linkrelation = $page['linkrelation'];
691 $pagename = $page['pagename'];
692 if (!empty($this->_options['exclude'])
693 and in_array($pagename, $this->_options['exclude'])
695 return $this->next();
698 if (!empty($this->_options['exclude'])
699 and in_array($page, $this->_options['exclude'])
701 return $this->next();
702 return array('pagename' => $page);
707 reset($this->_pages);
712 $this->_pages = array();
716 class WikiDB_backend_dbaBase_linktable
718 function WikiDB_backend_dbaBase_linktable(&$dba)
723 //TODO: try storing link lists as hashes rather than arrays.
724 // backlink deletion would be faster.
725 function get_links($page, $reversed = true, $want_relations = false)
727 if ($want_relations) {
728 $this->found_relations = 0;
729 $links = $this->_get_links($reversed ? 'i' : 'o', $page);
730 $linksonly = array();
731 foreach ($links as $link) { // linkto => page, linkrelation => page
732 if (is_array($link) and isset($link['relation'])) {
733 if ($link['relation'])
734 $this->found_relations++;
735 $linksonly[] = array('pagename' => $link['linkto'],
736 'linkrelation' => $link['relation']);
737 } else { // empty relations are stripped
738 $linksonly[] = array('pagename' => $link['linkto']);
743 $links = $this->_get_links($reversed ? 'i' : 'o', $page);
744 $linksonly = array();
745 foreach ($links as $link) {
746 if (is_array($link)) {
747 $linksonly[] = $link['linkto'];
749 $linksonly[] = $link;
755 // fixed: relations ready
756 function set_links($page, $links)
759 $oldlinks = $this->get_links($page, false, false);
761 if (!is_array($links)) {
762 assert(empty($links));
765 $this->_set_links('o', $page, $links);
767 /* Now for the backlink update we squash the linkto hashes into a simple array */
769 foreach ($links as $hash) {
770 if (!empty($hash['linkto']) and !in_array($hash['linkto'], $newlinks))
771 // for attributes it's empty
772 $newlinks[] = $hash['linkto'];
773 elseif (is_string($hash) and !in_array($hash, $newlinks))
776 //$newlinks = array_unique($newlinks);
782 $new = current($newlinks);
783 $old = current($oldlinks);
784 while ($new !== false || $old !== false) {
785 if ($old === false || ($new !== false && $new < $old)) {
786 // $new is a new link (not in $oldlinks).
787 $this->_add_backlink($new, $page);
788 $new = next($newlinks);
789 } elseif ($new === false || $old < $new) {
790 // $old is a obsolete link (not in $newlinks).
791 $this->_delete_backlink($old, $page);
792 $old = next($oldlinks);
794 // Unchanged link (in both $newlist and $oldlinks).
795 assert($new == $old);
796 $new = next($newlinks);
797 $old = next($oldlinks);
803 * Rebuild the back-link index.
805 * This should never be needed, but if the database gets hosed for some reason,
806 * this should put it back into a consistent state.
808 * We assume the forward links in the our table are correct, and recalculate
809 * all the backlinks appropriately.
815 // Delete the backlink tables, make a list of lo.page keys.
817 for ($key = $db->firstkey(); $key; $key = $db->nextkey()) {
820 elseif ($key[0] == 'o')
821 $okeys[] = $key; else {
822 trigger_error("Bad key in linktable: '$key'", E_USER_WARNING);
826 foreach ($okeys as $key) {
827 $page = substr($key, 1);
828 $links = $this->_get_links('o', $page);
830 $this->set_links($page, $links);
838 // FIXME: check for sortedness and uniqueness in links lists.
840 for ($key = $db->firstkey(); $key; $key = $db->nextkey()) {
841 if (strlen($key) < 1 || ($key[0] != 'i' && $key[0] != 'o')) {
842 $errs[] = "Bad key '$key' in table";
845 $page = substr($key, 1);
846 if ($key[0] == 'o') {
848 foreach ($this->_get_links('o', $page) as $link) {
849 $link = $link['linkto'];
850 if (!$this->_has_link('i', $link, $page))
851 $errs[] = "backlink entry missing for link '$page'->'$link'";
854 assert($key[0] == 'i');
856 foreach ($this->_get_links('i', $page) as $link) {
857 if (!$this->_has_link('o', $link, $page))
858 $errs[] = "link entry missing for backlink '$page'<-'$link'";
862 //if ($errs) $this->rebuild();
863 return isset($errs) ? $errs : false;
866 /* TODO: Add another lrRelationName key for relations.
867 * lrRelationName: frompage => topage
870 function _add_relation($page, $linkedfrom)
872 $relations = $this->_get_links('r', $page);
873 $backlinks[] = $linkedfrom;
875 $this->_set_links('i', $page, $backlinks);
878 function _add_backlink($page, $linkedfrom)
880 $backlinks = $this->_get_links('i', $page);
881 $backlinks[] = $linkedfrom;
883 $this->_set_links('i', $page, $backlinks);
886 function _delete_backlink($page, $linkedfrom)
888 $backlinks = $this->_get_links('i', $page);
889 foreach ($backlinks as $key => $backlink) {
890 if ($backlink == $linkedfrom)
891 unset($backlinks[$key]);
893 $this->_set_links('i', $page, $backlinks);
896 function _has_link($which, $page, $link)
898 $links = $this->_get_links($which, $page);
899 // since links are always sorted, break if >
900 // TODO: binary search
901 foreach ($links as $l) {
902 if ($l['linkto'] == $link)
904 if ($l['linkto'] > $link)
910 function _get_links($which, $page)
912 $data = $this->_db->get($which . $page);
913 return $data ? unserialize($data) : array();
916 function _set_links($which, $page, &$links)
918 $key = $which . $page;
920 $this->_db->set($key, serialize($links));
922 $this->_db->set($key, false);
930 // c-hanging-comment-ender-p: nil
931 // indent-tabs-mode: nil