2 rcs_id('$Id: WikiDB.php,v 1.143 2006-09-06 05:46:40 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)
126 if (DEBUG || _DEBUG_SQL)
127 $this->_backend->check();
131 * Close database connection.
133 * The database may no longer be used after it is closed.
135 * Closing a WikiDB invalidates all <tt>WikiDB_Page</tt>s,
136 * <tt>WikiDB_PageRevision</tt>s and <tt>WikiDB_PageIterator</tt>s
137 * which have been obtained from it.
142 $this->_backend->close();
143 $this->_cache->close();
147 * Get a WikiDB_Page from a WikiDB.
149 * A {@link WikiDB} consists of the (infinite) set of all possible pages,
150 * therefore this method never fails.
153 * @param string $pagename Which page to get.
154 * @return WikiDB_Page The requested WikiDB_Page.
156 function getPage($pagename) {
157 static $error_displayed = false;
158 $pagename = (string) $pagename;
160 if ($pagename === '') {
161 if ($error_displayed) return false;
162 $error_displayed = true;
163 if (function_exists("xdebug_get_function_stack"))
164 var_dump(xdebug_get_function_stack());
165 trigger_error("empty pagename", E_USER_WARNING);
169 assert($pagename != '');
171 return new WikiDB_Page($this, $pagename);
175 * Determine whether page exists (in non-default form).
178 * $is_page = $dbi->isWikiPage($pagename);
182 * $page = $dbi->getPage($pagename);
183 * $current = $page->getCurrentRevision();
184 * $is_page = ! $current->hasDefaultContents();
186 * however isWikiPage may be implemented in a more efficient
187 * manner in certain back-ends.
191 * @param string $pagename string Which page to check.
193 * @return boolean True if the page actually exists with
194 * non-default contents in the WikiDataBase.
196 function isWikiPage ($pagename) {
197 $page = $this->getPage($pagename);
198 return $page->exists();
202 * Delete page from the WikiDB.
204 * Deletes the page from the WikiDB with the possibility to revert and diff.
205 * //Also resets all page meta-data to the default values.
207 * Note: purgePage() effectively destroys all revisions of the page from the WikiDB.
211 * @param string $pagename Name of page to delete.
213 function deletePage($pagename) {
214 // don't create empty revisions of already purged pages.
215 if ($this->_backend->get_latest_version($pagename))
216 $result = $this->_cache->delete_page($pagename);
220 /* Generate notification emails? */
221 if (! $this->isWikiPage($pagename) and !isa($GLOBALS['request'],'MockRequest')) {
222 $notify = $this->get('notify');
223 if (!empty($notify) and is_array($notify)) {
225 //TODO: deferr it (quite a massive load if you remove some pages).
226 //TODO: notification class which catches all changes,
227 // and decides at the end of the request what to mail.
228 // (type, page, who, what, users, emails)
229 // could be used for PageModeration and RSS2 Cloud xml-rpc also.
230 $page = new WikiDB_Page($this, $pagename);
231 list($emails, $userids) = $page->getPageChangeEmails($notify);
232 if (!empty($emails)) {
233 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
234 $editedby = sprintf(_("Removed by: %s"), $from);
235 $emails = join(',', $emails);
236 $subject = sprintf(_("Page removed %s"), urlencode($pagename));
237 if (mail("<undisclosed-recipients>","[".WIKI_NAME."] ".$subject,
241 "From: $from\r\nBcc: $emails"))
242 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
243 $pagename, join(',',$userids)), E_USER_NOTICE);
245 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
246 $pagename, join(',',$userids)), E_USER_WARNING);
251 //How to create a RecentChanges entry with explaining summary? Dynamically
253 $page = $this->getPage($pagename);
254 $current = $page->getCurrentRevision();
255 $meta = $current->_data;
256 $version = $current->getVersion();
257 $meta['summary'] = _("removed");
258 $page->save($current->getPackedContent(), $version + 1, $meta);
264 * Completely remove the page from the WikiDB, without undo possibility.
266 function purgePage($pagename) {
267 $result = $this->_cache->purge_page($pagename);
268 $this->deletePage($pagename); // just for the notification
273 * Retrieve all pages.
275 * Gets the set of all pages with non-default contents.
279 * @param boolean $include_defaulted Normally pages whose most
280 * recent revision has empty content are considered to be
281 * non-existant. Unless $include_defaulted is set to true, those
282 * pages will not be returned.
284 * @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages
285 * in the WikiDB which have non-default contents.
287 function getAllPages($include_empty=false, $sortby=false, $limit=false,
290 // HACK: memory_limit=8M will fail on too large pagesets. old php on unix only!
292 $mem = ini_get("memory_limit");
293 if ($mem and !$limit and !isWindows() and !check_php_version(4,3)) {
295 $GLOBALS['request']->setArg('limit', $limit);
296 $GLOBALS['request']->setArg('paging', 'auto');
299 $result = $this->_backend->get_all_pages($include_empty, $sortby, $limit,
301 return new WikiDB_PageIterator($this, $result,
302 array('include_empty' => $include_empty,
303 'exclude' => $exclude,
308 * $include_empty = true: include also empty pages
309 * exclude: comma-seperated list pagenames: TBD: array of pagenames
311 function numPages($include_empty=false, $exclude='') {
312 if (method_exists($this->_backend, 'numPages'))
313 // FIXME: currently are all args ignored.
314 $count = $this->_backend->numPages($include_empty, $exclude);
316 // FIXME: exclude ignored.
317 $iter = $this->getAllPages($include_empty, false, false, $exclude);
318 $count = $iter->count();
327 * Search for pages containing (or not containing) certain words
330 * Pages are returned in alphabetical order whenever it is
331 * practical to do so.
333 * FIXME: clarify $search syntax. provide glob=>TextSearchQuery converters
336 * @param TextSearchQuery $search A TextSearchQuery object
337 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
338 * @see TextSearchQuery
340 function titleSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
341 $result = $this->_backend->text_search($search, false, $sortby, $limit, $exclude);
342 return new WikiDB_PageIterator($this, $result,
343 array('exclude' => $exclude,
350 * Search for pages containing (or not containing) certain words
351 * in their entire text (this includes the page content and the
354 * Pages are returned in alphabetical order whenever it is
355 * practical to do so.
359 * @param TextSearchQuery $search A TextSearchQuery object.
360 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
361 * @see TextSearchQuery
363 function fullSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
364 $result = $this->_backend->text_search($search, true, $sortby, $limit, $exclude);
365 return new WikiDB_PageIterator($this, $result,
366 array('exclude' => $exclude,
368 'stoplisted' => $result->stoplisted
373 * Find the pages with the greatest hit counts.
375 * Pages are returned in reverse order by hit count.
379 * @param integer $limit The maximum number of pages to return.
380 * Set $limit to zero to return all pages. If $limit < 0, pages will
381 * be sorted in decreasing order of popularity.
383 * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching
386 function mostPopular($limit = 20, $sortby = '-hits') {
387 $result = $this->_backend->most_popular($limit, $sortby);
388 return new WikiDB_PageIterator($this, $result);
392 * Find recent page revisions.
394 * Revisions are returned in reverse order by creation time.
398 * @param hash $params This hash is used to specify various optional
402 * <dd> (integer) At most this many revisions will be returned.
404 * <dd> (integer) Only revisions since this time (unix-timestamp) will be returned.
405 * <dt> include_minor_revisions
406 * <dd> (boolean) Also include minor revisions. (Default is not to.)
407 * <dt> exclude_major_revisions
408 * <dd> (boolean) Don't include non-minor revisions.
409 * (Exclude_major_revisions implies include_minor_revisions.)
410 * <dt> include_all_revisions
411 * <dd> (boolean) Return all matching revisions for each page.
412 * Normally only the most recent matching revision is returned
416 * @return WikiDB_PageRevisionIterator A WikiDB_PageRevisionIterator containing the
417 * matching revisions.
419 function mostRecent($params = false) {
420 $result = $this->_backend->most_recent($params);
421 return new WikiDB_PageRevisionIterator($this, $result);
427 * @return Iterator A generic iterator containing rows of (duplicate) pagename, wantedfrom.
429 function wantedPages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
430 return $this->_backend->wanted_pages($exclude_from, $exclude, $sortby, $limit);
431 //return new WikiDB_PageIterator($this, $result);
437 * @return array of pagename => linkrelation or just all related pages
439 function listRelations($sortby=false, $limit=false, $exclude=false) {
440 if (method_exists($this->_backend, "list_relations"))
441 return $this->_backend->list_relations($sortby, $limit, $exclude);
442 $iter = $this->getAllPages(false, false, false, $exclude);
443 while ($page = $iter->next()) {
444 $reliter = $page->getRelations();
446 while ($rel = $reliter->next()) {
447 $names[] = $rel->getName();
449 $relations = array_merge($relations, $names);
457 * Call the appropriate backend method.
460 * @param string $from Page to rename
461 * @param string $to New name
462 * @param boolean $updateWikiLinks If the text in all pages should be replaced.
463 * @return boolean true or false
465 function renamePage($from, $to, $updateWikiLinks = false) {
466 assert(is_string($from) && $from != '');
467 assert(is_string($to) && $to != '');
469 if (method_exists($this->_backend, 'rename_page')) {
470 $oldpage = $this->getPage($from);
471 $newpage = $this->getPage($to);
472 //update all WikiLinks in existing pages
473 //non-atomic! i.e. if rename fails the links are not undone
474 if ($updateWikiLinks) {
475 require_once('lib/plugin/WikiAdminSearchReplace.php');
476 $links = $oldpage->getBackLinks();
477 while ($linked_page = $links->next()) {
478 WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
479 $linked_page->getName(),
482 $links = $newpage->getBackLinks();
483 while ($linked_page = $links->next()) {
484 WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
485 $linked_page->getName(),
489 if ($oldpage->exists() and ! $newpage->exists()) {
490 if ($result = $this->_backend->rename_page($from, $to)) {
491 //create a RecentChanges entry with explaining summary
492 $page = $this->getPage($to);
493 $current = $page->getCurrentRevision();
494 $meta = $current->_data;
495 $version = $current->getVersion();
496 $meta['summary'] = sprintf(_("renamed from %s"), $from);
497 $page->save($current->getPackedContent(), $version + 1, $meta);
499 } elseif (!$oldpage->getCurrentRevision(false) and !$newpage->exists()) {
500 // if a version 0 exists try it also.
501 $result = $this->_backend->rename_page($from, $to);
504 trigger_error(_("WikiDB::renamePage() not yet implemented for this backend"),
507 /* Generate notification emails? */
508 if ($result and !isa($GLOBALS['request'], 'MockRequest')) {
509 $notify = $this->get('notify');
510 if (!empty($notify) and is_array($notify)) {
511 list($emails, $userids) = $oldpage->getPageChangeEmails($notify);
512 if (!empty($emails)) {
513 $oldpage->sendPageRenameNotification($to, $meta, $emails, $userids);
520 /** Get timestamp when database was last modified.
522 * @return string A string consisting of two integers,
523 * separated by a space. The first is the time in
524 * unix timestamp format, the second is a modification
525 * count for the database.
527 * The idea is that you can cast the return value to an
528 * int to get a timestamp, or you can use the string value
529 * as a good hash for the entire database.
531 function getTimestamp() {
532 $ts = $this->get('_timestamp');
533 return sprintf("%d %d", $ts[0], $ts[1]);
537 * Update the database timestamp.
541 $ts = $this->get('_timestamp');
542 $this->set('_timestamp', array(time(), $ts[1] + 1));
547 * Access WikiDB global meta-data.
549 * NOTE: this is currently implemented in a hackish and
550 * not very efficient manner.
554 * @param string $key Which meta data to get.
555 * Some reserved meta-data keys are:
557 * <dt>'_timestamp' <dd> Data used by getTimestamp().
560 * @return scalar The requested value, or false if the requested data
564 if (!$key || $key[0] == '%')
567 * Hack Alert: We can use any page (existing or not) to store
568 * this data (as long as we always use the same one.)
570 $gd = $this->getPage('global_data');
571 $data = $gd->get('__global');
573 if ($data && isset($data[$key]))
580 * Set global meta-data.
582 * NOTE: this is currently implemented in a hackish and
583 * not very efficient manner.
588 * @param string $key Meta-data key to set.
589 * @param string $newval New value.
591 function set($key, $newval) {
592 if (!$key || $key[0] == '%')
595 $gd = $this->getPage('global_data');
596 $data = $gd->get('__global');
603 $data[$key] = $newval;
605 $gd->set('__global', $data);
608 /* TODO: these are really backend methods */
610 // SQL result: for simple select or create/update queries
611 // returns the database specific resource type
612 function genericSqlQuery($sql, $args=false) {
613 if (function_exists('debug_backtrace')) { // >= 4.3.0
614 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
616 trigger_error("no SQL database", E_USER_ERROR);
620 // SQL iter: for simple select or create/update queries
621 // returns the generic iterator object (count,next)
622 function genericSqlIter($sql, $field_list = NULL) {
623 if (function_exists('debug_backtrace')) { // >= 4.3.0
624 echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
626 trigger_error("no SQL database", E_USER_ERROR);
630 // see backend upstream methods
631 // ADODB adds surrounding quotes, SQL not yet!
632 function quote ($s) {
638 if (!$request->_dbi) return false;
639 else return false; /* so far only needed for sql so false it.
640 later we have to check dba also */
643 function getParam($param) {
645 if (isset($DBParams[$param])) return $DBParams[$param];
646 elseif ($param == 'prefix') return '';
650 function getAuthParam($param) {
651 global $DBAuthParams;
652 if (isset($DBAuthParams[$param])) return $DBAuthParams[$param];
653 elseif ($param == 'USER_AUTH_ORDER') return $GLOBALS['USER_AUTH_ORDER'];
654 elseif ($param == 'USER_AUTH_POLICY') return $GLOBALS['USER_AUTH_POLICY'];
661 * An abstract base class which representing a wiki-page within a
664 * A WikiDB_Page contains a number (at least one) of
665 * WikiDB_PageRevisions.
669 function WikiDB_Page(&$wikidb, $pagename) {
670 $this->_wikidb = &$wikidb;
671 $this->_pagename = $pagename;
673 if (!(is_string($pagename) and $pagename != '')) {
674 if (function_exists("xdebug_get_function_stack")) {
675 echo "xdebug_get_function_stack(): "; var_dump(xdebug_get_function_stack());
676 } elseif (function_exists("debug_backtrace")) { // >= 4.3.0
677 printSimpleTrace(debug_backtrace());
679 trigger_error("empty pagename", E_USER_WARNING);
683 assert(is_string($pagename) and $pagename != '');
688 * Get the name of the wiki page.
692 * @return string The page name.
695 return $this->_pagename;
698 // To reduce the memory footprint for larger sets of pagelists,
699 // we don't cache the content (only true or false) and
700 // we purge the pagedata (_cached_html) also
702 if (isset($this->_wikidb->_cache->_id_cache[$this->_pagename])) return true;
703 $current = $this->getCurrentRevision(false);
704 if (!$current) return false;
705 return ! $current->hasDefaultContents();
709 * Delete an old revision of a WikiDB_Page.
711 * Deletes the specified revision of the page.
712 * It is a fatal error to attempt to delete the current revision.
716 * @param integer $version Which revision to delete. (You can also
717 * use a WikiDB_PageRevision object here.)
719 function deleteRevision($version) {
720 $backend = &$this->_wikidb->_backend;
721 $cache = &$this->_wikidb->_cache;
722 $pagename = &$this->_pagename;
724 $version = $this->_coerce_to_version($version);
728 $backend->lock(array('page','version'));
729 $latestversion = $cache->get_latest_version($pagename);
730 if ($latestversion && ($version == $latestversion)) {
731 $backend->unlock(array('page','version'));
732 trigger_error(sprintf("Attempt to delete most recent revision of '%s'",
733 $pagename), E_USER_ERROR);
737 $cache->delete_versiondata($pagename, $version);
738 $backend->unlock(array('page','version'));
742 * Delete a revision, or possibly merge it with a previous
746 * Suppose an author make a (major) edit to a page. Shortly
747 * after that the same author makes a minor edit (e.g. to fix
748 * spelling mistakes he just made.)
750 * Now some time later, where cleaning out old saved revisions,
751 * and would like to delete his minor revision (since there's
752 * really no point in keeping minor revisions around for a long
755 * Note that the text after the minor revision probably represents
756 * what the author intended to write better than the text after
757 * the preceding major edit.
759 * So what we really want to do is merge the minor edit with the
762 * We will only do this when:
764 * <li>The revision being deleted is a minor one, and
765 * <li>It has the same author as the immediately preceding revision.
768 function mergeRevision($version) {
769 $backend = &$this->_wikidb->_backend;
770 $cache = &$this->_wikidb->_cache;
771 $pagename = &$this->_pagename;
773 $version = $this->_coerce_to_version($version);
777 $backend->lock(array('version'));
778 $latestversion = $cache->get_latest_version($pagename);
779 if ($latestversion && $version == $latestversion) {
780 $backend->unlock(array('version'));
781 trigger_error(sprintf("Attempt to merge most recent revision of '%s'",
782 $pagename), E_USER_ERROR);
786 $versiondata = $cache->get_versiondata($pagename, $version, true);
788 // Not there? ... we're done!
789 $backend->unlock(array('version'));
793 if ($versiondata['is_minor_edit']) {
794 $previous = $backend->get_previous_version($pagename, $version);
796 $prevdata = $cache->get_versiondata($pagename, $previous);
797 if ($prevdata['author_id'] == $versiondata['author_id']) {
798 // This is a minor revision, previous version is
799 // by the same author. We will merge the
801 $cache->update_versiondata($pagename, $previous,
802 array('%content' => $versiondata['%content'],
803 '_supplanted' => $versiondata['_supplanted']));
808 $cache->delete_versiondata($pagename, $version);
809 $backend->unlock(array('version'));
814 * Create a new revision of a {@link WikiDB_Page}.
818 * @param int $version Version number for new revision.
819 * To ensure proper serialization of edits, $version must be
820 * exactly one higher than the current latest version.
821 * (You can defeat this check by setting $version to
822 * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
824 * @param string $content Contents of new revision.
826 * @param hash $metadata Metadata for new revision.
827 * All values in the hash should be scalars (strings or integers).
829 * @param hash $links List of linkto=>pagename, relation=>pagename which this page links to.
831 * @return WikiDB_PageRevision Returns the new WikiDB_PageRevision object. If
832 * $version was incorrect, returns false
834 function createRevision($version, &$content, $metadata, $links) {
835 $backend = &$this->_wikidb->_backend;
836 $cache = &$this->_wikidb->_cache;
837 $pagename = &$this->_pagename;
838 $cache->invalidate_cache($pagename);
840 $backend->lock(array('version','page','recent','link','nonempty'));
842 $latestversion = $backend->get_latest_version($pagename);
843 $newversion = ($latestversion ? $latestversion : 0) + 1;
844 assert($newversion >= 1);
846 if ($version != WIKIDB_FORCE_CREATE and $version != $newversion) {
847 $backend->unlock(array('version','page','recent','link','nonempty'));
853 foreach ($data as $key => $val) {
854 if (empty($val) || $key[0] == '_' || $key[0] == '%')
858 assert(!empty($data['author']));
859 if (empty($data['author_id']))
860 @$data['author_id'] = $data['author'];
862 if (empty($data['mtime']))
863 $data['mtime'] = time();
865 if ($latestversion and $version != WIKIDB_FORCE_CREATE) {
866 // Ensure mtimes are monotonic.
867 $pdata = $cache->get_versiondata($pagename, $latestversion);
868 if ($data['mtime'] < $pdata['mtime']) {
869 trigger_error(sprintf(_("%s: Date of new revision is %s"),
870 $pagename,"'non-monotonic'"),
872 $data['orig_mtime'] = $data['mtime'];
873 $data['mtime'] = $pdata['mtime'];
876 // FIXME: use (possibly user specified) 'mtime' time or
878 $cache->update_versiondata($pagename, $latestversion,
879 array('_supplanted' => $data['mtime']));
882 $data['%content'] = &$content;
884 $cache->set_versiondata($pagename, $newversion, $data);
886 //$cache->update_pagedata($pagename, array(':latestversion' => $newversion,
887 //':deleted' => empty($content)));
889 $backend->set_links($pagename, $links);
891 $backend->unlock(array('version','page','recent','link','nonempty'));
893 return new WikiDB_PageRevision($this->_wikidb, $pagename, $newversion,
897 /** A higher-level interface to createRevision.
899 * This takes care of computing the links, and storing
900 * a cached version of the transformed wiki-text.
902 * @param string $wikitext The page content.
904 * @param int $version Version number for new revision.
905 * To ensure proper serialization of edits, $version must be
906 * exactly one higher than the current latest version.
907 * (You can defeat this check by setting $version to
908 * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
910 * @param hash $meta Meta-data for new revision.
912 function save($wikitext, $version, $meta) {
913 $formatted = new TransformedText($this, $wikitext, $meta);
914 $type = $formatted->getType();
915 $meta['pagetype'] = $type->getName();
916 $links = $formatted->getWikiPageLinks(); // linkto => relation
918 $backend = &$this->_wikidb->_backend;
919 $newrevision = $this->createRevision($version, $wikitext, $meta, $links);
920 if ($newrevision and !WIKIDB_NOCACHE_MARKUP)
921 $this->set('_cached_html', $formatted->pack());
923 // FIXME: probably should have some global state information
924 // in the backend to control when to optimize.
926 // We're doing this here rather than in createRevision because
927 // postgresql can't optimize while locked.
928 if ((DEBUG & _DEBUG_SQL)
929 or (DATABASE_OPTIMISE_FREQUENCY > 0 and
930 (time() % DATABASE_OPTIMISE_FREQUENCY == 0))) {
931 if ($backend->optimize()) {
933 trigger_error(_("Optimizing database"), E_USER_NOTICE);
937 /* Generate notification emails? */
938 if (isa($newrevision, 'WikiDB_PageRevision')) {
939 // Save didn't fail because of concurrent updates.
940 $notify = $this->_wikidb->get('notify');
941 if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'],'MockRequest')) {
942 list($emails, $userids) = $this->getPageChangeEmails($notify);
943 if (!empty($emails)) {
944 $this->sendPageChangeNotification($wikitext, $version, $meta, $emails, $userids);
947 $newrevision->_transformedContent = $formatted;
953 function getPageChangeEmails($notify) {
954 $emails = array(); $userids = array();
955 foreach ($notify as $page => $users) {
956 if (glob_match($page, $this->_pagename)) {
957 foreach ($users as $userid => $user) {
958 if (!$user) { // handle the case for ModeratePage: no prefs, just userid's.
960 $u = $request->getUser();
961 if ($u->UserName() == $userid) {
962 $prefs = $u->getPreferences();
965 if (ENABLE_USER_NEW) {
966 $u = WikiUser($userid);
967 $u->getPreferences();
968 $prefs = &$u->_prefs;
970 $u = new WikiUser($GLOBALS['request'], $userid);
971 $prefs = $u->getPreferences();
974 $emails[] = $prefs->get('email');
975 $userids[] = $userid;
977 if (!empty($user['verified']) and !empty($user['email'])) {
978 $emails[] = $user['email'];
979 $userids[] = $userid;
980 } elseif (!empty($user['email'])) {
982 // do a dynamic emailVerified check update
983 $u = $request->getUser();
984 if ($u->UserName() == $userid) {
985 if ($request->_prefs->get('emailVerified')) {
986 $emails[] = $user['email'];
987 $userids[] = $userid;
988 $notify[$page][$userid]['verified'] = 1;
989 $request->_dbi->set('notify', $notify);
993 if (ENABLE_USER_NEW) {
994 $u = WikiUser($userid);
995 $u->getPreferences();
996 $prefs = &$u->_prefs;
998 $u = new WikiUser($GLOBALS['request'], $userid);
999 $prefs = $u->getPreferences();
1001 if ($prefs->get('emailVerified')) {
1002 $emails[] = $user['email'];
1003 $userids[] = $userid;
1004 $notify[$page][$userid]['verified'] = 1;
1005 $request->_dbi->set('notify', $notify);
1008 // ignore verification
1011 if (!in_array($user['email'],$emails))
1012 $emails[] = $user['email'];
1020 $emails = array_unique($emails);
1021 $userids = array_unique($userids);
1022 return array($emails, $userids);
1026 * Send udiff for a changed page to multiple users.
1027 * See rename and remove methods also
1029 function sendPageChangeNotification(&$wikitext, $version, $meta, $emails, $userids) {
1031 if (@is_array($request->_deferredPageChangeNotification)) {
1032 // collapse multiple changes (loaddir) into one email
1033 $request->_deferredPageChangeNotification[]
1034 = array($this->_pagename, $emails, $userids);
1037 $backend = &$this->_wikidb->_backend;
1038 //$backend = &$request->_dbi->_backend;
1039 $subject = _("Page change").' '.urlencode($this->_pagename);
1040 $previous = $backend->get_previous_version($this->_pagename, $version);
1041 if (!isset($meta['mtime'])) $meta['mtime'] = time();
1043 $difflink = WikiURL($this->_pagename, array('action'=>'diff'), true);
1044 $cache = &$this->_wikidb->_cache;
1045 //$cache = &$request->_dbi->_cache;
1046 $this_content = explode("\n", $wikitext);
1047 $prevdata = $cache->get_versiondata($this->_pagename, $previous, true);
1048 if (empty($prevdata['%content']))
1049 $prevdata = $backend->get_versiondata($this->_pagename, $previous, true);
1050 $other_content = explode("\n", $prevdata['%content']);
1052 include_once("lib/difflib.php");
1053 $diff2 = new Diff($other_content, $this_content);
1054 //$context_lines = max(4, count($other_content) + 1,
1055 // count($this_content) + 1);
1056 $fmt = new UnifiedDiffFormatter(/*$context_lines*/);
1057 $content = $this->_pagename . " " . $previous . " " .
1058 Iso8601DateTime($prevdata['mtime']) . "\n";
1059 $content .= $this->_pagename . " " . $version . " " .
1060 Iso8601DateTime($meta['mtime']) . "\n";
1061 $content .= $fmt->format($diff2);
1064 $difflink = WikiURL($this->_pagename,array(),true);
1065 $content = $this->_pagename . " " . $version . " " .
1066 Iso8601DateTime($meta['mtime']) . "\n";
1067 $content .= _("New page");
1069 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
1070 $editedby = sprintf(_("Edited by: %s"), $from);
1071 $emails = join(',',$emails);
1072 if (mail("<undisclosed-recipients>",
1073 "[".WIKI_NAME."] ".$subject,
1074 $subject."\n". $editedby."\n". $difflink."\n\n". $content,
1075 "From: $from\r\nBcc: $emails"))
1076 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
1077 $this->_pagename, join(',',$userids)), E_USER_NOTICE);
1079 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
1080 $this->_pagename, join(',',$userids)), E_USER_WARNING);
1083 /** support mass rename / remove (not yet tested)
1085 function sendPageRenameNotification($to, &$meta, $emails, $userids) {
1087 if (@is_array($request->_deferredPageRenameNotification)) {
1088 $request->_deferredPageRenameNotification[] = array($this->_pagename,
1089 $to, $meta, $emails, $userids);
1091 $oldname = $this->_pagename;
1092 $from = $request->_user->getId() . '@' . $request->get('REMOTE_HOST');
1093 $editedby = sprintf(_("Edited by: %s"), $from);
1094 $emails = join(',',$emails);
1095 $subject = sprintf(_("Page rename %s to %s"), urlencode($oldname), urlencode($to));
1096 $link = WikiURL($to, true);
1097 if (mail("<undisclosed-recipients>",
1098 "[".WIKI_NAME."] ".$subject,
1099 $subject."\n".$editedby."\n".$link."\n\n"."Renamed $from to $to",
1100 "From: $from\r\nBcc: $emails"))
1101 trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
1102 $oldname, join(',',$userids)), E_USER_NOTICE);
1104 trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
1105 $oldname, join(',',$userids)), E_USER_WARNING);
1110 * Get the most recent revision of a page.
1114 * @return WikiDB_PageRevision The current WikiDB_PageRevision object.
1116 function getCurrentRevision ($need_content = true) {
1117 $backend = &$this->_wikidb->_backend;
1118 $cache = &$this->_wikidb->_cache;
1119 $pagename = &$this->_pagename;
1121 // Prevent deadlock in case of memory exhausted errors
1122 // Pure selection doesn't really need locking here.
1123 // sf.net bug#927395
1124 // I know it would be better to lock, but with lots of pages this deadlock is more
1125 // severe than occasionally get not the latest revision.
1126 // In spirit to wikiwiki: read fast, edit slower.
1128 $version = $cache->get_latest_version($pagename);
1129 // getRevision gets the content also!
1130 $revision = $this->getRevision($version, $need_content);
1131 //$backend->unlock();
1137 * Get a specific revision of a WikiDB_Page.
1141 * @param integer $version Which revision to get.
1143 * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or
1144 * false if the requested revision does not exist in the {@link WikiDB}.
1145 * Note that version zero of any page always exists.
1147 function getRevision ($version, $need_content=true) {
1148 $cache = &$this->_wikidb->_cache;
1149 $pagename = &$this->_pagename;
1151 if (! $version or $version == -1) // 0 or false
1152 return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
1154 assert($version > 0);
1155 $vdata = $cache->get_versiondata($pagename, $version, $need_content);
1157 return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
1159 return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
1164 * Get previous page revision.
1166 * This method find the most recent revision before a specified
1171 * @param integer $version Find most recent revision before this version.
1172 * You can also use a WikiDB_PageRevision object to specify the $version.
1174 * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or false if the
1175 * requested revision does not exist in the {@link WikiDB}. Note that
1176 * unless $version is greater than zero, a revision (perhaps version zero,
1177 * the default revision) will always be found.
1179 function getRevisionBefore ($version=false, $need_content=true) {
1180 $backend = &$this->_wikidb->_backend;
1181 $pagename = &$this->_pagename;
1182 if ($version === false)
1183 $version = $this->_wikidb->_cache->get_latest_version($pagename);
1185 $version = $this->_coerce_to_version($version);
1190 $previous = $backend->get_previous_version($pagename, $version);
1191 $revision = $this->getRevision($previous, $need_content);
1192 //$backend->unlock();
1198 * Get all revisions of the WikiDB_Page.
1200 * This does not include the version zero (default) revision in the
1201 * returned revision set.
1203 * @return WikiDB_PageRevisionIterator A
1204 * WikiDB_PageRevisionIterator containing all revisions of this
1205 * WikiDB_Page in reverse order by version number.
1207 function getAllRevisions() {
1208 $backend = &$this->_wikidb->_backend;
1209 $revs = $backend->get_all_revisions($this->_pagename);
1210 return new WikiDB_PageRevisionIterator($this->_wikidb, $revs);
1214 * Find pages which link to or are linked from a page.
1215 * relations: $backend->get_links is responsible to add the relation to the pagehash
1216 * as 'linkrelation' key as pagename. See WikiDB_PageIterator::next
1217 * if (isset($next['linkrelation']))
1221 * @param boolean $reversed Which links to find: true for backlinks (default).
1223 * @return WikiDB_PageIterator A WikiDB_PageIterator containing
1224 * all matching pages.
1226 function getLinks ($reversed = true, $include_empty=false, $sortby=false,
1227 $limit=false, $exclude=false, $want_relations=false)
1229 $backend = &$this->_wikidb->_backend;
1230 $result = $backend->get_links($this->_pagename, $reversed,
1231 $include_empty, $sortby, $limit, $exclude,
1233 return new WikiDB_PageIterator($this->_wikidb, $result,
1234 array('include_empty' => $include_empty,
1235 'sortby' => $sortby,
1237 'exclude' => $exclude,
1238 'want_relations'=> $want_relations));
1242 * All Links from other pages to this page.
1244 function getBackLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false,
1245 $want_relations=false)
1247 return $this->getLinks(true, $include_empty, $sortby, $limit, $exclude);
1250 * Forward Links: All Links from this page to other pages.
1252 function getPageLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false,
1253 $want_relations=false)
1255 return $this->getLinks(false, $include_empty, $sortby, $limit, $exclude);
1258 * Relations: All links from this page to other pages with relation <> 0.
1261 function getRelations($sortby=false, $limit=false, $exclude=false) {
1262 $backend = &$this->_wikidb->_backend;
1263 $result = $backend->get_links($this->_pagename, false, true,
1264 $sortby, $limit, $exclude,
1266 // we do not care for the linked page versiondata, just the pagename and linkrelation
1267 return new WikiDB_PageIterator($this->_wikidb, $result,
1268 array('include_empty' => true,
1269 'sortby' => $sortby,
1271 'exclude' => $exclude,
1272 'want_relations'=> true));
1276 * possibly faster link existance check. not yet accelerated.
1278 function existLink($link, $reversed=false) {
1279 $backend = &$this->_wikidb->_backend;
1280 if (method_exists($backend,'exists_link'))
1281 return $backend->exists_link($this->_pagename, $link, $reversed);
1282 //$cache = &$this->_wikidb->_cache;
1283 // TODO: check cache if it is possible
1284 $iter = $this->getLinks($reversed, false);
1285 while ($page = $iter->next()) {
1286 if ($page->getName() == $link)
1293 /* Semantic relations are links with the relation pointing to another page,
1294 the so called "RDF Triple".
1295 [San Diego] is%20a::city
1296 => "At the page San Diego there is a relation link of 'is a' to the page 'city'."
1299 /* Semantic attributes for a page.
1300 [San Diego] population:=1,305,736
1301 Attributes are links with the relation pointing to another page.
1305 * Access WikiDB_Page non version-specific meta-data.
1309 * @param string $key Which meta data to get.
1310 * Some reserved meta-data keys are:
1312 * <dt>'date' <dd> Created as unixtime
1313 * <dt>'locked'<dd> Is page locked? 'yes' or 'no'
1314 * <dt>'hits' <dd> Page hit counter.
1315 * <dt>'_cached_html' <dd> Transformed CachedMarkup object, serialized + optionally gzipped.
1316 * In SQL stored now in an extra column.
1318 * <dt>'pref' <dd> Users preferences, stored only in homepages.
1319 * <dt>'owner' <dd> Default: first author_id. We might add a group with a dot here:
1320 * E.g. "owner.users"
1321 * <dt>'perm' <dd> Permission flag to authorize read/write/execution of
1322 * page-headers and content.
1323 + <dt>'moderation'<dd> ModeratedPage data
1324 * <dt>'score' <dd> Page score (not yet implement, do we need?)
1327 * @return scalar The requested value, or false if the requested data
1330 function get($key) {
1331 $cache = &$this->_wikidb->_cache;
1332 $backend = &$this->_wikidb->_backend;
1333 if (!$key || $key[0] == '%')
1335 // several new SQL backends optimize this.
1336 if (!WIKIDB_NOCACHE_MARKUP
1337 and $key == '_cached_html'
1338 and method_exists($backend, 'get_cached_html'))
1340 return $backend->get_cached_html($this->_pagename);
1342 $data = $cache->get_pagedata($this->_pagename);
1343 return isset($data[$key]) ? $data[$key] : false;
1347 * Get all the page meta-data as a hash.
1349 * @return hash The page meta-data.
1351 function getMetaData() {
1352 $cache = &$this->_wikidb->_cache;
1353 $data = $cache->get_pagedata($this->_pagename);
1355 foreach ($data as $key => $val) {
1356 if (/*!empty($val) &&*/ $key[0] != '%')
1363 * Set page meta-data.
1368 * @param string $key Meta-data key to set.
1369 * @param string $newval New value.
1371 function set($key, $newval) {
1372 $cache = &$this->_wikidb->_cache;
1373 $backend = &$this->_wikidb->_backend;
1374 $pagename = &$this->_pagename;
1376 assert($key && $key[0] != '%');
1378 // several new SQL backends optimize this.
1379 if (!WIKIDB_NOCACHE_MARKUP
1380 and $key == '_cached_html'
1381 and method_exists($backend, 'set_cached_html'))
1383 return $backend->set_cached_html($pagename, $newval);
1386 $data = $cache->get_pagedata($pagename);
1388 if (!empty($newval)) {
1389 if (!empty($data[$key]) && $data[$key] == $newval)
1390 return; // values identical, skip update.
1393 if (empty($data[$key]))
1394 return; // values identical, skip update.
1397 $cache->update_pagedata($pagename, array($key => $newval));
1401 * Increase page hit count.
1403 * FIXME: IS this needed? Probably not.
1405 * This is a convenience function.
1406 * <pre> $page->increaseHitCount(); </pre>
1407 * is functionally identical to
1408 * <pre> $page->set('hits',$page->get('hits')+1); </pre>
1409 * but less expensive (ignores the pagadata string)
1411 * Note that this method may be implemented in more efficient ways
1412 * in certain backends.
1416 function increaseHitCount() {
1417 if (method_exists($this->_wikidb->_backend, 'increaseHitCount'))
1418 $this->_wikidb->_backend->increaseHitCount($this->_pagename);
1420 @$newhits = $this->get('hits') + 1;
1421 $this->set('hits', $newhits);
1426 * Return a string representation of the WikiDB_Page
1428 * This is really only for debugging.
1432 * @return string Printable representation of the WikiDB_Page.
1434 function asString () {
1436 printf("[%s:%s\n", get_class($this), $this->getName());
1437 print_r($this->getMetaData());
1439 $strval = ob_get_contents();
1447 * @param integer_or_object $version_or_pagerevision
1448 * Takes either the version number (and int) or a WikiDB_PageRevision
1450 * @return integer The version number.
1452 function _coerce_to_version($version_or_pagerevision) {
1453 if (method_exists($version_or_pagerevision, "getContent"))
1454 $version = $version_or_pagerevision->getVersion();
1456 $version = (int) $version_or_pagerevision;
1458 assert($version >= 0);
1462 function isUserPage ($include_empty = true) {
1463 if (!$include_empty and !$this->exists()) return false;
1464 return $this->get('pref') ? true : false;
1467 // May be empty. Either the stored owner (/Chown), or the first authorized author
1468 function getOwner() {
1469 if ($owner = $this->get('owner'))
1470 return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
1471 // check all revisions forwards for the first author_id
1472 $backend = &$this->_wikidb->_backend;
1473 $pagename = &$this->_pagename;
1474 $latestversion = $backend->get_latest_version($pagename);
1475 for ($v=1; $v <= $latestversion; $v++) {
1476 $rev = $this->getRevision($v,false);
1477 if ($rev and $owner = $rev->get('author_id')) {
1478 return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
1484 // The authenticated author of the first revision or empty if not authenticated then.
1485 function getCreator() {
1486 if ($current = $this->getRevision(1,false)) return $current->get('author_id');
1490 // The authenticated author of the current revision.
1491 function getAuthor() {
1492 if ($current = $this->getCurrentRevision(false)) return $current->get('author_id');
1499 * This class represents a specific revision of a WikiDB_Page within
1502 * A WikiDB_PageRevision has read-only semantics. You may only create
1503 * new revisions (and delete old ones) --- you cannot modify existing
1506 class WikiDB_PageRevision
1508 //var $_transformedContent = false; // set by WikiDB_Page::save()
1510 function WikiDB_PageRevision(&$wikidb, $pagename, $version, $versiondata = false) {
1511 $this->_wikidb = &$wikidb;
1512 $this->_pagename = $pagename;
1513 $this->_version = $version;
1514 $this->_data = $versiondata ? $versiondata : array();
1515 $this->_transformedContent = false; // set by WikiDB_Page::save()
1519 * Get the WikiDB_Page which this revision belongs to.
1523 * @return WikiDB_Page The WikiDB_Page which this revision belongs to.
1525 function getPage() {
1526 return new WikiDB_Page($this->_wikidb, $this->_pagename);
1530 * Get the version number of this revision.
1534 * @return integer The version number of this revision.
1536 function getVersion() {
1537 return $this->_version;
1541 * Determine whether this revision has defaulted content.
1543 * The default revision (version 0) of each page, as well as any
1544 * pages which are created with empty content have their content
1545 * defaulted to something like:
1547 * Describe [ThisPage] here.
1552 * @return boolean Returns true if the page has default content.
1554 function hasDefaultContents() {
1555 $data = &$this->_data;
1556 return empty($data['%content']); // FIXME: what if it's the number 0? <>'' or === false
1560 * Get the content as an array of lines.
1564 * @return array An array of lines.
1565 * The lines should contain no trailing white space.
1567 function getContent() {
1568 return explode("\n", $this->getPackedContent());
1572 * Get the pagename of the revision.
1576 * @return string pagename.
1578 function getPageName() {
1579 return $this->_pagename;
1581 function getName() {
1582 return $this->_pagename;
1586 * Determine whether revision is the latest.
1590 * @return boolean True iff the revision is the latest (most recent) one.
1592 function isCurrent() {
1593 if (!isset($this->_iscurrent)) {
1594 $page = $this->getPage();
1595 $current = $page->getCurrentRevision(false);
1596 $this->_iscurrent = $this->getVersion() == $current->getVersion();
1598 return $this->_iscurrent;
1602 * Get the transformed content of a page.
1604 * @param string $pagetype Override the page-type of the revision.
1606 * @return object An XmlContent-like object containing the page transformed
1609 function getTransformedContent($pagetype_override=false) {
1610 $backend = &$this->_wikidb->_backend;
1612 if ($pagetype_override) {
1613 // Figure out the normal page-type for this page.
1614 $type = PageType::GetPageType($this->get('pagetype'));
1615 if ($type->getName() == $pagetype_override)
1616 $pagetype_override = false; // Not really an override...
1619 if ($pagetype_override) {
1620 // Overriden page type, don't cache (or check cache).
1621 return new TransformedText($this->getPage(),
1622 $this->getPackedContent(),
1623 $this->getMetaData(),
1624 $pagetype_override);
1627 $possibly_cache_results = true;
1629 if (!USECACHE or WIKIDB_NOCACHE_MARKUP) {
1630 if (WIKIDB_NOCACHE_MARKUP == 'purge') {
1631 // flush cache for this page.
1632 $page = $this->getPage();
1633 $page->set('_cached_html', ''); // ignored with !USECACHE
1635 $possibly_cache_results = false;
1637 elseif (USECACHE and !$this->_transformedContent) {
1639 if ($this->isCurrent()) {
1640 $page = $this->getPage();
1641 $this->_transformedContent = TransformedText::unpack($page->get('_cached_html'));
1644 $possibly_cache_results = false;
1646 //$backend->unlock();
1649 if (!$this->_transformedContent) {
1650 $this->_transformedContent
1651 = new TransformedText($this->getPage(),
1652 $this->getPackedContent(),
1653 $this->getMetaData());
1655 if ($possibly_cache_results and !WIKIDB_NOCACHE_MARKUP) {
1656 // If we're still the current version, cache the transfomed page.
1658 if ($this->isCurrent()) {
1659 $page->set('_cached_html', $this->_transformedContent->pack());
1661 //$backend->unlock();
1665 return $this->_transformedContent;
1669 * Get the content as a string.
1673 * @return string The page content.
1674 * Lines are separated by new-lines.
1676 function getPackedContent() {
1677 $data = &$this->_data;
1680 if (empty($data['%content'])) {
1681 include_once('lib/InlineParser.php');
1683 // A feature similar to taglines at http://www.wlug.org.nz/
1684 // Lib from http://www.aasted.org/quote/
1685 if (defined('FORTUNE_DIR')
1686 and is_dir(FORTUNE_DIR)
1687 and in_array($GLOBALS['request']->getArg('action'),
1688 array('create','edit')))
1690 include_once("lib/fortune.php");
1691 $fortune = new Fortune();
1692 $quote = str_replace("\n<br>","\n", $fortune->quoteFromDir(FORTUNE_DIR));
1693 return sprintf("<verbatim>\n%s</verbatim>\n\n"._("Describe %s here."),
1694 $quote, "[" . WikiEscape($this->_pagename) . "]");
1696 // Replace empty content with default value.
1697 return sprintf(_("Describe %s here."),
1698 "[" . WikiEscape($this->_pagename) . "]");
1701 // There is (non-default) content.
1702 assert($this->_version > 0);
1704 if (!is_string($data['%content'])) {
1705 // Content was not provided to us at init time.
1706 // (This is allowed because for some backends, fetching
1707 // the content may be expensive, and often is not wanted
1710 // In any case, now we need to get it.
1711 $data['%content'] = $this->_get_content();
1712 assert(is_string($data['%content']));
1715 return $data['%content'];
1718 function _get_content() {
1719 $cache = &$this->_wikidb->_cache;
1720 $pagename = $this->_pagename;
1721 $version = $this->_version;
1723 assert($version > 0);
1725 $newdata = $cache->get_versiondata($pagename, $version, true);
1727 assert(is_string($newdata['%content']));
1728 return $newdata['%content'];
1731 // else revision has been deleted... What to do?
1732 return __sprintf("Oops! Revision %s of %s seems to have been deleted!",
1733 $version, $pagename);
1738 * Get meta-data for this revision.
1743 * @param string $key Which meta-data to access.
1745 * Some reserved revision meta-data keys are:
1747 * <dt> 'mtime' <dd> Time this revision was created (seconds since midnight Jan 1, 1970.)
1748 * The 'mtime' meta-value is normally set automatically by the database
1749 * backend, but it may be specified explicitly when creating a new revision.
1751 * <dd> To ensure consistency of RecentChanges, the mtimes of the versions
1752 * of a page must be monotonically increasing. If an attempt is
1753 * made to create a new revision with an mtime less than that of
1754 * the preceeding revision, the new revisions timestamp is force
1755 * to be equal to that of the preceeding revision. In that case,
1756 * the originally requested mtime is preserved in 'orig_mtime'.
1757 * <dt> '_supplanted' <dd> Time this revision ceased to be the most recent.
1758 * This meta-value is <em>always</em> automatically maintained by the database
1759 * backend. (It is set from the 'mtime' meta-value of the superceding
1760 * revision.) '_supplanted' has a value of 'false' for the current revision.
1762 * FIXME: this could be refactored:
1764 * <dd> Author of the page (as he should be reported in, e.g. RecentChanges.)
1766 * <dd> Authenticated author of a page. This is used to identify
1767 * the distinctness of authors when cleaning old revisions from
1769 * <dt> 'is_minor_edit' <dd> Set if change was marked as a minor revision by the author.
1770 * <dt> 'summary' <dd> Short change summary entered by page author.
1773 * Meta-data keys must be valid C identifers (they have to start with a letter
1774 * or underscore, and can contain only alphanumerics and underscores.)
1776 * @return string The requested value, or false if the requested value
1779 function get($key) {
1780 if (!$key || $key[0] == '%')
1782 $data = &$this->_data;
1783 return isset($data[$key]) ? $data[$key] : false;
1787 * Get all the revision page meta-data as a hash.
1789 * @return hash The revision meta-data.
1791 function getMetaData() {
1793 foreach ($this->_data as $key => $val) {
1794 if (!empty($val) && $key[0] != '%')
1802 * Return a string representation of the revision.
1804 * This is really only for debugging.
1808 * @return string Printable representation of the WikiDB_Page.
1810 function asString () {
1812 printf("[%s:%d\n", get_class($this), $this->get('version'));
1813 print_r($this->_data);
1814 echo $this->getPackedContent() . "\n]\n";
1815 $strval = ob_get_contents();
1823 * Class representing a sequence of WikiDB_Pages.
1824 * TODO: Enhance to php5 iterators
1826 * apply filters for options like 'sortby', 'limit', 'exclude'
1827 * for simple queries like titleSearch, where the backend is not ready yet.
1829 class WikiDB_PageIterator
1831 function WikiDB_PageIterator(&$wikidb, &$iter, $options=false) {
1832 $this->_iter = $iter; // a WikiDB_backend_iterator
1833 $this->_wikidb = &$wikidb;
1834 $this->_options = $options;
1838 return $this->_iter->count();
1842 * Get next WikiDB_Page in sequence.
1846 * @return WikiDB_Page The next WikiDB_Page in the sequence.
1849 if ( ! ($next = $this->_iter->next()) )
1852 $pagename = &$next['pagename'];
1853 if (!is_string($pagename)) { // Bug #1327912 fixed by Joachim Lous
1854 $pagename = strval($pagename);
1857 trigger_error('empty pagename in WikiDB_PageIterator::next()', E_USER_WARNING);
1861 // There's always hits, but we cache only if more
1862 // (well not with file, cvs and dba)
1863 if (isset($next['pagedata']) and count($next['pagedata']) > 1) {
1864 $this->_wikidb->_cache->cache_data($next);
1865 // cache existing page id's since we iterate over all links in GleanDescription
1866 // and need them later for LinkExistingWord
1867 } elseif ($this->_options and array_key_exists('include_empty', $this->_options)
1868 and !$this->_options['include_empty'] and isset($next['id'])) {
1869 $this->_wikidb->_cache->_id_cache[$next['pagename']] = $next['id'];
1871 $page = new WikiDB_Page($this->_wikidb, $pagename);
1872 if (isset($next['linkrelation']))
1873 $page->set('linkrelation', $next['linkrelation']);
1878 * Release resources held by this iterator.
1880 * The iterator may not be used after free() is called.
1882 * There is no need to call free(), if next() has returned false.
1883 * (I.e. if you iterate through all the pages in the sequence,
1884 * you do not need to call free() --- you only need to call it
1885 * if you stop before the end of the iterator is reached.)
1890 $this->_iter->free();
1893 function asArray() {
1895 while ($page = $this->next())
1902 * Apply filters for options like 'sortby', 'limit', 'exclude'
1903 * for simple queries like titleSearch, where the backend is not ready yet.
1904 * Since iteration is usually destructive for SQL results,
1905 * we have to generate a copy.
1907 function applyFilters($options = false) {
1908 if (!$options) $options = $this->_options;
1909 if (isset($options['sortby'])) {
1911 /* this is destructive */
1912 while ($page = $this->next())
1913 $result[] = $page->getName();
1914 $this->_doSort($array, $options['sortby']);
1916 /* the rest is not destructive.
1917 * reconstruct a new iterator
1919 $pagenames = array(); $i = 0;
1920 if (isset($options['limit']))
1921 $limit = $options['limit'];
1924 if (isset($options['exclude']))
1925 $exclude = $options['exclude'];
1926 if (is_string($exclude) and !is_array($exclude))
1927 $exclude = PageList::explodePageList($exclude, false, false, $limit);
1928 foreach($array as $pagename) {
1929 if ($limit and $i++ > $limit)
1930 return new WikiDB_Array_PageIterator($pagenames);
1931 if (!empty($exclude) and !in_array($pagename, $exclude))
1932 $pagenames[] = $pagename;
1933 elseif (empty($exclude))
1934 $pagenames[] = $pagename;
1936 return new WikiDB_Array_PageIterator($pagenames);
1940 function _doSort(&$array, $sortby) {
1941 $sortby = PageList::sortby($sortby, 'init');
1942 if ($sortby == '+pagename')
1943 sort($array, SORT_STRING);
1944 elseif ($sortby == '-pagename')
1945 rsort($array, SORT_STRING);
1952 * A class which represents a sequence of WikiDB_PageRevisions.
1953 * TODO: Enhance to php5 iterators
1955 class WikiDB_PageRevisionIterator
1957 function WikiDB_PageRevisionIterator(&$wikidb, &$revisions, $options=false) {
1958 $this->_revisions = $revisions;
1959 $this->_wikidb = &$wikidb;
1960 $this->_options = $options;
1964 return $this->_revisions->count();
1968 * Get next WikiDB_PageRevision in sequence.
1972 * @return WikiDB_PageRevision
1973 * The next WikiDB_PageRevision in the sequence.
1976 if ( ! ($next = $this->_revisions->next()) )
1979 //$this->_wikidb->_cache->cache_data($next);
1981 $pagename = $next['pagename'];
1982 $version = $next['version'];
1983 $versiondata = $next['versiondata'];
1985 if (!(is_string($pagename) and $pagename != '')) {
1986 trigger_error("empty pagename",E_USER_WARNING);
1989 } else assert(is_string($pagename) and $pagename != '');
1991 if (!is_array($versiondata)) {
1992 trigger_error("empty versiondata",E_USER_WARNING);
1995 } else assert(is_array($versiondata));
1997 if (!($version > 0)) {
1998 trigger_error("invalid version",E_USER_WARNING);
2001 } else assert($version > 0);
2003 return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
2008 * Release resources held by this iterator.
2010 * The iterator may not be used after free() is called.
2012 * There is no need to call free(), if next() has returned false.
2013 * (I.e. if you iterate through all the revisions in the sequence,
2014 * you do not need to call free() --- you only need to call it
2015 * if you stop before the end of the iterator is reached.)
2020 $this->_revisions->free();
2023 function asArray() {
2025 while ($rev = $this->next())
2034 class WikiDB_Array_PageIterator
2036 function WikiDB_Array_PageIterator($pagenames) {
2038 $this->_dbi = $request->getDbh();
2039 $this->_pages = $pagenames;
2040 reset($this->_pages);
2043 $c =& current($this->_pages);
2044 next($this->_pages);
2045 return $c !== false ? $this->_dbi->getPage($c) : false;
2048 return count($this->_pages);
2051 function asArray() {
2052 reset($this->_pages);
2053 return $this->_pages;
2057 class WikiDB_Array_generic_iter
2059 function WikiDB_Array_generic_iter($result) {
2060 // $result may be either an array or a query result
2061 if (is_array($result)) {
2062 $this->_array = $result;
2063 } elseif (is_object($result)) {
2064 $this->_array = $result->asArray();
2066 $this->_array = array();
2068 if (!empty($this->_array))
2069 reset($this->_array);
2072 $c =& current($this->_array);
2073 next($this->_array);
2074 return $c !== false ? $c : false;
2077 return count($this->_array);
2080 function asArray() {
2081 if (!empty($this->_array))
2082 reset($this->_array);
2083 return $this->_array;
2088 * Data cache used by WikiDB.
2090 * FIXME: Maybe rename this to caching_backend (or some such).
2096 // FIXME: beautify versiondata cache. Cache only limited data?
2098 function WikiDB_cache (&$backend) {
2099 $this->_backend = &$backend;
2101 $this->_pagedata_cache = array();
2102 $this->_versiondata_cache = array();
2103 array_push ($this->_versiondata_cache, array());
2104 $this->_glv_cache = array();
2105 $this->_id_cache = array(); // formerly ->_dbi->_iwpcache (nonempty pages => id)
2109 $this->_pagedata_cache = array();
2110 $this->_versiondata_cache = array();
2111 $this->_glv_cache = array();
2112 $this->_id_cache = array();
2115 function get_pagedata($pagename) {
2116 assert(is_string($pagename) && $pagename != '');
2118 $cache = &$this->_pagedata_cache;
2119 if (!isset($cache[$pagename]) || !is_array($cache[$pagename])) {
2120 $cache[$pagename] = $this->_backend->get_pagedata($pagename);
2121 if (empty($cache[$pagename]))
2122 $cache[$pagename] = array();
2124 return $cache[$pagename];
2126 return $this->_backend->get_pagedata($pagename);
2130 function update_pagedata($pagename, $newdata) {
2131 assert(is_string($pagename) && $pagename != '');
2133 $this->_backend->update_pagedata($pagename, $newdata);
2136 if (!empty($this->_pagedata_cache[$pagename])
2137 and is_array($this->_pagedata_cache[$pagename]))
2139 $cachedata = &$this->_pagedata_cache[$pagename];
2140 foreach($newdata as $key => $val)
2141 $cachedata[$key] = $val;
2143 $this->_pagedata_cache[$pagename] = $newdata;
2147 function invalidate_cache($pagename) {
2148 unset ($this->_pagedata_cache[$pagename]);
2149 unset ($this->_versiondata_cache[$pagename]);
2150 unset ($this->_glv_cache[$pagename]);
2151 unset ($this->_id_cache[$pagename]);
2152 //unset ($this->_backend->_page_data);
2155 function delete_page($pagename) {
2156 $result = $this->_backend->delete_page($pagename);
2157 $this->invalidate_cache($pagename);
2161 function purge_page($pagename) {
2162 $result = $this->_backend->purge_page($pagename);
2163 $this->invalidate_cache($pagename);
2167 // FIXME: ugly and wrong. may overwrite full cache with partial cache
2168 function cache_data($data) {
2170 //if (isset($data['pagedata']))
2171 // $this->_pagedata_cache[$data['pagename']] = $data['pagedata'];
2174 function get_versiondata($pagename, $version, $need_content = false) {
2175 // FIXME: Seriously ugly hackage
2177 if (USECACHE) { //temporary - for debugging
2178 assert(is_string($pagename) && $pagename != '');
2179 // There is a bug here somewhere which results in an assertion failure at line 105
2180 // of ArchiveCleaner.php It goes away if we use the next line.
2181 //$need_content = true;
2182 $nc = $need_content ? '1':'0';
2183 $cache = &$this->_versiondata_cache;
2184 if (!isset($cache[$pagename][$version][$nc])
2185 || !(is_array ($cache[$pagename]))
2186 || !(is_array ($cache[$pagename][$version])))
2188 $cache[$pagename][$version][$nc] =
2189 $this->_backend->get_versiondata($pagename, $version, $need_content);
2191 // If we have retrieved all data, we may as well set the cache for
2192 // $need_content = false
2194 $cache[$pagename][$version]['0'] =& $cache[$pagename][$version]['1'];
2197 $vdata = $cache[$pagename][$version][$nc];
2199 $vdata = $this->_backend->get_versiondata($pagename, $version, $need_content);
2202 if ($readdata && $vdata && !empty($vdata['%pagedata'])) {
2203 $this->_pagedata_cache[$pagename] =& $vdata['%pagedata'];
2208 function set_versiondata($pagename, $version, $data) {
2209 //unset($this->_versiondata_cache[$pagename][$version]);
2211 $new = $this->_backend->set_versiondata($pagename, $version, $data);
2213 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
2214 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
2215 // Is this necessary?
2216 unset($this->_glv_cache[$pagename]);
2219 function update_versiondata($pagename, $version, $data) {
2220 $new = $this->_backend->update_versiondata($pagename, $version, $data);
2222 $this->_versiondata_cache[$pagename][$version]['1'] = $data;
2224 $this->_versiondata_cache[$pagename][$version]['0'] = $data;
2225 // Is this necessary?
2226 unset($this->_glv_cache[$pagename]);
2229 function delete_versiondata($pagename, $version) {
2230 $new = $this->_backend->delete_versiondata($pagename, $version);
2231 if (isset($this->_versiondata_cache[$pagename][$version]))
2232 unset ($this->_versiondata_cache[$pagename][$version]);
2233 // dirty latest version cache only if latest version gets deleted
2234 if (isset($this->_glv_cache[$pagename]) and $this->_glv_cache[$pagename] == $version)
2235 unset ($this->_glv_cache[$pagename]);
2238 function get_latest_version($pagename) {
2240 assert (is_string($pagename) && $pagename != '');
2241 $cache = &$this->_glv_cache;
2242 if (!isset($cache[$pagename])) {
2243 $cache[$pagename] = $this->_backend->get_latest_version($pagename);
2244 if (empty($cache[$pagename]))
2245 $cache[$pagename] = 0;
2247 return $cache[$pagename];
2249 return $this->_backend->get_latest_version($pagename);
2254 function _sql_debuglog($msg, $newline=true, $shutdown=false) {
2258 $stamp = strftime("%y%m%d-%H%M%S");
2259 $fp = fopen("/tmp/sql-$stamp.log", "a");
2260 register_shutdown_function("_sql_debuglog_shutdown_function");
2261 } elseif ($shutdown) {
2265 if ($newline) fputs($fp, "[$i++] $msg");
2266 else fwrite($fp, $msg);
2269 function _sql_debuglog_shutdown_function() {
2270 _sql_debuglog('',false,true);
2273 // $Log: not supported by cvs2svn $
2274 // Revision 1.142 2006/06/10 11:55:58 rurban
2275 // print optimize only when DEBUG
2277 // Revision 1.141 2006/04/17 17:28:21 rurban
2278 // honor getWikiPageLinks change linkto=>relation
2280 // Revision 1.140 2006/03/19 14:23:51 rurban
2281 // sf.net patch #1377011 by Matt Brown: add DATABASE_OPTIMISE_FREQUENCY
2283 // Revision 1.139 2006/01/12 16:38:07 rurban
2284 // add page method listRelations()
2285 // fix bug #1327912 numeric pagenames can break plugins (Joachim Lous)
2287 // Revision 1.138 2005/11/14 22:27:07 rurban
2288 // add linkrelation support
2289 // getPageLinks returns now an array of hashes
2290 // pass stoplist through iterator
2292 // Revision 1.137 2005/10/12 06:16:18 rurban
2293 // better From header
2295 // Revision 1.136 2005/10/03 16:14:57 rurban
2296 // improve description
2298 // Revision 1.135 2005/09/11 14:19:44 rurban
2299 // enable LIMIT support for fulltext search
2301 // Revision 1.134 2005/09/10 21:28:10 rurban
2302 // applyFilters hack to use filters after methods, which do not support them (titleSearch)
2304 // Revision 1.133 2005/08/27 09:39:10 rurban
2305 // dumphtml when not at admin page: dump the current or given page
2307 // Revision 1.132 2005/08/07 10:10:07 rurban
2308 // clean whole version cache
2310 // Revision 1.131 2005/04/23 11:30:12 rurban
2311 // allow emtpy WikiDB::getRevisionBefore(), for simplier templates (revert)
2313 // Revision 1.130 2005/04/06 06:19:30 rurban
2314 // Revert the previous wrong bugfix #1175761: USECACHE was mixed with WIKIDB_NOCACHE_MARKUP.
2315 // Fix WIKIDB_NOCACHE_MARKUP in main (always set it) and clarify it in WikiDB
2317 // Revision 1.129 2005/04/06 05:50:29 rurban
2318 // honor !USECACHE for _cached_html, fixes #1175761
2320 // Revision 1.128 2005/04/01 16:11:42 rurban
2323 // Revision 1.127 2005/02/18 20:43:40 uckelman
2324 // WikiDB::genericWarnings() is no longer used.
2326 // Revision 1.126 2005/02/04 17:58:06 rurban
2327 // minor versioncache improvement. part 2/3 of Charles Corrigan cache patch. not sure about the 0/1 issue
2329 // Revision 1.125 2005/02/03 05:08:39 rurban
2330 // ref fix by Charles Corrigan
2332 // Revision 1.124 2005/01/29 20:43:32 rurban
2333 // protect against empty request: on some occasion this happens
2335 // Revision 1.123 2005/01/25 06:58:21 rurban
2338 // Revision 1.122 2005/01/20 10:18:17 rurban
2341 // Revision 1.121 2005/01/04 20:25:01 rurban
2342 // remove old [%pagedata][_cached_html] code
2344 // Revision 1.120 2004/12/23 14:12:31 rurban
2345 // dont email on unittest
2347 // Revision 1.119 2004/12/20 16:05:00 rurban
2348 // gettext msg unification
2350 // Revision 1.118 2004/12/13 13:22:57 rurban
2351 // new BlogArchives plugin for the new blog theme. enable default box method
2352 // for all plugins. Minor search improvement.
2354 // Revision 1.117 2004/12/13 08:15:09 rurban
2355 // false is wrong. null might be better but lets play safe.
2357 // Revision 1.116 2004/12/10 22:15:00 rurban
2358 // fix $page->get('_cached_html)
2359 // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also.
2360 // support 2nd genericSqlQuery param (bind huge arg)
2362 // Revision 1.115 2004/12/10 02:45:27 rurban
2363 // SQL optimization:
2364 // put _cached_html from pagedata into a new seperate blob, not huge serialized string.
2365 // it is only rarelely needed: for current page only, if-not-modified
2366 // but was extracted for every simple page iteration.
2368 // Revision 1.114 2004/12/09 22:24:44 rurban
2369 // optimize on _DEBUG_SQL only. but now again on every 50th request, not just save.
2371 // Revision 1.113 2004/12/06 19:49:55 rurban
2372 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
2373 // renamed delete_page to purge_page.
2374 // enable action=edit&version=-1 to force creation of a new version.
2375 // added BABYCART_PATH config
2376 // fixed magiqc in adodb.inc.php
2377 // and some more docs
2379 // Revision 1.112 2004/11/30 17:45:53 rurban
2380 // exists_links backend implementation
2382 // Revision 1.111 2004/11/28 20:39:43 rurban
2383 // deactivate pagecache overwrite: it is wrong
2385 // Revision 1.110 2004/11/26 18:39:01 rurban
2386 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
2388 // Revision 1.109 2004/11/25 17:20:50 rurban
2389 // and again a couple of more native db args: backlinks
2391 // Revision 1.108 2004/11/23 13:35:31 rurban
2392 // add case_exact search
2394 // Revision 1.107 2004/11/21 11:59:16 rurban
2395 // remove final \n to be ob_cache independent
2397 // Revision 1.106 2004/11/20 17:35:56 rurban
2398 // improved WantedPages SQL backends
2399 // PageList::sortby new 3rd arg valid_fields (override db fields)
2400 // WantedPages sql pager inexact for performance reasons:
2401 // assume 3 wantedfrom per page, to be correct, no getTotal()
2402 // support exclude argument for get_all_pages, new _sql_set()
2404 // Revision 1.105 2004/11/20 09:16:27 rurban
2405 // Fix bad-style Cut&Paste programming errors, detected by Charles Corrigan.
2407 // Revision 1.104 2004/11/19 19:22:03 rurban
2408 // ModeratePage part1: change status
2410 // Revision 1.103 2004/11/16 17:29:04 rurban
2411 // fix remove notification error
2412 // fix creation + update id_cache update
2414 // Revision 1.102 2004/11/11 18:31:26 rurban
2415 // add simple backtrace on such general failures to get at least an idea where
2417 // Revision 1.101 2004/11/10 19:32:22 rurban
2418 // * optimize increaseHitCount, esp. for mysql.
2419 // * prepend dirs to the include_path (phpwiki_dir for faster searches)
2420 // * Pear_DB version logic (awful but needed)
2421 // * fix broken ADODB quote
2422 // * _extract_page_data simplification
2424 // Revision 1.100 2004/11/10 15:29:20 rurban
2425 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
2426 // * ACCESS_LOG_SQL: fix cause request not yet initialized
2427 // * WikiDB: moved SQL specific methods upwards
2428 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
2429 // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
2431 // Revision 1.99 2004/11/09 17:11:05 rurban
2432 // * revert to the wikidb ref passing. there's no memory abuse there.
2433 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
2434 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
2435 // are also needed at the rendering for linkExistingWikiWord().
2436 // pass options to pageiterator.
2437 // use this cache also for _get_pageid()
2438 // This saves about 8 SELECT count per page (num all pagelinks).
2439 // * fix passing of all page fields to the pageiterator.
2440 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
2442 // Revision 1.98 2004/11/07 18:34:29 rurban
2443 // more logging fixes
2445 // Revision 1.97 2004/11/07 16:02:51 rurban
2446 // new sql access log (for spam prevention), and restructured access log class
2447 // dbh->quote (generic)
2448 // pear_db: mysql specific parts seperated (using replace)
2450 // Revision 1.96 2004/11/05 22:32:15 rurban
2451 // encode the subject to be 7-bit safe
2453 // Revision 1.95 2004/11/05 20:53:35 rurban
2454 // login cleanup: better debug msg on failing login,
2455 // checked password less immediate login (bogo or anon),
2456 // checked olduser pref session error,
2457 // better PersonalPage without password warning on minimal password length=0
2458 // (which is default now)
2460 // Revision 1.94 2004/11/01 10:43:56 rurban
2461 // seperate PassUser methods into seperate dir (memory usage)
2462 // fix WikiUser (old) overlarge data session
2463 // remove wikidb arg from various page class methods, use global ->_dbi instead
2466 // Revision 1.93 2004/10/14 17:17:57 rurban
2467 // remove dbi WikiDB_Page param: use global request object instead. (memory)
2468 // allow most_popular sortby arguments
2470 // Revision 1.92 2004/10/05 17:00:04 rurban
2471 // support paging for simple lists
2472 // fix RatingDb sql backend.
2473 // remove pages from AllPages (this is ListPages then)
2475 // Revision 1.91 2004/10/04 23:41:19 rurban
2476 // delete notify: fix, @unset syntax error
2478 // Revision 1.90 2004/09/28 12:50:22 rurban
2479 // https://sourceforge.net/forum/forum.php?thread_id=1150924&forum_id=18929
2481 // Revision 1.89 2004/09/26 10:54:42 rurban
2482 // silence deferred check
2484 // Revision 1.88 2004/09/25 18:16:40 rurban
2485 // unset more unneeded _cached_html. (Guess this should fix sf.net now)
2487 // Revision 1.87 2004/09/25 16:25:40 rurban
2488 // notify on rename and remove (to be improved)
2490 // Revision 1.86 2004/09/23 18:52:06 rurban
2491 // only fortune at create
2493 // Revision 1.85 2004/09/16 08:00:51 rurban
2494 // just some comments
2496 // Revision 1.84 2004/09/14 10:34:30 rurban
2497 // fix TransformedText call to use refs
2499 // Revision 1.83 2004/09/08 13:38:00 rurban
2500 // improve loadfile stability by using markup=2 as default for undefined markup-style.
2501 // use more refs for huge objects.
2502 // fix debug=static issue in WikiPluginCached
2504 // Revision 1.82 2004/09/06 12:08:49 rurban
2505 // memory_limit on unix workaround
2506 // VisualWiki: default autosize image
2508 // Revision 1.81 2004/09/06 08:28:00 rurban
2509 // rename genericQuery to genericSqlQuery
2511 // Revision 1.80 2004/07/09 13:05:34 rurban
2514 // Revision 1.79 2004/07/09 10:06:49 rurban
2515 // Use backend specific sortby and sortable_columns method, to be able to
2516 // select between native (Db backend) and custom (PageList) sorting.
2517 // Fixed PageList::AddPageList (missed the first)
2518 // Added the author/creator.. name to AllPagesBy...
2519 // display no pages if none matched.
2520 // Improved dba and file sortby().
2521 // Use &$request reference
2523 // Revision 1.78 2004/07/08 21:32:35 rurban
2524 // Prevent from more warnings, minor db and sort optimizations
2526 // Revision 1.77 2004/07/08 19:04:42 rurban
2527 // more unittest fixes (file backend, metadata RatingsDb)
2529 // Revision 1.76 2004/07/08 17:31:43 rurban
2530 // improve numPages for file (fixing AllPagesTest)
2532 // Revision 1.75 2004/07/05 13:56:22 rurban
2533 // sqlite autoincrement fix
2535 // Revision 1.74 2004/07/03 16:51:05 rurban
2536 // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
2537 // added atomic mysql REPLACE for PearDB as in ADODB
2538 // fixed _lock_tables typo links => link
2539 // fixes unserialize ADODB bug in line 180
2541 // Revision 1.73 2004/06/29 08:52:22 rurban
2542 // Use ...version() $need_content argument in WikiDB also:
2543 // To reduce the memory footprint for larger sets of pagelists,
2544 // we don't cache the content (only true or false) and
2545 // we purge the pagedata (_cached_html) also.
2546 // _cached_html is only cached for the current pagename.
2547 // => Vastly improved page existance check, ACL check, ...
2549 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
2551 // Revision 1.72 2004/06/25 14:15:08 rurban
2552 // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
2554 // Revision 1.71 2004/06/21 16:22:30 rurban
2555 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
2556 // fixed dumping buttons locally (images/buttons/),
2557 // support pages arg for dumphtml,
2558 // optional directory arg for dumpserial + dumphtml,
2559 // fix a AllPages warning,
2560 // show dump warnings/errors on DEBUG,
2561 // don't warn just ignore on wikilens pagelist columns, if not loaded.
2562 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
2564 // Revision 1.70 2004/06/18 14:39:31 rurban
2565 // actually check USECACHE
2567 // Revision 1.69 2004/06/13 15:33:20 rurban
2568 // new support for arguments owner, author, creator in most relevant
2569 // PageList plugins. in WikiAdmin* via preSelectS()
2571 // Revision 1.68 2004/06/08 21:03:20 rurban
2572 // updated RssParser for XmlParser quirks (store parser object params in globals)
2574 // Revision 1.67 2004/06/07 19:12:49 rurban
2575 // fixed rename version=0, bug #966284
2577 // Revision 1.66 2004/06/07 18:57:27 rurban
2578 // fix rename: Change pagename in all linked pages
2580 // Revision 1.65 2004/06/04 20:32:53 rurban
2581 // Several locale related improvements suggested by Pierrick Meignen
2582 // LDAP fix by John Cole
2583 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
2585 // Revision 1.64 2004/06/04 16:50:00 rurban
2586 // add random quotes to empty pages
2588 // Revision 1.63 2004/06/04 11:58:38 rurban
2589 // added USE_TAGLINES
2591 // Revision 1.62 2004/06/03 22:24:41 rurban
2592 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
2594 // Revision 1.61 2004/06/02 17:13:48 rurban
2595 // fix getRevisionBefore assertion
2597 // Revision 1.60 2004/05/28 10:09:58 rurban
2598 // fix bug #962117, incorrect init of auth_dsn
2600 // Revision 1.59 2004/05/27 17:49:05 rurban
2601 // renamed DB_Session to DbSession (in CVS also)
2602 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
2603 // remove leading slash in error message
2604 // added force_unlock parameter to File_Passwd (no return on stale locks)
2605 // fixed adodb session AffectedRows
2606 // added FileFinder helpers to unify local filenames and DATA_PATH names
2607 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
2609 // Revision 1.58 2004/05/18 13:59:14 rurban
2610 // rename simpleQuery to genericQuery
2612 // Revision 1.57 2004/05/16 22:07:35 rurban
2613 // check more config-default and predefined constants
2614 // various PagePerm fixes:
2615 // fix default PagePerms, esp. edit and view for Bogo and Password users
2616 // implemented Creator and Owner
2617 // BOGOUSERS renamed to BOGOUSER
2618 // fixed syntax errors in signin.tmpl
2620 // Revision 1.56 2004/05/15 22:54:49 rurban
2621 // fixed important WikiDB bug with DEBUG > 0: wrong assertion
2622 // improved SetAcl (works) and PagePerms, some WikiGroup helpers.
2624 // Revision 1.55 2004/05/12 19:27:47 rurban
2625 // revert wrong inline optimization.
2627 // Revision 1.54 2004/05/12 10:49:55 rurban
2628 // require_once fix for those libs which are loaded before FileFinder and
2629 // its automatic include_path fix, and where require_once doesn't grok
2630 // dirname(__FILE__) != './lib'
2631 // upgrade fix with PearDB
2632 // navbar.tmpl: remove spaces for IE button alignment
2634 // Revision 1.53 2004/05/08 14:06:12 rurban
2635 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
2636 // minor stability and portability fixes
2638 // Revision 1.52 2004/05/06 19:26:16 rurban
2639 // improve stability, trying to find the InlineParser endless loop on sf.net
2641 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
2643 // Revision 1.51 2004/05/06 17:30:37 rurban
2644 // CategoryGroup: oops, dos2unix eol
2645 // improved phpwiki_version:
2646 // pre -= .0001 (1.3.10pre: 1030.099)
2647 // -p1 += .001 (1.3.9-p1: 1030.091)
2648 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
2649 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
2650 // backend->backendType(), backend->database(),
2651 // backend->listOfFields(),
2652 // backend->listOfTables(),
2654 // Revision 1.50 2004/05/04 22:34:25 rurban
2657 // Revision 1.49 2004/05/03 11:16:40 rurban
2658 // fixed sendPageChangeNotification
2659 // subject rewording
2661 // Revision 1.48 2004/04/29 23:03:54 rurban
2662 // fixed sf.net bug #940996
2664 // Revision 1.47 2004/04/29 19:39:44 rurban
2665 // special support for formatted plugins (one-liners)
2666 // like <small><plugin BlaBla ></small>
2667 // iter->asArray() helper for PopularNearby
2668 // db_session for older php's (no &func() allowed)
2670 // Revision 1.46 2004/04/26 20:44:34 rurban
2671 // locking table specific for better databases
2673 // Revision 1.45 2004/04/20 00:06:03 rurban
2674 // themable paging support
2676 // Revision 1.44 2004/04/19 18:27:45 rurban
2677 // Prevent from some PHP5 warnings (ref args, no :: object init)
2678 // php5 runs now through, just one wrong XmlElement object init missing
2679 // Removed unneccesary UpgradeUser lines
2680 // Changed WikiLink to omit version if current (RecentChanges)
2682 // Revision 1.43 2004/04/18 01:34:20 rurban
2683 // protect most_popular from sortby=mtime
2685 // Revision 1.42 2004/04/18 01:11:51 rurban
2686 // more numeric pagename fixes.
2687 // fixed action=upload with merge conflict warnings.
2688 // charset changed from constant to global (dynamic utf-8 switching)
2694 // c-basic-offset: 4
2695 // c-hanging-comment-ender-p: nil
2696 // indent-tabs-mode: nil