]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB.php
enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for...
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PearDB.php,v 1.77 2004-12-06 19:50:04 rurban Exp $');
3
4 require_once('lib/WikiDB/backend.php');
5 //require_once('lib/FileFinder.php');
6 //require_once('lib/ErrorManager.php');
7
8 class WikiDB_backend_PearDB
9 extends WikiDB_backend
10 {
11     var $_dbh;
12
13     function WikiDB_backend_PearDB ($dbparams) {
14         // Find and include PEAR's DB.php. maybe we should force our private version again...
15         // if DB would have exported its version number, it would be easier.
16         @require_once('DB/common.php'); // Either our local pear copy or the system one
17         // check the version!
18         $name = check_php_version(5) ? "escapeSimple" : strtolower("escapeSimple");
19         if (!in_array($name, get_class_methods("DB_common"))) {
20             $finder = new FileFinder;
21             $dir = dirname(__FILE__)."/../../pear";
22             $finder->_prepend_to_include_path($dir);
23             include_once("$dir/DB/common.php"); // use our version instead.
24             if (!in_array($name, get_class_methods("DB_common"))) {
25                 $pearFinder = new PearFileFinder("lib/pear");
26                 $pearFinder->includeOnce('DB.php');
27             } else {
28                 include_once("$dir/DB.php");
29             }
30         } else {
31           include_once("DB.php");
32         }
33
34         // Install filter to handle bogus error notices from buggy DB.php's.
35         // TODO: check the Pear_DB version, but how?
36         if (0) {
37             global $ErrorManager;
38             $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_pear_notice_filter'));
39             $this->_pearerrhandler = true;
40         }
41         
42         // Open connection to database
43         $this->_dsn = $dbparams['dsn'];
44         $this->_dbparams = $dbparams;
45         $dboptions = array('persistent' => true,
46                            'debug' => 2);
47         if (preg_match('/^pgsql/',$this->_dsn))
48             $dboptions['persistent'] = false;
49         $this->_dbh = DB::connect($this->_dsn, $dboptions);
50         $dbh = &$this->_dbh;
51         if (DB::isError($dbh)) {
52             trigger_error(sprintf("Can't connect to database: %s",
53                                   $this->_pear_error_message($dbh)),
54                           E_USER_ERROR);
55         }
56         $dbh->setErrorHandling(PEAR_ERROR_CALLBACK,
57                                array($this, '_pear_error_callback'));
58         $dbh->setFetchMode(DB_FETCHMODE_ASSOC);
59
60         $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
61         $this->_table_names
62             = array('page_tbl'     => $prefix . 'page',
63                     'version_tbl'  => $prefix . 'version',
64                     'link_tbl'     => $prefix . 'link',
65                     'recent_tbl'   => $prefix . 'recent',
66                     'nonempty_tbl' => $prefix . 'nonempty');
67         $page_tbl = $this->_table_names['page_tbl'];
68         $version_tbl = $this->_table_names['version_tbl'];
69         $this->page_tbl_fields = "$page_tbl.id AS id, $page_tbl.pagename AS pagename, $page_tbl.hits AS hits";
70         $this->version_tbl_fields = "$version_tbl.version AS version, $version_tbl.mtime AS mtime, ".
71             "$version_tbl.minor_edit AS minor_edit, $version_tbl.content AS content, $version_tbl.versiondata AS versiondata";
72
73         $this->_expressions
74             = array('maxmajor'     => "MAX(CASE WHEN minor_edit=0 THEN version END)",
75                     'maxminor'     => "MAX(CASE WHEN minor_edit<>0 THEN version END)",
76                     'maxversion'   => "MAX(version)",
77                     'notempty'     => "<>''",
78                     'iscontent'    => "content<>''");
79         
80         $this->_lock_count = 0;
81     }
82     
83     /**
84      * Close database connection.
85      */
86     function close () {
87         if (!$this->_dbh)
88             return;
89         if ($this->_lock_count) {
90             trigger_error( "WARNING: database still locked " . '(lock_count = $this->_lock_count)' . "\n<br />",
91                           E_USER_WARNING);
92         }
93         $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT);        // prevent recursive loops.
94         $this->unlock('force');
95
96         $this->_dbh->disconnect();
97
98         if (!empty($this->_pearerrhandler)) {
99             $GLOBALS['ErrorManager']->popErrorHandler();
100         }
101     }
102
103
104     /*
105      * Test fast wikipage.
106      */
107     function is_wiki_page($pagename) {
108         $dbh = &$this->_dbh;
109         extract($this->_table_names);
110         return $dbh->getOne(sprintf("SELECT $page_tbl.id as id"
111                                     . " FROM $nonempty_tbl, $page_tbl"
112                                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
113                                     . "   AND pagename='%s'",
114                                     $dbh->escapeSimple($pagename)));
115     }
116         
117     function get_all_pagenames() {
118         $dbh = &$this->_dbh;
119         extract($this->_table_names);
120         return $dbh->getCol("SELECT pagename"
121                             . " FROM $nonempty_tbl, $page_tbl"
122                             . " WHERE $nonempty_tbl.id=$page_tbl.id");
123     }
124
125     function numPages($filter=false, $exclude='') {
126         $dbh = &$this->_dbh;
127         extract($this->_table_names);
128         return $dbh->getOne("SELECT count(*)"
129                             . " FROM $nonempty_tbl, $page_tbl"
130                             . " WHERE $nonempty_tbl.id=$page_tbl.id");
131     }
132     
133     function increaseHitCount($pagename) {
134         $dbh = &$this->_dbh;
135         // Hits is the only thing we can update in a fast manner.
136         // Note that this will fail silently if the page does not
137         // have a record in the page table.  Since it's just the
138         // hit count, who cares?
139         $dbh->query(sprintf("UPDATE %s SET hits=hits+1 WHERE pagename='%s'",
140                             $this->_table_names['page_tbl'],
141                             $dbh->escapeSimple($pagename)));
142         return;
143     }
144
145     /**
146      * Read page information from database.
147      */
148     function get_pagedata($pagename) {
149         $dbh = &$this->_dbh;
150         //trigger_error("GET_PAGEDATA $pagename", E_USER_NOTICE);
151         $result = $dbh->getRow(sprintf("SELECT hits,pagedata FROM %s WHERE pagename='%s'",
152                                        $this->_table_names['page_tbl'],
153                                        $dbh->escapeSimple($pagename)),
154                                DB_FETCHMODE_ASSOC);
155         return $result ? $this->_extract_page_data($result) : false;
156     }
157
158     function  _extract_page_data($data) {
159         if (empty($data)) return array();
160         elseif (empty($data['pagedata'])) return $data;
161         else {
162             $data = array_merge($data, $this->_unserialize($data['pagedata']));
163             unset($data['pagedata']);
164             return $data;
165         }
166     }
167
168     function update_pagedata($pagename, $newdata) {
169         $dbh = &$this->_dbh;
170         $page_tbl = $this->_table_names['page_tbl'];
171
172         // Hits is the only thing we can update in a fast manner.
173         if (count($newdata) == 1 && isset($newdata['hits'])) {
174             // Note that this will fail silently if the page does not
175             // have a record in the page table.  Since it's just the
176             // hit count, who cares?
177             $dbh->query(sprintf("UPDATE $page_tbl SET hits=%d WHERE pagename='%s'",
178                                 $newdata['hits'], $dbh->escapeSimple($pagename)));
179             return;
180         }
181
182         $this->lock(array($page_tbl), true);
183         $data = $this->get_pagedata($pagename);
184         if (!$data) {
185             $data = array();
186             $this->_get_pageid($pagename, true); // Creates page record
187         }
188         
189         @$hits = (int)$data['hits'];
190         unset($data['hits']);
191
192         foreach ($newdata as $key => $val) {
193             if ($key == 'hits')
194                 $hits = (int)$val;
195             else if (empty($val))
196                 unset($data[$key]);
197             else
198                 $data[$key] = $val;
199         }
200
201         /* Portability issue -- not all DBMS supports huge strings 
202          * so we need to 'bind' instead of building a simple SQL statment.
203          * Note that we do not need to escapeSimple when we bind
204         $dbh->query(sprintf("UPDATE $page_tbl"
205                             . " SET hits=%d, pagedata='%s'"
206                             . " WHERE pagename='%s'",
207                             $hits,
208                             $dbh->escapeSimple($this->_serialize($data)),
209                             $dbh->escapeSimple($pagename)));
210         */
211         $sth = $dbh->query("UPDATE $page_tbl"
212                            . " SET hits=?, pagedata=?"
213                            . " WHERE pagename=?",
214                            array($hits, $this->_serialize($data), $pagename));
215         $this->unlock(array($page_tbl));
216     }
217
218     function _get_pageid($pagename, $create_if_missing = false) {
219         
220         // check id_cache
221         global $request;
222         $cache =& $request->_dbi->_cache->_id_cache;
223         if (isset($cache[$pagename])) return $cache[$pagename];
224
225         $dbh = &$this->_dbh;
226         $page_tbl = $this->_table_names['page_tbl'];
227         
228         $query = sprintf("SELECT id FROM $page_tbl WHERE pagename='%s'",
229                          $dbh->escapeSimple($pagename));
230
231         if (!$create_if_missing)
232             return $dbh->getOne($query);
233
234         $id = $dbh->getOne($query);
235         if (empty($id)) {
236             $this->lock(array($page_tbl), true); // write lock
237             $max_id = $dbh->getOne("SELECT MAX(id) FROM $page_tbl");
238             $id = $max_id + 1;
239             $dbh->query(sprintf("INSERT INTO $page_tbl"
240                                 . " (id,pagename,hits)"
241                                 . " VALUES (%d,'%s',0)",
242                                 $id, $dbh->escapeSimple($pagename)));
243             $this->unlock(array($page_tbl));
244         }
245         return $id;
246     }
247
248     function get_latest_version($pagename) {
249         $dbh = &$this->_dbh;
250         extract($this->_table_names);
251         return
252             (int)$dbh->getOne(sprintf("SELECT latestversion"
253                                       . " FROM $page_tbl, $recent_tbl"
254                                       . " WHERE $page_tbl.id=$recent_tbl.id"
255                                       . "  AND pagename='%s'",
256                                       $dbh->escapeSimple($pagename)));
257     }
258
259     function get_previous_version($pagename, $version) {
260         $dbh = &$this->_dbh;
261         extract($this->_table_names);
262         
263         return
264             (int)$dbh->getOne(sprintf("SELECT version"
265                                       . " FROM $version_tbl, $page_tbl"
266                                       . " WHERE $version_tbl.id=$page_tbl.id"
267                                       . "  AND pagename='%s'"
268                                       . "  AND version < %d"
269                                       . " ORDER BY version DESC",
270                                       /* Non portable and useless anyway with getOne
271                                       . " LIMIT 1",
272                                       */
273                                       $dbh->escapeSimple($pagename),
274                                       $version));
275     }
276     
277     /**
278      * Get version data.
279      *
280      * @param $version int Which version to get.
281      *
282      * @return hash The version data, or false if specified version does not
283      *              exist.
284      */
285     function get_versiondata($pagename, $version, $want_content = false) {
286         $dbh = &$this->_dbh;
287         extract($this->_table_names);
288         extract($this->_expressions);
289
290         assert(is_string($pagename) and $pagename != "");
291         assert($version > 0);
292         
293         //trigger_error("GET_REVISION $pagename $version $want_content", E_USER_NOTICE);
294         // FIXME: optimization: sometimes don't get page data?
295         if ($want_content) {
296             $fields = $this->page_tbl_fields 
297                 . ",$page_tbl.pagedata as pagedata," 
298                 . $this->version_tbl_fields;
299         }
300         else {
301             $fields = $this->page_tbl_fields . ","
302                 . "mtime, minor_edit, versiondata,"
303                 . "$iscontent AS have_content";
304         }
305
306         $result = $dbh->getRow(sprintf("SELECT $fields"
307                                        . " FROM $page_tbl, $version_tbl"
308                                        . " WHERE $page_tbl.id=$version_tbl.id"
309                                        . "  AND pagename='%s'"
310                                        . "  AND version=%d",
311                                        $dbh->escapeSimple($pagename), $version),
312                                DB_FETCHMODE_ASSOC);
313
314         return $this->_extract_version_data($result);
315     }
316
317     function _extract_version_data($query_result) {
318         if (!$query_result)
319             return false;
320
321         $data = $this->_unserialize($query_result['versiondata']);
322         
323         $data['mtime'] = $query_result['mtime'];
324         $data['is_minor_edit'] = !empty($query_result['minor_edit']);
325         
326         if (isset($query_result['content']))
327             $data['%content'] = $query_result['content'];
328         elseif ($query_result['have_content'])
329             $data['%content'] = true;
330         else
331             $data['%content'] = '';
332
333         // FIXME: this is ugly.
334         if (isset($query_result['pagename'])) {
335             // Query also includes page data.
336             // We might as well send that back too...
337             unset($query_result['versiondata']);
338             $data['%pagedata'] = $this->_extract_page_data($query_result);
339         }
340
341         return $data;
342     }
343
344
345     /**
346      * Create a new revision of a page.
347      */
348     function set_versiondata($pagename, $version, $data) {
349         $dbh = &$this->_dbh;
350         $version_tbl = $this->_table_names['version_tbl'];
351         
352         $minor_edit = (int) !empty($data['is_minor_edit']);
353         unset($data['is_minor_edit']);
354         
355         $mtime = (int)$data['mtime'];
356         unset($data['mtime']);
357         assert(!empty($mtime));
358
359         @$content = (string) $data['%content'];
360         unset($data['%content']);
361
362         unset($data['%pagedata']);
363         
364         $this->lock();
365         $id = $this->_get_pageid($pagename, true);
366
367         // FIXME: optimize: mysql can do this with one REPLACE INTO (I think).
368         $dbh->query(sprintf("DELETE FROM $version_tbl"
369                             . " WHERE id=%d AND version=%d",
370                             $id, $version));
371
372         /* mysql optimized version. 
373         $dbh->query(sprintf("INSERT INTO $version_tbl"
374                             . " (id,version,mtime,minor_edit,content,versiondata)"
375                             . " VALUES(%d,%d,%d,%d,'%s','%s')",
376                             $id, $version, $mtime, $minor_edit,
377                             $dbh->quoteSmart($content),
378                             $dbh->quoteSmart($this->_serialize($data))));
379         */
380         // generic slow PearDB bind eh quoting.
381         $dbh->query("INSERT INTO $version_tbl"
382                     . " (id,version,mtime,minor_edit,content,versiondata)"
383                     . " VALUES(?, ?, ?, ?, ?, ?)",
384                     array($id, $version, $mtime, $minor_edit, $content,
385                     $this->_serialize($data)));
386
387         $this->_update_recent_table($id);
388         $this->_update_nonempty_table($id);
389         
390         $this->unlock();
391     }
392     
393     /**
394      * Delete an old revision of a page.
395      */
396     function delete_versiondata($pagename, $version) {
397         $dbh = &$this->_dbh;
398         extract($this->_table_names);
399
400         $this->lock();
401         if ( ($id = $this->_get_pageid($pagename)) ) {
402             $dbh->query("DELETE FROM $version_tbl"
403                         . " WHERE id=$id AND version=$version");
404             $this->_update_recent_table($id);
405             // This shouldn't be needed (as long as the latestversion
406             // never gets deleted.)  But, let's be safe.
407             $this->_update_nonempty_table($id);
408         }
409         $this->unlock();
410     }
411
412     /**
413      * See ADODB for a better delete_page(), which can be undone and is seen in RecentChanges.
414      */
415     function delete_page($pagename) {
416         $this->purge_page($pagename);
417     }
418
419     /**
420      * Delete page completely from the database.
421      * I'm not sure if this is what we want. Maybe just delete the revisions
422      */
423     function purge_page($pagename) {
424         $dbh = &$this->_dbh;
425         extract($this->_table_names);
426         
427         $this->lock();
428         if ( ($id = $this->_get_pageid($pagename, false)) ) {
429             $dbh->query("DELETE FROM $version_tbl  WHERE id=$id");
430             $dbh->query("DELETE FROM $recent_tbl   WHERE id=$id");
431             $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$id");
432             $dbh->query("DELETE FROM $link_tbl     WHERE linkfrom=$id");
433             $nlinks = $dbh->getOne("SELECT COUNT(*) FROM $link_tbl WHERE linkto=$id");
434             if ($nlinks) {
435                 // We're still in the link table (dangling link) so we can't delete this
436                 // altogether.
437                 $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
438                 $result = 0;
439             }
440             else {
441                 $dbh->query("DELETE FROM $page_tbl WHERE id=$id");
442                 $result = 1;
443             }
444             $this->_update_recent_table();
445             $this->_update_nonempty_table();
446         } else {
447             $result = -1; // already purged or not existing
448         }
449         $this->unlock();
450         return $result;
451     }
452
453     // The only thing we might be interested in updating which we can
454     // do fast in the flags (minor_edit).   I think the default
455     // update_versiondata will work fine...
456     //function update_versiondata($pagename, $version, $data) {
457     //}
458
459     function set_links($pagename, $links) {
460         // Update link table.
461         // FIXME: optimize: mysql can do this all in one big INSERT.
462
463         $dbh = &$this->_dbh;
464         extract($this->_table_names);
465
466         $this->lock();
467         $pageid = $this->_get_pageid($pagename, true);
468
469         $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
470
471         if ($links) {
472             foreach($links as $link) {
473                 if (isset($linkseen[$link]))
474                     continue;
475                 $linkseen[$link] = true;
476                 $linkid = $this->_get_pageid($link, true);
477                 $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto)"
478                             . " VALUES ($pageid, $linkid)");
479             }
480         }
481         $this->unlock();
482     }
483     
484     /**
485      * Find pages which link to or are linked from a page.
486      */
487     function get_links($pagename, $reversed=true, $include_empty=false,
488                        $sortby=false, $limit=false, $exclude='') {
489         $dbh = &$this->_dbh;
490         extract($this->_table_names);
491
492         if ($reversed)
493             list($have,$want) = array('linkee', 'linker');
494         else
495             list($have,$want) = array('linker', 'linkee');
496         $orderby = $this->sortby($sortby, 'db', array('pagename'));
497         if ($orderby) $orderby = ' ORDER BY $want.' . $orderby;
498         if ($exclude) // array of pagenames
499             $exclude = " AND $want.pagename NOT IN ".$this->_sql_set($exclude);
500         else 
501             $exclude='';
502
503         $qpagename = $dbh->escapeSimple($pagename);
504         $sql = "SELECT $want.id as id, $want.pagename as pagename, $want.hits as hits"
505             // Looks like 'AS' in column alias is a MySQL thing, Oracle does not like it
506             // and the PostgresSQL manual does not have it either
507             // Since it is optional in mySQL, just remove it...
508             . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee"
509             . (!$include_empty ? ", $nonempty_tbl" : '')
510             . " WHERE linkfrom=linker.id AND linkto=linkee.id"
511             . "  AND $have.pagename='$qpagename'"
512             . (!$include_empty ? " AND $nonempty_tbl.id=$want.id" : "")
513             //. " GROUP BY $want.id"
514             . $exclude
515             . $orderby;
516         if ($limit) {
517             // extract from,count from limit
518             list($from,$count) = $this->limit($limit);
519             $result = $dbh->limitQuery($sql, $from, $count);
520         } else {
521             $result = $dbh->query($sql);
522         }
523         
524         return new WikiDB_backend_PearDB_iter($this, $result);
525     }
526
527     /**
528      * Find if a page links to another page
529      */
530     function exists_link($pagename, $link, $reversed=false) {
531         $dbh = &$this->_dbh;
532         extract($this->_table_names);
533
534         if ($reversed)
535             list($have, $want) = array('linkee', 'linker');
536         else
537             list($have, $want) = array('linker', 'linkee');
538         $qpagename = $dbh->escapeSimple($pagename);
539         $qlink = $dbh->escapeSimple($link);
540         $row = $dbh->GetRow("SELECT IF($want.pagename,1,0) as result"
541                                 . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee, $nonempty_tbl"
542                                 . " WHERE linkfrom=linker.id AND linkto=linkee.id"
543                                 . " AND $have.pagename=$qpagename"
544                                 . " AND $want.pagename=$qlink"
545                                 . "LIMIT 1");
546         return $row['result'];
547     }
548
549     function get_all_pages($include_empty=false, $sortby=false, $limit=false, $exclude='') {
550         $dbh = &$this->_dbh;
551         extract($this->_table_names);
552         $orderby = $this->sortby($sortby, 'db');
553         if ($orderby) $orderby = ' ORDER BY ' . $orderby;
554         if ($exclude) // array of pagenames
555             $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude);
556         else 
557             $exclude='';
558
559         if (strstr($orderby, 'mtime ')) { // multiple columns possible
560             if ($include_empty) {
561                 $sql = "SELECT "
562                     . $this->page_tbl_fields
563                     . " FROM $page_tbl, $recent_tbl, $version_tbl"
564                     . " WHERE $page_tbl.id=$recent_tbl.id"
565                     . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
566                     . $exclude
567                     . $orderby;
568             }
569             else {
570                 $sql = "SELECT "
571                     . $this->page_tbl_fields
572                     . " FROM $nonempty_tbl, $page_tbl, $recent_tbl, $version_tbl"
573                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
574                     . " AND $page_tbl.id=$recent_tbl.id"
575                     . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
576                     . $exclude
577                     . $orderby;
578             }
579         } else {
580             if ($include_empty) {
581                 $sql = "SELECT "
582                     . $this->page_tbl_fields 
583                     ." FROM $page_tbl"
584                     . $exclude ? " WHERE $exclude" : ''
585                     . $orderby;
586             }
587             else {
588                 $sql = "SELECT "
589                     . $this->page_tbl_fields
590                     . " FROM $nonempty_tbl, $page_tbl"
591                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
592                     . $exclude
593                     . $orderby;
594             }
595         }
596         if ($limit) {
597             // extract from,count from limit
598             list($from,$count) = $this->limit($limit);
599             $result = $dbh->limitQuery($sql, $from, $count);
600         } else {
601             $result = $dbh->query($sql);
602         }
603         return new WikiDB_backend_PearDB_iter($this, $result);
604     }
605         
606     /**
607      * Title search.
608      */
609     function text_search($search, $fulltext=false) {
610         $dbh = &$this->_dbh;
611         extract($this->_table_names);
612
613         $searchclass = get_class($this)."_search";
614         // no need to define it everywhere and then fallback. memory!
615         if (!class_exists($searchclass))
616             $searchclass = "WikiDB_backend_PearDB_search";
617         $searchobj = new $searchclass($search, $dbh);
618         
619         $table = "$nonempty_tbl, $page_tbl";
620         $join_clause = "$nonempty_tbl.id=$page_tbl.id";
621         $fields = $this->page_tbl_fields;
622
623         if ($fulltext) {
624             $table .= ", $recent_tbl";
625             $join_clause .= " AND $page_tbl.id=$recent_tbl.id";
626
627             $table .= ", $version_tbl";
628             $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";
629
630             $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields;
631             $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
632         } else {
633             $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");
634         }
635         $search_clause = $search->makeSqlClauseObj($callback);
636         
637         $result = $dbh->query("SELECT $fields FROM $table"
638                               . " WHERE $join_clause"
639                               . "  AND ($search_clause)"
640                               . " ORDER BY pagename");
641         
642         return new WikiDB_backend_PearDB_iter($this, $result);
643     }
644
645     //Todo: check if the better Mysql MATCH operator is supported,
646     // (ranked search) and also google like expressions.
647     function _sql_match_clause($word) {
648         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
649         $word = $this->_dbh->escapeSimple($word);
650         //$page_tbl = $this->_table_names['page_tbl'];
651         //Note: Mysql 4.1.0 has a bug which fails with binary fields.
652         //      e.g. if word is lowercased.
653         // http://bugs.mysql.com/bug.php?id=1491
654         return "LOWER(pagename) LIKE '%$word%'";
655     }
656     function _sql_casematch_clause($word) {
657         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
658         $word = $this->_dbh->escapeSimple($word);
659         return "pagename LIKE '%$word%'";
660     }
661     function _fullsearch_sql_match_clause($word) {
662         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
663         $word = $this->_dbh->escapeSimple($word);
664         //$page_tbl = $this->_table_names['page_tbl'];
665         //Mysql 4.1.1 has a bug which fails here if word is lowercased.
666         return "LOWER(pagename) LIKE '%$word%' OR content LIKE '%$word%'";
667     }
668     function _fullsearch_sql_casematch_clause($word) {
669         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
670         $word = $this->_dbh->escapeSimple($word);
671         return "pagename LIKE '%$word%' OR content LIKE '%$word%'";
672     }
673
674     /**
675      * Find highest or lowest hit counts.
676      */
677     function most_popular($limit=0, $sortby='-hits') {
678         $dbh = &$this->_dbh;
679         extract($this->_table_names);
680         if ($limit < 0){ 
681             $order = "hits ASC";
682             $limit = -$limit;
683             $where = ""; 
684         } else {
685             $order = "hits DESC";
686             $where = " AND hits > 0";
687         }
688         $orderby = '';
689         if ($sortby != '-hits') {
690             if ($order = $this->sortby($sortby, 'db'))
691                 $orderby = " ORDER BY " . $order;
692         } else {
693             $orderby = " ORDER BY $order";
694         }
695         //$limitclause = $limit ? " LIMIT $limit" : '';
696         $sql = "SELECT "
697             . $this->page_tbl_fields
698             . " FROM $nonempty_tbl, $page_tbl"
699             . " WHERE $nonempty_tbl.id=$page_tbl.id" 
700             . $where
701             . $orderby;
702          if ($limit) {
703              list($from, $count) = $this->limit($limit);
704              $result = $dbh->limitQuery($sql, $from, $count);
705          } else {
706              $result = $dbh->query($sql);
707          }
708
709         return new WikiDB_backend_PearDB_iter($this, $result);
710     }
711
712     /**
713      * Find recent changes.
714      */
715     function most_recent($params) {
716         $limit = 0;
717         $since = 0;
718         $include_minor_revisions = false;
719         $exclude_major_revisions = false;
720         $include_all_revisions = false;
721         extract($params);
722
723         $dbh = &$this->_dbh;
724         extract($this->_table_names);
725
726         $pick = array();
727         if ($since)
728             $pick[] = "mtime >= $since";
729                         
730         
731         if ($include_all_revisions) {
732             // Include all revisions of each page.
733             $table = "$page_tbl, $version_tbl";
734             $join_clause = "$page_tbl.id=$version_tbl.id";
735
736             if ($exclude_major_revisions) {
737                 // Include only minor revisions
738                 $pick[] = "minor_edit <> 0";
739             }
740             elseif (!$include_minor_revisions) {
741                 // Include only major revisions
742                 $pick[] = "minor_edit = 0";
743             }
744         }
745         else {
746             $table = "$page_tbl, $recent_tbl";
747             $join_clause = "$page_tbl.id=$recent_tbl.id";
748             $table .= ", $version_tbl";
749             $join_clause .= " AND $version_tbl.id=$page_tbl.id";
750             
751             if ($exclude_major_revisions) {
752                 // Include only most recent minor revision
753                 $pick[] = 'version=latestminor';
754             }
755             elseif (!$include_minor_revisions) {
756                 // Include only most recent major revision
757                 $pick[] = 'version=latestmajor';
758             }
759             else {
760                 // Include only the latest revision (whether major or minor).
761                 $pick[] ='version=latestversion';
762             }
763         }
764         $order = "DESC";
765         if($limit < 0){
766             $order = "ASC";
767             $limit = -$limit;
768         }
769         // $limitclause = $limit ? " LIMIT $limit" : '';
770         $where_clause = $join_clause;
771         if ($pick)
772             $where_clause .= " AND " . join(" AND ", $pick);
773
774         // FIXME: use SQL_BUFFER_RESULT for mysql?
775         $sql = "SELECT " 
776                . $this->page_tbl_fields . ", " . $this->version_tbl_fields
777                . " FROM $table"
778                . " WHERE $where_clause"
779                . " ORDER BY mtime $order";
780         if ($limit) {
781              list($from, $count) = $this->limit($limit);
782              $result = $dbh->limitQuery($sql, $from, $count);
783         } else {
784             $result = $dbh->query($sql);
785         }
786         return new WikiDB_backend_PearDB_iter($this, $result);
787     }
788
789     /**
790      * Find referenced empty pages.
791      */
792     function wanted_pages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
793         $dbh = &$this->_dbh;
794         extract($this->_table_names);
795         if ($orderby = $this->sortby($sortby, 'db', array('pagename','wantedfrom')))
796             $orderby = 'ORDER BY ' . $orderby;
797
798         if ($exclude_from) // array of pagenames
799             $exclude_from = " AND linked.pagename NOT IN ".$this->_sql_set($exclude_from);
800         if ($exclude) // array of pagenames
801             $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude);
802
803         $sql = "SELECT $page_tbl.pagename,linked.pagename as wantedfrom"
804             . " FROM $link_tbl,$page_tbl as linked "
805             . " LEFT JOIN $page_tbl ON($link_tbl.linkto=$page_tbl.id)"
806             . " LEFT JOIN $nonempty_tbl ON($link_tbl.linkto=$nonempty_tbl.id)" 
807             . " WHERE ISNULL($nonempty_tbl.id) AND linked.id=$link_tbl.linkfrom"
808             . $exclude_from
809             . $exclude
810             . $orderby;
811         if ($limit) {
812             list($from, $count) = $this->limit($limit);
813             $result = $dbh->limitQuery($sql, $from, $count * 3);
814         } else {
815             $result = $dbh->query($sql);
816         }
817         return new WikiDB_backend_PearDB_generic_iter($this, $result);
818     }
819
820     function _sql_set(&$pagenames) {
821         $s = '(';
822         foreach ($pagenames as $p) {
823             $s .= ("'".$this->_dbh->escapeSimple($p)."',");
824         }
825         return substr($s,0,-1).")";
826     }
827
828     /**
829      * Rename page in the database.
830      */
831     function rename_page($pagename, $to) {
832         $dbh = &$this->_dbh;
833         extract($this->_table_names);
834         
835         $this->lock();
836         if ( ($id = $this->_get_pageid($pagename, false)) ) {
837             if ($new = $this->_get_pageid($to, false)) {
838                 //cludge alert!
839                 //this page does not exist (already verified before), but exists in the page table.
840                 //so we delete this page.
841                 $dbh->query("DELETE FROM $page_tbl WHERE id=$id");
842             }
843             $dbh->query(sprintf("UPDATE $page_tbl SET pagename='%s' WHERE id=$id",
844                                 $dbh->escapeSimple($to)));
845         }
846         $this->unlock();
847         return $id;
848     }
849
850     function _update_recent_table($pageid = false) {
851         $dbh = &$this->_dbh;
852         extract($this->_table_names);
853         extract($this->_expressions);
854
855         $pageid = (int)$pageid;
856
857         $this->lock();
858         $dbh->query("DELETE FROM $recent_tbl"
859                     . ( $pageid ? " WHERE id=$pageid" : ""));
860         $dbh->query( "INSERT INTO $recent_tbl"
861                      . " (id, latestversion, latestmajor, latestminor)"
862                      . " SELECT id, $maxversion, $maxmajor, $maxminor"
863                      . " FROM $version_tbl"
864                      . ( $pageid ? " WHERE id=$pageid" : "")
865                      . " GROUP BY id" );
866         $this->unlock();
867     }
868
869     function _update_nonempty_table($pageid = false) {
870         $dbh = &$this->_dbh;
871         extract($this->_table_names);
872
873         $pageid = (int)$pageid;
874
875         extract($this->_expressions);
876         $this->lock();
877         $dbh->query("DELETE FROM $nonempty_tbl"
878                     . ( $pageid ? " WHERE id=$pageid" : ""));
879         $dbh->query("INSERT INTO $nonempty_tbl (id)"
880                     . " SELECT $recent_tbl.id"
881                     . " FROM $recent_tbl, $version_tbl"
882                     . " WHERE $recent_tbl.id=$version_tbl.id"
883                     . "       AND version=latestversion"
884                     // We have some specifics here (Oracle)
885                     //. "  AND content<>''"
886                     . "  AND content $notempty"
887                     . ( $pageid ? " AND $recent_tbl.id=$pageid" : ""));
888         
889         $this->unlock();
890     }
891
892
893     /**
894      * Grab a write lock on the tables in the SQL database.
895      *
896      * Calls can be nested.  The tables won't be unlocked until
897      * _unlock_database() is called as many times as _lock_database().
898      *
899      * @access protected
900      */
901     function lock($tables = false, $write_lock = true) {
902         if ($this->_lock_count++ == 0)
903             $this->_lock_tables($write_lock);
904     }
905
906     /**
907      * Actually lock the required tables.
908      */
909     function _lock_tables($write_lock) {
910         trigger_error("virtual", E_USER_ERROR);
911     }
912     
913     /**
914      * Release a write lock on the tables in the SQL database.
915      *
916      * @access protected
917      *
918      * @param $force boolean Unlock even if not every call to lock() has been matched
919      * by a call to unlock().
920      *
921      * @see _lock_database
922      */
923     function unlock($tables = false, $force = false) {
924         if ($this->_lock_count == 0)
925             return;
926         if (--$this->_lock_count <= 0 || $force) {
927             $this->_unlock_tables();
928             $this->_lock_count = 0;
929         }
930     }
931
932     /**
933      * Actually unlock the required tables.
934      */
935     function _unlock_tables($write_lock) {
936         trigger_error("virtual", E_USER_ERROR);
937     }
938
939
940     /**
941      * Serialize data
942      */
943     function _serialize($data) {
944         if (empty($data))
945             return '';
946         assert(is_array($data));
947         return serialize($data);
948     }
949
950     /**
951      * Unserialize data
952      */
953     function _unserialize($data) {
954         return empty($data) ? array() : unserialize($data);
955     }
956     
957     /**
958      * Callback for PEAR (DB) errors.
959      *
960      * @access protected
961      *
962      * @param A PEAR_error object.
963      */
964     function _pear_error_callback($error) {
965         if ($this->_is_false_error($error))
966             return;
967         
968         $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT);        // prevent recursive loops.
969         $this->close();
970         trigger_error($this->_pear_error_message($error), E_USER_ERROR);
971     }
972
973     /**
974      * Detect false errors messages from PEAR DB.
975      *
976      * The version of PEAR DB which ships with PHP 4.0.6 has a bug in that
977      * it doesn't recognize "LOCK" and "UNLOCK" as SQL commands which don't
978      * return any data.  (So when a "LOCK" command doesn't return any data,
979      * DB reports it as an error, when in fact, it's not.)
980      *
981      * @access private
982      * @return bool True iff error is not really an error.
983      */
984     function _is_false_error($error) {
985         if ($error->getCode() != DB_ERROR)
986             return false;
987
988         $query = $this->_dbh->last_query;
989
990         if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE'
991                          . '|DROP|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s/', $query)) {
992             // Last query was not of the sort which doesn't return any data.
993             //" <--kludge for brain-dead syntax coloring
994             return false;
995         }
996         
997         if (! in_array('ismanip', get_class_methods('DB'))) {
998             // Pear shipped with PHP 4.0.4pl1 (and before, presumably)
999             // does not have the DB::isManip method.
1000             return true;
1001         }
1002         
1003         if (DB::isManip($query)) {
1004             // If Pear thinks it's an isManip then it wouldn't have thrown
1005             // the error we're testing for....
1006             return false;
1007         }
1008
1009         return true;
1010     }
1011
1012     function _pear_error_message($error) {
1013         $class = get_class($this);
1014         $message = "$class: fatal database error\n"
1015              . "\t" . $error->getMessage() . "\n"
1016              . "\t(" . $error->getDebugInfo() . ")\n";
1017
1018         // Prevent password from being exposed during a connection error
1019         $safe_dsn = preg_replace('| ( :// .*? ) : .* (?=@) |xs',
1020                                  '\\1:XXXXXXXX', $this->_dsn);
1021         return str_replace($this->_dsn, $safe_dsn, $message);
1022     }
1023
1024     /**
1025      * Filter PHP errors notices from PEAR DB code.
1026      *
1027      * The PEAR DB code which ships with PHP 4.0.6 produces spurious
1028      * errors and notices.  This is an error callback (for use with
1029      * ErrorManager which will filter out those spurious messages.)
1030      * @see _is_false_error, ErrorManager
1031      * @access private
1032      */
1033     function _pear_notice_filter($err) {
1034         return ( $err->isNotice()
1035                  && preg_match('|DB[/\\\\]common.php$|', $err->errfile)
1036                  && $err->errline == 126
1037                  && preg_match('/Undefined offset: +0\b/', $err->errstr) );
1038     }
1039
1040     /* some variables and functions for DB backend abstraction (action=upgrade) */
1041     function database () {
1042         return $this->_dbh->dsn['database'];
1043     }
1044     function backendType() {
1045         return $this->_dbh->phptype;
1046     }
1047     function connection() {
1048         return $this->_dbh->connection;
1049     }
1050
1051     function listOfTables() {
1052         return $this->_dbh->getListOf('tables');
1053     }
1054     function listOfFields($database,$table) {
1055         if ($this->backendType() == 'mysql') {
1056             $fields = array();
1057             assert(!empty($database));
1058             assert(!empty($table));
1059             $result = mysql_list_fields($database, $table, $this->_dbh->connection) or 
1060                 trigger_error(__FILE__.':'.__LINE__.' '.mysql_error(), E_USER_WARNING);
1061             if (!$result) return array();
1062               $columns = mysql_num_fields($result);
1063             for ($i = 0; $i < $columns; $i++) {
1064                 $fields[] = mysql_field_name($result, $i);
1065             }
1066             mysql_free_result($result);
1067             return $fields;
1068         } else {
1069             // TODO: try ADODB version?
1070             trigger_error("Unsupported dbtype and backend. Either switch to ADODB or check it manually.");
1071         }
1072     }
1073
1074 };
1075
1076 /**
1077  * This class is a generic iterator.
1078  *
1079  * WikiDB_backend_PearDB_iter only iterates over things that have
1080  * 'pagename', 'pagedata', etc. etc.
1081  *
1082  * Probably WikiDB_backend_PearDB_iter and this class should be merged
1083  * (most of the code is cut-and-paste :-( ), but I am trying to make
1084  * changes that could be merged easily.
1085  *
1086  * @author: Dan Frankowski
1087  */
1088 class WikiDB_backend_PearDB_generic_iter
1089 extends WikiDB_backend_iterator
1090 {
1091     function WikiDB_backend_PearDB_generic_iter($backend, $query_result, $field_list = NULL) {
1092         if (DB::isError($query_result)) {
1093             // This shouldn't happen, I thought.
1094             $backend->_pear_error_callback($query_result);
1095         }
1096         
1097         $this->_backend = &$backend;
1098         $this->_result = $query_result;
1099     }
1100
1101     function count() {
1102         if (!$this->_result)
1103             return false;
1104         return $this->_result->numRows();
1105     }
1106     
1107     function next() {
1108         $backend = &$this->_backend;
1109         if (!$this->_result)
1110             return false;
1111
1112         $record = $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
1113         if (!$record) {
1114             $this->free();
1115             return false;
1116         }
1117         
1118         return $record;
1119     }
1120
1121     function free () {
1122         if ($this->_result) {
1123             $this->_result->free();
1124             $this->_result = false;
1125         }
1126     }
1127 }
1128
1129 class WikiDB_backend_PearDB_iter
1130 extends WikiDB_backend_PearDB_generic_iter
1131 {
1132
1133     function next() {
1134         $backend = &$this->_backend;
1135         if (!$this->_result)
1136             return false;
1137
1138         $record = $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
1139         if (!$record) {
1140             $this->free();
1141             return false;
1142         }
1143         
1144         $pagedata = $backend->_extract_page_data($record);
1145         $rec = array('pagename' => $record['pagename'],
1146                      'pagedata' => $pagedata);
1147
1148         if (!empty($record['version'])) {
1149             $rec['versiondata'] = $backend->_extract_version_data($record);
1150             $rec['version'] = $record['version'];
1151         }
1152         
1153         return $rec;
1154     }
1155 }
1156
1157 // word search
1158 class WikiDB_backend_PearDB_search
1159 extends WikiDB_backend_search
1160 {
1161     function WikiDB_backend_PearDB_search(&$search, &$dbh) {
1162         $this->_dbh = $dbh;
1163         $this->_case_exact = $search->_case_exact;
1164     }
1165     function _pagename_match_clause($node) { 
1166         $word = $node->sql();
1167         if ($node->op == 'REGEX') { // posix regex extensions
1168             if (preg_match("/mysql/i", $this->_dbh->phptype))
1169                 return "pagename REGEXP '$word'";
1170         } else {
1171             return $this->_case_exact ? "pagename LIKE '$word'" 
1172                                       : "LOWER(pagename) LIKE '$word'";
1173         }
1174     }
1175     function _fulltext_match_clause($node) { 
1176         $word = $node->sql();
1177         return $this->_pagename_match_clause($node)
1178                // probably convert this MATCH AGAINST or SUBSTR/POSITION without wildcards
1179                . ($this->_case_exact ? " OR content LIKE '$word'" 
1180                                      : " OR LOWER(content) LIKE '$word'");
1181     }
1182 }
1183
1184 // $Log: not supported by cvs2svn $
1185 // Revision 1.76  2004/11/30 17:45:53  rurban
1186 // exists_links backend implementation
1187 //
1188 // Revision 1.75  2004/11/28 20:42:33  rurban
1189 // Optimize PearDB _extract_version_data and _extract_page_data.
1190 //
1191 // Revision 1.74  2004/11/27 14:39:05  rurban
1192 // simpified regex search architecture:
1193 //   no db specific node methods anymore,
1194 //   new sql() method for each node
1195 //   parallel to regexp() (which returns pcre)
1196 //   regex types bitmasked (op's not yet)
1197 // new regex=sql
1198 // clarified WikiDB::quote() backend methods:
1199 //   ->quote() adds surrounsing quotes
1200 //   ->qstr() (new method) assumes strings and adds no quotes! (in contrast to ADODB)
1201 //   pear and adodb have now unified quote methods for all generic queries.
1202 //
1203 // Revision 1.73  2004/11/26 18:39:02  rurban
1204 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
1205 //
1206 // Revision 1.72  2004/11/25 17:20:51  rurban
1207 // and again a couple of more native db args: backlinks
1208 //
1209 // Revision 1.71  2004/11/23 13:35:48  rurban
1210 // add case_exact search
1211 //
1212 // Revision 1.70  2004/11/21 11:59:26  rurban
1213 // remove final \n to be ob_cache independent
1214 //
1215 // Revision 1.69  2004/11/20 17:49:39  rurban
1216 // add fast exclude support to SQL get_all_pages
1217 //
1218 // Revision 1.68  2004/11/20 17:35:58  rurban
1219 // improved WantedPages SQL backends
1220 // PageList::sortby new 3rd arg valid_fields (override db fields)
1221 // WantedPages sql pager inexact for performance reasons:
1222 //   assume 3 wantedfrom per page, to be correct, no getTotal()
1223 // support exclude argument for get_all_pages, new _sql_set()
1224 //
1225 // Revision 1.67  2004/11/10 19:32:24  rurban
1226 // * optimize increaseHitCount, esp. for mysql.
1227 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1228 // * Pear_DB version logic (awful but needed)
1229 // * fix broken ADODB quote
1230 // * _extract_page_data simplification
1231 //
1232 // Revision 1.66  2004/11/10 15:29:21  rurban
1233 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
1234 // * ACCESS_LOG_SQL: fix cause request not yet initialized
1235 // * WikiDB: moved SQL specific methods upwards
1236 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
1237 //   fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
1238 //
1239 // Revision 1.65  2004/11/09 17:11:17  rurban
1240 // * revert to the wikidb ref passing. there's no memory abuse there.
1241 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1242 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
1243 //   are also needed at the rendering for linkExistingWikiWord().
1244 //   pass options to pageiterator.
1245 //   use this cache also for _get_pageid()
1246 //   This saves about 8 SELECT count per page (num all pagelinks).
1247 // * fix passing of all page fields to the pageiterator.
1248 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1249 //
1250 // Revision 1.64  2004/11/07 16:02:52  rurban
1251 // new sql access log (for spam prevention), and restructured access log class
1252 // dbh->quote (generic)
1253 // pear_db: mysql specific parts seperated (using replace)
1254 //
1255 // Revision 1.63  2004/11/01 10:43:58  rurban
1256 // seperate PassUser methods into seperate dir (memory usage)
1257 // fix WikiUser (old) overlarge data session
1258 // remove wikidb arg from various page class methods, use global ->_dbi instead
1259 // ...
1260 //
1261 // Revision 1.62  2004/10/14 19:19:34  rurban
1262 // loadsave: check if the dumped file will be accessible from outside.
1263 // and some other minor fixes. (cvsclient native not yet ready)
1264 //
1265 // Revision 1.61  2004/10/14 17:19:17  rurban
1266 // allow most_popular sortby arguments
1267 //
1268 // Revision 1.60  2004/07/09 10:06:50  rurban
1269 // Use backend specific sortby and sortable_columns method, to be able to
1270 // select between native (Db backend) and custom (PageList) sorting.
1271 // Fixed PageList::AddPageList (missed the first)
1272 // Added the author/creator.. name to AllPagesBy...
1273 //   display no pages if none matched.
1274 // Improved dba and file sortby().
1275 // Use &$request reference
1276 //
1277 // Revision 1.59  2004/07/08 21:32:36  rurban
1278 // Prevent from more warnings, minor db and sort optimizations
1279 //
1280 // Revision 1.58  2004/07/08 16:56:16  rurban
1281 // use the backendType abstraction
1282 //
1283 // Revision 1.57  2004/07/05 12:57:54  rurban
1284 // add mysql timeout
1285 //
1286 // Revision 1.56  2004/07/04 10:24:43  rurban
1287 // forgot the expressions
1288 //
1289 // Revision 1.55  2004/07/03 16:51:06  rurban
1290 // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
1291 // added atomic mysql REPLACE for PearDB as in ADODB
1292 // fixed _lock_tables typo links => link
1293 // fixes unserialize ADODB bug in line 180
1294 //
1295 // Revision 1.54  2004/06/29 08:52:24  rurban
1296 // Use ...version() $need_content argument in WikiDB also:
1297 // To reduce the memory footprint for larger sets of pagelists,
1298 // we don't cache the content (only true or false) and
1299 // we purge the pagedata (_cached_html) also.
1300 // _cached_html is only cached for the current pagename.
1301 // => Vastly improved page existance check, ACL check, ...
1302 //
1303 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
1304 //
1305 // Revision 1.53  2004/06/27 10:26:03  rurban
1306 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1307 //
1308 // Revision 1.52  2004/06/25 14:15:08  rurban
1309 // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
1310 //
1311 // Revision 1.51  2004/05/12 10:49:55  rurban
1312 // require_once fix for those libs which are loaded before FileFinder and
1313 //   its automatic include_path fix, and where require_once doesn't grok
1314 //   dirname(__FILE__) != './lib'
1315 // upgrade fix with PearDB
1316 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1317 //
1318 // Revision 1.50  2004/05/06 17:30:39  rurban
1319 // CategoryGroup: oops, dos2unix eol
1320 // improved phpwiki_version:
1321 //   pre -= .0001 (1.3.10pre: 1030.099)
1322 //   -p1 += .001 (1.3.9-p1: 1030.091)
1323 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1324 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1325 //   backend->backendType(), backend->database(),
1326 //   backend->listOfFields(),
1327 //   backend->listOfTables(),
1328 //
1329 // Revision 1.49  2004/05/03 21:35:30  rurban
1330 // don't use persistent connections with postgres
1331 //
1332 // Revision 1.48  2004/04/26 20:44:35  rurban
1333 // locking table specific for better databases
1334 //
1335 // Revision 1.47  2004/04/20 00:06:04  rurban
1336 // themable paging support
1337 //
1338 // Revision 1.46  2004/04/19 21:51:41  rurban
1339 // php5 compatibility: it works!
1340 //
1341 // Revision 1.45  2004/04/16 14:19:39  rurban
1342 // updated ADODB notes
1343 //
1344
1345 // (c-file-style: "gnu")
1346 // Local Variables:
1347 // mode: php
1348 // tab-width: 8
1349 // c-basic-offset: 4
1350 // c-hanging-comment-ender-p: nil
1351 // indent-tabs-mode: nil
1352 // End:   
1353 ?>