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