2 rcs_id('$Id: ADODB.php,v 1.88 2006-05-14 12:28:03 rurban Exp $');
5 Copyright 2002,2004,2005 $ThePhpWikiProgrammingTeam
7 This file is part of PhpWiki.
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.
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.
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
26 * Based on PearDB.php.
27 * @author: Lawrence Akka, Reini Urban
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
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
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.
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
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.
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');
73 class WikiDB_backend_ADODB
74 extends WikiDB_backend
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';
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']);
93 $conn = $this->_dbh->Connect($parsed['hostspec'],$parsed['username'],
94 $parsed['password'], $parsed['database']);
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;
102 $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
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',
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;
132 * Close database connection.
137 if ($this->_lock_count) {
138 trigger_error("WARNING: database still locked " .
139 '(lock_count = $this->_lock_count)' . "\n<br />",
142 // $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT); // prevent recursive loops.
143 $this->unlock(false,'force');
145 $this->_dbh->close();
150 * Fast test for wikipage.
152 function is_wiki_page($pagename) {
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;
163 function get_all_pagenames() {
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();
173 * filter (nonempty pages) currently ignored
175 function numPages($filter=false, $exclude='') {
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");
184 function increaseHitCount($pagename) {
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)));
197 * Read page information from database.
199 function get_pagedata($pagename) {
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;
207 function _extract_page_data($data, $hits) {
209 return array('hits' => $hits);
211 return array_merge(array('hits' => $hits), $this->_unserialize($data));
214 function update_pagedata($pagename, $newdata) {
216 $page_tbl = $this->_table_names['page_tbl'];
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)));
227 $where = sprintf("pagename=%s", $dbh->qstr($pagename));
229 $dbh->RowLock($page_tbl,$where);
231 $data = $this->get_pagedata($pagename);
234 $this->_get_pageid($pagename, true); // Creates page record
237 $hits = (empty($data['hits'])) ? 0 : (int)$data['hits'];
238 unset($data['hits']);
240 foreach ($newdata as $key => $val) {
243 else if (empty($val))
248 if ($dbh->Execute("UPDATE $page_tbl"
249 . " SET hits=?, pagedata=?"
250 . " WHERE pagename=?",
251 array($hits, $this->_serialize($data), $pagename))) {
252 $dbh->CommitTrans( );
255 $dbh->RollbackTrans( );
260 function get_cached_html($pagename) {
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;
268 function set_cached_html($pagename, $data) {
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));
278 function _get_pageid($pagename, $create_if_missing = false) {
282 $cache =& $request->_dbi->_cache->_id_cache;
283 if (isset($cache[$pagename])) {
284 if ($cache[$pagename] or !$create_if_missing) {
285 return $cache[$pagename];
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;
297 $row = $dbh->GetRow($query);
299 //TODO: Does the DBM has subselects? Then we can do it with select max(id)+1
300 // $this->lock(array('page'));
302 $dbh->CommitLock($page_tbl);
303 if ($dbh->hasGenID) {
304 $id = $dbh->GenID($page_tbl."_id");
306 // Better generic version than with adodb::genID
307 $row = $dbh->GetRow("SELECT MAX(id) FROM $page_tbl");
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'));
324 function get_latest_version($pagename) {
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;
335 function get_previous_version($pagename, $version) {
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"
343 . " AND version < %d"
344 . " ORDER BY version DESC",
345 $dbh->qstr($pagename),
348 return $rs->fields ? (int)$rs->fields[0] : false;
354 * @param $version int Which version to get.
356 * @return hash The version data, or false if specified version does not
359 function get_versiondata($pagename, $version, $want_content = false) {
361 extract($this->_table_names);
362 extract($this->_expressions);
364 assert(is_string($pagename) and $pagename != '');
365 assert($version > 0);
367 // FIXME: optimization: sometimes don't get page data?
369 $fields = $this->page_tbl_fields . ", $page_tbl.pagedata AS pagedata"
370 . ', ' . $this->version_tbl_fields;
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";
377 $row = $dbh->GetRow(sprintf("SELECT $fields"
378 . " FROM $page_tbl, $version_tbl"
379 . " WHERE $page_tbl.id=$version_tbl.id"
382 $dbh->qstr($pagename), $version));
383 return $row ? $this->_extract_version_data_num($row, $want_content) : false;
386 function _extract_version_data_num($row, $want_content) {
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]);
396 $data['%content'] = $row[7];
398 $data['%content'] = !empty($row[7]);
400 if (!empty($row[3])) {
401 $data['%pagedata'] = $this->_extract_page_data($row[3], $row[2]);
406 function _extract_version_data_assoc($row) {
411 $data = empty($versiondata) ? array() : $this->_unserialize($versiondata);
412 $data['mtime'] = $mtime;
413 $data['is_minor_edit'] = !empty($minor_edit);
415 $data['%content'] = $content;
416 elseif ($have_content)
417 $data['%content'] = true;
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;
429 * Create a new revision of a page.
431 function set_versiondata($pagename, $version, $data) {
433 $version_tbl = $this->_table_names['version_tbl'];
435 $minor_edit = (int) !empty($data['is_minor_edit']);
436 unset($data['is_minor_edit']);
438 $mtime = (int)$data['mtime'];
439 unset($data['mtime']);
440 assert(!empty($mtime));
442 @$content = (string) $data['%content'];
443 unset($data['%content']);
444 unset($data['%pagedata']);
446 $this->lock(array('page','recent','version','nonempty'));
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",
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'));
467 * Delete an old revision of a page.
469 function delete_versiondata($pagename, $version) {
471 extract($this->_table_names);
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);
482 $this->unlock(array('version'));
486 * Delete page from the database with backup possibility.
487 * i.e save_page('') and DELETE nonempty id
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.
494 function delete_page($pagename) {
496 extract($this->_table_names);
499 $dbh->CommitLock($recent_tbl);
500 if (($id = $this->_get_pageid($pagename, false)) === false) {
501 $dbh->RollbackTrans( );
505 $user =& $GLOBALS['request']->_user;
506 $meta = array('author' => $user->getId(),
507 'author_id' => $user->getAuthenticatedId(),
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")
526 $this->unlock(array('version','recent','nonempty','page','link'));
527 $dbh->CommitTrans( );
530 $this->unlock(array('version','recent','nonempty','page','link'));
531 $dbh->RollbackTrans( );
536 function purge_page($pagename) {
538 extract($this->_table_names);
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
550 $dbh->Execute("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
554 $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id");
558 $result = -1; // already purged or not existing
560 $this->unlock(array('version','recent','nonempty','page','link'));
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) {
571 function set_links($pagename, $links) {
572 // Update link table.
573 // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE.
576 extract($this->_table_names);
578 $this->lock(array('link'));
579 $pageid = $this->_get_pageid($pagename, true);
582 $dbh->Execute("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
583 foreach ($links as $link) {
584 $linkto = $link['linkto'];
585 if ($link['relation'])
586 $relation = $this->_get_pageid($link['relation'], true);
590 if (isset($linkseen[$linkto]) and !$relation)
593 $linkseen[$linkto] = true;
594 $linkid = $this->_get_pageid($linkto, true);
597 $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto, relation)"
598 . " VALUES ($pageid, $linkid, $relation)");
600 $dbh->Execute("INSERT INTO $link_tbl (linkfrom, linkto)"
601 . " VALUES ($pageid, $linkid)");
604 } elseif (0 and DEBUG) {
605 // purge page table: delete all non-referenced pages
606 // for all previously linked pages...
607 foreach ($dbh->getRow("SELECT $link_tbl.linkto as id FROM $link_tbl".
608 " WHERE linkfrom=$pageid") as $id) {
609 // ...check if the page is empty and has no version
610 if ($dbh->getRow("SELECT $page_tbl.id FROM $page_tbl"
611 . " LEFT JOIN $nonempty_tbl USING (id) "
612 . " LEFT JOIN $version_tbl USING (id)"
613 . " WHERE $nonempty_tbl.id is NULL"
614 . " AND $version_tbl.id is NULL"
615 . " AND $page_tbl.id=$id")) {
616 $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id"); // this purges the link
617 $dbh->Execute("DELETE FROM $recent_tbl WHERE id=$id"); // may fail
620 $dbh->Execute("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
622 $this->unlock(array('link'));
627 * Find pages which link to or are linked from a page.
629 * Optimization: save request->_dbi->_iwpcache[] to avoid further iswikipage checks
630 * (linkExistingWikiWord or linkUnknownWikiWord)
631 * This is called on every page header GleanDescription, so we can store all the
634 * relations: $backend->get_links is responsible to add the relation to the pagehash
635 * as 'linkrelation' key as pagename. See WikiDB_PageIterator::next
636 * if (isset($next['linkrelation']))
638 function get_links($pagename, $reversed=true, $include_empty=false,
639 $sortby=false, $limit=false, $exclude='',
640 $want_relations = false)
643 extract($this->_table_names);
646 list($have,$want) = array('linkee', 'linker');
648 list($have,$want) = array('linker', 'linkee');
649 $orderby = $this->sortby($sortby, 'db', array('pagename'));
650 if ($orderby) $orderby = ' ORDER BY $want.' . $orderby;
651 if ($exclude) // array of pagenames
652 $exclude = " AND $want.pagename NOT IN ".$this->_sql_set($exclude);
656 $qpagename = $dbh->qstr($pagename);
657 // removed ref to FETCH_MODE in next line
658 $sql = "SELECT $want.id AS id, $want.pagename AS pagename, "
659 . ($want_relations ? " related.pagename as linkrelation" : " $want.hits AS hits")
661 . (!$include_empty ? "$nonempty_tbl, " : '')
662 . " $page_tbl linkee, $page_tbl linker, $link_tbl "
663 . ($want_relations ? " JOIN $page_tbl related ON ($link_tbl.relation=related.id)" : '')
664 . " WHERE linkfrom=linker.id AND linkto=linkee.id"
665 . " AND $have.pagename=$qpagename"
666 . (!$include_empty ? " AND $nonempty_tbl.id=$want.id" : "")
667 //. " GROUP BY $want.id"
671 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
672 id pagename linkrelation
673 2268 California located_in
676 // extract from,count from limit
677 list($offset,$count) = $this->limit($limit);
678 $result = $dbh->SelectLimit($sql, $count, $offset);
680 $result = $dbh->Execute($sql);
682 $fields = $this->links_field_list;
683 if ($want_relations) // instead of hits
684 $fields[2] = 'linkrelation';
685 return new WikiDB_backend_ADODB_iter($this, $result, $fields);
689 * Find if a page links to another page
691 function exists_link($pagename, $link, $reversed=false) {
693 extract($this->_table_names);
696 list($have, $want) = array('linkee', 'linker');
698 list($have, $want) = array('linker', 'linkee');
699 $qpagename = $dbh->qstr($pagename);
700 $qlink = $dbh->qstr($link);
701 $row = $dbh->GetRow("SELECT IF($want.pagename,1,0)"
702 . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee, $nonempty_tbl"
703 . " WHERE linkfrom=linker.id AND linkto=linkee.id"
704 . " AND $have.pagename=$qpagename"
705 . " AND $want.pagename=$qlink");
712 function get_all_pages($include_empty=false, $sortby=false, $limit=false, $exclude='') {
714 extract($this->_table_names);
715 $orderby = $this->sortby($sortby, 'db');
716 if ($orderby) $orderby = ' ORDER BY ' . $orderby;
717 if ($exclude) // array of pagenames
718 $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude);
722 //$dbh->SetFetchMode(ADODB_FETCH_ASSOC);
723 if (strstr($orderby, 'mtime ')) { // was ' mtime'
724 if ($include_empty) {
726 . $this->page_tbl_fields
727 ." FROM $page_tbl, $recent_tbl, $version_tbl"
728 . " WHERE $page_tbl.id=$recent_tbl.id"
729 . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
735 . $this->page_tbl_fields
736 . " FROM $nonempty_tbl, $page_tbl, $recent_tbl, $version_tbl"
737 . " WHERE $nonempty_tbl.id=$page_tbl.id"
738 . " AND $page_tbl.id=$recent_tbl.id"
739 . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
744 if ($include_empty) {
746 . $this->page_tbl_fields
748 . ($exclude ? " WHERE $exclude" : '')
752 . $this->page_tbl_fields
753 . " FROM $nonempty_tbl, $page_tbl"
754 . " WHERE $nonempty_tbl.id=$page_tbl.id"
760 // extract from,count from limit
761 list($offset,$count) = $this->limit($limit);
762 $result = $dbh->SelectLimit($sql, $count, $offset);
764 $result = $dbh->Execute($sql);
766 //$dbh->SetFetchMode(ADODB_FETCH_NUM);
767 return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list);
771 * Title and fulltext search.
773 function text_search($search, $fullsearch=false,
774 $sortby=false, $limit=false, $exclude=false)
777 extract($this->_table_names);
778 $orderby = $this->sortby($sortby, 'db');
779 if ($orderby) $orderby = ' ORDER BY ' . $orderby;
781 $table = "$nonempty_tbl, $page_tbl";
782 $join_clause = "$nonempty_tbl.id=$page_tbl.id";
783 $fields = $this->page_tbl_fields;
784 $field_list = $this->page_tbl_field_list;
785 $searchobj = new WikiDB_backend_ADODB_search($search, $dbh);
788 $table .= ", $recent_tbl";
789 $join_clause .= " AND $page_tbl.id=$recent_tbl.id";
791 $table .= ", $version_tbl";
792 $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";
794 $fields .= ",$page_tbl.pagedata as pagedata," . $this->version_tbl_fields;
795 $field_list = array_merge($field_list, array('pagedata'),
796 $this->version_tbl_field_list);
797 $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
799 $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");
802 $search_clause = $search->makeSqlClauseObj($callback);
803 $sql = "SELECT $fields FROM $table"
804 . " WHERE $join_clause"
805 . " AND ($search_clause)"
808 // extract from,count from limit
809 list($offset,$count) = $this->limit($limit);
810 $result = $dbh->SelectLimit($sql, $count, $offset);
812 $result = $dbh->Execute($sql);
814 $iter = new WikiDB_backend_ADODB_iter($this, $result, $field_list);
816 $iter->stoplisted = $searchobj->stoplisted;
821 * TODO: efficiently handle wildcards exclusion: exclude=Php* => 'Php%',
822 * not sets. See above, but the above methods find too much.
823 * This is only for already resolved wildcards:
824 * " WHERE $page_tbl.pagename NOT IN ".$this->_sql_set(array('page1','page2'));
826 function _sql_set(&$pagenames) {
828 foreach ($pagenames as $p) {
829 $s .= ($this->_dbh->qstr($p).",");
831 return substr($s,0,-1).")";
835 * Find highest or lowest hit counts.
837 function most_popular ($limit=20, $sortby='-hits') {
839 extract($this->_table_names);
846 $where = " AND hits > 0";
848 if ($sortby != '-hits') {
849 if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order;
852 $orderby = " ORDER BY hits $order";
854 . $this->page_tbl_fields
855 . " FROM $nonempty_tbl, $page_tbl"
856 . " WHERE $nonempty_tbl.id=$page_tbl.id"
860 // extract from,count from limit
861 list($offset,$count) = $this->limit($limit);
862 $result = $dbh->SelectLimit($sql, $count, $offset);
864 $result = $dbh->Execute($sql);
866 return new WikiDB_backend_ADODB_iter($this, $result, $this->page_tbl_field_list);
870 * Find recent changes.
872 function most_recent($params) {
875 $include_minor_revisions = false;
876 $exclude_major_revisions = false;
877 $include_all_revisions = false;
881 extract($this->_table_names);
885 $pick[] = "mtime >= $since";
887 if ($include_all_revisions) {
888 // Include all revisions of each page.
889 $table = "$page_tbl, $version_tbl";
890 $join_clause = "$page_tbl.id=$version_tbl.id";
892 if ($exclude_major_revisions) {
893 // Include only minor revisions
894 $pick[] = "minor_edit <> 0";
896 elseif (!$include_minor_revisions) {
897 // Include only major revisions
898 $pick[] = "minor_edit = 0";
902 $table = "$page_tbl, $recent_tbl";
903 $join_clause = "$page_tbl.id=$recent_tbl.id";
904 $table .= ", $version_tbl";
905 $join_clause .= " AND $version_tbl.id=$page_tbl.id";
907 if ($exclude_major_revisions) {
908 // Include only most recent minor revision
909 $pick[] = 'version=latestminor';
911 elseif (!$include_minor_revisions) {
912 // Include only most recent major revision
913 $pick[] = 'version=latestmajor';
916 // Include only the latest revision (whether major or minor).
917 $pick[] ='version=latestversion';
925 $where_clause = $join_clause;
927 $where_clause .= " AND " . join(" AND ", $pick);
929 . $this->page_tbl_fields . ", " . $this->version_tbl_fields
931 . " WHERE $where_clause"
932 . " ORDER BY mtime $order";
933 // FIXME: use SQL_BUFFER_RESULT for mysql?
935 // extract from,count from limit
936 list($offset,$count) = $this->limit($limit);
937 $result = $dbh->SelectLimit($sql, $count, $offset);
939 $result = $dbh->Execute($sql);
941 //$result->fields['version'] = $result->fields[6];
942 return new WikiDB_backend_ADODB_iter($this, $result,
943 array_merge($this->page_tbl_field_list, $this->version_tbl_field_list));
947 * Find referenced empty pages.
949 function wanted_pages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
951 extract($this->_table_names);
952 if ($orderby = $this->sortby($sortby, 'db', array('pagename','wantedfrom')))
953 $orderby = 'ORDER BY ' . $orderby;
955 if ($exclude_from) // array of pagenames
956 $exclude_from = " AND pp.pagename NOT IN ".$this->_sql_set($exclude_from);
957 if ($exclude) // array of pagenames
958 $exclude = " AND p.pagename NOT IN ".$this->_sql_set($exclude);
961 all empty pages, independent of linkstatus:
962 select pagename as empty from page left join nonempty using(id) where is null(nonempty.id);
963 only all empty pages, which have a linkto:
964 select page.pagename, linked.pagename as wantedfrom from link, page linked
965 left join page on link.linkto=page.id left join nonempty on link.linkto=nonempty.id
966 where nonempty.id is null and linked.id=link.linkfrom;
968 $sql = "SELECT p.pagename, pp.pagename as wantedfrom"
969 . " FROM $page_tbl p JOIN $link_tbl linked "
970 . " LEFT JOIN $page_tbl pp ON linked.linkto = pp.id"
971 . " LEFT JOIN $nonempty_tbl ne ON linked.linkto = ne.id"
972 . " WHERE ne.id is NULL"
973 . " AND p.id = linked.linkfrom"
978 // extract from,count from limit
979 list($offset,$count) = $this->limit($limit);
980 $result = $dbh->SelectLimit($sql, $count, $offset);
982 $result = $dbh->Execute($sql);
984 return new WikiDB_backend_ADODB_iter($this, $result, array('pagename','wantedfrom'));
988 * Rename page in the database.
990 function rename_page($pagename, $to) {
992 extract($this->_table_names);
994 $this->lock(array('page','version','recent','nonempty','link'));
995 if ( ($id = $this->_get_pageid($pagename, false)) ) {
996 if ($new = $this->_get_pageid($to, false)) {
998 // This page does not exist (already verified before), but exists in the page table.
999 // So we delete this page.
1000 $dbh->query("DELETE FROM $page_tbl WHERE id=$new");
1001 $dbh->query("DELETE FROM $version_tbl WHERE id=$new");
1002 $dbh->query("DELETE FROM $recent_tbl WHERE id=$new");
1003 $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$new");
1004 // We have to fix all referring tables to the old id
1005 $dbh->query("UPDATE $link_tbl SET linkfrom=$id WHERE linkfrom=$new");
1006 $dbh->query("UPDATE $link_tbl SET linkto=$id WHERE linkto=$new");
1008 $dbh->query(sprintf("UPDATE $page_tbl SET pagename=%s WHERE id=$id",
1011 $this->unlock(array('page'));
1015 function _update_recent_table($pageid = false) {
1016 $dbh = &$this->_dbh;
1017 extract($this->_table_names);
1018 extract($this->_expressions);
1020 $pageid = (int)$pageid;
1022 // optimize: mysql can do this with one REPLACE INTO.
1023 $backend_type = $this->backendType();
1024 if (substr($backend_type,0,5) == 'mysql') {
1025 $dbh->Execute("REPLACE INTO $recent_tbl"
1026 . " (id, latestversion, latestmajor, latestminor)"
1027 . " SELECT id, $maxversion, $maxmajor, $maxminor"
1028 . " FROM $version_tbl"
1029 . ( $pageid ? " WHERE id=$pageid" : "")
1032 $this->lock(array('recent'));
1033 $dbh->Execute("DELETE FROM $recent_tbl"
1034 . ( $pageid ? " WHERE id=$pageid" : ""));
1035 $dbh->Execute( "INSERT INTO $recent_tbl"
1036 . " (id, latestversion, latestmajor, latestminor)"
1037 . " SELECT id, $maxversion, $maxmajor, $maxminor"
1038 . " FROM $version_tbl"
1039 . ( $pageid ? " WHERE id=$pageid" : "")
1041 $this->unlock(array('recent'));
1045 function _update_nonempty_table($pageid = false) {
1046 $dbh = &$this->_dbh;
1047 extract($this->_table_names);
1048 extract($this->_expressions);
1050 $pageid = (int)$pageid;
1052 extract($this->_expressions);
1053 $this->lock(array('nonempty'));
1054 $dbh->Execute("DELETE FROM $nonempty_tbl"
1055 . ( $pageid ? " WHERE id=$pageid" : ""));
1056 $dbh->Execute("INSERT INTO $nonempty_tbl (id)"
1057 . " SELECT $recent_tbl.id"
1058 . " FROM $recent_tbl, $version_tbl"
1059 . " WHERE $recent_tbl.id=$version_tbl.id"
1060 . " AND version=latestversion"
1061 // We have some specifics here (Oracle)
1062 //. " AND content<>''"
1063 . " AND content $notempty" // On Oracle not just "<>''"
1064 . ( $pageid ? " AND $recent_tbl.id=$pageid" : ""));
1065 $this->unlock(array('nonempty'));
1069 * Grab a write lock on the tables in the SQL database.
1071 * Calls can be nested. The tables won't be unlocked until
1072 * _unlock_database() is called as many times as _lock_database().
1076 function lock($tables, $write_lock = true) {
1077 $this->_dbh->StartTrans();
1078 if ($this->_lock_count++ == 0) {
1079 $this->_current_lock = $tables;
1080 $this->_lock_tables($tables, $write_lock);
1085 * Overridden by non-transaction safe backends.
1087 function _lock_tables($tables, $write_lock) {
1088 return $this->_current_lock;
1092 * Release a write lock on the tables in the SQL database.
1096 * @param $force boolean Unlock even if not every call to lock() has been matched
1097 * by a call to unlock().
1099 * @see _lock_database
1101 function unlock($tables = false, $force = false) {
1102 if ($this->_lock_count == 0) {
1103 $this->_dbh->CompleteTrans(! $force);
1104 $this->_current_lock = false;
1107 if (--$this->_lock_count <= 0 || $force) {
1108 $this->_unlock_tables($tables, $force);
1109 $this->_current_lock = false;
1110 $this->_lock_count = 0;
1112 $this->_dbh->CompleteTrans(! $force);
1116 * overridden by non-transaction safe backends
1118 function _unlock_tables($tables, $write_lock=false) {
1125 function _serialize($data) {
1128 assert(is_array($data));
1129 return serialize($data);
1135 function _unserialize($data) {
1136 return empty($data) ? array() : unserialize($data);
1139 /* some variables and functions for DB backend abstraction (action=upgrade) */
1140 function database () {
1141 return $this->_dbh->database;
1143 function backendType() {
1144 return $this->_dbh->databaseType;
1146 function connection() {
1147 return $this->_dbh->_connectionID;
1149 function getRow($query) {
1150 return $this->_dbh->getRow($query);
1153 function listOfTables() {
1154 return $this->_dbh->MetaTables();
1157 // other database needs another connection and other privileges.
1158 function listOfFields($database, $table) {
1159 $field_list = array();
1160 $old_db = $this->database();
1161 if ($database != $old_db) {
1162 $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'],
1163 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],
1164 DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password'],
1167 foreach ($this->_dbh->MetaColumns($table, false) as $field) {
1168 $field_list[] = $field->name;
1170 if ($database != $old_db) {
1171 $this->_dbh->close();
1172 $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'],
1173 $this->_parsedDSN['username'],
1174 $this->_parsedDSN['password'],
1182 class WikiDB_backend_ADODB_generic_iter
1183 extends WikiDB_backend_iterator
1185 function WikiDB_backend_ADODB_generic_iter($backend, $query_result, $field_list = NULL) {
1186 $this->_backend = &$backend;
1187 $this->_result = $query_result;
1189 if (is_null($field_list)) {
1190 // No field list passed, retrieve from DB
1191 // WikiLens is using the iterator behind the scene
1192 $field_list = array();
1193 $fields = $query_result->FieldCount();
1194 for ($i = 0; $i < $fields ; $i++) {
1195 $field_info = $query_result->FetchField($i);
1196 array_push($field_list, $field_info->name);
1200 $this->_fields = $field_list;
1204 if (!$this->_result) {
1207 $count = $this->_result->numRows();
1208 //$this->_result->Close();
1213 $result = &$this->_result;
1214 $backend = &$this->_backend;
1215 if (!$result || $result->EOF) {
1220 // Convert array to hash
1222 $rec_num = $result->fields;
1223 foreach ($this->_fields as $field) {
1224 $rec_assoc[$field] = $rec_num[$i++];
1226 // check if the cache can be populated here?
1228 $result->MoveNext();
1233 if ($this->_result) {
1234 /* call mysql_free_result($this->_queryID) */
1235 $this->_result->Close();
1236 $this->_result = false;
1241 class WikiDB_backend_ADODB_iter
1242 extends WikiDB_backend_ADODB_generic_iter
1245 $result = &$this->_result;
1246 $backend = &$this->_backend;
1247 if (!$result || $result->EOF) {
1252 // Convert array to hash
1254 $rec_num = $result->fields;
1255 foreach ($this->_fields as $field) {
1256 $rec_assoc[$field] = $rec_num[$i++];
1259 $result->MoveNext();
1260 if (isset($rec_assoc['pagedata']))
1261 $rec_assoc['pagedata'] = $backend->_extract_page_data($rec_assoc['pagedata'], $rec_assoc['hits']);
1262 if (!empty($rec_assoc['version'])) {
1263 $rec_assoc['versiondata'] = $backend->_extract_version_data_assoc($rec_assoc);
1265 if (!empty($rec_assoc['linkrelation'])) {
1266 $rec_assoc['linkrelation'] = $rec_assoc['linkrelation']; // pagename enough?
1272 class WikiDB_backend_ADODB_search extends WikiDB_backend_search_sql
1274 // no surrounding quotes because we know it's a string
1275 // function _quote($word) { return $this->_dbh->escapeSimple($word); }
1278 // Following function taken from Pear::DB (prev. from adodb-pear.inc.php).
1279 // Eventually, change index.php to provide the relevant information
1282 * Parse a data source name.
1284 * Additional keys can be added by appending a URI query string to the
1287 * The format of the supplied DSN is in its fullest form:
1289 * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
1292 * Most variations are allowed:
1294 * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
1295 * phptype://username:password@hostspec/database_name
1296 * phptype://username:password@hostspec
1297 * phptype://username@hostspec
1298 * phptype://hostspec/database
1299 * phptype://hostspec
1304 * @param string $dsn Data Source Name to be parsed
1306 * @return array an associative array with the following keys:
1307 * + phptype: Database backend used in PHP (mysql, odbc etc.)
1308 * + dbsyntax: Database used with regards to SQL syntax etc.
1309 * + protocol: Communication protocol to use (tcp, unix etc.)
1310 * + hostspec: Host specification (hostname[:port])
1311 * + database: Database to use on the DBMS server
1312 * + username: User name for login
1313 * + password: Password for login
1315 * @author Tomas V.V.Cox <cox@idecnet.com>
1317 function parseDSN($dsn)
1321 'dbsyntax' => false,
1322 'username' => false,
1323 'password' => false,
1324 'protocol' => false,
1325 'hostspec' => false,
1328 'database' => false,
1331 if (is_array($dsn)) {
1332 $dsn = array_merge($parsed, $dsn);
1333 if (!$dsn['dbsyntax']) {
1334 $dsn['dbsyntax'] = $dsn['phptype'];
1339 // Find phptype and dbsyntax
1340 if (($pos = strpos($dsn, '://')) !== false) {
1341 $str = substr($dsn, 0, $pos);
1342 $dsn = substr($dsn, $pos + 3);
1348 // Get phptype and dbsyntax
1349 // $str => phptype(dbsyntax)
1350 if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
1351 $parsed['phptype'] = $arr[1];
1352 $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
1354 $parsed['phptype'] = $str;
1355 $parsed['dbsyntax'] = $str;
1362 // Get (if found): username and password
1363 // $dsn => username:password@protocol+hostspec/database
1364 if (($at = strrpos($dsn,'@')) !== false) {
1365 $str = substr($dsn, 0, $at);
1366 $dsn = substr($dsn, $at + 1);
1367 if (($pos = strpos($str, ':')) !== false) {
1368 $parsed['username'] = rawurldecode(substr($str, 0, $pos));
1369 $parsed['password'] = rawurldecode(substr($str, $pos + 1));
1371 $parsed['username'] = rawurldecode($str);
1375 // Find protocol and hostspec
1377 // $dsn => proto(proto_opts)/database
1378 if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
1380 $proto_opts = $match[2] ? $match[2] : false;
1383 // $dsn => protocol+hostspec/database (old format)
1385 if (strpos($dsn, '+') !== false) {
1386 list($proto, $dsn) = explode('+', $dsn, 2);
1388 if (strpos($dsn, '/') !== false) {
1389 list($proto_opts, $dsn) = explode('/', $dsn, 2);
1396 // process the different protocol options
1397 $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
1398 $proto_opts = rawurldecode($proto_opts);
1399 if ($parsed['protocol'] == 'tcp') {
1400 if (strpos($proto_opts, ':') !== false) {
1401 list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
1403 $parsed['hostspec'] = $proto_opts;
1405 } elseif ($parsed['protocol'] == 'unix') {
1406 $parsed['socket'] = $proto_opts;
1409 // Get dabase if any
1413 if (($pos = strpos($dsn, '?')) === false) {
1414 $parsed['database'] = $dsn;
1415 // /database?param1=value1¶m2=value2
1417 $parsed['database'] = substr($dsn, 0, $pos);
1418 $dsn = substr($dsn, $pos + 1);
1419 if (strpos($dsn, '&') !== false) {
1420 $opts = explode('&', $dsn);
1421 } else { // database?param1=value1
1422 $opts = array($dsn);
1424 foreach ($opts as $opt) {
1425 list($key, $value) = explode('=', $opt);
1426 if (!isset($parsed[$key])) {
1427 // don't allow params overwrite
1428 $parsed[$key] = rawurldecode($value);
1437 // $Log: not supported by cvs2svn $
1438 // Revision 1.87 2006/04/17 17:28:21 rurban
1439 // honor getWikiPageLinks change linkto=>relation
1441 // Revision 1.86 2006/04/17 10:02:44 rurban
1442 // fix syntax error missing }
1444 // Revision 1.85 2006/04/15 12:48:04 rurban
1445 // use genID, dont lock here
1447 // Revision 1.84 2006/02/22 21:49:50 rurban
1448 // Remove hits from links query
1449 // force old set_links method. need to test IS NULL
1451 // Revision 1.83 2005/11/14 22:24:33 rurban
1452 // fix fulltext search,
1453 // Eliminate stoplist words,
1454 // don't extract %pagedate twice in ADODB,
1455 // add SemanticWeb support: link(relation),
1456 // major postgresql update: stored procedures, tsearch2 for fulltext
1458 // Revision 1.82 2005/10/31 16:48:22 rurban
1459 // move mysql-specifics into its special class
1461 // Revision 1.81 2005/10/10 19:42:14 rurban
1462 // fix wanted_pages SQL syntax
1464 // Revision 1.80 2005/09/28 19:26:05 rurban
1465 // working on improved postgresql support: better quoting, bytea support
1467 // Revision 1.79 2005/09/28 19:08:41 rurban
1468 // dont use LIMIT on modifying queries
1470 // Revision 1.78 2005/09/14 06:04:43 rurban
1471 // optimize searching for ALL (ie %), use the stoplist on PDO
1473 // Revision 1.77 2005/09/11 14:55:05 rurban
1474 // implement fulltext stoplist
1476 // Revision 1.76 2005/09/11 13:25:12 rurban
1477 // enhance LIMIT support
1479 // Revision 1.75 2005/09/10 21:30:16 rurban
1480 // enhance titleSearch
1482 // Revision 1.74 2005/02/10 19:04:22 rurban
1483 // move getRow up one level to our backend class
1485 // Revision 1.73 2005/02/04 13:43:30 rurban
1486 // fix purge cache error
1488 // Revision 1.72 2005/01/29 19:51:03 rurban
1489 // Bugs item #1077769 fixed by frugal.
1490 // Deleted the wrong page. Fix all other tables also.
1492 // Revision 1.71 2005/01/25 08:01:00 rurban
1493 // fix listOfFields with different database
1495 // Revision 1.70 2005/01/18 20:55:43 rurban
1496 // reformatting and two bug fixes: adding missing parens
1498 // Revision 1.69 2004/12/26 17:14:03 rurban
1499 // fix ADODB MostPopular, avoid limit -1, pass hits on empty data
1501 // Revision 1.68 2004/12/22 18:33:25 rurban
1502 // fix page _id_cache logic for _get_pageid create_if_missing
1504 // Revision 1.67 2004/12/22 15:47:41 rurban
1505 // fix wrong _update_nonempty_table on empty content (i.e. the new deletePage)
1507 // Revision 1.66 2004/12/13 14:39:16 rurban
1510 // Revision 1.65 2004/12/10 22:15:00 rurban
1511 // fix $page->get('_cached_html)
1512 // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also.
1513 // support 2nd genericSqlQuery param (bind huge arg)
1515 // Revision 1.64 2004/12/10 02:45:27 rurban
1516 // SQL optimization:
1517 // put _cached_html from pagedata into a new seperate blob, not huge serialized string.
1518 // it is only rarelely needed: for current page only, if-not-modified
1519 // but was extracted for every simple page iteration.
1521 // Revision 1.63 2004/12/08 12:55:51 rurban
1522 // support new non-destructive delete_page via generic backend method
1524 // Revision 1.62 2004/12/06 19:50:04 rurban
1525 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
1526 // renamed delete_page to purge_page.
1527 // enable action=edit&version=-1 to force creation of a new version.
1528 // added BABYCART_PATH config
1529 // fixed magiqc in adodb.inc.php
1530 // and some more docs
1532 // Revision 1.61 2004/11/30 17:45:53 rurban
1533 // exists_links backend implementation
1535 // Revision 1.60 2004/11/28 20:42:18 rurban
1536 // Optimize PearDB _extract_version_data and _extract_page_data.
1538 // Revision 1.59 2004/11/27 14:39:05 rurban
1539 // simpified regex search architecture:
1540 // no db specific node methods anymore,
1541 // new sql() method for each node
1542 // parallel to regexp() (which returns pcre)
1543 // regex types bitmasked (op's not yet)
1545 // clarified WikiDB::quote() backend methods:
1546 // ->quote() adds surrounsing quotes
1547 // ->qstr() (new method) assumes strings and adds no quotes! (in contrast to ADODB)
1548 // pear and adodb have now unified quote methods for all generic queries.
1550 // Revision 1.58 2004/11/26 18:39:02 rurban
1551 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
1553 // Revision 1.57 2004/11/25 17:20:51 rurban
1554 // and again a couple of more native db args: backlinks
1556 // Revision 1.56 2004/11/23 13:35:48 rurban
1557 // add case_exact search
1559 // Revision 1.55 2004/11/21 11:59:26 rurban
1560 // remove final \n to be ob_cache independent
1562 // Revision 1.54 2004/11/20 17:49:39 rurban
1563 // add fast exclude support to SQL get_all_pages
1565 // Revision 1.53 2004/11/20 17:35:58 rurban
1566 // improved WantedPages SQL backends
1567 // PageList::sortby new 3rd arg valid_fields (override db fields)
1568 // WantedPages sql pager inexact for performance reasons:
1569 // assume 3 wantedfrom per page, to be correct, no getTotal()
1570 // support exclude argument for get_all_pages, new _sql_set()
1572 // Revision 1.52 2004/11/17 20:07:17 rurban
1575 // Revision 1.51 2004/11/15 15:57:37 rurban
1576 // silent cache warning
1578 // Revision 1.50 2004/11/10 19:32:23 rurban
1579 // * optimize increaseHitCount, esp. for mysql.
1580 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
1581 // * Pear_DB version logic (awful but needed)
1582 // * fix broken ADODB quote
1583 // * _extract_page_data simplification
1585 // Revision 1.49 2004/11/10 15:29:21 rurban
1586 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
1587 // * ACCESS_LOG_SQL: fix cause request not yet initialized
1588 // * WikiDB: moved SQL specific methods upwards
1589 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
1590 // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
1592 // Revision 1.48 2004/11/09 17:11:16 rurban
1593 // * revert to the wikidb ref passing. there's no memory abuse there.
1594 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1595 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
1596 // are also needed at the rendering for linkExistingWikiWord().
1597 // pass options to pageiterator.
1598 // use this cache also for _get_pageid()
1599 // This saves about 8 SELECT count per page (num all pagelinks).
1600 // * fix passing of all page fields to the pageiterator.
1601 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1603 // Revision 1.47 2004/11/06 17:11:42 rurban
1604 // The optimized version doesn't query for pagedata anymore.
1606 // Revision 1.46 2004/11/01 10:43:58 rurban
1607 // seperate PassUser methods into seperate dir (memory usage)
1608 // fix WikiUser (old) overlarge data session
1609 // remove wikidb arg from various page class methods, use global ->_dbi instead
1612 // Revision 1.45 2004/10/14 17:19:17 rurban
1613 // allow most_popular sortby arguments
1615 // Revision 1.44 2004/09/06 08:33:09 rurban
1616 // force explicit mysql auto-incrementing, atomic version
1618 // Revision 1.43 2004/07/10 08:50:24 rurban
1619 // applied patch by Philippe Vanhaesendonck:
1620 // pass column list to iterators so we can FETCH_NUM in all cases.
1621 // bind UPDATE pramas for huge pagedata.
1622 // portable oracle backend
1624 // Revision 1.42 2004/07/09 10:06:50 rurban
1625 // Use backend specific sortby and sortable_columns method, to be able to
1626 // select between native (Db backend) and custom (PageList) sorting.
1627 // Fixed PageList::AddPageList (missed the first)
1628 // Added the author/creator.. name to AllPagesBy...
1629 // display no pages if none matched.
1630 // Improved dba and file sortby().
1631 // Use &$request reference
1633 // Revision 1.41 2004/07/08 21:32:35 rurban
1634 // Prevent from more warnings, minor db and sort optimizations
1636 // Revision 1.40 2004/07/08 16:56:16 rurban
1637 // use the backendType abstraction
1639 // Revision 1.39 2004/07/05 13:56:22 rurban
1640 // sqlite autoincrement fix
1642 // Revision 1.38 2004/07/05 12:57:54 rurban
1643 // add mysql timeout
1645 // Revision 1.37 2004/07/04 10:24:43 rurban
1646 // forgot the expressions
1648 // Revision 1.36 2004/07/03 16:51:06 rurban
1649 // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
1650 // added atomic mysql REPLACE for PearDB as in ADODB
1651 // fixed _lock_tables typo links => link
1652 // fixes unserialize ADODB bug in line 180
1654 // Revision 1.35 2004/06/28 14:45:12 rurban
1655 // fix adodb_sqlite to have the same dsn syntax as pear, use pconnect if requested
1657 // Revision 1.34 2004/06/28 14:17:38 rurban
1658 // updated DSN parser from Pear. esp. for sqlite
1660 // Revision 1.33 2004/06/27 10:26:02 rurban
1661 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1663 // Revision 1.32 2004/06/25 14:15:08 rurban
1664 // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
1666 // Revision 1.31 2004/06/16 10:38:59 rurban
1667 // Disallow refernces in calls if the declaration is a reference
1668 // ("allow_call_time_pass_reference clean").
1669 // PhpWiki is now allow_call_time_pass_reference = Off clean,
1670 // but several external libraries may not.
1671 // In detail these libs look to be affected (not tested):
1675 // Revision 1.30 2004/06/07 19:31:31 rurban
1676 // fixed ADOOB upgrade: listOfFields()
1678 // Revision 1.29 2004/05/12 10:49:55 rurban
1679 // require_once fix for those libs which are loaded before FileFinder and
1680 // its automatic include_path fix, and where require_once doesn't grok
1681 // dirname(__FILE__) != './lib'
1682 // upgrade fix with PearDB
1683 // navbar.tmpl: remove spaces for IE button alignment
1685 // Revision 1.28 2004/05/06 19:26:16 rurban
1686 // improve stability, trying to find the InlineParser endless loop on sf.net
1688 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1690 // Revision 1.27 2004/05/06 17:30:38 rurban
1691 // CategoryGroup: oops, dos2unix eol
1692 // improved phpwiki_version:
1693 // pre -= .0001 (1.3.10pre: 1030.099)
1694 // -p1 += .001 (1.3.9-p1: 1030.091)
1695 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1696 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1697 // backend->backendType(), backend->database(),
1698 // backend->listOfFields(),
1699 // backend->listOfTables(),
1701 // Revision 1.26 2004/04/26 20:44:35 rurban
1702 // locking table specific for better databases
1704 // Revision 1.25 2004/04/20 00:06:04 rurban
1705 // themable paging support
1707 // Revision 1.24 2004/04/18 01:34:20 rurban
1708 // protect most_popular from sortby=mtime
1710 // Revision 1.23 2004/04/16 14:19:39 rurban
1711 // updated ADODB notes
1714 // (c-file-style: "gnu")
1718 // c-basic-offset: 4
1719 // c-hanging-comment-ender-p: nil
1720 // indent-tabs-mode: nil