]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/ADODB.php
Replace IF by CASE in exists_link()
[SourceForge/phpwiki.git] / lib / WikiDB / backend / ADODB.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ADODB.php,v 1.91 2006-11-19 14:03:32 rurban Exp $');
3
4 /*
5  Copyright 2002,2004,2005,2006 $ThePhpWikiProgrammingTeam
6
7  This file is part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
23 */ 
24
25 /**
26  * Based on PearDB.php. 
27  * @author: Lawrence Akka, Reini Urban
28  *
29  * Now (since phpwiki-1.3.10) with adodb-4.22, by Reini Urban:
30  * 1) Extended to use all available database backends, not only mysql.
31  * 2) It uses the ultra-fast binary adodb extension if loaded.
32  * 3) We use FETCH_NUM instead of FETCH_ASSOC (faster and more generic)
33  * 4) To support generic iterators which return ASSOC fields, and to support queries with 
34  *    variable columns, some trickery was needed to use recordset specific fetchMode.
35  *    The first Execute uses the global fetchMode (ASSOC), then it's resetted back to NUM 
36  *    and the recordset fetchmode is set to ASSOC.
37  * 5) Transaction support, and locking as fallback.
38  * 6) 2004-12-10 added extra page.cached_html
39  *
40  * phpwiki-1.3.11, by Philippe Vanhaesendonck
41  * - pass column list to iterators so we can FETCH_NUM in all cases
42  * phpwiki-1.3.12: get rid of ISNULL
43  * phpwiki-1.3.13: tsearch2 and stored procedures
44  *
45  * ADODB basic differences to PearDB: It pre-fetches the first row into fields, 
46  * is dirtier in style, layout and more low-level ("worse is better").
47  * It has less needed basic features (modifyQuery, locks, ...), but some more 
48  * unneeded features included: paging, monitoring and sessions, and much more drivers.
49  * No locking (which PearDB supports in some backends), and sequences are very 
50  * bad compared to PearDB.
51
52  * Old Comments, by Lawrence Akka:
53  * 1)  ADODB's GetRow() is slightly different from that in PEAR.  It does not 
54  *     accept a fetchmode parameter
55  *     That doesn't matter too much here, since we only ever use FETCHMODE_ASSOC
56  * 2)  No need for ''s around strings in sprintf arguments - qstr puts them 
57  *     there automatically
58  * 3)  ADODB has a version of GetOne, but it is difficult to use it when 
59  *     FETCH_ASSOC is in effect.
60  *     Instead, use $rs = Execute($query); $value = $rs->fields["$colname"]
61  * 4)  No error handling yet - could use ADOConnection->raiseErrorFn
62  * 5)  It used to be faster then PEAR/DB at the beginning of 2002. 
63  *     Now at August 2002 PEAR/DB with our own page cache added, 
64  *     performance is comparable.
65  */
66
67 require_once('lib/WikiDB/backend.php');
68 // Error handling - calls trigger_error.  NB - does not close the connection.  Does it need to?
69 include_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php');
70 // include the main adodb file
71 require_once('lib/WikiDB/adodb/adodb.inc.php');
72
73 class WikiDB_backend_ADODB
74 extends WikiDB_backend
75 {
76
77     function WikiDB_backend_ADODB ($dbparams) {
78         $parsed = parseDSN($dbparams['dsn']);
79         $this->_dbparams = $dbparams;
80         $this->_parsedDSN =& $parsed;
81         $this->_dbh = &ADONewConnection($parsed['phptype']);
82         if (DEBUG & _DEBUG_SQL) {
83             $this->_dbh->debug = true;
84             $GLOBALS['ADODB_OUTP'] = '_sql_debuglog';
85         }
86         $this->_dsn = $parsed;
87         // persistent is defined as DSN option, or with a config value.
88         //   phptype://username:password@hostspec/database?persistent=false
89         if (!empty($parsed['persistent']) or DATABASE_PERSISTENT)
90             $conn = $this->_dbh->PConnect($parsed['hostspec'],$parsed['username'], 
91                                           $parsed['password'], $parsed['database']);
92         else
93             $conn = $this->_dbh->Connect($parsed['hostspec'],$parsed['username'], 
94                                          $parsed['password'], $parsed['database']);
95
96         // Since 1.3.10 we use the faster ADODB_FETCH_NUM,
97         // with some ASSOC based recordsets.
98         $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM;
99         $this->_dbh->SetFetchMode(ADODB_FETCH_NUM);
100         $GLOBALS['ADODB_COUNTRECS'] = false;
101
102         $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
103         $this->_table_names
104             = array('page_tbl'     => $prefix . 'page',
105                     'version_tbl'  => $prefix . 'version',
106                     'link_tbl'     => $prefix . 'link',
107                     'recent_tbl'   => $prefix . 'recent',
108                     'nonempty_tbl' => $prefix . 'nonempty');
109         $page_tbl = $this->_table_names['page_tbl'];
110         $version_tbl = $this->_table_names['version_tbl'];
111         $this->page_tbl_fields = "$page_tbl.id AS id, $page_tbl.pagename AS pagename, "
112             . "$page_tbl.hits AS hits";
113         $this->links_field_list = array('id', 'pagename');
114         $this->page_tbl_field_list = array('id', 'pagename', 'hits');
115         $this->version_tbl_fields = "$version_tbl.version AS version, "
116             . "$version_tbl.mtime AS mtime, "
117             . "$version_tbl.minor_edit AS minor_edit, $version_tbl.content AS content, "
118             . "$version_tbl.versiondata AS versiondata";
119         $this->version_tbl_field_list = array('version', 'mtime', 'minor_edit', 'content',
120             'versiondata');
121
122         $this->_expressions
123             = array('maxmajor'     => "MAX(CASE WHEN minor_edit=0 THEN version END)",
124                     'maxminor'     => "MAX(CASE WHEN minor_edit<>0 THEN version END)",
125                     'maxversion'   => "MAX(version)",
126                     'notempty'     => "<>''",
127                     'iscontent'    => "$version_tbl.content<>''");
128         $this->_lock_count = 0;
129     }
130
131     /**
132      * Close database connection.
133      */
134     function close () {
135         if (!$this->_dbh)
136             return;
137         if ($this->_lock_count) {
138             trigger_error("WARNING: database still locked " . 
139                           '(lock_count = $this->_lock_count)' . "\n<br />",
140                           E_USER_WARNING);
141         }
142 //      $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT);        // prevent recursive loops.
143         $this->unlock(false,'force');
144
145         $this->_dbh->close();
146         $this->_dbh = false;
147     }
148
149     /*
150      * Fast test for wikipage.
151      */
152     function is_wiki_page($pagename) {
153         $dbh = &$this->_dbh;
154         extract($this->_table_names);
155         $row = $dbh->GetRow(sprintf("SELECT $page_tbl.id AS id"
156                                     . " FROM $nonempty_tbl, $page_tbl"
157                                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
158                                     . "   AND pagename=%s",
159                                     $dbh->qstr($pagename)));
160         return $row ? $row[0] : false;
161     }
162         
163     function get_all_pagenames() {
164         $dbh = &$this->_dbh;
165         extract($this->_table_names);
166         $result = $dbh->Execute("SELECT pagename"
167                                 . " FROM $nonempty_tbl, $page_tbl"
168                                 . " WHERE $nonempty_tbl.id=$page_tbl.id");
169         return $result->GetArray();
170     }
171
172     /*
173      * filter (nonempty pages) currently ignored
174      */
175     function numPages($filter=false, $exclude='') {
176         $dbh = &$this->_dbh;
177         extract($this->_table_names);
178         $result = $dbh->getRow("SELECT count(*)"
179                             . " FROM $nonempty_tbl, $page_tbl"
180                             . " WHERE $nonempty_tbl.id=$page_tbl.id");
181         return $result[0];
182     }
183
184     function increaseHitCount($pagename) {
185         $dbh = &$this->_dbh;
186         // Hits is the only thing we can update in a fast manner.
187         // Note that this will fail silently if the page does not
188         // have a record in the page table.  Since it's just the
189         // hit count, who cares?
190         $dbh->Execute(sprintf("UPDATE %s SET hits=hits+1 WHERE pagename=%s",
191                               $this->_table_names['page_tbl'],
192                               $dbh->qstr($pagename)));
193         return;
194     }
195
196     /**
197      * Read page information from database.
198      */
199     function get_pagedata($pagename) {
200         $dbh = &$this->_dbh;
201         $row = $dbh->GetRow(sprintf("SELECT id,pagename,hits,pagedata FROM %s WHERE pagename=%s",
202                                     $this->_table_names['page_tbl'],
203                                     $dbh->qstr($pagename)));
204         return $row ? $this->_extract_page_data($row[3], $row[2]) : false;
205     }
206
207     function  _extract_page_data($data, $hits) {
208         if (empty($data))
209             return array('hits' => $hits);
210         else 
211             return array_merge(array('hits' => $hits), $this->_unserialize($data));
212     }
213
214     function update_pagedata($pagename, $newdata) {
215         $dbh = &$this->_dbh;
216         $page_tbl = $this->_table_names['page_tbl'];
217
218         // Hits is the only thing we can update in a fast manner.
219         if (count($newdata) == 1 && isset($newdata['hits'])) {
220             // Note that this will fail silently if the page does not
221             // have a record in the page table.  Since it's just the
222             // hit count, who cares?
223             $dbh->Execute(sprintf("UPDATE $page_tbl SET hits=%d WHERE pagename=%s",
224                                   $newdata['hits'], $dbh->qstr($pagename)));
225             return;
226         }
227         $where = sprintf("pagename=%s", $dbh->qstr($pagename));
228         $dbh->BeginTrans( );
229         $dbh->RowLock($page_tbl,$where);
230         
231         $data = $this->get_pagedata($pagename);
232         if (!$data) {
233             $data = array();
234             $this->_get_pageid($pagename, true); // Creates page record
235         }
236         
237         $hits = (empty($data['hits'])) ? 0 : (int)$data['hits'];
238         unset($data['hits']);
239
240         foreach ($newdata as $key => $val) {
241             if ($key == 'hits')
242                 $hits = (int)$val;
243             else if (empty($val))
244                 unset($data[$key]);
245             else
246                 $data[$key] = $val;
247         }
248         if ($dbh->Execute("UPDATE $page_tbl"
249                           . " SET hits=?, pagedata=?"
250                           . " WHERE pagename=?",
251                           array($hits, $this->_serialize($data), $pagename))) {
252             $dbh->CommitTrans( );
253             return true;
254         } else {
255             $dbh->RollbackTrans( );
256             return false;
257         }
258     }
259
260     function get_cached_html($pagename) {
261         $dbh = &$this->_dbh;
262         $page_tbl = $this->_table_names['page_tbl'];
263         $row = $dbh->GetRow(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s",
264                                     $dbh->qstr($pagename)));
265         return $row ? $row[0] : false;
266     }
267
268     function set_cached_html($pagename, $data) {
269         $dbh = &$this->_dbh;
270         $page_tbl = $this->_table_names['page_tbl'];
271         if (empty($data)) $data = '';
272         $rs = $dbh->Execute("UPDATE $page_tbl"
273                             . " SET cached_html=?"
274                             . " WHERE pagename=?",
275                             array($data, $pagename));
276     }
277
278     function _get_pageid($pagename, $create_if_missing = false) {
279
280         // check id_cache
281         global $request;
282         $cache =& $request->_dbi->_cache->_id_cache;
283         if (isset($cache[$pagename])) {
284             if ($cache[$pagename] or !$create_if_missing) {
285                 return $cache[$pagename];
286             }
287         }
288         
289         $dbh = &$this->_dbh;
290         $page_tbl = $this->_table_names['page_tbl'];
291         $query = sprintf("SELECT id FROM $page_tbl WHERE pagename=%s",
292                          $dbh->qstr($pagename));
293         if (! $create_if_missing ) {
294             $row = $dbh->GetRow($query);
295             return $row ? $row[0] : false;
296         }
297         $row = $dbh->GetRow($query);
298         if (! $row ) {
299             //TODO: Does the DBM has subselects? Then we can do it with select max(id)+1
300             // $this->lock(array('page'));
301             $dbh->BeginTrans( );
302             $dbh->CommitLock($page_tbl);
303             if ($dbh->hasGenID) {
304                 $id = $dbh->GenID($page_tbl."_id");
305             } else {
306                 // Better generic version than with adodb::genID
307                 $row = $dbh->GetRow("SELECT MAX(id) FROM $page_tbl");
308                 $id = $row[0] + 1;
309             }
310             $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl"
311                                         . " (id,pagename,hits)"
312                                         . " VALUES (%d,%s,0)",
313                                         $id, $dbh->qstr($pagename)));
314             if ($rs) $dbh->CommitTrans( );
315             else $dbh->RollbackTrans( );
316             // $this->unlock(array('page'));
317         } else {
318             $id = $row[0];
319         }
320         assert($id);
321         return $id;
322     }
323
324     function get_latest_version($pagename) {
325         $dbh = &$this->_dbh;
326         extract($this->_table_names);
327         $row = $dbh->GetRow(sprintf("SELECT latestversion"
328                                     . " FROM $page_tbl, $recent_tbl"
329                                     . " WHERE $page_tbl.id=$recent_tbl.id"
330                                     . "  AND pagename=%s",
331                                     $dbh->qstr($pagename)));
332         return $row ? (int)$row[0] : false;
333     }
334
335     function get_previous_version($pagename, $version) {
336         $dbh = &$this->_dbh;
337         extract($this->_table_names);
338         // Use SELECTLIMIT for maximum portability
339         $rs = $dbh->SelectLimit(sprintf("SELECT version"
340                                         . " FROM $version_tbl, $page_tbl"
341                                         . " WHERE $version_tbl.id=$page_tbl.id"
342                                         . "  AND pagename=%s"
343                                         . "  AND version < %d"
344                                         . " ORDER BY version DESC",
345                                         $dbh->qstr($pagename),
346                                         $version),
347                                 1);
348         return $rs->fields ? (int)$rs->fields[0] : false;
349     }
350     
351     /**
352      * Get version data.
353      *
354      * @param $version int Which version to get.
355      *
356      * @return hash The version data, or false if specified version does not
357      *              exist.
358      */
359     function get_versiondata($pagename, $version, $want_content = false) {
360         $dbh = &$this->_dbh;
361         extract($this->_table_names);
362         extract($this->_expressions);
363                 
364         assert(is_string($pagename) and $pagename != '');
365         assert($version > 0);
366         
367         // FIXME: optimization: sometimes don't get page data?
368         if ($want_content) {
369             $fields = $this->page_tbl_fields . ", $page_tbl.pagedata AS pagedata"
370                 . ', ' . $this->version_tbl_fields;
371         } else {
372             $fields = $this->page_tbl_fields . ", '' AS pagedata"
373                 . ", $version_tbl.version AS version, $version_tbl.mtime AS mtime, "
374                 . "$version_tbl.minor_edit AS minor_edit, $iscontent AS have_content, "
375                 . "$version_tbl.versiondata as versiondata";
376         }
377         $row = $dbh->GetRow(sprintf("SELECT $fields"
378                                     . " FROM $page_tbl, $version_tbl"
379                                     . " WHERE $page_tbl.id=$version_tbl.id"
380                                     . "  AND pagename=%s"
381                                     . "  AND version=%d",
382                                     $dbh->qstr($pagename), $version));
383         return $row ? $this->_extract_version_data_num($row, $want_content) : false;
384     }
385
386     function _extract_version_data_num($row, $want_content) {
387         if (!$row)
388             return false;
389
390         //$id       &= $row[0];
391         //$pagename &= $row[1];
392         $data = empty($row[8]) ? array() : $this->_unserialize($row[8]);
393         $data['mtime']         = $row[5];
394         $data['is_minor_edit'] = !empty($row[6]);
395         if ($want_content) {
396             $data['%content'] = $row[7];
397         } else {
398             $data['%content'] = !empty($row[7]);
399         }
400         if (!empty($row[3])) {
401             $data['%pagedata'] = $this->_extract_page_data($row[3], $row[2]);
402         }
403         return $data;
404     }
405
406     function _extract_version_data_assoc($row) {
407         if (!$row)
408             return false;
409
410         extract($row);
411         $data = empty($versiondata) ? array() : $this->_unserialize($versiondata);
412         $data['mtime'] = $mtime;
413         $data['is_minor_edit'] = !empty($minor_edit);
414         if (isset($content))
415             $data['%content'] = $content;
416         elseif ($have_content)
417             $data['%content'] = true;
418         else
419             $data['%content'] = '';
420         if (!empty($pagedata)) {
421             // hmm, $pagedata = is already extracted by WikiDB_backend_ADODB_iter
422             //$data['%pagedata'] = $this->_extract_page_data($pagedata, $hits);
423             $data['%pagedata'] = $pagedata;
424         }
425         return $data;
426     }
427
428     /**
429      * Create a new revision of a page.
430      */
431     function set_versiondata($pagename, $version, $data) {
432         $dbh = &$this->_dbh;
433         $version_tbl = $this->_table_names['version_tbl'];
434         
435         $minor_edit = (int) !empty($data['is_minor_edit']);
436         unset($data['is_minor_edit']);
437         
438         $mtime = (int)$data['mtime'];
439         unset($data['mtime']);
440         assert(!empty($mtime));
441
442         @$content = (string) $data['%content'];
443         unset($data['%content']);
444         unset($data['%pagedata']);
445         
446         $this->lock(array('page','recent','version','nonempty'));
447         $dbh->BeginTrans( );
448         $dbh->CommitLock($version_tbl);
449         $id = $this->_get_pageid($pagename, true);
450         $backend_type = $this->backendType();
451         $dbh->Execute(sprintf("DELETE FROM $version_tbl"
452                               . " WHERE id=%d AND version=%d",
453                               $id, $version));
454         $rs = $dbh->Execute("INSERT INTO $version_tbl"
455                             . " (id,version,mtime,minor_edit,content,versiondata)"
456                             . " VALUES(?,?,?,?,?,?)",
457                             array($id, $version, $mtime, $minor_edit,
458                                   $content, $this->_serialize($data)));
459         $this->_update_recent_table($id);
460         $this->_update_nonempty_table($id);
461         if ($rs) $dbh->CommitTrans( );
462         else $dbh->RollbackTrans( );
463         $this->unlock(array('page','recent','version','nonempty'));
464     }
465     
466     /**
467      * Delete an old revision of a page.
468      */
469     function delete_versiondata($pagename, $version) {
470         $dbh = &$this->_dbh;
471         extract($this->_table_names);
472
473         $this->lock(array('version'));
474         if ( ($id = $this->_get_pageid($pagename)) ) {
475             $dbh->Execute("DELETE FROM $version_tbl"
476                         . " WHERE id=$id AND version=$version");
477             $this->_update_recent_table($id);
478             // This shouldn't be needed (as long as the latestversion
479             // never gets deleted.)  But, let's be safe.
480             $this->_update_nonempty_table($id);
481         }
482         $this->unlock(array('version'));
483     }
484
485     /**
486      * Delete page from the database with backup possibility.
487      * i.e save_page('') and DELETE nonempty id
488      * 
489      * deletePage increments latestversion in recent to a non-existent version, 
490      * and removes the nonempty row,
491      * so that get_latest_version returns id+1 and get_previous_version returns prev id 
492      * and page->exists returns false.
493      */
494     function delete_page($pagename) {
495         $dbh = &$this->_dbh;
496         extract($this->_table_names);
497
498         $dbh->BeginTrans();
499         $dbh->CommitLock($recent_tbl);
500         if (($id = $this->_get_pageid($pagename, false)) === false) {
501             $dbh->RollbackTrans( );
502             return false;
503         }
504         $mtime = time();
505         $user =& $GLOBALS['request']->_user;
506         $meta = array('author' => $user->getId(),
507                       'author_id' => $user->getAuthenticatedId(),
508                       'mtime' => $mtime);
509         $this->lock(array('version','recent','nonempty','page','link'));
510         $version = $this->get_latest_version($pagename);
511         if ($dbh->Execute("UPDATE $recent_tbl SET latestversion=latestversion+1,"
512                           . "latestmajor=latestversion+1,latestminor=NULL WHERE id=$id")
513             and $dbh->Execute("INSERT INTO $version_tbl"
514                                 . " (id,version,mtime,minor_edit,content,versiondata)"
515                                 . " VALUES(?,?,?,?,?,?)",
516                                   array($id, $version+1, $mtime, 0,
517                                         '', $this->_serialize($meta)))
518             and $dbh->Execute("DELETE FROM $nonempty_tbl WHERE id=$id")
519             and $this->set_links($pagename, false)
520             // need to keep perms and LOCKED, otherwise you can reset the perm 
521             // by action=remove and re-create it with default perms
522             // keep hits but delete meta-data 
523             //and $dbh->Execute("UPDATE $page_tbl SET pagedata='' WHERE id=$id") 
524            )
525         {
526             $this->unlock(array('version','recent','nonempty','page','link'));  
527             $dbh->CommitTrans( );
528             return true;
529         } else {
530             $this->unlock(array('version','recent','nonempty','page','link'));  
531             $dbh->RollbackTrans( );
532             return false;
533         }
534     }
535
536     function purge_page($pagename) {
537         $dbh = &$this->_dbh;
538         extract($this->_table_names);
539         
540         $this->lock(array('version','recent','nonempty','page','link'));
541         if ( ($id = $this->_get_pageid($pagename, false)) ) {
542             $dbh->Execute("DELETE FROM $version_tbl  WHERE id=$id");
543             $dbh->Execute("DELETE FROM $recent_tbl   WHERE id=$id");
544             $dbh->Execute("DELETE FROM $nonempty_tbl WHERE id=$id");
545             $this->set_links($pagename, false);
546             $row = $dbh->GetRow("SELECT COUNT(*) FROM $link_tbl WHERE linkto=$id");
547             if ($row and $row[0]) {
548                 // We're still in the link table (dangling link) so we can't delete this
549                 // altogether.
550                 $dbh->Execute("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
551                 $result = 0;
552             }
553             else {
554                 $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id");
555                 $result = 1;
556             }
557         } else {
558             $result = -1; // already purged or not existing
559         }
560         $this->unlock(array('version','recent','nonempty','page','link'));
561         return $result;
562     }
563
564
565     // The only thing we might be interested in updating which we can
566     // do fast in the flags (minor_edit).   I think the default
567     // update_versiondata will work fine...
568     //function update_versiondata($pagename, $version, $data) {
569     //}
570
571     /* 
572      * Update link table.
573      * on DEBUG: delete old, deleted links from page
574      */
575     function set_links($pagename, $links) {
576         // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE.
577
578         $dbh = &$this->_dbh;
579         extract($this->_table_names);
580
581         $this->lock(array('link'));
582         $pageid = $this->_get_pageid($pagename, true);
583
584         $oldlinks = $dbh->getAssoc("SELECT $link_tbl.linkto as id, page.pagename FROM $link_tbl"
585                                   ." JOIN page ON ($link_tbl.linkto = page.id)"
586                                   ." WHERE linkfrom=$pageid");
587         // Delete current links,
588         $dbh->Execute("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
589         // and insert new links. Faster than checking for all single links
590         if ($links) {
591             foreach ($links as $link) {
592                 $linkto = $link['linkto'];
593                 if ($link['relation'])
594                     $relation = $this->_get_pageid($link['relation'], true);
595                 else 
596                     $relation = 0;
597                 // avoid duplicates
598                 if (isset($linkseen[$linkto]) and !$relation) {
599                     continue;
600                 }
601                 if (!$relation) {
602                     $linkseen[$linkto] = true;
603                 }
604                 $linkid = $this->_get_pageid($linkto, true);
605                 assert($linkid);
606                 if ($relation) {
607                     $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto, relation)"
608                                   . " VALUES ($pageid, $linkid, $relation)");
609                 } else {              
610                     $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto)"
611                                   . " VALUES ($pageid, $linkid)");
612                 }
613                 if (array_key_exists($linkid, $oldlinks)) {
614                     // This was also in the previous page
615                     unset($oldlinks[$linkid]); 
616                 }
617             }
618         }
619         // purge page table: delete all non-referenced pages
620         // for all previously linked pages...
621         if (DEBUG and $oldlinks) {
622             // trigger_error("purge page table: delete all non-referenced pages...", E_USER_NOTICE);
623             foreach ($oldlinks as $id => $name) {
624                 // ...check if the page is empty and has no version
625                 if ($dbh->getRow("SELECT $page_tbl.id FROM $page_tbl"
626                                      . " LEFT JOIN $nonempty_tbl USING (id) "
627                                      . " LEFT JOIN $version_tbl USING (id)"
628                                      . " WHERE $nonempty_tbl.id is NULL"
629                                      . " AND $version_tbl.id is NULL"
630                                      . " AND $page_tbl.id=$id")) 
631                 {
632                         trigger_error("delete empty and non-referenced link $name ($id)", E_USER_NOTICE);
633                         $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id");   // this purges the link
634                         $dbh->Execute("DELETE FROM $recent_tbl WHERE id=$id"); // may fail
635                 }
636             }
637         }
638         $this->unlock(array('link'));
639         return true;
640     }
641
642     /* get all oldlinks in hash => id, relation
643        check for all new links
644      */
645     function set_links1($pagename, $links) {
646
647         $dbh = &$this->_dbh;
648         extract($this->_table_names);
649
650         $this->lock(array('link'));
651         $pageid = $this->_get_pageid($pagename, true);
652
653         $oldlinks = $dbh->getAssoc("SELECT $link_tbl.linkto as linkto, $link_tbl.relation, page.pagename"
654                                   ." FROM $link_tbl"
655                                   ." JOIN page ON ($link_tbl.linkto = page.id)"
656                                   ." WHERE linkfrom=$pageid");
657         /*      old                  new
658          *      X => [1,0 2,0 1,1]   X => [1,1 3,0]
659          * => delete 1,0 2,0 + insert 3,0
660          */
661         if ($links) {
662             foreach ($links as $link) {
663                 $linkto = $link['linkto'];
664                 if ($link['relation'])
665                     $relation = $this->_get_pageid($link['relation'], true);
666                 else 
667                     $relation = 0;
668                 // avoid duplicates
669                 if (isset($linkseen[$linkto]) and !$relation) {
670                     continue;
671                 }
672                 if (!$relation) {
673                     $linkseen[$linkto] = true;
674                 }
675                 $linkid = $this->_get_pageid($linkto, true);
676                 assert($linkid);
677                 $skip = 0;
678                 // find linkfrom,linkto,relation triple in oldlinks
679                 foreach ($oldlinks as $l) {
680                     if ($relation) { // relation NOT NULL
681                         if ($l['linkto'] == $linkid and $l['relation'] == $relation) {
682                             // found and skip
683                             $skip = 1;
684                         }
685                     }
686                 }
687                 if (! $skip ) {
688                     if ($update) {
689                     }
690                     if ($relation) {
691                         $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto, relation)"
692                                       . " VALUES ($pageid, $linkid, $relation)");
693                     } else {              
694                         $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto)"
695                                       . " VALUES ($pageid, $linkid)");
696                     }
697                 }
698
699                 if (array_key_exists($linkid, $oldlinks)) {
700                     // This was also in the previous page
701                     unset($oldlinks[$linkid]); 
702                 }
703             }
704         }
705         // purge page table: delete all non-referenced pages
706         // for all previously linked pages...
707         if (DEBUG and $oldlinks) {
708             // trigger_error("purge page table: delete all non-referenced pages...", E_USER_NOTICE);
709             foreach ($oldlinks as $id => $name) {
710                 // ...check if the page is empty and has no version
711                 if ($dbh->getRow("SELECT $page_tbl.id FROM $page_tbl"
712                                      . " LEFT JOIN $nonempty_tbl USING (id) "
713                                      . " LEFT JOIN $version_tbl USING (id)"
714                                      . " WHERE $nonempty_tbl.id is NULL"
715                                      . " AND $version_tbl.id is NULL"
716                                      . " AND $page_tbl.id=$id")) 
717                 {
718                         trigger_error("delete empty and non-referenced link $name ($id)", E_USER_NOTICE);
719                         $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id");   // this purges the link
720                         $dbh->Execute("DELETE FROM $recent_tbl WHERE id=$id"); // may fail
721                 }
722             }
723         }
724         $this->unlock(array('link'));
725         return true;
726     }
727     
728     /**
729      * Find pages which link to or are linked from a page.
730      *
731      * Optimization: save request->_dbi->_iwpcache[] to avoid further iswikipage checks
732      * (linkExistingWikiWord or linkUnknownWikiWord)
733      * This is called on every page header GleanDescription, so we can store all the 
734      * existing links.
735      * 
736      * relations: $backend->get_links is responsible to add the relation to the pagehash 
737      * as 'linkrelation' key as pagename. See WikiDB_PageIterator::next 
738      *   if (isset($next['linkrelation']))
739      */
740     function get_links($pagename, $reversed=true,   $include_empty=false,
741                        $sortby=false, $limit=false, $exclude='',
742                        $want_relations = false)
743     {
744         $dbh = &$this->_dbh;
745         extract($this->_table_names);
746
747         if ($reversed)
748             list($have,$want) = array('linkee', 'linker');
749         else
750             list($have,$want) = array('linker', 'linkee');
751         $orderby = $this->sortby($sortby, 'db', array('pagename'));
752         if ($orderby) $orderby = ' ORDER BY $want.' . $orderby;
753         if ($exclude) // array of pagenames
754             $exclude = " AND $want.pagename NOT IN ".$this->_sql_set($exclude);
755         else 
756             $exclude='';
757
758         $qpagename = $dbh->qstr($pagename);
759         // removed ref to FETCH_MODE in next line
760         $sql = "SELECT $want.id AS id, $want.pagename AS pagename, "
761             . ($want_relations ? " related.pagename as linkrelation" : " $want.hits AS hits")
762             . " FROM "
763             . (!$include_empty ? "$nonempty_tbl, " : '')
764             . " $page_tbl linkee, $page_tbl linker, $link_tbl "
765             . ($want_relations ? " JOIN $page_tbl related ON ($link_tbl.relation=related.id)" : '')
766             . " WHERE linkfrom=linker.id AND linkto=linkee.id"
767             . " AND $have.pagename=$qpagename"
768             . (!$include_empty ? " AND $nonempty_tbl.id=$want.id" : "")
769             //. " GROUP BY $want.id"
770             . $exclude
771             . $orderby;
772 /*
773   echo "SELECT linkee.id AS id, linkee.pagename AS pagename, related.pagename as linkrelation FROM link, page linkee, page linker JOIN page related ON (link.relation=related.id) WHERE linkfrom=linker.id AND linkto=linkee.id AND linker.pagename='SanDiego'" | mysql phpwiki
774 id      pagename        linkrelation
775 2268    California      located_in
776 */            
777         if ($limit) {
778             // extract from,count from limit
779             list($offset,$count) = $this->limit($limit);
780             $result = $dbh->SelectLimit($sql, $count, $offset);
781         } else {
782             $result = $dbh->Execute($sql);
783         }
784         $fields = $this->links_field_list;
785         if ($want_relations) // instead of hits
786             $fields[2] = 'linkrelation';
787         return new WikiDB_backend_ADODB_iter($this, $result, $fields);
788     }
789
790     /**
791      * Find if a page links to another page
792      */
793     function exists_link($pagename, $link, $reversed=false) {
794         $dbh = &$this->_dbh;
795         extract($this->_table_names);
796
797         if ($reversed)
798             list($have, $want) = array('linkee', 'linker');
799         else
800             list($have, $want) = array('linker', 'linkee');
801         $qpagename = $dbh->qstr($pagename);
802         $qlink = $dbh->qstr($link);
803         $row = $dbh->GetRow("SELECT CASE WHEN $want.pagename THEN 1 ELSE 0 END"
804                             . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee, $nonempty_tbl"
805                             . " WHERE linkfrom=linker.id AND linkto=linkee.id"
806                             . " AND $have.pagename=$qpagename"
807                             . " AND $want.pagename=$qlink");
808         return $row[0];
809     }
810
811     /*
812      * 
813      */
814     function get_all_pages($include_empty=false, $sortby=false, $limit=false, $exclude='') {
815         $dbh = &$this->_dbh;
816         extract($this->_table_names);
817         $orderby = $this->sortby($sortby, 'db');
818         if ($orderby) $orderby = ' ORDER BY ' . $orderby;
819         if ($exclude) // array of pagenames
820             $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude);
821         else 
822             $exclude='';
823
824         //$dbh->SetFetchMode(ADODB_FETCH_ASSOC);
825         if (strstr($orderby, 'mtime ')) { // was ' mtime'
826             if ($include_empty) {
827                 $sql = "SELECT "
828                     . $this->page_tbl_fields
829                     ." FROM $page_tbl, $recent_tbl, $version_tbl"
830                     . " WHERE $page_tbl.id=$recent_tbl.id"
831                     . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
832                     . $exclude
833                     . $orderby;
834             }
835             else {
836                 $sql = "SELECT "
837                     . $this->page_tbl_fields
838                     . " FROM $nonempty_tbl, $page_tbl, $recent_tbl, $version_tbl"
839                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
840                     . " AND $page_tbl.id=$recent_tbl.id"
841                     . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
842                     . $exclude
843                     . $orderby;
844             }
845         } else {
846             if ($include_empty) {
847                 $sql = "SELECT "
848                     . $this->page_tbl_fields
849                     . " FROM $page_tbl"
850                     . ($exclude ? " WHERE $exclude" : '')
851                     . $orderby;
852             } else {
853                 $sql = "SELECT "
854                     . $this->page_tbl_fields
855                     . " FROM $nonempty_tbl, $page_tbl"
856                     . " WHERE $nonempty_tbl.id=$page_tbl.id"
857                     . $exclude
858                     . $orderby;
859             }
860         }
861         if ($limit) {
862             // extract from,count from limit
863             list($offset,$count) = $this->limit($limit);
864             $result = $dbh->SelectLimit($sql, $count, $offset);
865         } else {
866             $result = $dbh->Execute($sql);
867         }
868         //$dbh->SetFetchMode(ADODB_FETCH_NUM);
869         return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list);
870     }
871         
872     /**
873      * Title and fulltext search.
874      */
875     function text_search($search, $fullsearch=false, 
876                          $sortby=false, $limit=false, $exclude=false) 
877     {
878         $dbh = &$this->_dbh;
879         extract($this->_table_names);
880         $orderby = $this->sortby($sortby, 'db');
881         if ($orderby) $orderby = ' ORDER BY ' . $orderby;
882         
883         $table = "$nonempty_tbl, $page_tbl";
884         $join_clause = "$nonempty_tbl.id=$page_tbl.id";
885         $fields = $this->page_tbl_fields;
886         $field_list = $this->page_tbl_field_list;
887         $searchobj = new WikiDB_backend_ADODB_search($search, $dbh);
888         
889         if ($fullsearch) {
890             $table .= ", $recent_tbl";
891             $join_clause .= " AND $page_tbl.id=$recent_tbl.id";
892
893             $table .= ", $version_tbl";
894             $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";
895
896             $fields .= ",$page_tbl.pagedata as pagedata," . $this->version_tbl_fields;
897             $field_list = array_merge($field_list, array('pagedata'), 
898                                       $this->version_tbl_field_list);
899             $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
900         } else {
901             $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");
902         }
903         
904         $search_clause = $search->makeSqlClauseObj($callback);
905         $sql = "SELECT $fields FROM $table"
906             . " WHERE $join_clause"
907             . " AND ($search_clause)"
908             . $orderby;
909         if ($limit) {
910             // extract from,count from limit
911             list($offset,$count) = $this->limit($limit);
912             $result = $dbh->SelectLimit($sql, $count, $offset);
913         } else {
914             $result = $dbh->Execute($sql);
915         }
916         $iter = new WikiDB_backend_ADODB_iter($this, $result, $field_list);
917         if ($fullsearch)
918             $iter->stoplisted = $searchobj->stoplisted;
919         return $iter;
920     }
921
922     /*
923      * TODO: efficiently handle wildcards exclusion: exclude=Php* => 'Php%', 
924      *       not sets. See above, but the above methods find too much. 
925      * This is only for already resolved wildcards:
926      * " WHERE $page_tbl.pagename NOT IN ".$this->_sql_set(array('page1','page2'));
927      */
928     function _sql_set(&$pagenames) {
929         $s = '(';
930         foreach ($pagenames as $p) {
931             $s .= ($this->_dbh->qstr($p).",");
932         }
933         return substr($s,0,-1).")";
934     }
935
936     /**
937      * Find highest or lowest hit counts.
938      */
939     function most_popular($limit=20, $sortby='-hits') {
940         $dbh = &$this->_dbh;
941         extract($this->_table_names);
942         $order = "DESC";
943         if ($limit < 0){ 
944             $order = "ASC"; 
945             $limit = -$limit;
946             $where = "";
947         } else {
948             $where = " AND hits > 0";
949         }
950         if ($sortby != '-hits') {
951             if ($order = $this->sortby($sortby, 'db'))  $orderby = " ORDER BY " . $order;
952             else $orderby = "";
953         } else
954             $orderby = " ORDER BY hits $order";
955         $sql = "SELECT " 
956             . $this->page_tbl_fields
957             . " FROM $nonempty_tbl, $page_tbl"
958             . " WHERE $nonempty_tbl.id=$page_tbl.id"
959             . $where
960             . $orderby;
961         if ($limit) {
962             // extract from,count from limit
963             list($offset,$count) = $this->limit($limit);
964             $result = $dbh->SelectLimit($sql, $count, $offset);
965         } else {
966             $result = $dbh->Execute($sql);
967         }
968         return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list);
969     }
970
971     /**
972      * Find recent changes.
973      */
974     function most_recent($params) {
975         $limit = 0;
976         $since = 0;
977         $include_minor_revisions = false;
978         $exclude_major_revisions = false;
979         $include_all_revisions = false;
980         extract($params);
981
982         $dbh = &$this->_dbh;
983         extract($this->_table_names);
984
985         $pick = array();
986         if ($since)
987             $pick[] = "mtime >= $since";
988         
989         if ($include_all_revisions) {
990             // Include all revisions of each page.
991             $table = "$page_tbl, $version_tbl";
992             $join_clause = "$page_tbl.id=$version_tbl.id";
993
994             if ($exclude_major_revisions) {
995                 // Include only minor revisions
996                 $pick[] = "minor_edit <> 0";
997             }
998             elseif (!$include_minor_revisions) {
999                 // Include only major revisions
1000                 $pick[] = "minor_edit = 0";
1001             }
1002         }
1003         else {
1004             $table = "$page_tbl, $recent_tbl";
1005             $join_clause = "$page_tbl.id=$recent_tbl.id";
1006             $table .= ", $version_tbl";
1007             $join_clause .= " AND $version_tbl.id=$page_tbl.id";
1008                 
1009             if ($exclude_major_revisions) {
1010                 // Include only most recent minor revision
1011                 $pick[] = 'version=latestminor';
1012             }
1013             elseif (!$include_minor_revisions) {
1014                 // Include only most recent major revision
1015                 $pick[] = 'version=latestmajor';
1016             }
1017             else {
1018                 // Include only the latest revision (whether major or minor).
1019                 $pick[] ='version=latestversion';
1020             }
1021         }
1022         $order = "DESC";
1023         if($limit < 0){
1024             $order = "ASC";
1025             $limit = -$limit;
1026         }
1027         $where_clause = $join_clause;
1028         if ($pick)
1029             $where_clause .= " AND " . join(" AND ", $pick);
1030         $sql = "SELECT "
1031             . $this->page_tbl_fields . ", " . $this->version_tbl_fields
1032             . " FROM $table"
1033             . " WHERE $where_clause"
1034             . " ORDER BY mtime $order";
1035         // FIXME: use SQL_BUFFER_RESULT for mysql?
1036         if ($limit) {
1037             // extract from,count from limit
1038             list($offset,$count) = $this->limit($limit);
1039             $result = $dbh->SelectLimit($sql, $count, $offset);
1040         } else {
1041             $result = $dbh->Execute($sql);
1042         }
1043         //$result->fields['version'] = $result->fields[6];
1044         return new WikiDB_backend_ADODB_iter($this, $result, 
1045             array_merge($this->page_tbl_field_list, $this->version_tbl_field_list));
1046     }
1047
1048     /**
1049      * Find referenced empty pages.
1050      */
1051     function wanted_pages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
1052         $dbh = &$this->_dbh;
1053         extract($this->_table_names);
1054         if ($orderby = $this->sortby($sortby, 'db', array('pagename','wantedfrom')))
1055             $orderby = 'ORDER BY ' . $orderby;
1056             
1057         if ($exclude_from) // array of pagenames
1058             $exclude_from = " AND pp.pagename NOT IN ".$this->_sql_set($exclude_from);
1059         if ($exclude) // array of pagenames
1060             $exclude = " AND p.pagename NOT IN ".$this->_sql_set($exclude);
1061
1062         /* 
1063          all empty pages, independent of linkstatus:
1064            select pagename as empty from page left join nonempty using(id) where is null(nonempty.id);
1065          only all empty pages, which have a linkto:
1066             select page.pagename, linked.pagename as wantedfrom from link, page linked 
1067               left join page on link.linkto=page.id left join nonempty on link.linkto=nonempty.id
1068               where nonempty.id is null and linked.id=link.linkfrom;  
1069         */
1070         $sql = "SELECT p.pagename, pp.pagename as wantedfrom"
1071             . " FROM $page_tbl p JOIN $link_tbl linked "
1072             . " LEFT JOIN $page_tbl pp ON linked.linkto = pp.id"
1073             . " LEFT JOIN $nonempty_tbl ne ON linked.linkto = ne.id" 
1074             . " WHERE ne.id is NULL"
1075             .       " AND p.id = linked.linkfrom"
1076             . $exclude_from
1077             . $exclude
1078             . $orderby;
1079         if ($limit) {
1080             // extract from,count from limit
1081             list($offset,$count) = $this->limit($limit);
1082             $result = $dbh->SelectLimit($sql, $count, $offset);
1083         } else {
1084             $result = $dbh->Execute($sql);
1085         }
1086         return new WikiDB_backend_ADODB_iter($this, $result, array('pagename','wantedfrom'));
1087     }
1088
1089     /**
1090      * Rename page in the database.
1091      */
1092     function rename_page($pagename, $to) {
1093         $dbh = &$this->_dbh;
1094         extract($this->_table_names);
1095         
1096         $this->lock(array('page','version','recent','nonempty','link'));
1097         if ( ($id = $this->_get_pageid($pagename, false)) ) {
1098             if ($new = $this->_get_pageid($to, false)) {
1099                 // Cludge Alert!
1100                 // This page does not exist (already verified before), but exists in the page table.
1101                 // So we delete this page.
1102                 $dbh->query("DELETE FROM $page_tbl WHERE id=$new");
1103                 $dbh->query("DELETE FROM $version_tbl WHERE id=$new");
1104                 $dbh->query("DELETE FROM $recent_tbl WHERE id=$new");
1105                 $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$new");
1106                 // We have to fix all referring tables to the old id
1107                 $dbh->query("UPDATE $link_tbl SET linkfrom=$id WHERE linkfrom=$new");
1108                 $dbh->query("UPDATE $link_tbl SET linkto=$id WHERE linkto=$new");
1109             }
1110             $dbh->query(sprintf("UPDATE $page_tbl SET pagename=%s WHERE id=$id",
1111                                 $dbh->qstr($to)));
1112         }
1113         $this->unlock(array('page'));
1114         return $id;
1115     }
1116
1117     function _update_recent_table($pageid = false) {
1118         $dbh = &$this->_dbh;
1119         extract($this->_table_names);
1120         extract($this->_expressions);
1121
1122         $pageid = (int)$pageid;
1123
1124         // optimize: mysql can do this with one REPLACE INTO.
1125         $backend_type = $this->backendType();
1126         if (substr($backend_type,0,5) == 'mysql') {
1127             $dbh->Execute("REPLACE INTO $recent_tbl"
1128                           . " (id, latestversion, latestmajor, latestminor)"
1129                           . " SELECT id, $maxversion, $maxmajor, $maxminor"
1130                           . " FROM $version_tbl"
1131                           . ( $pageid ? " WHERE id=$pageid" : "")
1132                           . " GROUP BY id" );
1133         } else {
1134             $this->lock(array('recent'));
1135             $dbh->Execute("DELETE FROM $recent_tbl"
1136                       . ( $pageid ? " WHERE id=$pageid" : ""));
1137             $dbh->Execute( "INSERT INTO $recent_tbl"
1138                            . " (id, latestversion, latestmajor, latestminor)"
1139                            . " SELECT id, $maxversion, $maxmajor, $maxminor"
1140                            . " FROM $version_tbl"
1141                            . ( $pageid ? " WHERE id=$pageid" : "")
1142                            . " GROUP BY id" );
1143             $this->unlock(array('recent'));
1144         }
1145     }
1146
1147     function _update_nonempty_table($pageid = false) {
1148         $dbh = &$this->_dbh;
1149         extract($this->_table_names);
1150         extract($this->_expressions);
1151
1152         $pageid = (int)$pageid;
1153
1154         extract($this->_expressions);
1155         $this->lock(array('nonempty'));
1156         $dbh->Execute("DELETE FROM $nonempty_tbl"
1157                       . ( $pageid ? " WHERE id=$pageid" : ""));
1158         $dbh->Execute("INSERT INTO $nonempty_tbl (id)"
1159                       . " SELECT $recent_tbl.id"
1160                       . " FROM $recent_tbl, $version_tbl"
1161                       . " WHERE $recent_tbl.id=$version_tbl.id"
1162                       .       " AND version=latestversion"
1163                       // We have some specifics here (Oracle)
1164                       //. "  AND content<>''"
1165                       . "  AND content $notempty" // On Oracle not just "<>''"
1166                       . ( $pageid ? " AND $recent_tbl.id=$pageid" : ""));
1167         $this->unlock(array('nonempty'));
1168     }
1169
1170     /**
1171      * Grab a write lock on the tables in the SQL database.
1172      *
1173      * Calls can be nested.  The tables won't be unlocked until
1174      * _unlock_database() is called as many times as _lock_database().
1175      *
1176      * @access protected
1177      */
1178     function lock($tables, $write_lock = true) {
1179         $this->_dbh->StartTrans();
1180         if ($this->_lock_count++ == 0) {
1181             $this->_current_lock = $tables;
1182             $this->_lock_tables($tables, $write_lock);
1183         }
1184     }
1185
1186     /**
1187      * Overridden by non-transaction safe backends.
1188      */
1189     function _lock_tables($tables, $write_lock) {
1190         return $this->_current_lock;
1191     }
1192     
1193     /**
1194      * Release a write lock on the tables in the SQL database.
1195      *
1196      * @access protected
1197      *
1198      * @param $force boolean Unlock even if not every call to lock() has been matched
1199      * by a call to unlock().
1200      *
1201      * @see _lock_database
1202      */
1203     function unlock($tables = false, $force = false) {
1204         if ($this->_lock_count == 0) {
1205             $this->_dbh->CompleteTrans(! $force);
1206             $this->_current_lock = false;
1207             return;
1208         }
1209         if (--$this->_lock_count <= 0 || $force) {
1210             $this->_unlock_tables($tables, $force);
1211             $this->_current_lock = false;
1212             $this->_lock_count = 0;
1213         }
1214             $this->_dbh->CompleteTrans(! $force);
1215     }
1216
1217     /**
1218      * overridden by non-transaction safe backends
1219      */
1220     function _unlock_tables($tables, $write_lock=false) {
1221         return;
1222     }
1223
1224     /**
1225      * Serialize data
1226      */
1227     function _serialize($data) {
1228         if (empty($data))
1229             return '';
1230         assert(is_array($data));
1231         return serialize($data);
1232     }
1233
1234     /**
1235      * Unserialize data
1236      */
1237     function _unserialize($data) {
1238         return empty($data) ? array() : unserialize($data);
1239     }
1240
1241     /* some variables and functions for DB backend abstraction (action=upgrade) */
1242     function database () {
1243         return $this->_dbh->database;
1244     }
1245     function backendType() {
1246         return $this->_dbh->databaseType;
1247     }
1248     function connection() {
1249         return $this->_dbh->_connectionID;
1250     }
1251     function getRow($query) {
1252         return $this->_dbh->getRow($query);
1253     }
1254
1255     function listOfTables() {
1256         return $this->_dbh->MetaTables();
1257     }
1258     
1259     // other database needs another connection and other privileges.
1260     function listOfFields($database, $table) {
1261         $field_list = array();
1262         $old_db = $this->database();
1263         if ($database != $old_db) {
1264             $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'], 
1265                                          DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'], 
1266                                          DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password'], 
1267                                          $database);
1268         }
1269         foreach ($this->_dbh->MetaColumns($table, false) as $field) {
1270             $field_list[] = $field->name;
1271         }
1272         if ($database != $old_db) {
1273             $this->_dbh->close();
1274             $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'], 
1275                                          $this->_parsedDSN['username'], 
1276                                          $this->_parsedDSN['password'], 
1277                                          $old_db);
1278         }
1279         return $field_list;
1280     }
1281
1282 };
1283
1284 class WikiDB_backend_ADODB_generic_iter
1285 extends WikiDB_backend_iterator
1286 {
1287     function WikiDB_backend_ADODB_generic_iter($backend, $query_result, $field_list = NULL) {
1288         $this->_backend = &$backend;
1289         $this->_result = $query_result;
1290
1291         if (is_null($field_list)) {
1292             // No field list passed, retrieve from DB
1293             // WikiLens is using the iterator behind the scene
1294             $field_list = array();
1295             $fields = $query_result->FieldCount();
1296             for ($i = 0; $i < $fields ; $i++) {
1297                 $field_info = $query_result->FetchField($i);
1298                 array_push($field_list, $field_info->name);
1299             }
1300         }
1301
1302         $this->_fields = $field_list;
1303     }
1304     
1305     function count() {
1306         if (!$this->_result) {
1307             return false;
1308         }
1309         $count = $this->_result->numRows();
1310         //$this->_result->Close();
1311         return $count;
1312     }
1313
1314     function next() {
1315         $result = &$this->_result;
1316         $backend = &$this->_backend;
1317         if (!$result || $result->EOF) {
1318             $this->free();
1319             return false;
1320         }
1321
1322         // Convert array to hash
1323         $i = 0;
1324         $rec_num = $result->fields;
1325         foreach ($this->_fields as $field) {
1326             $rec_assoc[$field] = $rec_num[$i++];
1327         }
1328         // check if the cache can be populated here?
1329
1330         $result->MoveNext();
1331         return $rec_assoc;
1332     }
1333
1334     function free () {
1335         if ($this->_result) {
1336             /* call mysql_free_result($this->_queryID) */
1337             $this->_result->Close();
1338             $this->_result = false;
1339         }
1340     }
1341 }
1342
1343 class WikiDB_backend_ADODB_iter
1344 extends WikiDB_backend_ADODB_generic_iter
1345 {
1346     function next() {
1347         $result = &$this->_result;
1348         $backend = &$this->_backend;
1349         if (!$result || $result->EOF) {
1350             $this->free();
1351             return false;
1352         }
1353
1354         // Convert array to hash
1355         $i = 0;
1356         $rec_num = $result->fields;
1357         foreach ($this->_fields as $field) {
1358             $rec_assoc[$field] = $rec_num[$i++];
1359         }
1360
1361         $result->MoveNext();
1362         if (isset($rec_assoc['pagedata']))
1363             $rec_assoc['pagedata'] = $backend->_extract_page_data($rec_assoc['pagedata'], $rec_assoc['hits']);
1364         if (!empty($rec_assoc['version'])) {
1365             $rec_assoc['versiondata'] = $backend->_extract_version_data_assoc($rec_assoc);
1366         }
1367         if (!empty($rec_assoc['linkrelation'])) {
1368             $rec_assoc['linkrelation'] = $rec_assoc['linkrelation']; // pagename enough?
1369         }
1370         return $rec_assoc;
1371     }
1372 }
1373
1374 class WikiDB_backend_ADODB_search extends WikiDB_backend_search_sql 
1375 {
1376     // no surrounding quotes because we know it's a string
1377     // function _quote($word) { return $this->_dbh->escapeSimple($word); }
1378 }
1379
1380 // Following function taken from Pear::DB (prev. from adodb-pear.inc.php).
1381 // Eventually, change index.php to provide the relevant information
1382 // directly?
1383     /**
1384      * Parse a data source name.
1385      *
1386      * Additional keys can be added by appending a URI query string to the
1387      * end of the DSN.
1388      *
1389      * The format of the supplied DSN is in its fullest form:
1390      * <code>
1391      *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
1392      * </code>
1393      *
1394      * Most variations are allowed:
1395      * <code>
1396      *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
1397      *  phptype://username:password@hostspec/database_name
1398      *  phptype://username:password@hostspec
1399      *  phptype://username@hostspec
1400      *  phptype://hostspec/database
1401      *  phptype://hostspec
1402      *  phptype(dbsyntax)
1403      *  phptype
1404      * </code>
1405      *
1406      * @param string $dsn Data Source Name to be parsed
1407      *
1408      * @return array an associative array with the following keys:
1409      *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
1410      *  + dbsyntax: Database used with regards to SQL syntax etc.
1411      *  + protocol: Communication protocol to use (tcp, unix etc.)
1412      *  + hostspec: Host specification (hostname[:port])
1413      *  + database: Database to use on the DBMS server
1414      *  + username: User name for login
1415      *  + password: Password for login
1416      *
1417      * @author Tomas V.V.Cox <cox@idecnet.com>
1418      */
1419     function parseDSN($dsn)
1420     {
1421         $parsed = array(
1422             'phptype'  => false,
1423             'dbsyntax' => false,
1424             'username' => false,
1425             'password' => false,
1426             'protocol' => false,
1427             'hostspec' => false,
1428             'port'     => false,
1429             'socket'   => false,
1430             'database' => false,
1431         );
1432
1433         if (is_array($dsn)) {
1434             $dsn = array_merge($parsed, $dsn);
1435             if (!$dsn['dbsyntax']) {
1436                 $dsn['dbsyntax'] = $dsn['phptype'];
1437             }
1438             return $dsn;
1439         }
1440
1441         // Find phptype and dbsyntax
1442         if (($pos = strpos($dsn, '://')) !== false) {
1443             $str = substr($dsn, 0, $pos);
1444             $dsn = substr($dsn, $pos + 3);
1445         } else {
1446             $str = $dsn;
1447             $dsn = null;
1448         }
1449
1450         // Get phptype and dbsyntax
1451         // $str => phptype(dbsyntax)
1452         if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
1453             $parsed['phptype']  = $arr[1];
1454             $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
1455         } else {
1456             $parsed['phptype']  = $str;
1457             $parsed['dbsyntax'] = $str;
1458         }
1459
1460         if (!count($dsn)) {
1461             return $parsed;
1462         }
1463
1464         // Get (if found): username and password
1465         // $dsn => username:password@protocol+hostspec/database
1466         if (($at = strrpos($dsn,'@')) !== false) {
1467             $str = substr($dsn, 0, $at);
1468             $dsn = substr($dsn, $at + 1);
1469             if (($pos = strpos($str, ':')) !== false) {
1470                 $parsed['username'] = rawurldecode(substr($str, 0, $pos));
1471                 $parsed['password'] = rawurldecode(substr($str, $pos + 1));
1472             } else {
1473                 $parsed['username'] = rawurldecode($str);
1474             }
1475         }
1476
1477         // Find protocol and hostspec
1478
1479         // $dsn => proto(proto_opts)/database
1480         if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
1481             $proto       = $match[1];
1482             $proto_opts  = $match[2] ? $match[2] : false;
1483             $dsn         = $match[3];
1484
1485         // $dsn => protocol+hostspec/database (old format)
1486         } else {
1487             if (strpos($dsn, '+') !== false) {
1488                 list($proto, $dsn) = explode('+', $dsn, 2);
1489             }
1490             if (strpos($dsn, '/') !== false) {
1491                 list($proto_opts, $dsn) = explode('/', $dsn, 2);
1492             } else {
1493                 $proto_opts = $dsn;
1494                 $dsn = null;
1495             }
1496         }
1497
1498         // process the different protocol options
1499         $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
1500         $proto_opts = rawurldecode($proto_opts);
1501         if ($parsed['protocol'] == 'tcp') {
1502             if (strpos($proto_opts, ':') !== false) {
1503                 list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
1504             } else {
1505                 $parsed['hostspec'] = $proto_opts;
1506             }
1507         } elseif ($parsed['protocol'] == 'unix') {
1508             $parsed['socket'] = $proto_opts;
1509         }
1510
1511         // Get dabase if any
1512         // $dsn => database
1513         if ($dsn) {
1514             // /database
1515             if (($pos = strpos($dsn, '?')) === false) {
1516                 $parsed['database'] = $dsn;
1517             // /database?param1=value1&param2=value2
1518             } else {
1519                 $parsed['database'] = substr($dsn, 0, $pos);
1520                 $dsn = substr($dsn, $pos + 1);
1521                 if (strpos($dsn, '&') !== false) {
1522                     $opts = explode('&', $dsn);
1523                 } else { // database?param1=value1
1524                     $opts = array($dsn);
1525                 }
1526                 foreach ($opts as $opt) {
1527                     list($key, $value) = explode('=', $opt);
1528                     if (!isset($parsed[$key])) {
1529                         // don't allow params overwrite
1530                         $parsed[$key] = rawurldecode($value);
1531                     }
1532                 }
1533             }
1534         }
1535
1536         return $parsed;
1537     }
1538
1539 // $Log: not supported by cvs2svn $
1540 // Revision 1.90  2006/09/06 05:50:19  rurban
1541 // please XEmacs font-lock
1542 //
1543 // Revision 1.89  2006/06/10 11:59:46  rurban
1544 // purge empty, non-references pages when link is deleted
1545 //
1546 // Revision 1.88  2006/05/14 12:28:03  rurban
1547 // mysql 5.x fix for wantedpages join
1548 //
1549 // Revision 1.87  2006/04/17 17:28:21  rurban
1550 // honor getWikiPageLinks change linkto=>relation
1551 //
1552 // Revision 1.86  2006/04/17 10:02:44  rurban
1553 // fix syntax error missing }
1554 //
1555 // Revision 1.85  2006/04/15 12:48:04  rurban
1556 // use genID, dont lock here
1557 //
1558 // Revision 1.84  2006/02/22 21:49:50  rurban
1559 // Remove hits from links query
1560 // force old set_links method. need to test IS NULL
1561 //
1562 // Revision 1.83  2005/11/14 22:24:33  rurban
1563 // fix fulltext search,
1564 // Eliminate stoplist words,
1565 // don't extract %pagedate twice in ADODB,
1566 // add SemanticWeb support: link(relation),
1567 // major postgresql update: stored procedures, tsearch2 for fulltext
1568 //
1569 // Revision 1.82  2005/10/31 16:48:22  rurban
1570 // move mysql-specifics into its special class
1571 //
1572 // Revision 1.81  2005/10/10 19:42:14  rurban
1573 // fix wanted_pages SQL syntax
1574 //
1575 // Revision 1.80  2005/09/28 19:26:05  rurban
1576 // working on improved postgresql support: better quoting, bytea support
1577 //
1578 // Revision 1.79  2005/09/28 19:08:41  rurban
1579 // dont use LIMIT on modifying queries
1580 //
1581 // Revision 1.78  2005/09/14 06:04:43  rurban
1582 // optimize searching for ALL (ie %), use the stoplist on PDO
1583 //
1584 // Revision 1.77  2005/09/11 14:55:05  rurban
1585 // implement fulltext stoplist
1586 //
1587 // Revision 1.76  2005/09/11 13:25:12  rurban
1588 // enhance LIMIT support
1589 //
1590 // Revision 1.75  2005/09/10 21:30:16  rurban
1591 // enhance titleSearch
1592 //
1593 // Revision 1.74  2005/02/10 19:04:22  rurban
1594 // move getRow up one level to our backend class
1595 //
1596 // Revision 1.73  2005/02/04 13:43:30  rurban
1597 // fix purge cache error
1598 //
1599 // Revision 1.72  2005/01/29 19:51:03  rurban
1600 // Bugs item #1077769 fixed by frugal.
1601 // Deleted the wrong page. Fix all other tables also.
1602 //
1603 // Revision 1.71  2005/01/25 08:01:00  rurban
1604 // fix listOfFields with different database
1605 //
1606 // Revision 1.70  2005/01/18 20:55:43  rurban
1607 // reformatting and two bug fixes: adding missing parens
1608 //
1609 // Revision 1.69  2004/12/26 17:14:03  rurban
1610 // fix ADODB MostPopular, avoid limit -1, pass hits on empty data
1611 //
1612 // Revision 1.68  2004/12/22 18:33:25  rurban
1613 // fix page _id_cache logic for _get_pageid create_if_missing
1614 //
1615 // Revision 1.67  2004/12/22 15:47:41  rurban
1616 // fix wrong _update_nonempty_table on empty content (i.e. the new deletePage)
1617 //
1618 // Revision 1.66  2004/12/13 14:39:16  rurban
1619 // avoid warning
1620 //
1621 // Revision 1.65  2004/12/10 22:15:00  rurban
1622 // fix $page->get('_cached_html)
1623 // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also.
1624 // support 2nd genericSqlQuery param (bind huge arg)
1625 //
1626 // Revision 1.64  2004/12/10 02:45:27  rurban
1627 // SQL optimization:
1628 //   put _cached_html from pagedata into a new seperate blob, not huge serialized string.
1629 //   it is only rarelely needed: for current page only, if-not-modified
1630 //   but was extracted for every simple page iteration.
1631 //
1632 // Revision 1.63  2004/12/08 12:55:51  rurban
1633 // support new non-destructive delete_page via generic backend method
1634 //
1635 // Revision 1.62  2004/12/06 19:50:04  rurban
1636 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
1637 // renamed delete_page to purge_page.
1638 // enable action=edit&version=-1 to force creation of a new version.
1639 // added BABYCART_PATH config
1640 // fixed magiqc in adodb.inc.php
1641 // and some more docs
1642 //
1643 // Revision 1.61  2004/11/30 17:45:53  rurban
1644 // exists_links backend implementation
1645 //
1646 // Revision 1.60  2004/11/28 20:42:18  rurban
1647 // Optimize PearDB _extract_version_data and _extract_page_data.
1648 //
1649 // Revision 1.59  2004/11/27 14:39:05  rurban
1650 // simpified regex search architecture:
1651 //   no db specific node methods anymore,
1652 //   new sql() method for each node
1653 //   parallel to regexp() (which returns pcre)
1654 //   regex types bitmasked (op's not yet)
1655 // new regex=sql
1656 // clarified WikiDB::quote() backend methods:
1657 //   ->quote() adds surrounsing quotes
1658 //   ->qstr() (new method) assumes strings and adds no quotes! (in contrast to ADODB)
1659 //   pear and adodb have now unified quote methods for all generic queries.
1660 //
1661 // Revision 1.58  2004/11/26 18:39:02  rurban
1662 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
1663 //
1664 // Revision 1.57  2004/11/25 17:20:51  rurban
1665 // and again a couple of more native db args: backlinks
1666 //
1667 // Revision 1.56  2004/11/23 13:35:48  rurban
1668 // add case_exact search
1669 //
1670 // Revision 1.55  2004/11/21 11:59:26  rurban
1671 // remove final \n to be ob_cache independent
1672 //
1673 // Revision 1.54  2004/11/20 17:49:39  rurban
1674 // add fast exclude support to SQL get_all_pages
1675 //
1676 // Revision 1.53  2004/11/20 17:35:58  rurban
1677 // improved WantedPages SQL backends
1678 // PageList::sortby new 3rd arg valid_fields (override db fields)
1679 // WantedPages sql pager inexact for performance reasons:
1680 //   assume 3 wantedfrom per page, to be correct, no getTotal()
1681 // support exclude argument for get_all_pages, new _sql_set()
1682 //
1683 // Revision 1.52  2004/11/17 20:07:17  rurban
1684 // just whitespace
1685 //
1686 // Revision 1.51  2004/11/15 15:57:37  rurban
1687 // silent cache warning
1688 //
1689 // Revision 1.50  2004/11/10 19:32:23  rurban
1690 // * optimize increaseHitCount, esp. for mysql.
1691 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1692 // * Pear_DB version logic (awful but needed)
1693 // * fix broken ADODB quote
1694 // * _extract_page_data simplification
1695 //
1696 // Revision 1.49  2004/11/10 15:29:21  rurban
1697 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
1698 // * ACCESS_LOG_SQL: fix cause request not yet initialized
1699 // * WikiDB: moved SQL specific methods upwards
1700 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
1701 //   fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
1702 //
1703 // Revision 1.48  2004/11/09 17:11:16  rurban
1704 // * revert to the wikidb ref passing. there's no memory abuse there.
1705 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1706 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
1707 //   are also needed at the rendering for linkExistingWikiWord().
1708 //   pass options to pageiterator.
1709 //   use this cache also for _get_pageid()
1710 //   This saves about 8 SELECT count per page (num all pagelinks).
1711 // * fix passing of all page fields to the pageiterator.
1712 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1713 //
1714 // Revision 1.47  2004/11/06 17:11:42  rurban
1715 // The optimized version doesn't query for pagedata anymore.
1716 //
1717 // Revision 1.46  2004/11/01 10:43:58  rurban
1718 // seperate PassUser methods into seperate dir (memory usage)
1719 // fix WikiUser (old) overlarge data session
1720 // remove wikidb arg from various page class methods, use global ->_dbi instead
1721 // ...
1722 //
1723 // Revision 1.45  2004/10/14 17:19:17  rurban
1724 // allow most_popular sortby arguments
1725 //
1726 // Revision 1.44  2004/09/06 08:33:09  rurban
1727 // force explicit mysql auto-incrementing, atomic version
1728 //
1729 // Revision 1.43  2004/07/10 08:50:24  rurban
1730 // applied patch by Philippe Vanhaesendonck:
1731 //   pass column list to iterators so we can FETCH_NUM in all cases.
1732 //   bind UPDATE pramas for huge pagedata.
1733 //   portable oracle backend
1734 //
1735 // Revision 1.42  2004/07/09 10:06:50  rurban
1736 // Use backend specific sortby and sortable_columns method, to be able to
1737 // select between native (Db backend) and custom (PageList) sorting.
1738 // Fixed PageList::AddPageList (missed the first)
1739 // Added the author/creator.. name to AllPagesBy...
1740 //   display no pages if none matched.
1741 // Improved dba and file sortby().
1742 // Use &$request reference
1743 //
1744 // Revision 1.41  2004/07/08 21:32:35  rurban
1745 // Prevent from more warnings, minor db and sort optimizations
1746 //
1747 // Revision 1.40  2004/07/08 16:56:16  rurban
1748 // use the backendType abstraction
1749 //
1750 // Revision 1.39  2004/07/05 13:56:22  rurban
1751 // sqlite autoincrement fix
1752 //
1753 // Revision 1.38  2004/07/05 12:57:54  rurban
1754 // add mysql timeout
1755 //
1756 // Revision 1.37  2004/07/04 10:24:43  rurban
1757 // forgot the expressions
1758 //
1759 // Revision 1.36  2004/07/03 16:51:06  rurban
1760 // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
1761 // added atomic mysql REPLACE for PearDB as in ADODB
1762 // fixed _lock_tables typo links => link
1763 // fixes unserialize ADODB bug in line 180
1764 //
1765 // Revision 1.35  2004/06/28 14:45:12  rurban
1766 // fix adodb_sqlite to have the same dsn syntax as pear, use pconnect if requested
1767 //
1768 // Revision 1.34  2004/06/28 14:17:38  rurban
1769 // updated DSN parser from Pear. esp. for sqlite
1770 //
1771 // Revision 1.33  2004/06/27 10:26:02  rurban
1772 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1773 //
1774 // Revision 1.32  2004/06/25 14:15:08  rurban
1775 // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
1776 //
1777 // Revision 1.31  2004/06/16 10:38:59  rurban
1778 // Disallow refernces in calls if the declaration is a reference
1779 // ("allow_call_time_pass_reference clean").
1780 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
1781 //   but several external libraries may not.
1782 //   In detail these libs look to be affected (not tested):
1783 //   * Pear_DB odbc
1784 //   * adodb oracle
1785 //
1786 // Revision 1.30  2004/06/07 19:31:31  rurban
1787 // fixed ADOOB upgrade: listOfFields()
1788 //
1789 // Revision 1.29  2004/05/12 10:49:55  rurban
1790 // require_once fix for those libs which are loaded before FileFinder and
1791 //   its automatic include_path fix, and where require_once doesn't grok
1792 //   dirname(__FILE__) != './lib'
1793 // upgrade fix with PearDB
1794 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1795 //
1796 // Revision 1.28  2004/05/06 19:26:16  rurban
1797 // improve stability, trying to find the InlineParser endless loop on sf.net
1798 //
1799 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1800 //
1801 // Revision 1.27  2004/05/06 17:30:38  rurban
1802 // CategoryGroup: oops, dos2unix eol
1803 // improved phpwiki_version:
1804 //   pre -= .0001 (1.3.10pre: 1030.099)
1805 //   -p1 += .001 (1.3.9-p1: 1030.091)
1806 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1807 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1808 //   backend->backendType(), backend->database(),
1809 //   backend->listOfFields(),
1810 //   backend->listOfTables(),
1811 //
1812 // Revision 1.26  2004/04/26 20:44:35  rurban
1813 // locking table specific for better databases
1814 //
1815 // Revision 1.25  2004/04/20 00:06:04  rurban
1816 // themable paging support
1817 //
1818 // Revision 1.24  2004/04/18 01:34:20  rurban
1819 // protect most_popular from sortby=mtime
1820 //
1821 // Revision 1.23  2004/04/16 14:19:39  rurban
1822 // updated ADODB notes
1823 //
1824
1825 // (c-file-style: "gnu")
1826 // Local Variables:
1827 // mode: php
1828 // tab-width: 8
1829 // c-basic-offset: 4
1830 // c-hanging-comment-ender-p: nil
1831 // indent-tabs-mode: nil
1832 // End:   
1833 ?>