2 rcs_id('$Id: WikiDB.php,v 1.137 2005-10-12 06:16:18 rurban Exp $');
4 require_once('lib/PageType.php');
7 * The classes in the file define the interface to the
11 * @author Geoffrey T. Dairiki <dairiki@dairiki.org>
16 * Force the creation of a new revision.
17 * @see WikiDB_Page::createRevision()
19 if (!defined('WIKIDB_FORCE_CREATE'))
20 define('WIKIDB_FORCE_CREATE', -1);
23 * Abstract base class for the database used by PhpWiki.
25 * A <tt>WikiDB</tt> is a container for <tt>WikiDB_Page</tt>s which in
26 * turn contain <tt>WikiDB_PageRevision</tt>s.
28 * Conceptually a <tt>WikiDB</tt> contains all possible
29 * <tt>WikiDB_Page</tt>s, whether they have been initialized or not.
30 * Since all possible pages are already contained in a WikiDB, a call
31 * to WikiDB::getPage() will never fail (barring bugs and
32 * e.g. filesystem or SQL database problems.)
34 * Also each <tt>WikiDB_Page</tt> always contains at least one
35 * <tt>WikiDB_PageRevision</tt>: the default content (e.g. "Describe
36 * [PageName] here."). This default content has a version number of
39 * <tt>WikiDB_PageRevision</tt>s have read-only semantics. One can
40 * only create new revisions or delete old ones --- one can not modify
41 * an existing revision.
45 * Open a WikiDB database.
47 * This is a static member function. This function inspects its
48 * arguments to determine the proper subclass of WikiDB to
49 * instantiate, and then it instantiates it.
53 * @param hash $dbparams Database configuration parameters.
54 * Some pertinent paramters are:
57 * <dd> The back-end type. Current supported types are:
60 * <dd> Generic SQL backend based on the PEAR/DB database abstraction
61 * library. (More stable and conservative)
63 * <dd> Another generic SQL backend. (More current features are tested here. Much faster)
65 * <dd> Dba based backend. The default and by far the fastest.
73 * <dd> (Used by the SQL and ADODB backends.)
74 * The DSN specifying which database to connect to.
77 * <dd> Prefix to be prepended to database tables (and file names).
80 * <dd> (Used by the dba backend.)
81 * Which directory db files reside in.
84 * <dd> Used only by the dba backend so far.
85 * And: When optimizing mysql it closes timed out mysql processes.
86 * otherwise only used for dba: Timeout in seconds for opening (and
87 * obtaining lock) on the dbm file.
90 * <dd> (Used by the dba backend.)
92 * Which dba handler to use. Good choices are probably either
96 * @return WikiDB A WikiDB object.
98 function open ($dbparams) {
99 $dbtype = $dbparams{'dbtype'};
100 include_once("lib/WikiDB/$dbtype.php");
102 $class = 'WikiDB_' . $dbtype;
103 return new $class ($dbparams);
113 function WikiDB (&$backend, $dbparams) {
114 $this->_backend = &$backend;
115 // don't do the following with the auth_dsn!
116 if (isset($dbparams['auth_dsn'])) return;
118 $this->_cache = new WikiDB_cache($backend);
119 if (!empty($GLOBALS['request'])) $GLOBALS['request']->_dbi = $this;
121 // If the database doesn't yet have a timestamp, initialize it now.
122 if ($this->get('_timestamp') === false)
125 //FIXME: devel checking.
126 //$this->_backend->check();
130 * Close database connection.
132 * The database may no longer be used after it is closed.
134 * Closing a WikiDB invalidates all <tt>WikiDB_Page</tt>s,
135 * <tt>WikiDB_PageRevision</tt>s and <tt>WikiDB_PageIterator</tt>s
136 * which have been obtained from it.
141 $this->_backend->close();
142 $this->_cache->close();
146 * Get a WikiDB_Page from a WikiDB.
148 * A {@link WikiDB} consists of the (infinite) set of all possible pages,
149 * therefore this method never fails.
152 * @param string $pagename Which page to get.
153 * @return WikiDB_Page The requested WikiDB_Page.
155 function getPage($pagename) {
156 static $error_displayed = false;
157 $pagename = (string) $pagename;
159 if ($pagename === '') {
160 if ($error_displayed) return false;
161 $error_displayed = true;
162 if (function_exists("xdebug_get_function_stack"))
163 var_dump(xdebug_get_function_stack());
164 trigger_error("empty pagename", E_USER_WARNING);
168 assert($pagename != '');
170 return new WikiDB_Page($this, $pagename);
174 * Determine whether page exists (in non-default form).
177 * $is_page = $dbi->isWikiPage($pagename);
181 * $page = $dbi->getPage($pagename);
182 * $current = $page->getCurrentRevision();
183 * $is_page = ! $current->hasDefaultContents();
185 * however isWikiPage may be implemented in a more efficient
186 * manner in certain back-ends.
190 * @param string $pagename string Which page to check.
192 * @return boolean True if the page actually exists with
193 * non-default contents in the WikiDataBase.
195 function isWikiPage ($pagename) {
196 $page = $this->getPage($pagename);
197 return $page->exists();
201 * Delete page from the WikiDB.
203 * Deletes the page from the WikiDB with the possibility to revert and diff.
204 * //Also resets all page meta-data to the default values.
206 * Note: purgePage() effectively destroys all revisions of the page from the WikiDB.
210 * @param string $pagename Name of page to delete.
212 function deletePage($pagename) {
213 // don't create empty revisions of already purged pages.
214 if ($this->_backend->get_latest_version($pagename))
215 $result = $this->_cache->delete_page($pagename);
219 /* Generate notification emails? */
220 if (! $this->isWikiPage($pagename) and !isa($GLOBALS['request'],'MockRequest')) {
221 $notify = $this->get('notify');
222 if (!empty($notify) and is_array($notify)) {
224 //TODO: deferr it (quite a massive load if you remove some pages).
225 //TODO: notification class which catches all changes,
226 // and decides at the end of the request what to mail.
227 // (type, page, who, what, users, emails)
228 // could be used for PageModeration and RSS2 Cloud xml-rpc also.
229 $page = new WikiDB_Page($this, $pagename);
230 list($emails, $userids) = $page->getPageChangeEmails($notify);
231 if (!empty($emails)) {
232 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
233 $editedby = sprintf(_("Removed by: %s"), $from);
234 $emails = join(',', $emails);
235 $subject = sprintf(_("Page removed %s"), urlencode($pagename));
236 if (mail("<undisclosed-recipients>","[".WIKI_NAME."] ".$subject,
240 "From: $from\r\nBcc: $emails"))
241 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
242 $pagename, join(',',$userids)), E_USER_NOTICE);
244 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
245 $pagename, join(',',$userids)), E_USER_WARNING);
250 //How to create a RecentChanges entry with explaining summary? Dynamically
252 $page = $this->getPage($pagename);
253 $current = $page->getCurrentRevision();
254 $meta = $current->_data;
255 $version = $current->getVersion();
256 $meta['summary'] = _("removed");
257 $page->save($current->getPackedContent(), $version + 1, $meta);
263 * Completely remove the page from the WikiDB, without undo possibility.
265 function purgePage($pagename) {
266 $result = $this->_cache->purge_page($pagename);
267 $this->deletePage($pagename); // just for the notification
272 * Retrieve all pages.
274 * Gets the set of all pages with non-default contents.
278 * @param boolean $include_defaulted Normally pages whose most
279 * recent revision has empty content are considered to be
280 * non-existant. Unless $include_defaulted is set to true, those
281 * pages will not be returned.
283 * @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages
284 * in the WikiDB which have non-default contents.
286 function getAllPages($include_empty=false, $sortby=false, $limit=false,
289 // HACK: memory_limit=8M will fail on too large pagesets. old php on unix only!
291 $mem = ini_get("memory_limit");
292 if ($mem and !$limit and !isWindows() and !check_php_version(4,3)) {
294 $GLOBALS['request']->setArg('limit', $limit);
295 $GLOBALS['request']->setArg('paging', 'auto');
298 $result = $this->_backend->get_all_pages($include_empty, $sortby, $limit,
300 return new WikiDB_PageIterator($this, $result,
301 array('include_empty' => $include_empty,
302 'exclude' => $exclude,
307 * $include_empty = true: include also empty pages
308 * exclude: comma-seperated list pagenames: TBD: array of pagenames
310 function numPages($include_empty=false, $exclude='') {
311 if (method_exists($this->_backend, 'numPages'))
312 // FIXME: currently are all args ignored.
313 $count = $this->_backend->numPages($include_empty, $exclude);
315 // FIXME: exclude ignored.
316 $iter = $this->getAllPages($include_empty, false, false, $exclude);
317 $count = $iter->count();
326 * Search for pages containing (or not containing) certain words
329 * Pages are returned in alphabetical order whenever it is
330 * practical to do so.
332 * FIXME: clarify $search syntax. provide glob=>TextSearchQuery converters
335 * @param TextSearchQuery $search A TextSearchQuery object
336 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
337 * @see TextSearchQuery
339 function titleSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
340 $result = $this->_backend->text_search($search, false, $sortby, $limit, $exclude);
341 return new WikiDB_PageIterator($this, $result,
342 array('exclude' => $exclude,
349 * Search for pages containing (or not containing) certain words
350 * in their entire text (this includes the page content and the
353 * Pages are returned in alphabetical order whenever it is
354 * practical to do so.
358 * @param TextSearchQuery $search A TextSearchQuery object.
359 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
360 * @see TextSearchQuery
362 function fullSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
363 $result = $this->_backend->text_search($search, true, $sortby, $limit, $exclude);
364 return new WikiDB_PageIterator($this, $result,
365 array('exclude' => $exclude,
370 * Find the pages with the greatest hit counts.
372 * Pages are returned in reverse order by hit count.
376 * @param integer $limit The maximum number of pages to return.
377 * Set $limit to zero to return all pages. If $limit < 0, pages will
378 * be sorted in decreasing order of popularity.
380 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching
383 function mostPopular($limit = 20, $sortby = '-hits') {
384 $result = $this->_backend->most_popular($limit, $sortby);
385 return new WikiDB_PageIterator($this, $result);
389 * Find recent page revisions.
391 * Revisions are returned in reverse order by creation time.
395 * @param hash $params This hash is used to specify various optional
399 * <dd> (integer) At most this many revisions will be returned.
401 * <dd> (integer) Only revisions since this time (unix-timestamp) will be returned.
402 * <dt> include_minor_revisions
403 * <dd> (boolean) Also include minor revisions. (Default is not to.)
404 * <dt> exclude_major_revisions
405 * <dd> (boolean) Don't include non-minor revisions.
406 * (Exclude_major_revisions implies include_minor_revisions.)
407 * <dt> include_all_revisions
408 * <dd> (boolean) Return all matching revisions for each page.
409 * Normally only the most recent matching revision is returned
413 * @return WikiDB_PageRevisionIterator A WikiDB_PageRevisionIterator containing the
414 * matching revisions.
416 function mostRecent($params = false) {
417 $result = $this->_backend->most_recent($params);
418 return new WikiDB_PageRevisionIterator($this, $result);
424 * @return Iterator A generic iterator containing rows of (duplicate) pagename, wantedfrom.
426 function wantedPages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
427 return $this->_backend->wanted_pages($exclude_from, $exclude, $sortby, $limit);
428 //return new WikiDB_PageIterator($this, $result);
433 * Call the appropriate backend method.
436 * @param string $from Page to rename
437 * @param string $to New name
438 * @param boolean $updateWikiLinks If the text in all pages should be replaced.
439 * @return boolean true or false
441 function renamePage($from, $to, $updateWikiLinks = false) {
442 assert(is_string($from) && $from != '');
443 assert(is_string($to) && $to != '');
445 if (method_exists($this->_backend, 'rename_page')) {
446 $oldpage = $this->getPage($from);
447 $newpage = $this->getPage($to);
448 //update all WikiLinks in existing pages
449 //non-atomic! i.e. if rename fails the links are not undone
450 if ($updateWikiLinks) {
451 require_once('lib/plugin/WikiAdminSearchReplace.php');
452 $links = $oldpage->getBackLinks();
453 while ($linked_page = $links->next()) {
454 WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
455 $linked_page->getName(),
458 $links = $newpage->getBackLinks();
459 while ($linked_page = $links->next()) {
460 WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
461 $linked_page->getName(),
465 if ($oldpage->exists() and ! $newpage->exists()) {
466 if ($result = $this->_backend->rename_page($from, $to)) {
467 //create a RecentChanges entry with explaining summary
468 $page = $this->getPage($to);
469 $current = $page->getCurrentRevision();
470 $meta = $current->_data;
471 $version = $current->getVersion();
472 $meta['summary'] = sprintf(_("renamed from %s"), $from);
473 $page->save($current->getPackedContent(), $version + 1, $meta);
475 } elseif (!$oldpage->getCurrentRevision(false) and !$newpage->exists()) {
476 // if a version 0 exists try it also.
477 $result = $this->_backend->rename_page($from, $to);
480 trigger_error(_("WikiDB::renamePage() not yet implemented for this backend"),
483 /* Generate notification emails? */
484 if ($result and !isa($GLOBALS['request'], 'MockRequest')) {
485 $notify = $this->get('notify');
486 if (!empty($notify) and is_array($notify)) {
487 list($emails, $userids) = $oldpage->getPageChangeEmails($notify);
488 if (!empty($emails)) {
489 $oldpage->sendPageRenameNotification($to, $meta, $emails, $userids);
496 /** Get timestamp when database was last modified.
498 * @return string A string consisting of two integers,
499 * separated by a space. The first is the time in
500 * unix timestamp format, the second is a modification
501 * count for the database.
503 * The idea is that you can cast the return value to an
504 * int to get a timestamp, or you can use the string value
505 * as a good hash for the entire database.
507 function getTimestamp() {
508 $ts = $this->get('_timestamp');
509 return sprintf("%d %d", $ts[0], $ts[1]);
513 * Update the database timestamp.
517 $ts = $this->get('_timestamp');
518 $this->set('_timestamp', array(time(), $ts[1] + 1));
523 * Access WikiDB global meta-data.
525 * NOTE: this is currently implemented in a hackish and
526 * not very efficient manner.
530 * @param string $key Which meta data to get.
531 * Some reserved meta-data keys are:
533 * <dt>'_timestamp' <dd> Data used by getTimestamp().
536 * @return scalar The requested value, or false if the requested data
540 if (!$key || $key[0] == '%')
543 * Hack Alert: We can use any page (existing or not) to store
544 * this data (as long as we always use the same one.)
546 $gd = $this->getPage('global_data');
547 $data = $gd->get('__global');
549 if ($data && isset($data[$key]))
556 * Set global meta-data.
558 * NOTE: this is currently implemented in a hackish and
559 * not very efficient manner.
564 * @param string $key Meta-data key to set.
565 * @param string $newval New value.
567 function set($key, $newval) {
568 if (!$key || $key[0] == '%')
571 $gd = $this->getPage('global_data');
572 $data = $gd->get('__global');
579 $data[$key] = $newval;
581 $gd->set('__global', $data);
584 /* TODO: these are really backend methods */
586 // SQL result: for simple select or create/update queries
587 // returns the database specific resource type
588 function genericSqlQuery($sql, $args=false) {
589 if (function_exists('debug_backtrace')) { // >= 4.3.0
590 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
592 trigger_error("no SQL database", E_USER_ERROR);
596 // SQL iter: for simple select or create/update queries
597 // returns the generic iterator object (count,next)
598 function genericSqlIter($sql, $field_list = NULL) {
599 if (function_exists('debug_backtrace')) { // >= 4.3.0
600 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
602 trigger_error("no SQL database", E_USER_ERROR);
606 // see backend upstream methods
607 // ADODB adds surrounding quotes, SQL not yet!
608 function quote ($s) {
614 if (!$request->_dbi) return false;
615 else return false; /* so far only needed for sql so false it.
616 later we have to check dba also */
619 function getParam($param) {
621 if (isset($DBParams[$param])) return $DBParams[$param];
622 elseif ($param == 'prefix') return '';
626 function getAuthParam($param) {
627 global $DBAuthParams;
628 if (isset($DBAuthParams[$param])) return $DBAuthParams[$param];
629 elseif ($param == 'USER_AUTH_ORDER') return $GLOBALS['USER_AUTH_ORDER'];
630 elseif ($param == 'USER_AUTH_POLICY') return $GLOBALS['USER_AUTH_POLICY'];
637 * An abstract base class which representing a wiki-page within a
640 * A WikiDB_Page contains a number (at least one) of
641 * WikiDB_PageRevisions.
645 function WikiDB_Page(&$wikidb, $pagename) {
646 $this->_wikidb = &$wikidb;
647 $this->_pagename = $pagename;
649 if (!(is_string($pagename) and $pagename != '')) {
650 if (function_exists("xdebug_get_function_stack")) {
651 echo "xdebug_get_function_stack(): "; var_dump(xdebug_get_function_stack());
652 } elseif (function_exists("debug_backtrace")) { // >= 4.3.0
653 printSimpleTrace(debug_backtrace());
655 trigger_error("empty pagename", E_USER_WARNING);
659 assert(is_string($pagename) and $pagename != '');
663 * Get the name of the wiki page.
667 * @return string The page name.
670 return $this->_pagename;
673 // To reduce the memory footprint for larger sets of pagelists,
674 // we don't cache the content (only true or false) and
675 // we purge the pagedata (_cached_html) also
677 if (isset($this->_wikidb->_cache->_id_cache[$this->_pagename])) return true;
678 $current = $this->getCurrentRevision(false);
679 if (!$current) return false;
680 return ! $current->hasDefaultContents();
684 * Delete an old revision of a WikiDB_Page.
686 * Deletes the specified revision of the page.
687 * It is a fatal error to attempt to delete the current revision.
691 * @param integer $version Which revision to delete. (You can also
692 * use a WikiDB_PageRevision object here.)
694 function deleteRevision($version) {
695 $backend = &$this->_wikidb->_backend;
696 $cache = &$this->_wikidb->_cache;
697 $pagename = &$this->_pagename;
699 $version = $this->_coerce_to_version($version);
703 $backend->lock(array('page','version'));
704 $latestversion = $cache->get_latest_version($pagename);
705 if ($latestversion && ($version == $latestversion)) {
706 $backend->unlock(array('page','version'));
707 trigger_error(sprintf("Attempt to delete most recent revision of '%s'",
708 $pagename), E_USER_ERROR);
712 $cache->delete_versiondata($pagename, $version);
713 $backend->unlock(array('page','version'));
717 * Delete a revision, or possibly merge it with a previous
721 * Suppose an author make a (major) edit to a page. Shortly
722 * after that the same author makes a minor edit (e.g. to fix
723 * spelling mistakes he just made.)
725 * Now some time later, where cleaning out old saved revisions,
726 * and would like to delete his minor revision (since there's
727 * really no point in keeping minor revisions around for a long
730 * Note that the text after the minor revision probably represents
731 * what the author intended to write better than the text after
732 * the preceding major edit.
734 * So what we really want to do is merge the minor edit with the
737 * We will only do this when:
739 * <li>The revision being deleted is a minor one, and
740 * <li>It has the same author as the immediately preceding revision.
743 function mergeRevision($version) {
744 $backend = &$this->_wikidb->_backend;
745 $cache = &$this->_wikidb->_cache;
746 $pagename = &$this->_pagename;
748 $version = $this->_coerce_to_version($version);
752 $backend->lock(array('version'));
753 $latestversion = $cache->get_latest_version($pagename);
754 if ($latestversion && $version == $latestversion) {
755 $backend->unlock(array('version'));
756 trigger_error(sprintf("Attempt to merge most recent revision of '%s'",
757 $pagename), E_USER_ERROR);
761 $versiondata = $cache->get_versiondata($pagename, $version, true);
763 // Not there? ... we're done!
764 $backend->unlock(array('version'));
768 if ($versiondata['is_minor_edit']) {
769 $previous = $backend->get_previous_version($pagename, $version);
771 $prevdata = $cache->get_versiondata($pagename, $previous);
772 if ($prevdata['author_id'] == $versiondata['author_id']) {
773 // This is a minor revision, previous version is
774 // by the same author. We will merge the
776 $cache->update_versiondata($pagename, $previous,
777 array('%content' => $versiondata['%content'],
778 '_supplanted' => $versiondata['_supplanted']));
783 $cache->delete_versiondata($pagename, $version);
784 $backend->unlock(array('version'));
789 * Create a new revision of a {@link WikiDB_Page}.
793 * @param int $version Version number for new revision.
794 * To ensure proper serialization of edits, $version must be
795 * exactly one higher than the current latest version.
796 * (You can defeat this check by setting $version to
797 * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
799 * @param string $content Contents of new revision.
801 * @param hash $metadata Metadata for new revision.
802 * All values in the hash should be scalars (strings or integers).
804 * @param array $links List of pagenames which this page links to.
806 * @return WikiDB_PageRevision Returns the new WikiDB_PageRevision object. If
807 * $version was incorrect, returns false
809 function createRevision($version, &$content, $metadata, $links) {
810 $backend = &$this->_wikidb->_backend;
811 $cache = &$this->_wikidb->_cache;
812 $pagename = &$this->_pagename;
813 $cache->invalidate_cache($pagename);
815 $backend->lock(array('version','page','recent','link','nonempty'));
817 $latestversion = $backend->get_latest_version($pagename);
818 $newversion = ($latestversion ? $latestversion : 0) + 1;
819 assert($newversion >= 1);
821 if ($version != WIKIDB_FORCE_CREATE and $version != $newversion) {
822 $backend->unlock(array('version','page','recent','link','nonempty'));
828 foreach ($data as $key => $val) {
829 if (empty($val) || $key[0] == '_' || $key[0] == '%')
833 assert(!empty($data['author']));
834 if (empty($data['author_id']))
835 @$data['author_id'] = $data['author'];
837 if (empty($data['mtime']))
838 $data['mtime'] = time();
840 if ($latestversion and $version != WIKIDB_FORCE_CREATE) {
841 // Ensure mtimes are monotonic.
842 $pdata = $cache->get_versiondata($pagename, $latestversion);
843 if ($data['mtime'] < $pdata['mtime']) {
844 trigger_error(sprintf(_("%s: Date of new revision is %s"),
845 $pagename,"'non-monotonic'"),
847 $data['orig_mtime'] = $data['mtime'];
848 $data['mtime'] = $pdata['mtime'];
851 // FIXME: use (possibly user specified) 'mtime' time or
853 $cache->update_versiondata($pagename, $latestversion,
854 array('_supplanted' => $data['mtime']));
857 $data['%content'] = &$content;
859 $cache->set_versiondata($pagename, $newversion, $data);
861 //$cache->update_pagedata($pagename, array(':latestversion' => $newversion,
862 //':deleted' => empty($content)));
864 $backend->set_links($pagename, $links);
866 $backend->unlock(array('version','page','recent','link','nonempty'));
868 return new WikiDB_PageRevision($this->_wikidb, $pagename, $newversion,
872 /** A higher-level interface to createRevision.
874 * This takes care of computing the links, and storing
875 * a cached version of the transformed wiki-text.
877 * @param string $wikitext The page content.
879 * @param int $version Version number for new revision.
880 * To ensure proper serialization of edits, $version must be
881 * exactly one higher than the current latest version.
882 * (You can defeat this check by setting $version to
883 * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
885 * @param hash $meta Meta-data for new revision.
887 function save($wikitext, $version, $meta) {
888 $formatted = new TransformedText($this, $wikitext, $meta);
889 $type = $formatted->getType();
890 $meta['pagetype'] = $type->getName();
891 $links = $formatted->getWikiPageLinks();
893 $backend = &$this->_wikidb->_backend;
894 $newrevision = $this->createRevision($version, $wikitext, $meta, $links);
895 if ($newrevision and !WIKIDB_NOCACHE_MARKUP)
896 $this->set('_cached_html', $formatted->pack());
898 // FIXME: probably should have some global state information
899 // in the backend to control when to optimize.
901 // We're doing this here rather than in createRevision because
902 // postgres can't optimize while locked.
903 if ((DEBUG & _DEBUG_SQL) or (time() % 5 == 0)) {
904 if ($backend->optimize())
905 trigger_error(_("Optimizing database"), E_USER_NOTICE);
908 /* Generate notification emails? */
909 if (isa($newrevision, 'WikiDB_PageRevision')) {
910 // Save didn't fail because of concurrent updates.
911 $notify = $this->_wikidb->get('notify');
912 if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'],'MockRequest')) {
913 list($emails, $userids) = $this->getPageChangeEmails($notify);
914 if (!empty($emails)) {
915 $this->sendPageChangeNotification($wikitext, $version, $meta, $emails, $userids);
918 $newrevision->_transformedContent = $formatted;
924 function getPageChangeEmails($notify) {
925 $emails = array(); $userids = array();
926 foreach ($notify as $page => $users) {
927 if (glob_match($page, $this->_pagename)) {
928 foreach ($users as $userid => $user) {
929 if (!$user) { // handle the case for ModeratePage: no prefs, just userid's.
931 $u = $request->getUser();
932 if ($u->UserName() == $userid) {
933 $prefs = $u->getPreferences();
936 if (ENABLE_USER_NEW) {
937 $u = WikiUser($userid);
938 $u->getPreferences();
939 $prefs = &$u->_prefs;
941 $u = new WikiUser($GLOBALS['request'], $userid);
942 $prefs = $u->getPreferences();
945 $emails[] = $prefs->get('email');
946 $userids[] = $userid;
948 if (!empty($user['verified']) and !empty($user['email'])) {
949 $emails[] = $user['email'];
950 $userids[] = $userid;
951 } elseif (!empty($user['email'])) {
953 // do a dynamic emailVerified check update
954 $u = $request->getUser();
955 if ($u->UserName() == $userid) {
956 if ($request->_prefs->get('emailVerified')) {
957 $emails[] = $user['email'];
958 $userids[] = $userid;
959 $notify[$page][$userid]['verified'] = 1;
960 $request->_dbi->set('notify', $notify);
964 if (ENABLE_USER_NEW) {
965 $u = WikiUser($userid);
966 $u->getPreferences();
967 $prefs = &$u->_prefs;
969 $u = new WikiUser($GLOBALS['request'], $userid);
970 $prefs = $u->getPreferences();
972 if ($prefs->get('emailVerified')) {
973 $emails[] = $user['email'];
974 $userids[] = $userid;
975 $notify[$page][$userid]['verified'] = 1;
976 $request->_dbi->set('notify', $notify);
979 // ignore verification
982 if (!in_array($user['email'],$emails))
983 $emails[] = $user['email'];
991 $emails = array_unique($emails);
992 $userids = array_unique($userids);
993 return array($emails, $userids);
997 * Send udiff for a changed page to multiple users.
998 * See rename and remove methods also
1000 function sendPageChangeNotification(&$wikitext, $version, $meta, $emails, $userids) {
1002 if (@is_array($request->_deferredPageChangeNotification)) {
1003 // collapse multiple changes (loaddir) into one email
1004 $request->_deferredPageChangeNotification[]
1005 = array($this->_pagename, $emails, $userids);
1008 $backend = &$this->_wikidb->_backend;
1009 //$backend = &$request->_dbi->_backend;
1010 $subject = _("Page change").' '.urlencode($this->_pagename);
1011 $previous = $backend->get_previous_version($this->_pagename, $version);
1012 if (!isset($meta['mtime'])) $meta['mtime'] = time();
1014 $difflink = WikiURL($this->_pagename, array('action'=>'diff'), true);
1015 $cache = &$this->_wikidb->_cache;
1016 //$cache = &$request->_dbi->_cache;
1017 $this_content = explode("\n", $wikitext);
1018 $prevdata = $cache->get_versiondata($this->_pagename, $previous, true);
1019 if (empty($prevdata['%content']))
1020 $prevdata = $backend->get_versiondata($this->_pagename, $previous, true);
1021 $other_content = explode("\n", $prevdata['%content']);
1023 include_once("lib/difflib.php");
1024 $diff2 = new Diff($other_content, $this_content);
1025 //$context_lines = max(4, count($other_content) + 1,
1026 // count($this_content) + 1);
1027 $fmt = new UnifiedDiffFormatter(/*$context_lines*/);
1028 $content = $this->_pagename . " " . $previous . " " .
1029 Iso8601DateTime($prevdata['mtime']) . "\n";
1030 $content .= $this->_pagename . " " . $version . " " .
1031 Iso8601DateTime($meta['mtime']) . "\n";
1032 $content .= $fmt->format($diff2);
1035 $difflink = WikiURL($this->_pagename,array(),true);
1036 $content = $this->_pagename . " " . $version . " " .
1037 Iso8601DateTime($meta['mtime']) . "\n";
1038 $content .= _("New page");
1040 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
1041 $editedby = sprintf(_("Edited by: %s"), $from);
1042 $emails = join(',',$emails);
1043 if (mail("<undisclosed-recipients>",
1044 "[".WIKI_NAME."] ".$subject,
1045 $subject."\n". $editedby."\n". $difflink."\n\n". $content,
1046 "From: $from\r\nBcc: $emails"))
1047 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
1048 $this->_pagename, join(',',$userids)), E_USER_NOTICE);
1050 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
1051 $this->_pagename, join(',',$userids)), E_USER_WARNING);
1054 /** support mass rename / remove (not yet tested)
1056 function sendPageRenameNotification($to, &$meta, $emails, $userids) {
1058 if (@is_array($request->_deferredPageRenameNotification)) {
1059 $request->_deferredPageRenameNotification[] = array($this->_pagename,
1060 $to, $meta, $emails, $userids);
1062 $oldname = $this->_pagename;
1063 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
1064 $editedby = sprintf(_("Edited by: %s"), $from);
1065 $emails = join(',',$emails);
1066 $subject = sprintf(_("Page rename %s to %s"), urlencode($oldname), urlencode($to));
1067 $link = WikiURL($to, true);
1068 if (mail("<undisclosed-recipients>",
1069 "[".WIKI_NAME."] ".$subject,
1070 $subject."\n".$editedby."\n".$link."\n\n"."Renamed $from to $to",
1071 "From: $from\r\nBcc: $emails"))
1072 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
1073 $oldname, join(',',$userids)), E_USER_NOTICE);
1075 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
1076 $oldname, join(',',$userids)), E_USER_WARNING);
1081 * Get the most recent revision of a page.
1085 * @return WikiDB_PageRevision The current WikiDB_PageRevision object.
1087 function getCurrentRevision($need_content = true) {
1088 $backend = &$this->_wikidb->_backend;
1089 $cache = &$this->_wikidb->_cache;
1090 $pagename = &$this->_pagename;
1092 // Prevent deadlock in case of memory exhausted errors
1093 // Pure selection doesn't really need locking here.
1094 // sf.net bug#927395
1095 // I know it would be better to lock, but with lots of pages this deadlock is more
1096 // severe than occasionally get not the latest revision.
1097 // In spirit to wikiwiki: read fast, edit slower.
1099 $version = $cache->get_latest_version($pagename);
1100 // getRevision gets the content also!
1101 $revision = $this->getRevision($version, $need_content);
1102 //$backend->unlock();
1108 * Get a specific revision of a WikiDB_Page.
1112 * @param integer $version Which revision to get.
1114 * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or
1115 * false if the requested revision does not exist in the {@link WikiDB}.
1116 * Note that version zero of any page always exists.
1118 function getRevision($version, $need_content=true) {
1119 $cache = &$this->_wikidb->_cache;
1120 $pagename = &$this->_pagename;
1122 if (! $version or $version == -1) // 0 or false
1123 return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
1125 assert($version > 0);
1126 $vdata = $cache->get_versiondata($pagename, $version, $need_content);
1128 return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
1130 return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
1135 * Get previous page revision.
1137 * This method find the most recent revision before a specified
1142 * @param integer $version Find most recent revision before this version.
1143 * You can also use a WikiDB_PageRevision object to specify the $version.
1145 * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or false if the
1146 * requested revision does not exist in the {@link WikiDB}. Note that
1147 * unless $version is greater than zero, a revision (perhaps version zero,
1148 * the default revision) will always be found.
1150 function getRevisionBefore($version=false, $need_content=true) {
1151 $backend = &$this->_wikidb->_backend;
1152 $pagename = &$this->_pagename;
1153 if ($version === false)
1154 $version = $this->_wikidb->_cache->get_latest_version($pagename);
1156 $version = $this->_coerce_to_version($version);
1161 $previous = $backend->get_previous_version($pagename, $version);
1162 $revision = $this->getRevision($previous, $need_content);
1163 //$backend->unlock();
1169 * Get all revisions of the WikiDB_Page.
1171 * This does not include the version zero (default) revision in the
1172 * returned revision set.
1174 * @return WikiDB_PageRevisionIterator A
1175 * WikiDB_PageRevisionIterator containing all revisions of this
1176 * WikiDB_Page in reverse order by version number.
1178 function getAllRevisions() {
1179 $backend = &$this->_wikidb->_backend;
1180 $revs = $backend->get_all_revisions($this->_pagename);
1181 return new WikiDB_PageRevisionIterator($this->_wikidb, $revs);
1185 * Find pages which link to or are linked from a page.
1189 * @param boolean $reversed Which links to find: true for backlinks (default).
1191 * @return WikiDB_PageIterator A WikiDB_PageIterator containing
1192 * all matching pages.
1194 function getLinks($reversed = true, $include_empty=false, $sortby=false,
1195 $limit=false, $exclude=false) {
1196 $backend = &$this->_wikidb->_backend;
1197 $result = $backend->get_links($this->_pagename, $reversed,
1198 $include_empty, $sortby, $limit, $exclude);
1199 return new WikiDB_PageIterator($this->_wikidb, $result,
1200 array('include_empty' => $include_empty,
1201 'sortby' => $sortby,
1203 'exclude' => $exclude));
1207 * All Links from other pages to this page.
1209 function getBackLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false) {
1210 return $this->getLinks(true, $include_empty, $sortby, $limit, $exclude);
1213 * Forward Links: All Links from this page to other pages.
1215 function getPageLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false) {
1216 return $this->getLinks(false, $include_empty, $sortby, $limit, $exclude);
1220 * possibly faster link existance check. not yet accelerated.
1222 function existLink($link, $reversed=false) {
1223 $backend = &$this->_wikidb->_backend;
1224 if (method_exists($backend,'exists_link'))
1225 return $backend->exists_link($this->_pagename, $link, $reversed);
1226 //$cache = &$this->_wikidb->_cache;
1227 // TODO: check cache if it is possible
1228 $iter = $this->getLinks($reversed, false);
1229 while ($page = $iter->next()) {
1230 if ($page->getName() == $link)
1238 * Access WikiDB_Page non version-specific meta-data.
1242 * @param string $key Which meta data to get.
1243 * Some reserved meta-data keys are:
1245 * <dt>'date' <dd> Created as unixtime
1246 * <dt>'locked'<dd> Is page locked? 'yes' or 'no'
1247 * <dt>'hits' <dd> Page hit counter.
1248 * <dt>'_cached_html' <dd> Transformed CachedMarkup object, serialized + optionally gzipped.
1249 * In SQL stored now in an extra column.
1251 * <dt>'pref' <dd> Users preferences, stored only in homepages.
1252 * <dt>'owner' <dd> Default: first author_id. We might add a group with a dot here:
1253 * E.g. "owner.users"
1254 * <dt>'perm' <dd> Permission flag to authorize read/write/execution of
1255 * page-headers and content.
1256 + <dt>'moderation'<dd> ModeratedPage data
1257 * <dt>'score' <dd> Page score (not yet implement, do we need?)
1260 * @return scalar The requested value, or false if the requested data
1263 function get($key) {
1264 $cache = &$this->_wikidb->_cache;
1265 $backend = &$this->_wikidb->_backend;
1266 if (!$key || $key[0] == '%')
1268 // several new SQL backends optimize this.
1269 if (!WIKIDB_NOCACHE_MARKUP
1270 and $key == '_cached_html'
1271 and method_exists($backend, 'get_cached_html'))
1273 return $backend->get_cached_html($this->_pagename);
1275 $data = $cache->get_pagedata($this->_pagename);
1276 return isset($data[$key]) ? $data[$key] : false;
1280 * Get all the page meta-data as a hash.
1282 * @return hash The page meta-data.
1284 function getMetaData() {
1285 $cache = &$this->_wikidb->_cache;
1286 $data = $cache->get_pagedata($this->_pagename);
1288 foreach ($data as $key => $val) {
1289 if (/*!empty($val) &&*/ $key[0] != '%')
1296 * Set page meta-data.
1301 * @param string $key Meta-data key to set.
1302 * @param string $newval New value.
1304 function set($key, $newval) {
1305 $cache = &$this->_wikidb->_cache;
1306 $backend = &$this->_wikidb->_backend;
1307 $pagename = &$this->_pagename;
1309 assert($key && $key[0] != '%');
1311 // several new SQL backends optimize this.
1312 if (!WIKIDB_NOCACHE_MARKUP
1313 and $key == '_cached_html'
1314 and method_exists($backend, 'set_cached_html'))
1316 return $backend->set_cached_html($pagename, $newval);
1319 $data = $cache->get_pagedata($pagename);
1321 if (!empty($newval)) {
1322 if (!empty($data[$key]) && $data[$key] == $newval)
1323 return; // values identical, skip update.
1326 if (empty($data[$key]))
1327 return; // values identical, skip update.
1330 $cache->update_pagedata($pagename, array($key => $newval));
1334 * Increase page hit count.
1336 * FIXME: IS this needed? Probably not.
1338 * This is a convenience function.
1339 * <pre> $page->increaseHitCount(); </pre>
1340 * is functionally identical to
1341 * <pre> $page->set('hits',$page->get('hits')+1); </pre>
1342 * but less expensive (ignores the pagadata string)
1344 * Note that this method may be implemented in more efficient ways
1345 * in certain backends.
1349 function increaseHitCount() {
1350 if (method_exists($this->_wikidb->_backend, 'increaseHitCount'))
1351 $this->_wikidb->_backend->increaseHitCount($this->_pagename);
1353 @$newhits = $this->get('hits') + 1;
1354 $this->set('hits', $newhits);
1359 * Return a string representation of the WikiDB_Page
1361 * This is really only for debugging.
1365 * @return string Printable representation of the WikiDB_Page.
1367 function asString () {
1369 printf("[%s:%s\n", get_class($this), $this->getName());
1370 print_r($this->getMetaData());
1372 $strval = ob_get_contents();
1380 * @param integer_or_object $version_or_pagerevision
1381 * Takes either the version number (and int) or a WikiDB_PageRevision
1383 * @return integer The version number.
1385 function _coerce_to_version($version_or_pagerevision) {
1386 if (method_exists($version_or_pagerevision, "getContent"))
1387 $version = $version_or_pagerevision->getVersion();
1389 $version = (int) $version_or_pagerevision;
1391 assert($version >= 0);
1395 function isUserPage ($include_empty = true) {
1396 if (!$include_empty and !$this->exists()) return false;
1397 return $this->get('pref') ? true : false;
1400 // May be empty. Either the stored owner (/Chown), or the first authorized author
1401 function getOwner() {
1402 if ($owner = $this->get('owner'))
1403 return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
1404 // check all revisions forwards for the first author_id
1405 $backend = &$this->_wikidb->_backend;
1406 $pagename = &$this->_pagename;
1407 $latestversion = $backend->get_latest_version($pagename);
1408 for ($v=1; $v <= $latestversion; $v++) {
1409 $rev = $this->getRevision($v,false);
1410 if ($rev and $owner = $rev->get('author_id')) {
1411 return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
1417 // The authenticated author of the first revision or empty if not authenticated then.
1418 function getCreator() {
1419 if ($current = $this->getRevision(1,false)) return $current->get('author_id');
1423 // The authenticated author of the current revision.
1424 function getAuthor() {
1425 if ($current = $this->getCurrentRevision(false)) return $current->get('author_id');
1432 * This class represents a specific revision of a WikiDB_Page within
1435 * A WikiDB_PageRevision has read-only semantics. You may only create
1436 * new revisions (and delete old ones) --- you cannot modify existing
1439 class WikiDB_PageRevision
1441 //var $_transformedContent = false; // set by WikiDB_Page::save()
1443 function WikiDB_PageRevision(&$wikidb, $pagename, $version, $versiondata = false) {
1444 $this->_wikidb = &$wikidb;
1445 $this->_pagename = $pagename;
1446 $this->_version = $version;
1447 $this->_data = $versiondata ? $versiondata : array();
1448 $this->_transformedContent = false; // set by WikiDB_Page::save()
1452 * Get the WikiDB_Page which this revision belongs to.
1456 * @return WikiDB_Page The WikiDB_Page which this revision belongs to.
1458 function getPage() {
1459 return new WikiDB_Page($this->_wikidb, $this->_pagename);
1463 * Get the version number of this revision.
1467 * @return integer The version number of this revision.
1469 function getVersion() {
1470 return $this->_version;
1474 * Determine whether this revision has defaulted content.
1476 * The default revision (version 0) of each page, as well as any
1477 * pages which are created with empty content have their content
1478 * defaulted to something like:
1480 * Describe [ThisPage] here.
1485 * @return boolean Returns true if the page has default content.
1487 function hasDefaultContents() {
1488 $data = &$this->_data;
1489 return empty($data['%content']); // FIXME: what if it's the number 0? <>'' or === false
1493 * Get the content as an array of lines.
1497 * @return array An array of lines.
1498 * The lines should contain no trailing white space.
1500 function getContent() {
1501 return explode("\n", $this->getPackedContent());
1505 * Get the pagename of the revision.
1509 * @return string pagename.
1511 function getPageName() {
1512 return $this->_pagename;
1514 function getName() {
1515 return $this->_pagename;
1519 * Determine whether revision is the latest.
1523 * @return boolean True iff the revision is the latest (most recent) one.
1525 function isCurrent() {
1526 if (!isset($this->_iscurrent)) {
1527 $page = $this->getPage();
1528 $current = $page->getCurrentRevision(false);
1529 $this->_iscurrent = $this->getVersion() == $current->getVersion();
1531 return $this->_iscurrent;
1535 * Get the transformed content of a page.
1537 * @param string $pagetype Override the page-type of the revision.
1539 * @return object An XmlContent-like object containing the page transformed
1542 function getTransformedContent($pagetype_override=false) {
1543 $backend = &$this->_wikidb->_backend;
1545 if ($pagetype_override) {
1546 // Figure out the normal page-type for this page.
1547 $type = PageType::GetPageType($this->get('pagetype'));
1548 if ($type->getName() == $pagetype_override)
1549 $pagetype_override = false; // Not really an override...
1552 if ($pagetype_override) {
1553 // Overriden page type, don't cache (or check cache).
1554 return new TransformedText($this->getPage(),
1555 $this->getPackedContent(),
1556 $this->getMetaData(),
1557 $pagetype_override);
1560 $possibly_cache_results = true;
1562 if (!USECACHE or WIKIDB_NOCACHE_MARKUP) {
1563 if (WIKIDB_NOCACHE_MARKUP == 'purge') {
1564 // flush cache for this page.
1565 $page = $this->getPage();
1566 $page->set('_cached_html', ''); // ignored with !USECACHE
1568 $possibly_cache_results = false;
1570 elseif (USECACHE and !$this->_transformedContent) {
1572 if ($this->isCurrent()) {
1573 $page = $this->getPage();
1574 $this->_transformedContent = TransformedText::unpack($page->get('_cached_html'));
1577 $possibly_cache_results = false;
1579 //$backend->unlock();
1582 if (!$this->_transformedContent) {
1583 $this->_transformedContent
1584 = new TransformedText($this->getPage(),
1585 $this->getPackedContent(),
1586 $this->getMetaData());
1588 if ($possibly_cache_results and !WIKIDB_NOCACHE_MARKUP) {
1589 // If we're still the current version, cache the transfomed page.
1591 if ($this->isCurrent()) {
1592 $page->set('_cached_html', $this->_transformedContent->pack());
1594 //$backend->unlock();
1598 return $this->_transformedContent;
1602 * Get the content as a string.
1606 * @return string The page content.
1607 * Lines are separated by new-lines.
1609 function getPackedContent() {
1610 $data = &$this->_data;
1613 if (empty($data['%content'])) {
1614 include_once('lib/InlineParser.php');
1616 // A feature similar to taglines at http://www.wlug.org.nz/
1617 // Lib from http://www.aasted.org/quote/
1618 if (defined('FORTUNE_DIR')
1619 and is_dir(FORTUNE_DIR)
1620 and in_array($GLOBALS['request']->getArg('action'),
1621 array('create','edit')))
1623 include_once("lib/fortune.php");
1624 $fortune = new Fortune();
1625 $quote = str_replace("\n<br>","\n", $fortune->quoteFromDir(FORTUNE_DIR));
1626 return sprintf("<verbatim>\n%s</verbatim>\n\n"._("Describe %s here."),
1627 $quote, "[" . WikiEscape($this->_pagename) . "]");
1629 // Replace empty content with default value.
1630 return sprintf(_("Describe %s here."),
1631 "[" . WikiEscape($this->_pagename) . "]");
1634 // There is (non-default) content.
1635 assert($this->_version > 0);
1637 if (!is_string($data['%content'])) {
1638 // Content was not provided to us at init time.
1639 // (This is allowed because for some backends, fetching
1640 // the content may be expensive, and often is not wanted
1643 // In any case, now we need to get it.
1644 $data['%content'] = $this->_get_content();
1645 assert(is_string($data['%content']));
1648 return $data['%content'];
1651 function _get_content() {
1652 $cache = &$this->_wikidb->_cache;
1653 $pagename = $this->_pagename;
1654 $version = $this->_version;
1656 assert($version > 0);
1658 $newdata = $cache->get_versiondata($pagename, $version, true);
1660 assert(is_string($newdata['%content']));
1661 return $newdata['%content'];
1664 // else revision has been deleted... What to do?
1665 return __sprintf("Oops! Revision %s of %s seems to have been deleted!",
1666 $version, $pagename);
1671 * Get meta-data for this revision.
1676 * @param string $key Which meta-data to access.
1678 * Some reserved revision meta-data keys are:
1680 * <dt> 'mtime' <dd> Time this revision was created (seconds since midnight Jan 1, 1970.)
1681 * The 'mtime' meta-value is normally set automatically by the database
1682 * backend, but it may be specified explicitly when creating a new revision.
1684 * <dd> To ensure consistency of RecentChanges, the mtimes of the versions
1685 * of a page must be monotonically increasing. If an attempt is
1686 * made to create a new revision with an mtime less than that of
1687 * the preceeding revision, the new revisions timestamp is force
1688 * to be equal to that of the preceeding revision. In that case,
1689 * the originally requested mtime is preserved in 'orig_mtime'.
1690 * <dt> '_supplanted' <dd> Time this revision ceased to be the most recent.
1691 * This meta-value is <em>always</em> automatically maintained by the database
1692 * backend. (It is set from the 'mtime' meta-value of the superceding
1693 * revision.) '_supplanted' has a value of 'false' for the current revision.
1695 * FIXME: this could be refactored:
1697 * <dd> Author of the page (as he should be reported in, e.g. RecentChanges.)
1699 * <dd> Authenticated author of a page. This is used to identify
1700 * the distinctness of authors when cleaning old revisions from
1702 * <dt> 'is_minor_edit' <dd> Set if change was marked as a minor revision by the author.
1703 * <dt> 'summary' <dd> Short change summary entered by page author.
1706 * Meta-data keys must be valid C identifers (they have to start with a letter
1707 * or underscore, and can contain only alphanumerics and underscores.)
1709 * @return string The requested value, or false if the requested value
1712 function get($key) {
1713 if (!$key || $key[0] == '%')
1715 $data = &$this->_data;
1716 return isset($data[$key]) ? $data[$key] : false;
1720 * Get all the revision page meta-data as a hash.
1722 * @return hash The revision meta-data.
1724 function getMetaData() {
1726 foreach ($this->_data as $key => $val) {
1727 if (!empty($val) && $key[0] != '%')
1735 * Return a string representation of the revision.
1737 * This is really only for debugging.
1741 * @return string Printable representation of the WikiDB_Page.
1743 function asString () {
1745 printf("[%s:%d\n", get_class($this), $this->get('version'));
1746 print_r($this->_data);
1747 echo $this->getPackedContent() . "\n]\n";
1748 $strval = ob_get_contents();
1756 * Class representing a sequence of WikiDB_Pages.
1757 * TODO: Enhance to php5 iterators
1759 * apply filters for options like 'sortby', 'limit', 'exclude'
1760 * for simple queries like titleSearch, where the backend is not ready yet.
1762 class WikiDB_PageIterator
1764 function WikiDB_PageIterator(&$wikidb, &$iter, $options=false) {
1765 $this->_iter = $iter; // a WikiDB_backend_iterator
1766 $this->_wikidb = &$wikidb;
1767 $this->_options = $options;
1771 return $this->_iter->count();
1775 * Get next WikiDB_Page in sequence.
1779 * @return WikiDB_Page The next WikiDB_Page in the sequence.
1782 if ( ! ($next = $this->_iter->next()) )
1785 $pagename = &$next['pagename'];
1787 trigger_error('empty pagename in WikiDB_PageIterator::next()', E_USER_WARNING);
1791 // there's always hits, but we cache only if more
1792 // (well not with file, cvs and dba)
1793 if (isset($next['pagedata']) and count($next['pagedata']) > 1) {
1794 $this->_wikidb->_cache->cache_data($next);
1795 // cache existing page id's since we iterate over all links in GleanDescription
1796 // and need them later for LinkExistingWord
1797 } elseif ($this->_options and array_key_exists('include_empty', $this->_options)
1798 and !$this->_options['include_empty'] and isset($next['id'])) {
1799 $this->_wikidb->_cache->_id_cache[$next['pagename']] = $next['id'];
1801 return new WikiDB_Page($this->_wikidb, $pagename);
1805 * Release resources held by this iterator.
1807 * The iterator may not be used after free() is called.
1809 * There is no need to call free(), if next() has returned false.
1810 * (I.e. if you iterate through all the pages in the sequence,
1811 * you do not need to call free() --- you only need to call it
1812 * if you stop before the end of the iterator is reached.)
1817 $this->_iter->free();
1820 function asArray() {
1822 while ($page = $this->next())
1829 * Apply filters for options like 'sortby', 'limit', 'exclude'
1830 * for simple queries like titleSearch, where the backend is not ready yet.
1831 * Since iteration is usually destructive for SQL results,
1832 * we have to generate a copy.
1834 function applyFilters($options = false) {
1835 if (!$options) $options = $this->_options;
1836 if (isset($options['sortby'])) {
1838 /* this is destructive */
1839 while ($page = $this->next())
1840 $result[] = $page->getName();
1841 $this->_doSort($array, $options['sortby']);
1843 /* the rest is not destructive.
1844 * reconstruct a new iterator
1846 $pagenames = array(); $i = 0;
1847 if (isset($options['limit']))
1848 $limit = $options['limit'];
1851 if (isset($options['exclude']))
1852 $exclude = $options['exclude'];
1853 if (is_string($exclude) and !is_array($exclude))
1854 $exclude = PageList::explodePageList($exclude, false, false, $limit);
1855 foreach($array as $pagename) {
1856 if ($limit and $i++ > $limit)
1857 return new WikiDB_Array_PageIterator($pagenames);
1858 if (!empty($exclude) and !in_array($pagename, $exclude))
1859 $pagenames[] = $pagename;
1860 elseif (empty($exclude))
1861 $pagenames[] = $pagename;
1863 return new WikiDB_Array_PageIterator($pagenames);
1867 function _doSort(&$array, $sortby) {
1868 $sortby = PageList::sortby($sortby, 'init');
1869 if ($sortby == '+pagename')
1870 sort($array, SORT_STRING);
1871 elseif ($sortby == '-pagename')
1872 rsort($array, SORT_STRING);
1879 * A class which represents a sequence of WikiDB_PageRevisions.
1880 * TODO: Enhance to php5 iterators
1882 class WikiDB_PageRevisionIterator
1884 function WikiDB_PageRevisionIterator(&$wikidb, &$revisions, $options=false) {
1885 $this->_revisions = $revisions;
1886 $this->_wikidb = &$wikidb;
1887 $this->_options = $options;
1891 return $this->_revisions->count();
1895 * Get next WikiDB_PageRevision in sequence.
1899 * @return WikiDB_PageRevision
1900 * The next WikiDB_PageRevision in the sequence.
1903 if ( ! ($next = $this->_revisions->next()) )
1906 //$this->_wikidb->_cache->cache_data($next);
1908 $pagename = $next['pagename'];
1909 $version = $next['version'];
1910 $versiondata = $next['versiondata'];
1912 if (!(is_string($pagename) and $pagename != '')) {
1913 trigger_error("empty pagename",E_USER_WARNING);
1916 } else assert(is_string($pagename) and $pagename != '');
1918 if (!is_array($versiondata)) {
1919 trigger_error("empty versiondata",E_USER_WARNING);
1922 } else assert(is_array($versiondata));
1924 if (!($version > 0)) {
1925 trigger_error("invalid version",E_USER_WARNING);
1928 } else assert($version > 0);
1930 return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
1935 * Release resources held by this iterator.
1937 * The iterator may not be used after free() is called.
1939 * There is no need to call free(), if next() has returned false.
1940 * (I.e. if you iterate through all the revisions in the sequence,
1941 * you do not need to call free() --- you only need to call it
1942 * if you stop before the end of the iterator is reached.)
1947 $this->_revisions->free();
1950 function asArray() {
1952 while ($rev = $this->next())
1961 class WikiDB_Array_PageIterator
1963 function WikiDB_Array_PageIterator($pagenames) {
1965 $this->_dbi = $request->getDbh();
1966 $this->_pages = $pagenames;
1967 reset($this->_pages);
1970 $c =& current($this->_pages);
1971 next($this->_pages);
1972 return $c !== false ? $this->_dbi->getPage($c) : false;
1975 return count($this->_pages);
1978 function asArray() {
1979 reset($this->_pages);
1980 return $this->_pages;
1984 class WikiDB_Array_generic_iter
1986 function WikiDB_Array_generic_iter($result) {
1987 // $result may be either an array or a query result
1988 if (is_array($result)) {
1989 $this->_array = $result;
1990 } elseif (is_object($result)) {
1991 $this->_array = $result->asArray();
1993 $this->_array = array();
1995 if (!empty($this->_array))
1996 reset($this->_array);
1999 $c =& current($this->_array);
2000 next($this->_array);
2001 return $c !== false ? $c : false;
2004 return count($this->_array);
2007 function asArray() {
2008 if (!empty($this->_array))
2009 reset($this->_array);
2010 return $this->_array;
2015 * Data cache used by WikiDB.
2017 * FIXME: Maybe rename this to caching_backend (or some such).
2023 // FIXME: beautify versiondata cache. Cache only limited data?
2025 function WikiDB_cache (&$backend) {
2026 $this->_backend = &$backend;
2028 $this->_pagedata_cache = array();
2029 $this->_versiondata_cache = array();
2030 array_push ($this->_versiondata_cache, array());
2031 $this->_glv_cache = array();
2032 $this->_id_cache = array(); // formerly ->_dbi->_iwpcache (nonempty pages => id)
2036 $this->_pagedata_cache = array();
2037 $this->_versiondata_cache = array();
2038 $this->_glv_cache = array();
2039 $this->_id_cache = array();
2042 function get_pagedata($pagename) {
2043 assert(is_string($pagename) && $pagename != '');
2045 $cache = &$this->_pagedata_cache;
2046 if (!isset($cache[$pagename]) || !is_array($cache[$pagename])) {
2047 $cache[$pagename] = $this->_backend->get_pagedata($pagename);
2048 if (empty($cache[$pagename]))
2049 $cache[$pagename] = array();
2051 return $cache[$pagename];
2053 return $this->_backend->get_pagedata($pagename);
2057 function update_pagedata($pagename, $newdata) {
2058 assert(is_string($pagename) && $pagename != '');
2060 $this->_backend->update_pagedata($pagename, $newdata);
2063 if (!empty($this->_pagedata_cache[$pagename])
2064 and is_array($this->_pagedata_cache[$pagename]))
2066 $cachedata = &$this->_pagedata_cache[$pagename];
2067 foreach($newdata as $key => $val)
2068 $cachedata[$key] = $val;
2070 $this->_pagedata_cache[$pagename] = $newdata;
2074 function invalidate_cache($pagename) {
2075 unset ($this->_pagedata_cache[$pagename]);
2076 unset ($this->_versiondata_cache[$pagename]);
2077 unset ($this->_glv_cache[$pagename]);
2078 unset ($this->_id_cache[$pagename]);
2079 //unset ($this->_backend->_page_data);
2082 function delete_page($pagename) {
2083 $result = $this->_backend->delete_page($pagename);
2084 $this->invalidate_cache($pagename);
2088 function purge_page($pagename) {
2089 $result = $this->_backend->purge_page($pagename);
2090 $this->invalidate_cache($pagename);
2094 // FIXME: ugly and wrong. may overwrite full cache with partial cache
2095 function cache_data($data) {
2097 //if (isset($data['pagedata']))
2098 // $this->_pagedata_cache[$data['pagename']] = $data['pagedata'];
2101 function get_versiondata($pagename, $version, $need_content = false) {
2102 // FIXME: Seriously ugly hackage
2104 if (USECACHE) { //temporary - for debugging
2105 assert(is_string($pagename) && $pagename != '');
2106 // There is a bug here somewhere which results in an assertion failure at line 105
2107 // of ArchiveCleaner.php It goes away if we use the next line.
2108 //$need_content = true;
2109 $nc = $need_content ? '1':'0';
2110 $cache = &$this->_versiondata_cache;
2111 if (!isset($cache[$pagename][$version][$nc])
2112 || !(is_array ($cache[$pagename]))
2113 || !(is_array ($cache[$pagename][$version])))
2115 $cache[$pagename][$version][$nc] =
2116 $this->_backend->get_versiondata($pagename, $version, $need_content);
2118 // If we have retrieved all data, we may as well set the cache for
2119 // $need_content = false
2121 $cache[$pagename][$version]['0'] =& $cache[$pagename][$version]['1'];
2124 $vdata = $cache[$pagename][$version][$nc];
2126 $vdata = $this->_backend->get_versiondata($pagename, $version, $need_content);
2129 if ($readdata && $vdata && !empty($vdata['%pagedata'])) {
2130 $this->_pagedata_cache[$pagename] =& $vdata['%pagedata'];
2135 function set_versiondata($pagename, $version, $data) {
2136 //unset($this->_versiondata_cache[$pagename][$version]);
2138 $new = $this->_backend->set_versiondata($pagename, $version, $data);
2140 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
2141 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
2142 // Is this necessary?
2143 unset($this->_glv_cache[$pagename]);
2146 function update_versiondata($pagename, $version, $data) {
2147 $new = $this->_backend->update_versiondata($pagename, $version, $data);
2149 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
2151 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
2152 // Is this necessary?
2153 unset($this->_glv_cache[$pagename]);
2156 function delete_versiondata($pagename, $version) {
2157 $new = $this->_backend->delete_versiondata($pagename, $version);
2158 if (isset($this->_versiondata_cache[$pagename][$version]))
2159 unset ($this->_versiondata_cache[$pagename][$version]);
2160 // dirty latest version cache only if latest version gets deleted
2161 if (isset($this->_glv_cache[$pagename]) and $this->_glv_cache[$pagename] == $version)
2162 unset ($this->_glv_cache[$pagename]);
2165 function get_latest_version($pagename) {
2167 assert (is_string($pagename) && $pagename != '');
2168 $cache = &$this->_glv_cache;
2169 if (!isset($cache[$pagename])) {
2170 $cache[$pagename] = $this->_backend->get_latest_version($pagename);
2171 if (empty($cache[$pagename]))
2172 $cache[$pagename] = 0;
2174 return $cache[$pagename];
2176 return $this->_backend->get_latest_version($pagename);
2181 function _sql_debuglog($msg, $newline=true, $shutdown=false) {
2185 $stamp = strftime("%y%m%d-%H%M%S");
2186 $fp = fopen("/tmp/sql-$stamp.log", "a");
2187 register_shutdown_function("_sql_debuglog_shutdown_function");
2188 } elseif ($shutdown) {
2192 if ($newline) fputs($fp, "[$i++] $msg");
2193 else fwrite($fp, $msg);
2196 function _sql_debuglog_shutdown_function() {
2197 _sql_debuglog('',false,true);
2200 // $Log: not supported by cvs2svn $
2201 // Revision 1.136 2005/10/03 16:14:57 rurban
2202 // improve description
2204 // Revision 1.135 2005/09/11 14:19:44 rurban
2205 // enable LIMIT support for fulltext search
2207 // Revision 1.134 2005/09/10 21:28:10 rurban
2208 // applyFilters hack to use filters after methods, which do not support them (titleSearch)
2210 // Revision 1.133 2005/08/27 09:39:10 rurban
2211 // dumphtml when not at admin page: dump the current or given page
2213 // Revision 1.132 2005/08/07 10:10:07 rurban
2214 // clean whole version cache
2216 // Revision 1.131 2005/04/23 11:30:12 rurban
2217 // allow emtpy WikiDB::getRevisionBefore(), for simplier templates (revert)
2219 // Revision 1.130 2005/04/06 06:19:30 rurban
2220 // Revert the previous wrong bugfix #1175761: USECACHE was mixed with WIKIDB_NOCACHE_MARKUP.
2221 // Fix WIKIDB_NOCACHE_MARKUP in main (always set it) and clarify it in WikiDB
2223 // Revision 1.129 2005/04/06 05:50:29 rurban
2224 // honor !USECACHE for _cached_html, fixes #1175761
2226 // Revision 1.128 2005/04/01 16:11:42 rurban
2229 // Revision 1.127 2005/02/18 20:43:40 uckelman
2230 // WikiDB::genericWarnings() is no longer used.
2232 // Revision 1.126 2005/02/04 17:58:06 rurban
2233 // minor versioncache improvement. part 2/3 of Charles Corrigan cache patch. not sure about the 0/1 issue
2235 // Revision 1.125 2005/02/03 05:08:39 rurban
2236 // ref fix by Charles Corrigan
2238 // Revision 1.124 2005/01/29 20:43:32 rurban
2239 // protect against empty request: on some occasion this happens
2241 // Revision 1.123 2005/01/25 06:58:21 rurban
2244 // Revision 1.122 2005/01/20 10:18:17 rurban
2247 // Revision 1.121 2005/01/04 20:25:01 rurban
2248 // remove old [%pagedata][_cached_html] code
2250 // Revision 1.120 2004/12/23 14:12:31 rurban
2251 // dont email on unittest
2253 // Revision 1.119 2004/12/20 16:05:00 rurban
2254 // gettext msg unification
2256 // Revision 1.118 2004/12/13 13:22:57 rurban
2257 // new BlogArchives plugin for the new blog theme. enable default box method
2258 // for all plugins. Minor search improvement.
2260 // Revision 1.117 2004/12/13 08:15:09 rurban
2261 // false is wrong. null might be better but lets play safe.
2263 // Revision 1.116 2004/12/10 22:15:00 rurban
2264 // fix $page->get('_cached_html)
2265 // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also.
2266 // support 2nd genericSqlQuery param (bind huge arg)
2268 // Revision 1.115 2004/12/10 02:45:27 rurban
2269 // SQL optimization:
2270 // put _cached_html from pagedata into a new seperate blob, not huge serialized string.
2271 // it is only rarelely needed: for current page only, if-not-modified
2272 // but was extracted for every simple page iteration.
2274 // Revision 1.114 2004/12/09 22:24:44 rurban
2275 // optimize on _DEBUG_SQL only. but now again on every 50th request, not just save.
2277 // Revision 1.113 2004/12/06 19:49:55 rurban
2278 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
2279 // renamed delete_page to purge_page.
2280 // enable action=edit&version=-1 to force creation of a new version.
2281 // added BABYCART_PATH config
2282 // fixed magiqc in adodb.inc.php
2283 // and some more docs
2285 // Revision 1.112 2004/11/30 17:45:53 rurban
2286 // exists_links backend implementation
2288 // Revision 1.111 2004/11/28 20:39:43 rurban
2289 // deactivate pagecache overwrite: it is wrong
2291 // Revision 1.110 2004/11/26 18:39:01 rurban
2292 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
2294 // Revision 1.109 2004/11/25 17:20:50 rurban
2295 // and again a couple of more native db args: backlinks
2297 // Revision 1.108 2004/11/23 13:35:31 rurban
2298 // add case_exact search
2300 // Revision 1.107 2004/11/21 11:59:16 rurban
2301 // remove final \n to be ob_cache independent
2303 // Revision 1.106 2004/11/20 17:35:56 rurban
2304 // improved WantedPages SQL backends
2305 // PageList::sortby new 3rd arg valid_fields (override db fields)
2306 // WantedPages sql pager inexact for performance reasons:
2307 // assume 3 wantedfrom per page, to be correct, no getTotal()
2308 // support exclude argument for get_all_pages, new _sql_set()
2310 // Revision 1.105 2004/11/20 09:16:27 rurban
2311 // Fix bad-style Cut&Paste programming errors, detected by Charles Corrigan.
2313 // Revision 1.104 2004/11/19 19:22:03 rurban
2314 // ModeratePage part1: change status
2316 // Revision 1.103 2004/11/16 17:29:04 rurban
2317 // fix remove notification error
2318 // fix creation + update id_cache update
2320 // Revision 1.102 2004/11/11 18:31:26 rurban
2321 // add simple backtrace on such general failures to get at least an idea where
2323 // Revision 1.101 2004/11/10 19:32:22 rurban
2324 // * optimize increaseHitCount, esp. for mysql.
2325 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
2326 // * Pear_DB version logic (awful but needed)
2327 // * fix broken ADODB quote
2328 // * _extract_page_data simplification
2330 // Revision 1.100 2004/11/10 15:29:20 rurban
2331 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
2332 // * ACCESS_LOG_SQL: fix cause request not yet initialized
2333 // * WikiDB: moved SQL specific methods upwards
2334 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
2335 // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
2337 // Revision 1.99 2004/11/09 17:11:05 rurban
2338 // * revert to the wikidb ref passing. there's no memory abuse there.
2339 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
2340 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
2341 // are also needed at the rendering for linkExistingWikiWord().
2342 // pass options to pageiterator.
2343 // use this cache also for _get_pageid()
2344 // This saves about 8 SELECT count per page (num all pagelinks).
2345 // * fix passing of all page fields to the pageiterator.
2346 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
2348 // Revision 1.98 2004/11/07 18:34:29 rurban
2349 // more logging fixes
2351 // Revision 1.97 2004/11/07 16:02:51 rurban
2352 // new sql access log (for spam prevention), and restructured access log class
2353 // dbh->quote (generic)
2354 // pear_db: mysql specific parts seperated (using replace)
2356 // Revision 1.96 2004/11/05 22:32:15 rurban
2357 // encode the subject to be 7-bit safe
2359 // Revision 1.95 2004/11/05 20:53:35 rurban
2360 // login cleanup: better debug msg on failing login,
2361 // checked password less immediate login (bogo or anon),
2362 // checked olduser pref session error,
2363 // better PersonalPage without password warning on minimal password length=0
2364 // (which is default now)
2366 // Revision 1.94 2004/11/01 10:43:56 rurban
2367 // seperate PassUser methods into seperate dir (memory usage)
2368 // fix WikiUser (old) overlarge data session
2369 // remove wikidb arg from various page class methods, use global ->_dbi instead
2372 // Revision 1.93 2004/10/14 17:17:57 rurban
2373 // remove dbi WikiDB_Page param: use global request object instead. (memory)
2374 // allow most_popular sortby arguments
2376 // Revision 1.92 2004/10/05 17:00:04 rurban
2377 // support paging for simple lists
2378 // fix RatingDb sql backend.
2379 // remove pages from AllPages (this is ListPages then)
2381 // Revision 1.91 2004/10/04 23:41:19 rurban
2382 // delete notify: fix, @unset syntax error
2384 // Revision 1.90 2004/09/28 12:50:22 rurban
2385 // https://sourceforge.net/forum/forum.php?thread_id=1150924&forum_id=18929
2387 // Revision 1.89 2004/09/26 10:54:42 rurban
2388 // silence deferred check
2390 // Revision 1.88 2004/09/25 18:16:40 rurban
2391 // unset more unneeded _cached_html. (Guess this should fix sf.net now)
2393 // Revision 1.87 2004/09/25 16:25:40 rurban
2394 // notify on rename and remove (to be improved)
2396 // Revision 1.86 2004/09/23 18:52:06 rurban
2397 // only fortune at create
2399 // Revision 1.85 2004/09/16 08:00:51 rurban
2400 // just some comments
2402 // Revision 1.84 2004/09/14 10:34:30 rurban
2403 // fix TransformedText call to use refs
2405 // Revision 1.83 2004/09/08 13:38:00 rurban
2406 // improve loadfile stability by using markup=2 as default for undefined markup-style.
2407 // use more refs for huge objects.
2408 // fix debug=static issue in WikiPluginCached
2410 // Revision 1.82 2004/09/06 12:08:49 rurban
2411 // memory_limit on unix workaround
2412 // VisualWiki: default autosize image
2414 // Revision 1.81 2004/09/06 08:28:00 rurban
2415 // rename genericQuery to genericSqlQuery
2417 // Revision 1.80 2004/07/09 13:05:34 rurban
2420 // Revision 1.79 2004/07/09 10:06:49 rurban
2421 // Use backend specific sortby and sortable_columns method, to be able to
2422 // select between native (Db backend) and custom (PageList) sorting.
2423 // Fixed PageList::AddPageList (missed the first)
2424 // Added the author/creator.. name to AllPagesBy...
2425 // display no pages if none matched.
2426 // Improved dba and file sortby().
2427 // Use &$request reference
2429 // Revision 1.78 2004/07/08 21:32:35 rurban
2430 // Prevent from more warnings, minor db and sort optimizations
2432 // Revision 1.77 2004/07/08 19:04:42 rurban
2433 // more unittest fixes (file backend, metadata RatingsDb)
2435 // Revision 1.76 2004/07/08 17:31:43 rurban
2436 // improve numPages for file (fixing AllPagesTest)
2438 // Revision 1.75 2004/07/05 13:56:22 rurban
2439 // sqlite autoincrement fix
2441 // Revision 1.74 2004/07/03 16:51:05 rurban
2442 // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
2443 // added atomic mysql REPLACE for PearDB as in ADODB
2444 // fixed _lock_tables typo links => link
2445 // fixes unserialize ADODB bug in line 180
2447 // Revision 1.73 2004/06/29 08:52:22 rurban
2448 // Use ...version() $need_content argument in WikiDB also:
2449 // To reduce the memory footprint for larger sets of pagelists,
2450 // we don't cache the content (only true or false) and
2451 // we purge the pagedata (_cached_html) also.
2452 // _cached_html is only cached for the current pagename.
2453 // => Vastly improved page existance check, ACL check, ...
2455 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
2457 // Revision 1.72 2004/06/25 14:15:08 rurban
2458 // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
2460 // Revision 1.71 2004/06/21 16:22:30 rurban
2461 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
2462 // fixed dumping buttons locally (images/buttons/),
2463 // support pages arg for dumphtml,
2464 // optional directory arg for dumpserial + dumphtml,
2465 // fix a AllPages warning,
2466 // show dump warnings/errors on DEBUG,
2467 // don't warn just ignore on wikilens pagelist columns, if not loaded.
2468 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
2470 // Revision 1.70 2004/06/18 14:39:31 rurban
2471 // actually check USECACHE
2473 // Revision 1.69 2004/06/13 15:33:20 rurban
2474 // new support for arguments owner, author, creator in most relevant
2475 // PageList plugins. in WikiAdmin* via preSelectS()
2477 // Revision 1.68 2004/06/08 21:03:20 rurban
2478 // updated RssParser for XmlParser quirks (store parser object params in globals)
2480 // Revision 1.67 2004/06/07 19:12:49 rurban
2481 // fixed rename version=0, bug #966284
2483 // Revision 1.66 2004/06/07 18:57:27 rurban
2484 // fix rename: Change pagename in all linked pages
2486 // Revision 1.65 2004/06/04 20:32:53 rurban
2487 // Several locale related improvements suggested by Pierrick Meignen
2488 // LDAP fix by John Cole
2489 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
2491 // Revision 1.64 2004/06/04 16:50:00 rurban
2492 // add random quotes to empty pages
2494 // Revision 1.63 2004/06/04 11:58:38 rurban
2495 // added USE_TAGLINES
2497 // Revision 1.62 2004/06/03 22:24:41 rurban
2498 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
2500 // Revision 1.61 2004/06/02 17:13:48 rurban
2501 // fix getRevisionBefore assertion
2503 // Revision 1.60 2004/05/28 10:09:58 rurban
2504 // fix bug #962117, incorrect init of auth_dsn
2506 // Revision 1.59 2004/05/27 17:49:05 rurban
2507 // renamed DB_Session to DbSession (in CVS also)
2508 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
2509 // remove leading slash in error message
2510 // added force_unlock parameter to File_Passwd (no return on stale locks)
2511 // fixed adodb session AffectedRows
2512 // added FileFinder helpers to unify local filenames and DATA_PATH names
2513 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
2515 // Revision 1.58 2004/05/18 13:59:14 rurban
2516 // rename simpleQuery to genericQuery
2518 // Revision 1.57 2004/05/16 22:07:35 rurban
2519 // check more config-default and predefined constants
2520 // various PagePerm fixes:
2521 // fix default PagePerms, esp. edit and view for Bogo and Password users
2522 // implemented Creator and Owner
2523 // BOGOUSERS renamed to BOGOUSER
2524 // fixed syntax errors in signin.tmpl
2526 // Revision 1.56 2004/05/15 22:54:49 rurban
2527 // fixed important WikiDB bug with DEBUG > 0: wrong assertion
2528 // improved SetAcl (works) and PagePerms, some WikiGroup helpers.
2530 // Revision 1.55 2004/05/12 19:27:47 rurban
2531 // revert wrong inline optimization.
2533 // Revision 1.54 2004/05/12 10:49:55 rurban
2534 // require_once fix for those libs which are loaded before FileFinder and
2535 // its automatic include_path fix, and where require_once doesn't grok
2536 // dirname(__FILE__) != './lib'
2537 // upgrade fix with PearDB
2538 // navbar.tmpl: remove spaces for IE button alignment
2540 // Revision 1.53 2004/05/08 14:06:12 rurban
2541 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
2542 // minor stability and portability fixes
2544 // Revision 1.52 2004/05/06 19:26:16 rurban
2545 // improve stability, trying to find the InlineParser endless loop on sf.net
2547 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
2549 // Revision 1.51 2004/05/06 17:30:37 rurban
2550 // CategoryGroup: oops, dos2unix eol
2551 // improved phpwiki_version:
2552 // pre -= .0001 (1.3.10pre: 1030.099)
2553 // -p1 += .001 (1.3.9-p1: 1030.091)
2554 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
2555 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
2556 // backend->backendType(), backend->database(),
2557 // backend->listOfFields(),
2558 // backend->listOfTables(),
2560 // Revision 1.50 2004/05/04 22:34:25 rurban
2563 // Revision 1.49 2004/05/03 11:16:40 rurban
2564 // fixed sendPageChangeNotification
2565 // subject rewording
2567 // Revision 1.48 2004/04/29 23:03:54 rurban
2568 // fixed sf.net bug #940996
2570 // Revision 1.47 2004/04/29 19:39:44 rurban
2571 // special support for formatted plugins (one-liners)
2572 // like <small><plugin BlaBla ></small>
2573 // iter->asArray() helper for PopularNearby
2574 // db_session for older php's (no &func() allowed)
2576 // Revision 1.46 2004/04/26 20:44:34 rurban
2577 // locking table specific for better databases
2579 // Revision 1.45 2004/04/20 00:06:03 rurban
2580 // themable paging support
2582 // Revision 1.44 2004/04/19 18:27:45 rurban
2583 // Prevent from some PHP5 warnings (ref args, no :: object init)
2584 // php5 runs now through, just one wrong XmlElement object init missing
2585 // Removed unneccesary UpgradeUser lines
2586 // Changed WikiLink to omit version if current (RecentChanges)
2588 // Revision 1.43 2004/04/18 01:34:20 rurban
2589 // protect most_popular from sortby=mtime
2591 // Revision 1.42 2004/04/18 01:11:51 rurban
2592 // more numeric pagename fixes.
2593 // fixed action=upload with merge conflict warnings.
2594 // charset changed from constant to global (dynamic utf-8 switching)
2600 // c-basic-offset: 4
2601 // c-hanging-comment-ender-p: nil
2602 // indent-tabs-mode: nil