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