]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB.php
New methods:
[SourceForge/phpwiki.git] / lib / WikiDB.php
1 <?php //-*-php-*-
2 rcs_id('$Id: WikiDB.php,v 1.19 2003-02-16 19:43:10 dairiki Exp $');
3
4 //FIXME: arg on get*Revision to hint that content is wanted.
5
6 /**
7  * The classes in the file define the interface to the
8  * page database.
9  *
10  * @package WikiDB
11  * @author Geoffrey T. Dairiki <dairiki@dairiki.org>
12  */
13
14 /**
15  * Force the creation of a new revision.
16  * @see WikiDB_Page::createRevision()
17  */
18 define('WIKIDB_FORCE_CREATE', -1);
19
20 // FIXME:  used for debugging only.  Comment out if cache does not work
21 define('USECACHE', 1);
22
23 /** 
24  * Abstract base class for the database used by PhpWiki.
25  *
26  * A <tt>WikiDB</tt> is a container for <tt>WikiDB_Page</tt>s which in
27  * turn contain <tt>WikiDB_PageRevision</tt>s.
28  *
29  * Conceptually a <tt>WikiDB</tt> contains all possible
30  * <tt>WikiDB_Page</tt>s, whether they have been initialized or not.
31  * Since all possible pages are already contained in a WikiDB, a call
32  * to WikiDB::getPage() will never fail (barring bugs and
33  * e.g. filesystem or SQL database problems.)
34  *
35  * Also each <tt>WikiDB_Page</tt> always contains at least one
36  * <tt>WikiDB_PageRevision</tt>: the default content (e.g. "Describe
37  * [PageName] here.").  This default content has a version number of
38  * zero.
39  *
40  * <tt>WikiDB_PageRevision</tt>s have read-only semantics. One can
41  * only create new revisions or delete old ones --- one can not modify
42  * an existing revision.
43  */
44 class WikiDB {
45     /**
46      * Open a WikiDB database.
47      *
48      * This is a static member function. This function inspects its
49      * arguments to determine the proper subclass of WikiDB to
50      * instantiate, and then it instantiates it.
51      *
52      * @access public
53      *
54      * @param hash $dbparams Database configuration parameters.
55      * Some pertinent paramters are:
56      * <dl>
57      * <dt> dbtype
58      * <dd> The back-end type.  Current supported types are:
59      *   <dl>
60      *   <dt> SQL
61      *   <dd> Generic SQL backend based on the PEAR/DB database abstraction
62      *       library.
63      *   <dt> dba
64      *   <dd> Dba based backend.
65      *   </dl>
66      *
67      * <dt> dsn
68      * <dd> (Used by the SQL backend.)
69      *      The DSN specifying which database to connect to.
70      *
71      * <dt> prefix
72      * <dd> Prefix to be prepended to database table (and file names).
73      *
74      * <dt> directory
75      * <dd> (Used by the dba backend.)
76      *      Which directory db files reside in.
77      *
78      * <dt> timeout
79      * <dd> (Used by the dba backend.)
80      *      Timeout in seconds for opening (and obtaining lock) on the
81      *      db files.
82      *
83      * <dt> dba_handler
84      * <dd> (Used by the dba backend.)
85      *
86      *      Which dba handler to use. Good choices are probably either
87      *      'gdbm' or 'db2'.
88      * </dl>
89      *
90      * @return WikiDB A WikiDB object.
91      **/
92     function open ($dbparams) {
93         $dbtype = $dbparams{'dbtype'};
94         include_once("lib/WikiDB/$dbtype.php");
95                                 
96         $class = 'WikiDB_' . $dbtype;
97         return new $class ($dbparams);
98     }
99
100
101     /**
102      * Constructor.
103      *
104      * @access private
105      * @see open()
106      */
107     function WikiDB ($backend, $dbparams) {
108         $this->_backend = &$backend;
109         $this->_cache = new WikiDB_cache($backend);
110
111         // If the database doesn't yet have a timestamp, initialize it now.
112         if ($this->get('_timestamp') === false)
113             $this->touch();
114         
115         //FIXME: devel checking.
116         //$this->_backend->check();
117     }
118     
119     /**
120      * Get any user-level warnings about this WikiDB.
121      *
122      * Some back-ends, e.g. by default create there data files in the
123      * global /tmp directory. We would like to warn the user when this
124      * happens (since /tmp files tend to get wiped periodically.)
125      * Warnings such as these may be communicated from specific
126      * back-ends through this method.
127      *
128      * @access public
129      *
130      * @return string A warning message (or <tt>false</tt> if there is
131      * none.)
132      */
133     function genericWarnings() {
134         return false;
135     }
136      
137     /**
138      * Close database connection.
139      *
140      * The database may no longer be used after it is closed.
141      *
142      * Closing a WikiDB invalidates all <tt>WikiDB_Page</tt>s,
143      * <tt>WikiDB_PageRevision</tt>s and <tt>WikiDB_PageIterator</tt>s
144      * which have been obtained from it.
145      *
146      * @access public
147      */
148     function close () {
149         $this->_backend->close();
150         $this->_cache->close();
151     }
152     
153     /**
154      * Get a WikiDB_Page from a WikiDB.
155      *
156      * A {@link WikiDB} consists of the (infinite) set of all possible pages,
157      * therefore this method never fails.
158      *
159      * @access public
160      * @param string $pagename Which page to get.
161      * @return WikiDB_Page The requested WikiDB_Page.
162      */
163     function getPage($pagename) {
164         assert(is_string($pagename) && $pagename);
165         return new WikiDB_Page($this, $pagename);
166     }
167
168         
169     // Do we need this?
170     //function nPages() { 
171     //}
172
173
174     /**
175      * Determine whether page exists (in non-default form).
176      *
177      * <pre>
178      *   $is_page = $dbi->isWikiPage($pagename);
179      * </pre>
180      * is equivalent to
181      * <pre>
182      *   $page = $dbi->getPage($pagename);
183      *   $current = $page->getCurrentRevision();
184      *   $is_page = ! $current->hasDefaultContents();
185      * </pre>
186      * however isWikiPage may be implemented in a more efficient
187      * manner in certain back-ends.
188      *
189      * @access public
190      *
191      * @param string $pagename string Which page to check.
192      *
193      * @return boolean True if the page actually exists with
194      * non-default contents in the WikiDataBase.
195      */
196     function isWikiPage ($pagename) {
197         $page = $this->getPage($pagename);
198         $current = $page->getCurrentRevision();
199         return ! $current->hasDefaultContents();
200     }
201
202     /**
203      * Delete page from the WikiDB. 
204      *
205      * Deletes all revisions of the page from the WikiDB. Also resets
206      * all page meta-data to the default values.
207      *
208      * @access public
209      *
210      * @param string $pagename Name of page to delete.
211      */
212     function deletePage($pagename) {
213         $this->_cache->delete_page($pagename);
214         $this->_backend->set_links($pagename, false);
215     }
216
217     /**
218      * Retrieve all pages.
219      *
220      * Gets the set of all pages with non-default contents.
221      *
222      * FIXME: do we need this?  I think so.  The simple searches
223      *        need this stuff.
224      *
225      * @access public
226      *
227      * @param boolean $include_defaulted Normally pages whose most
228      * recent revision has empty content are considered to be
229      * non-existant. Unless $include_defaulted is set to true, those
230      * pages will not be returned.
231      *
232      * @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages
233      *     in the WikiDB which have non-default contents.
234      */
235     function getAllPages($include_defaulted = false) {
236         $result = $this->_backend->get_all_pages($include_defaulted);
237         return new WikiDB_PageIterator($this, $result);
238     }
239
240     /**
241      * Title search.
242      *
243      * Search for pages containing (or not containing) certain words
244      * in their names.
245      *
246      * Pages are returned in alphabetical order whenever it is
247      * practical to do so.
248      *
249      * FIXME: should titleSearch and fullSearch be combined?  I think so.
250      *
251      * @access public
252      * @param TextSearchQuery $search A TextSearchQuery object
253      * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
254      * @see TextSearchQuery
255      */
256     function titleSearch($search) {
257         $result = $this->_backend->text_search($search);
258         return new WikiDB_PageIterator($this, $result);
259     }
260
261     /**
262      * Full text search.
263      *
264      * Search for pages containing (or not containing) certain words
265      * in their entire text (this includes the page content and the
266      * page name).
267      *
268      * Pages are returned in alphabetical order whenever it is
269      * practical to do so.
270      *
271      * @access public
272      *
273      * @param TextSearchQuery $search A TextSearchQuery object.
274      * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
275      * @see TextSearchQuery
276      */
277     function fullSearch($search) {
278         $result = $this->_backend->text_search($search, 'full_text');
279         return new WikiDB_PageIterator($this, $result);
280     }
281
282     /**
283      * Find the pages with the greatest hit counts.
284      *
285      * Pages are returned in reverse order by hit count.
286      *
287      * @access public
288      *
289      * @param integer $limit The maximum number of pages to return.
290      * Set $limit to zero to return all pages.  If $limit < 0, pages will
291      * be sorted in decreasing order of popularity.
292      *
293      * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching
294      * pages.
295      */
296     function mostPopular($limit = 20) {
297         $result = $this->_backend->most_popular($limit);
298         return new WikiDB_PageIterator($this, $result);
299     }
300
301     /**
302      * Find recent page revisions.
303      *
304      * Revisions are returned in reverse order by creation time.
305      *
306      * @access public
307      *
308      * @param hash $params This hash is used to specify various optional
309      *   parameters:
310      * <dl>
311      * <dt> limit 
312      *    <dd> (integer) At most this many revisions will be returned.
313      * <dt> since
314      *    <dd> (integer) Only revisions since this time (unix-timestamp) will be returned. 
315      * <dt> include_minor_revisions
316      *    <dd> (boolean) Also include minor revisions.  (Default is not to.)
317      * <dt> exclude_major_revisions
318      *    <dd> (boolean) Don't include non-minor revisions.
319      *         (Exclude_major_revisions implies include_minor_revisions.)
320      * <dt> include_all_revisions
321      *    <dd> (boolean) Return all matching revisions for each page.
322      *         Normally only the most recent matching revision is returned
323      *         for each page.
324      * </dl>
325      *
326      * @return WikiDB_PageRevisionIterator A WikiDB_PageRevisionIterator containing the
327      * matching revisions.
328      */
329     function mostRecent($params = false) {
330         $result = $this->_backend->most_recent($params);
331         return new WikiDB_PageRevisionIterator($this, $result);
332     }
333
334    /**
335      * Blog search. (experimental)
336      *
337      * Search for blog entries related to a certain page.
338      *
339      * FIXME: with pagetype support and perhaps a RegexpSearchQuery
340      * we can make sure we are returning *ONLY* blog pages to the
341      * main routine.  Currently, we just use titleSearch which requires
342      * some furher checking in lib/plugin/WikiBlog.php (BAD).
343      *
344      * @access public
345      *
346      * @param string $order  'normal' (chronological) or 'reverse'
347      * @param string $page   Find blog entries related to this page.
348      * @return WikiDB_PageIterator A WikiDB_PageIterator containing the relevant pages.
349      */
350     function blogSearch($page, $order) {
351       //FIXME: implement ordering
352
353       require_once('lib/TextSearchQuery.php');
354       $query = new TextSearchQuery ($page . SUBPAGE_SEPARATOR);
355
356       return $this->titleSearch($query);
357     }
358
359     /** Get timestamp when database was last modified.
360      *
361      * @return string A string consisting of two integers,
362      * separated by a space.  The first is the time in
363      * unix timestamp format, the second is a modification
364      * count for the database.
365      *
366      * The idea is that you can cast the return value to an
367      * int to get a timestamp, or you can use the string value
368      * as a good hash for the entire database.
369      */
370     function getTimestamp() {
371         $ts = $this->get('_timestamp');
372         return sprintf("%d %d", $ts[0], $ts[1]);
373     }
374     
375     /**
376      * Update the database timestamp.
377      *
378      */
379     function touch() {
380         $ts = $this->get('_timestamp');
381         $this->set('_timestamp', array(time(), $ts[1] + 1));
382     }
383
384         
385     /**
386      * Access WikiDB global meta-data.
387      *
388      * NOTE: this is currently implemented in a hackish and
389      * not very efficient manner.
390      *
391      * @access public
392      *
393      * @param string $key Which meta data to get.
394      * Some reserved meta-data keys are:
395      * <dl>
396      * <dt>'_timestamp' <dd> Data used by getTimestamp().
397      * </dl>
398      *
399      * @return scalar The requested value, or false if the requested data
400      * is not set.
401      */
402     function get($key) {
403         if (!$key || $key[0] == '%')
404             return false;
405         /*
406          * Hack Alert: We can use any page (existing or not) to store
407          * this data (as long as we always use the same one.)
408          */
409         $gd = $this->getPage('global_data');
410         $data = $gd->get('__global');
411
412         if ($data && isset($data[$key]))
413             return $data[$key];
414         else
415             return false;
416     }
417
418     /**
419      * Set global meta-data.
420      *
421      * NOTE: this is currently implemented in a hackish and
422      * not very efficient manner.
423      *
424      * @see get
425      * @access public
426      *
427      * @param string $key  Meta-data key to set.
428      * @param string $newval  New value.
429      */
430     function set($key, $newval) {
431         if (!$key || $key[0] == '%')
432             return;
433         
434         $gd = $this->getPage('global_data');
435         
436         $data = $gd->get('__global');
437         if ($data === false)
438             $data = array();
439
440         if (empty($newval))
441             unset($data[$key]);
442         else
443             $data[$key] = $newval;
444
445         $gd->set('__global', $data);
446     }
447 };
448
449
450 /**
451  * An abstract base class which representing a wiki-page within a
452  * WikiDB.
453  *
454  * A WikiDB_Page contains a number (at least one) of
455  * WikiDB_PageRevisions.
456  */
457 class WikiDB_Page 
458 {
459     function WikiDB_Page(&$wikidb, $pagename) {
460         $this->_wikidb = &$wikidb;
461         $this->_pagename = $pagename;
462         assert(!empty($this->_pagename));
463     }
464
465     /**
466      * Get the name of the wiki page.
467      *
468      * @access public
469      *
470      * @return string The page name.
471      */
472     function getName() {
473         return $this->_pagename;
474     }
475
476
477     /**
478      * Delete an old revision of a WikiDB_Page.
479      *
480      * Deletes the specified revision of the page.
481      * It is a fatal error to attempt to delete the current revision.
482      *
483      * @access public
484      *
485      * @param integer $version Which revision to delete.  (You can also
486      *  use a WikiDB_PageRevision object here.)
487      */
488     function deleteRevision($version) {
489         $backend = &$this->_wikidb->_backend;
490         $cache = &$this->_wikidb->_cache;
491         $pagename = &$this->_pagename;
492
493         $version = $this->_coerce_to_version($version);
494         if ($version == 0)
495             return;
496
497         $backend->lock();
498         $latestversion = $cache->get_latest_version($pagename);
499         if ($latestversion && $version == $latestversion) {
500             $backend->unlock();
501             trigger_error(sprintf("Attempt to delete most recent revision of '%s'",
502                                   $pagename), E_USER_ERROR);
503             return;
504         }
505
506         $cache->delete_versiondata($pagename, $version);
507                 
508         $backend->unlock();
509     }
510
511     /*
512      * Delete a revision, or possibly merge it with a previous
513      * revision.
514      *
515      * The idea is this:
516      * Suppose an author make a (major) edit to a page.  Shortly
517      * after that the same author makes a minor edit (e.g. to fix
518      * spelling mistakes he just made.)
519      *
520      * Now some time later, where cleaning out old saved revisions,
521      * and would like to delete his minor revision (since there's
522      * really no point in keeping minor revisions around for a long
523      * time.)
524      *
525      * Note that the text after the minor revision probably represents
526      * what the author intended to write better than the text after
527      * the preceding major edit.
528      *
529      * So what we really want to do is merge the minor edit with the
530      * preceding edit.
531      *
532      * We will only do this when:
533      * <ul>
534      * <li>The revision being deleted is a minor one, and
535      * <li>It has the same author as the immediately preceding revision.
536      * </ul>
537      */
538     function mergeRevision($version) {
539         $backend = &$this->_wikidb->_backend;
540         $cache = &$this->_wikidb->_cache;
541         $pagename = &$this->_pagename;
542
543         $version = $this->_coerce_to_version($version);
544         if ($version == 0)
545             return;
546
547         $backend->lock();
548         $latestversion = $backend->get_latest_version($pagename);
549         if ($latestversion && $version == $latestversion) {
550             $backend->unlock();
551             trigger_error(sprintf("Attempt to merge most recent revision of '%s'",
552                                   $pagename), E_USER_ERROR);
553             return;
554         }
555
556         $versiondata = $cache->get_versiondata($pagename, $version, true);
557         if (!$versiondata) {
558             // Not there? ... we're done!
559             $backend->unlock();
560             return;
561         }
562
563         if ($versiondata['is_minor_edit']) {
564             $previous = $backend->get_previous_version($pagename, $version);
565             if ($previous) {
566                 $prevdata = $cache->get_versiondata($pagename, $previous);
567                 if ($prevdata['author_id'] == $versiondata['author_id']) {
568                     // This is a minor revision, previous version is
569                     // by the same author. We will merge the
570                     // revisions.
571                     $cache->update_versiondata($pagename, $previous,
572                                                array('%content' => $versiondata['%content'],
573                                                      '_supplanted' => $versiondata['_supplanted']));
574                 }
575             }
576         }
577
578         $cache->delete_versiondata($pagename, $version);
579         $backend->unlock();
580     }
581
582     
583     /**
584      * Create a new revision of a {@link WikiDB_Page}.
585      *
586      * @access public
587      *
588      * @param int $version Version number for new revision.  
589      * To ensure proper serialization of edits, $version must be
590      * exactly one higher than the current latest version.
591      * (You can defeat this check by setting $version to
592      * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
593      *
594      * @param string $content Contents of new revision.
595      *
596      * @param hash $metadata Metadata for new revision.
597      * All values in the hash should be scalars (strings or integers).
598      *
599      * @param array $links List of pagenames which this page links to.
600      *
601      * @return WikiDB_PageRevision  Returns the new WikiDB_PageRevision object. If
602      * $version was incorrect, returns false
603      */
604     function createRevision($version, &$content, $metadata, $links) {
605         $backend = &$this->_wikidb->_backend;
606         $cache = &$this->_wikidb->_cache;
607         $pagename = &$this->_pagename;
608                 
609         $backend->lock();
610
611         $latestversion = $backend->get_latest_version($pagename);
612         $newversion = $latestversion + 1;
613         assert($newversion >= 1);
614
615         if ($version != WIKIDB_FORCE_CREATE && $version != $newversion) {
616             $backend->unlock();
617             return false;
618         }
619
620         $data = $metadata;
621         
622         foreach ($data as $key => $val) {
623             if (empty($val) || $key[0] == '_' || $key[0] == '%')
624                 unset($data[$key]);
625         }
626                         
627         assert(!empty($data['author_id']));
628         if (empty($data['author_id']))
629             @$data['author_id'] = $data['author'];
630                 
631         if (empty($data['mtime']))
632             $data['mtime'] = time();
633
634         if ($latestversion) {
635             // Ensure mtimes are monotonic.
636             $pdata = $cache->get_versiondata($pagename, $latestversion);
637             if ($data['mtime'] < $pdata['mtime']) {
638                 trigger_error(sprintf(_("%s: Date of new revision is %s"),
639                                       $pagename,"'non-monotonic'"),
640                               E_USER_NOTICE);
641                 $data['orig_mtime'] = $data['mtime'];
642                 $data['mtime'] = $pdata['mtime'];
643             }
644             
645             // FIXME: use (possibly user specified) 'mtime' time or
646             // time()?
647             $cache->update_versiondata($pagename, $latestversion,
648                                        array('_supplanted' => $data['mtime']));
649         }
650
651         $data['%content'] = &$content;
652
653         $cache->set_versiondata($pagename, $newversion, $data);
654
655         //$cache->update_pagedata($pagename, array(':latestversion' => $newversion,
656         //':deleted' => empty($content)));
657         
658         $backend->set_links($pagename, $links);
659
660         $backend->unlock();
661
662         // FIXME: probably should have some global state information
663         // in the backend to control when to optimize.
664         if (time() % 50 == 0) {
665             trigger_error(sprintf(_("Optimizing %s"),'backend'), E_USER_NOTICE);
666             $backend->optimize();
667         }
668
669         return new WikiDB_PageRevision($this->_wikidb, $pagename, $newversion,
670                                        $data);
671     }
672
673     /**
674      * Get the most recent revision of a page.
675      *
676      * @access public
677      *
678      * @return WikiDB_PageRevision The current WikiDB_PageRevision object. 
679      */
680     function getCurrentRevision() {
681         $backend = &$this->_wikidb->_backend;
682         $cache = &$this->_wikidb->_cache;
683         $pagename = &$this->_pagename;
684
685         $backend->lock();
686         $version = $cache->get_latest_version($pagename);
687         $revision = $this->getRevision($version);
688         $backend->unlock();
689         assert($revision);
690         return $revision;
691     }
692
693     /**
694      * Get a specific revision of a WikiDB_Page.
695      *
696      * @access public
697      *
698      * @param integer $version  Which revision to get.
699      *
700      * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or
701      * false if the requested revision does not exist in the {@link WikiDB}.
702      * Note that version zero of any page always exists.
703      */
704     function getRevision($version) {
705         $cache = &$this->_wikidb->_cache;
706         $pagename = &$this->_pagename;
707         
708         if ($version == 0)
709             return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
710
711         assert($version > 0);
712         $vdata = $cache->get_versiondata($pagename, $version);
713         if (!$vdata)
714             return false;
715         return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
716                                        $vdata);
717     }
718
719     /**
720      * Get previous page revision.
721      *
722      * This method find the most recent revision before a specified
723      * version.
724      *
725      * @access public
726      *
727      * @param integer $version  Find most recent revision before this version.
728      *  You can also use a WikiDB_PageRevision object to specify the $version.
729      *
730      * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or false if the
731      * requested revision does not exist in the {@link WikiDB}.  Note that
732      * unless $version is greater than zero, a revision (perhaps version zero,
733      * the default revision) will always be found.
734      */
735     function getRevisionBefore($version) {
736         $backend = &$this->_wikidb->_backend;
737         $pagename = &$this->_pagename;
738
739         $version = $this->_coerce_to_version($version);
740
741         if ($version == 0)
742             return false;
743         $backend->lock();
744         $previous = $backend->get_previous_version($pagename, $version);
745         $revision = $this->getRevision($previous);
746         $backend->unlock();
747         assert($revision);
748         return $revision;
749     }
750
751     /**
752      * Get all revisions of the WikiDB_Page.
753      *
754      * This does not include the version zero (default) revision in the
755      * returned revision set.
756      *
757      * @return WikiDB_PageRevisionIterator A
758      * WikiDB_PageRevisionIterator containing all revisions of this
759      * WikiDB_Page in reverse order by version number.
760      */
761     function getAllRevisions() {
762         $backend = &$this->_wikidb->_backend;
763         $revs = $backend->get_all_revisions($this->_pagename);
764         return new WikiDB_PageRevisionIterator($this->_wikidb, $revs);
765     }
766     
767     /**
768      * Find pages which link to or are linked from a page.
769      *
770      * @access public
771      *
772      * @param boolean $reversed Which links to find: true for backlinks (default).
773      *
774      * @return WikiDB_PageIterator A WikiDB_PageIterator containing
775      * all matching pages.
776      */
777     function getLinks($reversed = true) {
778         $backend = &$this->_wikidb->_backend;
779         $result =  $backend->get_links($this->_pagename, $reversed);
780         return new WikiDB_PageIterator($this->_wikidb, $result);
781     }
782             
783     /**
784      * Access WikiDB_Page meta-data.
785      *
786      * @access public
787      *
788      * @param string $key Which meta data to get.
789      * Some reserved meta-data keys are:
790      * <dl>
791      * <dt>'locked'<dd> Is page locked?
792      * <dt>'hits'  <dd> Page hit counter.
793      * <dt>'pref'  <dd> Users preferences, stored in homepages.
794      * <dt>'owner' <dd> Default: first author_id. We might add a group with a dot here:
795      *                  E.g. "owner.users"
796      * <dt>'perm'  <dd> Permission flag to authorize read/write/execution of 
797      *                  page-headers and content.
798      * <dt>'score' <dd> Page score (not yet implement, do we need?)
799      * </dl>
800      *
801      * @return scalar The requested value, or false if the requested data
802      * is not set.
803      */
804     function get($key) {
805         $cache = &$this->_wikidb->_cache;
806         if (!$key || $key[0] == '%')
807             return false;
808         $data = $cache->get_pagedata($this->_pagename);
809         return isset($data[$key]) ? $data[$key] : false;
810     }
811
812     /**
813      * Get all the page meta-data as a hash.
814      *
815      * @return hash The page meta-data.
816      */
817     function getMetaData() {
818         $cache = &$this->_wikidb->_cache;
819         $data = $cache->get_pagedata($this->_pagename);
820         $meta = array();
821         foreach ($data as $key => $val) {
822             if (!empty($val) && $key[0] != '%')
823                 $meta[$key] = $val;
824         }
825         return $meta;
826     }
827
828     /**
829      * Set page meta-data.
830      *
831      * @see get
832      * @access public
833      *
834      * @param string $key  Meta-data key to set.
835      * @param string $newval  New value.
836      */
837     function set($key, $newval) {
838         $cache = &$this->_wikidb->_cache;
839         $pagename = &$this->_pagename;
840         
841         assert($key && $key[0] != '%');
842
843         $data = $cache->get_pagedata($pagename);
844
845         if (!empty($newval)) {
846             if (!empty($data[$key]) && $data[$key] == $newval)
847                 return;         // values identical, skip update.
848         }
849         else {
850             if (empty($data[$key]))
851                 return;         // values identical, skip update.
852         }
853
854         $cache->update_pagedata($pagename, array($key => $newval));
855     }
856
857     /**
858      * Increase page hit count.
859      *
860      * FIXME: IS this needed?  Probably not.
861      *
862      * This is a convenience function.
863      * <pre> $page->increaseHitCount(); </pre>
864      * is functionally identical to
865      * <pre> $page->set('hits',$page->get('hits')+1); </pre>
866      *
867      * Note that this method may be implemented in more efficient ways
868      * in certain backends.
869      *
870      * @access public
871      */
872     function increaseHitCount() {
873         @$newhits = $this->get('hits') + 1;
874         $this->set('hits', $newhits);
875     }
876
877     /**
878      * Return a string representation of the WikiDB_Page
879      *
880      * This is really only for debugging.
881      *
882      * @access public
883      *
884      * @return string Printable representation of the WikiDB_Page.
885      */
886     function asString () {
887         ob_start();
888         printf("[%s:%s\n", get_class($this), $this->getName());
889         print_r($this->getMetaData());
890         echo "]\n";
891         $strval = ob_get_contents();
892         ob_end_clean();
893         return $strval;
894     }
895
896
897     /**
898      * @access private
899      * @param integer_or_object $version_or_pagerevision
900      * Takes either the version number (and int) or a WikiDB_PageRevision
901      * object.
902      * @return integer The version number.
903      */
904     function _coerce_to_version($version_or_pagerevision) {
905         if (method_exists($version_or_pagerevision, "getContent"))
906             $version = $version_or_pagerevision->getVersion();
907         else
908             $version = (int) $version_or_pagerevision;
909
910         assert($version >= 0);
911         return $version;
912     }
913
914     function isUserPage ($include_empty = true) {
915         return $this->get('pref') ? true : false;
916         if ($include_empty)
917             return true;
918         $current = $this->getCurrentRevision();
919         return ! $current->hasDefaultContents();
920     }
921
922 };
923
924 /**
925  * This class represents a specific revision of a WikiDB_Page within
926  * a WikiDB.
927  *
928  * A WikiDB_PageRevision has read-only semantics. You may only create
929  * new revisions (and delete old ones) --- you cannot modify existing
930  * revisions.
931  */
932 class WikiDB_PageRevision
933 {
934     function WikiDB_PageRevision(&$wikidb, $pagename, $version,
935                                  $versiondata = false)
936         {
937             $this->_wikidb = &$wikidb;
938             $this->_pagename = $pagename;
939             $this->_version = $version;
940             $this->_data = $versiondata ? $versiondata : array();
941         }
942     
943     /**
944      * Get the WikiDB_Page which this revision belongs to.
945      *
946      * @access public
947      *
948      * @return WikiDB_Page The WikiDB_Page which this revision belongs to.
949      */
950     function getPage() {
951         return new WikiDB_Page($this->_wikidb, $this->_pagename);
952     }
953
954     /**
955      * Get the version number of this revision.
956      *
957      * @access public
958      *
959      * @return integer The version number of this revision.
960      */
961     function getVersion() {
962         return $this->_version;
963     }
964     
965     /**
966      * Determine whether this revision has defaulted content.
967      *
968      * The default revision (version 0) of each page, as well as any
969      * pages which are created with empty content have their content
970      * defaulted to something like:
971      * <pre>
972      *   Describe [ThisPage] here.
973      * </pre>
974      *
975      * @access public
976      *
977      * @return boolean Returns true if the page has default content.
978      */
979     function hasDefaultContents() {
980         $data = &$this->_data;
981         return empty($data['%content']);
982     }
983
984     /**
985      * Get the content as an array of lines.
986      *
987      * @access public
988      *
989      * @return array An array of lines.
990      * The lines should contain no trailing white space.
991      */
992     function getContent() {
993         return explode("\n", $this->getPackedContent());
994     }
995         
996         /**
997      * Get the pagename of the revision.
998      *
999      * @access public
1000      *
1001      * @return string pagename.
1002      */
1003     function getPageName() {
1004         return $this->_pagename;
1005     }
1006
1007     /**
1008      * Determine whether revision is the latest.
1009      *
1010      * @access public
1011      *
1012      * @return boolean True iff the revision is the latest (most recent) one.
1013      */
1014     function isCurrent() {
1015         if (!isset($this->_iscurrent)) {
1016             $page = $this->getPage();
1017             $current = $page->getCurrentRevision();
1018             $this->_iscurrent = $this->getVersion() == $current->getVersion();
1019         }
1020         return $this->_iscurrent;
1021     }
1022     
1023     /**
1024      * Get the content as a string.
1025      *
1026      * @access public
1027      *
1028      * @return string The page content.
1029      * Lines are separated by new-lines.
1030      */
1031     function getPackedContent() {
1032         $data = &$this->_data;
1033
1034         
1035         if (empty($data['%content'])) {
1036             // Replace empty content with default value.
1037             return sprintf(_("Describe %s here."),
1038                            "[". $this->_pagename ."]");
1039         }
1040
1041         // There is (non-default) content.
1042         assert($this->_version > 0);
1043         
1044         if (!is_string($data['%content'])) {
1045             // Content was not provided to us at init time.
1046             // (This is allowed because for some backends, fetching
1047             // the content may be expensive, and often is not wanted
1048             // by the user.)
1049             //
1050             // In any case, now we need to get it.
1051             $data['%content'] = $this->_get_content();
1052             assert(is_string($data['%content']));
1053         }
1054         
1055         return $data['%content'];
1056     }
1057
1058     function _get_content() {
1059         $cache = &$this->_wikidb->_cache;
1060         $pagename = $this->_pagename;
1061         $version = $this->_version;
1062
1063         assert($version > 0);
1064         
1065         $newdata = $cache->get_versiondata($pagename, $version, true);
1066         if ($newdata) {
1067             assert(is_string($newdata['%content']));
1068             return $newdata['%content'];
1069         }
1070         else {
1071             // else revision has been deleted... What to do?
1072             return __sprintf("Acck! Revision %s of %s seems to have been deleted!",
1073                              $version, $pagename);
1074         }
1075     }
1076
1077     /**
1078      * Get meta-data for this revision.
1079      *
1080      *
1081      * @access public
1082      *
1083      * @param string $key Which meta-data to access.
1084      *
1085      * Some reserved revision meta-data keys are:
1086      * <dl>
1087      * <dt> 'mtime' <dd> Time this revision was created (seconds since midnight Jan 1, 1970.)
1088      *        The 'mtime' meta-value is normally set automatically by the database
1089      *        backend, but it may be specified explicitly when creating a new revision.
1090      * <dt> orig_mtime
1091      *  <dd> To ensure consistency of RecentChanges, the mtimes of the versions
1092      *       of a page must be monotonically increasing.  If an attempt is
1093      *       made to create a new revision with an mtime less than that of
1094      *       the preceeding revision, the new revisions timestamp is force
1095      *       to be equal to that of the preceeding revision.  In that case,
1096      *       the originally requested mtime is preserved in 'orig_mtime'.
1097      * <dt> '_supplanted' <dd> Time this revision ceased to be the most recent.
1098      *        This meta-value is <em>always</em> automatically maintained by the database
1099      *        backend.  (It is set from the 'mtime' meta-value of the superceding
1100      *        revision.)  '_supplanted' has a value of 'false' for the current revision.
1101      *
1102      * FIXME: this could be refactored:
1103      * <dt> author
1104      *  <dd> Author of the page (as he should be reported in, e.g. RecentChanges.)
1105      * <dt> author_id
1106      *  <dd> Authenticated author of a page.  This is used to identify
1107      *       the distinctness of authors when cleaning old revisions from
1108      *       the database.
1109      * <dt> 'is_minor_edit' <dd> Set if change was marked as a minor revision by the author.
1110      * <dt> 'summary' <dd> Short change summary entered by page author.
1111      * </dl>
1112      *
1113      * Meta-data keys must be valid C identifers (they have to start with a letter
1114      * or underscore, and can contain only alphanumerics and underscores.)
1115      *
1116      * @return string The requested value, or false if the requested value
1117      * is not defined.
1118      */
1119     function get($key) {
1120         if (!$key || $key[0] == '%')
1121             return false;
1122         $data = &$this->_data;
1123         return isset($data[$key]) ? $data[$key] : false;
1124     }
1125
1126     /**
1127      * Get all the revision page meta-data as a hash.
1128      *
1129      * @return hash The revision meta-data.
1130      */
1131     function getMetaData() {
1132         $meta = array();
1133         foreach ($this->_data as $key => $val) {
1134             if (!empty($val) && $key[0] != '%')
1135                 $meta[$key] = $val;
1136         }
1137         return $meta;
1138     }
1139     
1140             
1141     /**
1142      * Return a string representation of the revision.
1143      *
1144      * This is really only for debugging.
1145      *
1146      * @access public
1147      *
1148      * @return string Printable representation of the WikiDB_Page.
1149      */
1150     function asString () {
1151         ob_start();
1152         printf("[%s:%d\n", get_class($this), $this->get('version'));
1153         print_r($this->_data);
1154         echo $this->getPackedContent() . "\n]\n";
1155         $strval = ob_get_contents();
1156         ob_end_clean();
1157         return $strval;
1158     }
1159 };
1160
1161
1162 /**
1163  * A class which represents a sequence of WikiDB_Pages.
1164  */
1165 class WikiDB_PageIterator
1166 {
1167     function WikiDB_PageIterator(&$wikidb, &$pages) {
1168         $this->_pages = $pages;
1169         $this->_wikidb = &$wikidb;
1170     }
1171     
1172     /**
1173      * Get next WikiDB_Page in sequence.
1174      *
1175      * @access public
1176      *
1177      * @return WikiDB_Page The next WikiDB_Page in the sequence.
1178      */
1179     function next () {
1180         if ( ! ($next = $this->_pages->next()) )
1181             return false;
1182
1183         $pagename = &$next['pagename'];
1184         if (isset($next['pagedata']))
1185             $this->_wikidb->_cache->cache_data($next);
1186
1187         return new WikiDB_Page($this->_wikidb, $pagename);
1188     }
1189
1190     /**
1191      * Release resources held by this iterator.
1192      *
1193      * The iterator may not be used after free() is called.
1194      *
1195      * There is no need to call free(), if next() has returned false.
1196      * (I.e. if you iterate through all the pages in the sequence,
1197      * you do not need to call free() --- you only need to call it
1198      * if you stop before the end of the iterator is reached.)
1199      *
1200      * @access public
1201      */
1202     function free() {
1203         $this->_pages->free();
1204     }
1205
1206     // Not yet used.
1207     function setSortby ($arg = false) {
1208         if (!$arg) {
1209             $arg = @$_GET['sortby'];
1210             if ($arg) {
1211                 $sortby = substr($arg,1);
1212                 $order  = substr($arg,0,1)=='+' ? 'ASC' : 'DESC';
1213             }
1214         }
1215         if (is_array($arg)) { // array('mtime' => 'desc')
1216             $sortby = $arg[0];
1217             $order = $arg[1];
1218         } else {
1219             $sortby = $arg;
1220             $order  = 'ASC';
1221         }
1222         // available column types to sort by:
1223         // todo: we must provide access methods for the generic dumb/iterator
1224         $this->_types = explode(',','pagename,mtime,hits,version,author,locked,minor,markup');
1225         if (in_array($sortby,$this->_types))
1226             $this->_options['sortby'] = $sortby;
1227         else
1228             trigger_error(fmt("Argument %s '%s' ignored",'sortby',$sortby), E_USER_WARNING);
1229         if (in_array(strtoupper($order),'ASC','DESC')) 
1230             $this->_options['order'] = strtoupper($order);
1231         else
1232             trigger_error(fmt("Argument %s '%s' ignored",'order',$order), E_USER_WARNING);
1233     }
1234
1235 };
1236
1237 /**
1238  * A class which represents a sequence of WikiDB_PageRevisions.
1239  */
1240 class WikiDB_PageRevisionIterator
1241 {
1242     function WikiDB_PageRevisionIterator(&$wikidb, &$revisions) {
1243         $this->_revisions = $revisions;
1244         $this->_wikidb = &$wikidb;
1245     }
1246     
1247     /**
1248      * Get next WikiDB_PageRevision in sequence.
1249      *
1250      * @access public
1251      *
1252      * @return WikiDB_PageRevision
1253      * The next WikiDB_PageRevision in the sequence.
1254      */
1255     function next () {
1256         if ( ! ($next = $this->_revisions->next()) )
1257             return false;
1258
1259         $this->_wikidb->_cache->cache_data($next);
1260
1261         $pagename = $next['pagename'];
1262         $version = $next['version'];
1263         $versiondata = $next['versiondata'];
1264         assert(!empty($pagename));
1265         assert(is_array($versiondata));
1266         assert($version > 0);
1267
1268         return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
1269                                        $versiondata);
1270     }
1271
1272     /**
1273      * Release resources held by this iterator.
1274      *
1275      * The iterator may not be used after free() is called.
1276      *
1277      * There is no need to call free(), if next() has returned false.
1278      * (I.e. if you iterate through all the revisions in the sequence,
1279      * you do not need to call free() --- you only need to call it
1280      * if you stop before the end of the iterator is reached.)
1281      *
1282      * @access public
1283      */
1284     function free() { 
1285         $this->_revisions->free();
1286     }
1287 };
1288
1289
1290 /**
1291  * Data cache used by WikiDB.
1292  *
1293  * FIXME: Maybe rename this to caching_backend (or some such).
1294  *
1295  * @access private
1296  */
1297 class WikiDB_cache 
1298 {
1299     // FIXME: beautify versiondata cache.  Cache only limited data?
1300
1301     function WikiDB_cache (&$backend) {
1302         $this->_backend = &$backend;
1303
1304         $this->_pagedata_cache = array();
1305         $this->_versiondata_cache = array();
1306         array_push ($this->_versiondata_cache, array());
1307         $this->_glv_cache = array();
1308     }
1309     
1310     function close() {
1311         $this->_pagedata_cache = false;
1312                 $this->_versiondata_cache = false;
1313                 $this->_glv_cache = false;
1314     }
1315
1316     function get_pagedata($pagename) {
1317         assert(is_string($pagename) && $pagename);
1318         $cache = &$this->_pagedata_cache;
1319
1320         if (!isset($cache[$pagename]) || !is_array($cache[$pagename])) {
1321             $cache[$pagename] = $this->_backend->get_pagedata($pagename);
1322             if (empty($cache[$pagename]))
1323                 $cache[$pagename] = array();
1324         }
1325
1326         return $cache[$pagename];
1327     }
1328     
1329     function update_pagedata($pagename, $newdata) {
1330         assert(is_string($pagename) && $pagename);
1331
1332         $this->_backend->update_pagedata($pagename, $newdata);
1333
1334         if (is_array($this->_pagedata_cache[$pagename])) {
1335             $cachedata = &$this->_pagedata_cache[$pagename];
1336             foreach($newdata as $key => $val)
1337                 $cachedata[$key] = $val;
1338         }
1339     }
1340
1341     function invalidate_cache($pagename) {
1342         unset ($this->_pagedata_cache[$pagename]);
1343                 unset ($this->_versiondata_cache[$pagename]);
1344                 unset ($this->_glv_cache[$pagename]);
1345     }
1346     
1347     function delete_page($pagename) {
1348         $this->_backend->delete_page($pagename);
1349         unset ($this->_pagedata_cache[$pagename]);
1350                 unset ($this->_glv_cache[$pagename]);
1351     }
1352
1353     // FIXME: ugly
1354     function cache_data($data) {
1355         if (isset($data['pagedata']))
1356             $this->_pagedata_cache[$data['pagename']] = $data['pagedata'];
1357     }
1358     
1359     function get_versiondata($pagename, $version, $need_content = false) {
1360                 //  FIXME: Seriously ugly hackage
1361         if (defined ('USECACHE')){   //temporary - for debugging
1362         assert(is_string($pagename) && $pagename);
1363                 // there is a bug here somewhere which results in an assertion failure at line 105
1364                 // of ArchiveCleaner.php  It goes away if we use the next line.
1365                 $need_content = true;
1366                 $nc = $need_content ? '1':'0';
1367         $cache = &$this->_versiondata_cache;
1368         if (!isset($cache[$pagename][$version][$nc])||
1369                                 !(is_array ($cache[$pagename])) || !(is_array ($cache[$pagename][$version]))) {
1370             $cache[$pagename][$version][$nc] = 
1371                                 $this->_backend->get_versiondata($pagename,$version, $need_content);
1372                         // If we have retrieved all data, we may as well set the cache for $need_content = false
1373                         if($need_content){
1374                                 $cache[$pagename][$version]['0'] = $cache[$pagename][$version]['1'];
1375                         }
1376                 }
1377         $vdata = $cache[$pagename][$version][$nc];
1378         }
1379         else
1380         {
1381     $vdata = $this->_backend->get_versiondata($pagename, $version, $need_content);
1382         }
1383         // FIXME: ugly
1384         if ($vdata && !empty($vdata['%pagedata']))
1385             $this->_pagedata_cache[$pagename] = $vdata['%pagedata'];
1386         return $vdata;
1387     }
1388
1389     function set_versiondata($pagename, $version, $data) {
1390         $new = $this->_backend->
1391              set_versiondata($pagename, $version, $data);
1392                 // Update the cache
1393                 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
1394                 // FIXME: hack
1395                 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
1396                 // Is this necessary?
1397                 unset($this->_glv_cache[$pagename]);
1398                 
1399     }
1400
1401     function update_versiondata($pagename, $version, $data) {
1402         $new = $this->_backend->
1403              update_versiondata($pagename, $version, $data);
1404                 // Update the cache
1405                 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
1406                 // FIXME: hack
1407                 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
1408                 // Is this necessary?
1409                 unset($this->_glv_cache[$pagename]);
1410
1411     }
1412
1413     function delete_versiondata($pagename, $version) {
1414         $new = $this->_backend->
1415             delete_versiondata($pagename, $version);
1416         unset ($this->_versiondata_cache[$pagename][$version]['1']);
1417         unset ($this->_versiondata_cache[$pagename][$version]['0']);
1418         unset ($this->_glv_cache[$pagename]);
1419     }
1420         
1421     function get_latest_version($pagename)  {
1422         if(defined('USECACHE')){
1423             assert (is_string($pagename) && $pagename);
1424             $cache = &$this->_glv_cache;        
1425             if (!isset($cache[$pagename])) {
1426                 $cache[$pagename] = $this->_backend->get_latest_version($pagename);
1427                 if (empty($cache[$pagename]))
1428                     $cache[$pagename] = 0;
1429             } 
1430             return $cache[$pagename];}
1431         else {
1432             return $this->_backend->get_latest_version($pagename); 
1433         }
1434     }
1435
1436 };
1437
1438 /**
1439  * FIXME! Class for externally authenticated users.
1440  *
1441  * We might have read-only access to the password and/or group membership,
1442  * or we might even be able to update the entries.
1443  *
1444  * FIXME: This was written before we stored prefs as %pagedata, so
1445  *
1446  * FIXME: I believe this is not currently used.
1447  */
1448 //  class WikiDB_User
1449 //  extends WikiUser
1450 //  {
1451 //      var $_authdb;
1452
1453 //      function WikiDB_User($userid, $authlevel = false) {
1454 //          global $request;
1455 //          $this->_authdb = new WikiAuthDB($GLOBALS['DBAuthParams']);
1456 //          $this->_authmethod = 'AuthDB';
1457 //          WikiUser::WikiUser($request, $userid, $authlevel);
1458 //      }
1459
1460 //      /*
1461 //      function getPreferences() {
1462 //          // external prefs override internal ones?
1463 //          if (! $this->_authdb->getPrefs() )
1464 //              if ($pref = WikiUser::getPreferences())
1465 //                  return $prefs;
1466 //          return false;
1467 //      }
1468
1469 //      function setPreferences($prefs) {
1470 //          if (! $this->_authdb->setPrefs($prefs) )
1471 //              return WikiUser::setPreferences();
1472 //      }
1473 //      */
1474
1475 //      function exists() {
1476 //          return $this->_authdb->exists($this->_userid);
1477 //      }
1478
1479 //      // create user and default user homepage
1480 //      function createUser ($pref) {
1481 //          if ($this->exists()) return;
1482 //          if (! $this->_authdb->createUser($pref)) {
1483 //              // external auth doesn't allow this.
1484 //              // do our policies allow local users instead?
1485 //              return WikiUser::createUser($pref);
1486 //          }
1487 //      }
1488
1489 //      function checkPassword($passwd) {
1490 //          return $this->_authdb->pwcheck($this->userid, $passwd);
1491 //      }
1492
1493 //      function changePassword($passwd) {
1494 //          if (! $this->mayChangePassword() ) {
1495 //              trigger_error(sprintf("Attempt to change an external password for '%s'",
1496 //                                    $this->_userid), E_USER_ERROR);
1497 //              return;
1498 //          }
1499 //          return $this->_authdb->changePass($this->userid, $passwd);
1500 //      }
1501
1502 //      function mayChangePassword() {
1503 //          return $this->_authdb->auth_update;
1504 //      }
1505 //  }
1506
1507 /*
1508  * FIXME: I believe this is not currently used.
1509  */
1510 //  class WikiAuthDB
1511 //  extends WikiDB
1512 //  {
1513 //      var $auth_dsn = false, $auth_check = false;
1514 //      var $auth_crypt_method = 'crypt', $auth_update = false;
1515 //      var $group_members = false, $user_groups = false;
1516 //      var $pref_update = false, $pref_select = false;
1517 //      var $_dbh;
1518
1519 //      function WikiAuthDB($DBAuthParams) {
1520 //          foreach ($DBAuthParams as $key => $value) {
1521 //              $this->$key = $value;
1522 //          }
1523 //          if (!$this->auth_dsn) {
1524 //              trigger_error(_("no \$DBAuthParams['dsn'] provided"), E_USER_ERROR);
1525 //              return false;
1526 //          }
1527 //          // compare auth DB to the existing page DB. reuse if it's on the same database.
1528 //          if (isa($this->_backend, 'WikiDB_backend_PearDB') and 
1529 //              $this->_backend->_dsn == $this->auth_dsn) {
1530 //              $this->_dbh = &$this->_backend->_dbh;
1531 //              return $this->_backend;
1532 //          }
1533 //          include_once("lib/WikiDB/SQL.php");
1534 //          return new WikiDB_SQL($DBAuthParams);
1535 //      }
1536
1537 //      function param_missing ($param) {
1538 //          trigger_error(sprintf(_("No \$DBAuthParams['%s'] provided."), $param), E_USER_ERROR);
1539 //          return;
1540 //      }
1541
1542 //      function getPrefs($prefs) {
1543 //          if ($this->pref_select) {
1544 //              $statement = $this->_backend->Prepare($this->pref_select);
1545 //              return unserialize($this->_backend->Execute($statement, 
1546 //                                                          $prefs->get('userid')));
1547 //          } else {
1548 //              param_missing('pref_select');
1549 //              return false;
1550 //          }
1551 //      }
1552
1553 //      function setPrefs($prefs) {
1554 //          if ($this->pref_write) {
1555 //              $statement = $this->_backend->Prepare($this->pref_write);
1556 //              return $this->_backend->Execute($statement, 
1557 //                                              $prefs->get('userid'), serialize($prefs->_prefs));
1558 //          } else {
1559 //              param_missing('pref_write');
1560 //              return false;
1561 //          }
1562 //      }
1563
1564 //      function createUser ($pref) {
1565 //          if ($this->user_create) {
1566 //              $statement = $this->_backend->Prepare($this->user_create);
1567 //              return $this->_backend->Execute($statement, 
1568 //                                          $prefs->get('userid'), serialize($prefs->_prefs));
1569 //          } else {
1570 //              param_missing('user_create');
1571 //              return false;
1572 //          }
1573 //      }
1574
1575 //      function exists($userid) {
1576 //          if ($this->user_check) {
1577 //              $statement = $this->_backend->Prepare($this->user_check);
1578 //              return $this->_backend->Execute($statement, $prefs->get('userid'));
1579 //          } else {
1580 //              param_missing('user_check');
1581 //              return false;
1582 //          }
1583 //      }
1584
1585 //      function pwcheck($userid, $pass) {
1586 //          if ($this->auth_check) {
1587 //              $statement = $this->_backend->Prepare($this->auth_check);
1588 //              return $this->_backend->Execute($statement, $userid, $pass);
1589 //          } else {
1590 //              param_missing('auth_check');
1591 //              return false;
1592 //          }
1593 //      }
1594 //  }
1595
1596 // Local Variables:
1597 // mode: php
1598 // tab-width: 8
1599 // c-basic-offset: 4
1600 // c-hanging-comment-ender-p: nil
1601 // indent-tabs-mode: nil
1602 // End:   
1603 ?>