-<?php //$Id: WikiDB.php 8089 2011-06-01 12:21:26Z vargenau $
+<?php
require_once 'lib/PageType.php';
/**
* only create new revisions or delete old ones --- one can not modify
* an existing revision.
*/
-class WikiDB {
+class WikiDB
+{
/**
* Open a WikiDB database.
*
*
* @return WikiDB A WikiDB object.
**/
- function open ($dbparams) {
+ function open($dbparams)
+ {
$dbtype = $dbparams{'dbtype'};
include_once("lib/WikiDB/$dbtype.php");
return new $class ($dbparams);
}
-
/**
* Constructor.
*
* @access private
* @see open()
*/
- function WikiDB (&$backend, $dbparams) {
+ function WikiDB(&$backend, $dbparams)
+ {
$this->_backend =& $backend;
// don't do the following with the auth_dsn!
if (isset($dbparams['auth_dsn'])) return;
// devel checking.
if ((int)DEBUG & _DEBUG_SQL) {
$this->_backend->check();
- }
+ }
// might be changed when opening the database fails
$this->readonly = defined("READONLY") ? READONLY : false;
}
*
* @access public
*/
- function close () {
+ function close()
+ {
$this->_backend->close();
$this->_cache->close();
}
* @param string $pagename Which page to get.
* @return WikiDB_Page The requested WikiDB_Page.
*/
- function getPage($pagename) {
+ function getPage($pagename)
+ {
static $error_displayed = false;
- $pagename = (string) $pagename;
+ $pagename = (string)$pagename;
if ((int)DEBUG) {
if ($pagename === '') {
if ($error_displayed) return false;
* @return boolean True if the page actually exists with
* non-default contents in the WikiDataBase.
*/
- function isWikiPage ($pagename) {
+ function isWikiPage($pagename)
+ {
$page = $this->getPage($pagename);
return ($page and $page->exists());
}
* @param string $pagename Name of page to delete.
* @see purgePage
*/
- function deletePage($pagename) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function deletePage($pagename)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
// don't create empty revisions of already purged pages.
if ($this->_backend->get_latest_version($pagename))
$result = $this->_cache->delete_page($pagename);
if (ENABLE_MAILNOTIFY) {
include_once 'lib/MailNotify.php';
$MailNotify = new MailNotify($pagename);
- $MailNotify->onDeletePage ($this, $pagename);
+ $MailNotify->onDeletePage($this, $pagename);
}
//How to create a RecentChanges entry with explaining summary? Dynamically
* @param string $pagename Name of page to delete.
* @see deletePage
*/
- function purgePage($pagename) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function purgePage($pagename)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$result = $this->_cache->purge_page($pagename);
$this->deletePage($pagename); // just for the notification
return $result;
* If false the result is faster in natural order.
* @param string or false $limit Optional. Encoded as "$offset,$count".
* $offset defaults to 0.
- * @param string $exclude: Optional comma-seperated list of pagenames.
+ * @param string $exclude: Optional comma-separated list of pagenames.
*
* @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages
* in the WikiDB which have non-default contents.
*/
- function getAllPages($include_empty=false, $sortby='', $limit='', $exclude='')
+ function getAllPages($include_empty = false, $sortby = '', $limit = '', $exclude = '')
{
$result = $this->_backend->get_all_pages($include_empty, $sortby, $limit,
- $exclude);
+ $exclude);
return new WikiDB_PageIterator($this, $result,
- array('include_empty' => $include_empty,
- 'exclude' => $exclude,
- 'limit_by_db' => $result->_options['limit_by_db'],
- 'limit' => $result->limit()));
+ array('include_empty' => $include_empty,
+ 'exclude' => $exclude,
+ 'limit_by_db' => $result->_options['limit_by_db'],
+ 'limit' => $result->limit()));
}
/**
* @access public
*
* @param boolean $include_empty If true include also empty pages
- * @param string $exclude: comma-seperated list of pagenames.
+ * @param string $exclude: comma-separated list of pagenames.
* TBD: array of pagenames
* @return integer
*
*/
- function numPages($include_empty=false, $exclude='') {
+ function numPages($include_empty = false, $exclude = '')
+ {
if (method_exists($this->_backend, 'numPages'))
// FIXME: currently are all args ignored.
$count = $this->_backend->numPages($include_empty, $exclude);
* If false the result is faster in natural order.
* @param string or false $limit Optional. Encoded as "$offset,$count".
* $offset defaults to 0.
- * @param string $exclude: Optional comma-seperated list of pagenames.
+ * @param string $exclude: Optional comma-separated list of pagenames.
* @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
* @see TextSearchQuery
*/
- function titleSearch($search, $sortby='pagename', $limit='', $exclude='') {
+ function titleSearch($search, $sortby = 'pagename', $limit = '', $exclude = '')
+ {
$result = $this->_backend->text_search($search, false, $sortby, $limit, $exclude);
$options = array('exclude' => $exclude,
- 'limit' => $limit);
+ 'limit' => $limit);
//if (isset($result->_count)) $options['count'] = $result->_count;
return new WikiDB_PageIterator($this, $result, $options);
}
* If false the result is faster in natural order.
* @param string or false $limit Optional. Encoded as "$offset,$count".
* $offset defaults to 0.
- * @param string $exclude: Optional comma-seperated list of pagenames.
+ * @param string $exclude: Optional comma-separated list of pagenames.
* @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
* @see TextSearchQuery
*/
- function fullSearch($search, $sortby='pagename', $limit='', $exclude='') {
+ function fullSearch($search, $sortby = 'pagename', $limit = '', $exclude = '')
+ {
$result = $this->_backend->text_search($search, true, $sortby, $limit, $exclude);
return new WikiDB_PageIterator($this, $result,
- array('exclude' => $exclude,
- 'limit' => $limit,
- 'stoplisted' => $result->stoplisted
- ));
+ array('exclude' => $exclude,
+ 'limit' => $limit,
+ 'stoplisted' => $result->stoplisted
+ ));
}
/**
* @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching
* pages.
*/
- function mostPopular($limit = 20, $sortby = '-hits') {
+ function mostPopular($limit = 20, $sortby = '-hits')
+ {
$result = $this->_backend->most_popular($limit, $sortby);
return new WikiDB_PageIterator($this, $result);
}
* @return WikiDB_PageRevisionIterator A WikiDB_PageRevisionIterator
* containing the matching revisions.
*/
- function mostRecent($params = false) {
+ function mostRecent($params = false)
+ {
$result = $this->_backend->most_recent($params);
return new WikiDB_PageRevisionIterator($this, $result);
}
* @return Iterator A generic iterator containing rows of
* (duplicate) pagename, wantedfrom.
*/
- function wantedPages($exclude_from='', $exclude='', $sortby='', $limit='') {
+ function wantedPages($exclude_from = '', $exclude = '', $sortby = '', $limit = '')
+ {
return $this->_backend->wanted_pages($exclude_from, $exclude, $sortby, $limit);
//return new WikiDB_PageIterator($this, $result);
}
* @return Iterator A generic iterator containing links to pages or values.
* hash of "pagename", "linkname", "linkvalue.
*/
- function linkSearch($pages, $search, $linktype, $relation=false) {
+ function linkSearch($pages, $search, $linktype, $relation = false)
+ {
return $this->_backend->link_search($pages, $search, $linktype, $relation);
}
*
* @return array of strings
*/
- function listRelations($also_attributes=false, $only_attributes=false, $sorted=true) {
+ function listRelations($also_attributes = false, $only_attributes = false, $sorted = true)
+ {
if (method_exists($this->_backend, "list_relations"))
return $this->_backend->list_relations($also_attributes, $only_attributes, $sorted);
- // dumb, slow fallback. no iter, so simply define it here.
+ // dumb, slow fallback. no iter, so simply define it here.
$relations = array();
$iter = $this->getAllPages();
while ($page = $iter->next()) {
$reliter = $page->getRelations();
$names = array();
while ($rel = $reliter->next()) {
- // if there's no pagename it's an attribute
+ // if there's no pagename it's an attribute
$names[] = $rel->getName();
}
$relations = array_merge($relations, $names);
$reliter->free();
}
$iter->free();
- if ($sorted) {
- sort($relations);
- reset($relations);
- }
+ if ($sorted) {
+ sort($relations);
+ reset($relations);
+ }
return $relations;
}
* @param boolean $updateWikiLinks If the text in all pages should be replaced.
* @return boolean true or false
*/
- function renamePage($from, $to, $updateWikiLinks = false) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function renamePage($from, $to, $updateWikiLinks = false)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
assert(is_string($from) && $from != '');
assert(is_string($to) && $to != '');
$result = false;
//update all WikiLinks in existing pages
//non-atomic! i.e. if rename fails the links are not undone
if ($updateWikiLinks) {
- $lookbehind = "/(?<=[\W:])\Q";
- $lookahead = "\E(?=[\W:])/";
+ $lookbehind = "/(?<=[\W:])\Q";
+ $lookahead = "\E(?=[\W:])/";
require_once 'lib/plugin/WikiAdminSearchReplace.php';
$links = $oldpage->getBackLinks();
while ($linked_page = $links->next()) {
WikiPlugin_WikiAdminSearchReplace::replaceHelper
- ($this,
- $linked_page->getName(),
- $lookbehind.$from.$lookahead, $to,
- true, true);
+ ($this,
+ $linked_page->getName(),
+ $lookbehind . $from . $lookahead, $to,
+ true, true);
}
// FIXME: Disabled to avoid recursive modification when renaming
// a page like 'PageFoo to 'PageFooTwo'
if (0) {
- $links = $newpage->getBackLinks();
- while ($linked_page = $links->next()) {
- WikiPlugin_WikiAdminSearchReplace::replaceHelper
- ($this,
- $linked_page->getName(),
- $lookbehind.$from.$lookahead, $to,
- true, true);
- }
+ $links = $newpage->getBackLinks();
+ while ($linked_page = $links->next()) {
+ WikiPlugin_WikiAdminSearchReplace::replaceHelper
+ ($this,
+ $linked_page->getName(),
+ $lookbehind . $from . $lookahead, $to,
+ true, true);
+ }
}
}
- if ($oldpage->exists() and ! $newpage->exists()) {
+ if ($oldpage->exists() and !$newpage->exists()) {
if ($result = $this->_backend->rename_page($from, $to)) {
// create a RecentChanges entry with explaining summary
$page = $this->getPage($to);
$meta = $current->_data;
$version = $current->getVersion();
$meta['summary'] = sprintf(_("renamed from %s"), $from);
- unset($meta['mtime']); // force new date
+ unset($meta['mtime']); // force new date
$page->save($current->getPackedContent(), $version + 1, $meta);
}
} elseif (!$oldpage->getCurrentRevision(false) and !$newpage->exists()) {
}
} else {
trigger_error(_("WikiDB::renamePage() not yet implemented for this backend"),
- E_USER_WARNING);
+ E_USER_WARNING);
}
/* Generate notification emails? */
if ($result and ENABLE_MAILNOTIFY and !isa($GLOBALS['request'], 'MockRequest')) {
if (!empty($notify) and is_array($notify)) {
include_once 'lib/MailNotify.php';
$MailNotify = new MailNotify($from);
- $MailNotify->onRenamePage ($this, $from, $to);
+ $MailNotify->onRenamePage($this, $from, $to);
}
}
return $result;
* int to get a timestamp, or you can use the string value
* as a good hash for the entire database.
*/
- function getTimestamp() {
+ function getTimestamp()
+ {
$ts = $this->get('_timestamp');
return sprintf("%d %d", $ts[0], $ts[1]);
}
* Update the database timestamp.
*
*/
- function touch() {
+ function touch()
+ {
$ts = $this->get('_timestamp');
$this->set('_timestamp', array(time(), $ts[1] + 1));
}
/**
* Roughly similar to the float in phpwiki_version(). Set by action=upgrade.
*/
- function get_db_version() {
- return (float) $this->get('_db_version');
+ function get_db_version()
+ {
+ return (float)$this->get('_db_version');
}
- function set_db_version($ver) {
+
+ function set_db_version($ver)
+ {
return $this->set('_db_version', (float)$ver);
}
* @return scalar The requested value, or false if the requested data
* is not set.
*/
- function get($key) {
+ function get($key)
+ {
if (!$key || $key[0] == '%')
return false;
/*
* @param string $key Meta-data key to set.
* @param string $newval New value.
*/
- function set($key, $newval) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function set($key, $newval)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
if (!$key || $key[0] == '%')
return;
// SQL result: for simple select or create/update queries
// returns the database specific resource type
- function genericSqlQuery($sql, $args=false) {
- echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
+ function genericSqlQuery($sql, $args = false)
+ {
+ echo "<pre>";
+ printSimpleTrace(debug_backtrace());
+ echo "</pre>\n";
trigger_error("no SQL database", E_USER_ERROR);
return false;
}
// SQL iter: for simple select or create/update queries
// returns the generic iterator object (count,next)
- function genericSqlIter($sql, $field_list = NULL) {
- echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
+ function genericSqlIter($sql, $field_list = NULL)
+ {
+ echo "<pre>";
+ printSimpleTrace(debug_backtrace());
+ echo "</pre>\n";
trigger_error("no SQL database", E_USER_ERROR);
return false;
}
// see backend upstream methods
// ADODB adds surrounding quotes, SQL not yet!
- function quote ($s) {
+ function quote($s)
+ {
return $s;
}
- function isOpen () {
+ function isOpen()
+ {
global $request;
if (!$request->_dbi) return false;
else return false; /* so far only needed for sql so false it.
later we have to check dba also */
}
- function getParam($param) {
+ function getParam($param)
+ {
global $DBParams;
if (isset($DBParams[$param])) return $DBParams[$param];
- elseif ($param == 'prefix') return '';
- else return false;
+ elseif ($param == 'prefix') return ''; else return false;
}
- function getAuthParam($param) {
+ function getAuthParam($param)
+ {
global $DBAuthParams;
if (isset($DBAuthParams[$param])) return $DBAuthParams[$param];
- elseif ($param == 'USER_AUTH_ORDER') return $GLOBALS['USER_AUTH_ORDER'];
- elseif ($param == 'USER_AUTH_POLICY') return $GLOBALS['USER_AUTH_POLICY'];
- else return false;
+ elseif ($param == 'USER_AUTH_ORDER') return $GLOBALS['USER_AUTH_ORDER']; elseif ($param == 'USER_AUTH_POLICY') return $GLOBALS['USER_AUTH_POLICY']; else return false;
}
-};
-
+}
/**
* A base class which representing a wiki-page within a
*/
class WikiDB_Page
{
- function WikiDB_Page(&$wikidb, $pagename) {
+ function WikiDB_Page(&$wikidb, $pagename)
+ {
$this->_wikidb = &$wikidb;
$this->_pagename = $pagename;
if ((int)DEBUG) {
if (!(is_string($pagename) and $pagename != '')) {
if (function_exists("xdebug_get_function_stack")) {
- echo "xdebug_get_function_stack(): "; var_dump(xdebug_get_function_stack());
+ echo "xdebug_get_function_stack(): ";
+ var_dump(xdebug_get_function_stack());
} else {
printSimpleTrace(debug_backtrace());
}
*
* @return string The page name.
*/
- function getName() {
+ function getName()
+ {
return $this->_pagename;
}
// To reduce the memory footprint for larger sets of pagelists,
// we don't cache the content (only true or false) and
// we purge the pagedata (_cached_html) also
- function exists() {
+ function exists()
+ {
if (isset($this->_wikidb->_cache->_id_cache[$this->_pagename])) return true;
$current = $this->getCurrentRevision(false);
if (!$current) return false;
- return ! $current->hasDefaultContents();
+ return !$current->hasDefaultContents();
}
/**
* @param integer $version Which revision to delete. (You can also
* use a WikiDB_PageRevision object here.)
*/
- function deleteRevision($version) {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function deleteRevision($version)
+ {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$backend = &$this->_wikidb->_backend;
$cache = &$this->_wikidb->_cache;
$pagename = &$this->_pagename;
if ($version == 0)
return;
- $backend->lock(array('page','version'));
+ $backend->lock(array('page', 'version'));
$latestversion = $cache->get_latest_version($pagename);
if ($latestversion && ($version == $latestversion)) {
- $backend->unlock(array('page','version'));
- trigger_error(sprintf("Attempt to delete most recent revision of '%s'",
- $pagename), E_USER_ERROR);
+ $backend->unlock(array('page', 'version'));
+ trigger_error(sprintf("Attempt to delete most recent revision of “%s”",
+ $pagename), E_USER_ERROR);
return;
}
$cache->delete_versiondata($pagename, $version);
- $backend->unlock(array('page','version'));
+ $backend->unlock(array('page', 'version'));
}
/*
* <li>It has the same author as the immediately preceding revision.
* </ul>
*/
- function mergeRevision($version) {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function mergeRevision($version)
+ {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$backend = &$this->_wikidb->_backend;
$cache = &$this->_wikidb->_cache;
$pagename = &$this->_pagename;
$latestversion = $cache->get_latest_version($pagename);
if ($latestversion && $version == $latestversion) {
$backend->unlock(array('version'));
- trigger_error(sprintf("Attempt to merge most recent revision of '%s'",
- $pagename), E_USER_ERROR);
+ trigger_error(sprintf("Attempt to merge most recent revision of “%s”",
+ $pagename), E_USER_ERROR);
return;
}
// by the same author. We will merge the
// revisions.
$cache->update_versiondata($pagename, $previous,
- array('%content' => $versiondata['%content'],
- '_supplanted' => $versiondata['_supplanted']));
+ array('%content' => $versiondata['%content'],
+ '_supplanted' => $versiondata['_supplanted']));
}
}
}
$backend->unlock(array('version'));
}
-
/**
* Create a new revision of a {@link WikiDB_Page}.
*
* @return WikiDB_PageRevision Returns the new WikiDB_PageRevision object. If
* $version was incorrect, returns false
*/
- function createRevision($version, &$content, $metadata, $links) {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function createRevision($version, &$content, $metadata, $links)
+ {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$backend = &$this->_wikidb->_backend;
$cache = &$this->_wikidb->_cache;
$pagename = &$this->_pagename;
$cache->invalidate_cache($pagename);
- $backend->lock(array('version','page','recent','link','nonempty'));
+ $backend->lock(array('version', 'page', 'recent', 'link', 'nonempty'));
$latestversion = $backend->get_latest_version($pagename);
$newversion = ($latestversion ? $latestversion : 0) + 1;
assert($newversion >= 1);
if ($version != WIKIDB_FORCE_CREATE and $version != $newversion) {
- $backend->unlock(array('version','page','recent','link','nonempty'));
+ $backend->unlock(array('version', 'page', 'recent', 'link', 'nonempty'));
return false;
}
$pdata = $cache->get_versiondata($pagename, $latestversion);
if ($data['mtime'] < $pdata['mtime']) {
trigger_error(sprintf(_("%s: Date of new revision is %s"),
- $pagename,"'non-monotonic'"),
- E_USER_NOTICE);
+ $pagename, "'non-monotonic'"),
+ E_USER_NOTICE);
$data['orig_mtime'] = $data['mtime'];
$data['mtime'] = $pdata['mtime'];
}
- // FIXME: use (possibly user specified) 'mtime' time or
- // time()?
+ // FIXME: use (possibly user specified) 'mtime' time or
+ // time()?
$cache->update_versiondata($pagename, $latestversion,
- array('_supplanted' => $data['mtime']));
+ array('_supplanted' => $data['mtime']));
}
$data['%content'] = &$content;
$backend->set_links($pagename, $links);
- $backend->unlock(array('version','page','recent','link','nonempty'));
+ $backend->unlock(array('version', 'page', 'recent', 'link', 'nonempty'));
return new WikiDB_PageRevision($this->_wikidb, $pagename, $newversion,
- $data);
+ $data);
}
/** A higher-level interface to createRevision.
*
* @param hash $meta Meta-data for new revision.
*/
- function save($wikitext, $version, $meta, $formatted = null) {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; }
- if (is_null($formatted))
- $formatted = new TransformedText($this, $wikitext, $meta);
+ function save($wikitext, $version, $meta, $formatted = null)
+ {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
+ if (is_null($formatted))
+ $formatted = new TransformedText($this, $wikitext, $meta);
$type = $formatted->getType();
- $meta['pagetype'] = $type->getName();
- $links = $formatted->getWikiPageLinks(); // linkto => relation
+ $meta['pagetype'] = $type->getName();
+ $links = $formatted->getWikiPageLinks(); // linkto => relation
$attributes = array();
foreach ($links as $link) {
if ($link['linkto'] === "" and !empty($link['relation'])) {
}
$meta['attribute'] = $attributes;
- $backend = &$this->_wikidb->_backend;
- $newrevision = $this->createRevision($version, $wikitext, $meta, $links);
- if ($newrevision and !WIKIDB_NOCACHE_MARKUP)
+ $backend = &$this->_wikidb->_backend;
+ $newrevision = $this->createRevision($version, $wikitext, $meta, $links);
+ if ($newrevision and !WIKIDB_NOCACHE_MARKUP)
$this->set('_cached_html', $formatted->pack());
- // FIXME: probably should have some global state information
- // in the backend to control when to optimize.
+ // FIXME: probably should have some global state information
+ // in the backend to control when to optimize.
//
// We're doing this here rather than in createRevision because
// postgresql can't optimize while locked.
if (((int)DEBUG & _DEBUG_SQL)
- or (DATABASE_OPTIMISE_FREQUENCY > 0 and
- (time() % DATABASE_OPTIMISE_FREQUENCY == 0))) {
+ or (DATABASE_OPTIMISE_FREQUENCY > 0 and
+ (time() % DATABASE_OPTIMISE_FREQUENCY == 0))
+ ) {
if ($backend->optimize()) {
if ((int)DEBUG)
trigger_error(_("Optimizing database"), E_USER_NOTICE);
// Save didn't fail because of concurrent updates.
$notify = $this->_wikidb->get('notify');
if (!empty($notify)
- and is_array($notify)
- and !isa($GLOBALS['request'],'MockRequest'))
- {
+ and is_array($notify)
+ and !isa($GLOBALS['request'], 'MockRequest')
+ ) {
include_once 'lib/MailNotify.php';
$MailNotify = new MailNotify($newrevision->getName());
- $MailNotify->onChangePage ($this->_wikidb, $wikitext, $version, $meta);
+ $MailNotify->onChangePage($this->_wikidb, $wikitext, $version, $meta);
}
$newrevision->_transformedContent = $formatted;
}
// more pagechange callbacks: (in a hackish manner for now)
if (ENABLE_RECENTCHANGESBOX
and empty($meta['is_minor_edit'])
- and !in_array($GLOBALS['request']->getArg('action'),
- array('loadfile','upgrade')))
- {
+ and !in_array($GLOBALS['request']->getArg('action'),
+ array('loadfile', 'upgrade'))
+ ) {
require_once 'lib/WikiPlugin.php';
- $w = new WikiPluginLoader;
+ $w = new WikiPluginLoader();
$p = $w->getPlugin("RecentChangesCached", false);
$p->box_update(false, $GLOBALS['request'], $this->_pagename);
}
- return $newrevision;
+ return $newrevision;
}
/**
*
* @return WikiDB_PageRevision The current WikiDB_PageRevision object.
*/
- function getCurrentRevision ($need_content=true) {
+ function getCurrentRevision($need_content = true)
+ {
$backend = &$this->_wikidb->_backend;
$cache = &$this->_wikidb->_cache;
$pagename = &$this->_pagename;
* false if the requested revision does not exist in the {@link WikiDB}.
* Note that version zero of any page always exists.
*/
- function getRevision ($version, $need_content=true) {
+ function getRevision($version, $need_content = true)
+ {
$cache = &$this->_wikidb->_cache;
$pagename = &$this->_pagename;
return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
}
return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
- $vdata);
+ $vdata);
}
/**
* unless $version is greater than zero, a revision (perhaps version zero,
* the default revision) will always be found.
*/
- function getRevisionBefore ($version=false, $need_content=true) {
+ function getRevisionBefore($version = false, $need_content = true)
+ {
$backend = &$this->_wikidb->_backend;
$pagename = &$this->_pagename;
if ($version === false)
* WikiDB_PageRevisionIterator containing all revisions of this
* WikiDB_Page in reverse order by version number.
*/
- function getAllRevisions() {
+ function getAllRevisions()
+ {
$backend = &$this->_wikidb->_backend;
$revs = $backend->get_all_revisions($this->_pagename);
return new WikiDB_PageRevisionIterator($this->_wikidb, $revs);
* @return WikiDB_PageIterator A WikiDB_PageIterator containing
* all matching pages.
*/
- function getLinks ($reversed=true, $include_empty=false, $sortby='',
- $limit='', $exclude='', $want_relations=false)
+ function getLinks($reversed = true, $include_empty = false, $sortby = '',
+ $limit = '', $exclude = '', $want_relations = false)
{
$backend = &$this->_wikidb->_backend;
- $result = $backend->get_links($this->_pagename, $reversed,
- $include_empty, $sortby, $limit, $exclude,
- $want_relations);
+ $result = $backend->get_links($this->_pagename, $reversed,
+ $include_empty, $sortby, $limit, $exclude,
+ $want_relations);
return new WikiDB_PageIterator($this->_wikidb, $result,
- array('include_empty' => $include_empty,
- 'sortby' => $sortby,
- 'limit' => $limit,
- 'exclude' => $exclude,
- 'want_relations'=> $want_relations));
+ array('include_empty' => $include_empty,
+ 'sortby' => $sortby,
+ 'limit' => $limit,
+ 'exclude' => $exclude,
+ 'want_relations' => $want_relations));
}
/**
* All Links from other pages to this page.
*/
- function getBackLinks($include_empty=false, $sortby='', $limit='', $exclude='',
- $want_relations=false)
+ function getBackLinks($include_empty = false, $sortby = '', $limit = '', $exclude = '',
+ $want_relations = false)
{
return $this->getLinks(true, $include_empty, $sortby, $limit, $exclude);
}
+
/**
* Forward Links: All Links from this page to other pages.
*/
- function getPageLinks($include_empty=false, $sortby='', $limit='', $exclude='',
- $want_relations=false)
+ function getPageLinks($include_empty = false, $sortby = '', $limit = '', $exclude = '',
+ $want_relations = false)
{
return $this->getLinks(false, $include_empty, $sortby, $limit, $exclude);
}
+
/**
* Relations: All links from this page to other pages with relation <> 0.
* is_a:=page or population:=number
*/
- function getRelations($sortby='', $limit='', $exclude='') {
+ function getRelations($sortby = '', $limit = '', $exclude = '')
+ {
$backend = &$this->_wikidb->_backend;
- $result = $backend->get_links($this->_pagename, false, true,
- $sortby, $limit, $exclude,
- true);
+ $result = $backend->get_links($this->_pagename, false, true,
+ $sortby, $limit, $exclude,
+ true);
// we do not care for the linked page versiondata, just the pagename and linkrelation
return new WikiDB_PageIterator($this->_wikidb, $result,
- array('include_empty' => true,
- 'sortby' => $sortby,
- 'limit' => $limit,
- 'exclude' => $exclude,
- 'want_relations'=> true));
+ array('include_empty' => true,
+ 'sortby' => $sortby,
+ 'limit' => $limit,
+ 'exclude' => $exclude,
+ 'want_relations' => true));
}
/**
* possibly faster link existance check. not yet accelerated.
*/
- function existLink($link, $reversed=false) {
+ function existLink($link, $reversed = false)
+ {
$backend = &$this->_wikidb->_backend;
- if (method_exists($backend,'exists_link'))
+ if (method_exists($backend, 'exists_link'))
return $backend->exists_link($this->_pagename, $link, $reversed);
//$cache = &$this->_wikidb->_cache;
// TODO: check cache if it is possible
* E.g. "owner.users"
* <dt>'perm' <dd> Permission flag to authorize read/write/execution of
* page-headers and content.
- + <dt>'moderation'<dd> ModeratedPage data. Handled by plugin/ModeratedPage
+ + <dt>'moderation'<dd> ModeratedPage data. Handled by plugin/ModeratedPage
* <dt>'rating' <dd> Page rating. Handled by plugin/RateIt
* </dl>
*
* @return scalar The requested value, or false if the requested data
* is not set.
*/
- function get($key) {
+ function get($key)
+ {
$cache = &$this->_wikidb->_cache;
$backend = &$this->_wikidb->_backend;
if (!$key || $key[0] == '%')
// several new SQL backends optimize this.
if (!WIKIDB_NOCACHE_MARKUP
and $key == '_cached_html'
- and method_exists($backend, 'get_cached_html'))
- {
+ and method_exists($backend, 'get_cached_html')
+ ) {
return $backend->get_cached_html($this->_pagename);
}
$data = $cache->get_pagedata($this->_pagename);
*
* @return hash The page meta-data.
*/
- function getMetaData() {
+ function getMetaData()
+ {
$cache = &$this->_wikidb->_cache;
$data = $cache->get_pagedata($this->_pagename);
$meta = array();
foreach ($data as $key => $val) {
- if (/*!empty($val) &&*/ $key[0] != '%')
+ if ( /*!empty($val) &&*/
+ $key[0] != '%'
+ )
$meta[$key] = $val;
}
return $meta;
* @param string $key Meta-data key to set.
* @param string $newval New value.
*/
- function set($key, $newval) {
+ function set($key, $newval)
+ {
$cache = &$this->_wikidb->_cache;
$backend = &$this->_wikidb->_backend;
$pagename = &$this->_pagename;
// several new SQL backends optimize this.
if (!WIKIDB_NOCACHE_MARKUP
and $key == '_cached_html'
- and method_exists($backend, 'set_cached_html'))
- {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_WARNING); return; }
+ and method_exists($backend, 'set_cached_html')
+ ) {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
return $backend->set_cached_html($pagename, $newval);
}
if (!empty($newval)) {
if (!empty($data[$key]) && $data[$key] == $newval)
- return; // values identical, skip update.
- }
- else {
+ return; // values identical, skip update.
+ } else {
if (empty($data[$key]))
- return; // values identical, skip update.
+ return; // values identical, skip update.
}
if (isset($this->_wikidb->readonly) and ($this->_wikidb->readonly)) {
*
* @access public
*/
- function increaseHitCount() {
- if ($this->_wikidb->readonly) { trigger_error("readonly database", E_USER_NOTICE); return; }
+ function increaseHitCount()
+ {
+ if ($this->_wikidb->readonly) {
+ trigger_error("readonly database", E_USER_NOTICE);
+ return;
+ }
if (method_exists($this->_wikidb->_backend, 'increaseHitCount'))
$this->_wikidb->_backend->increaseHitCount($this->_pagename);
else {
*
* @return string Printable representation of the WikiDB_Page.
*/
- function asString () {
+ function asString()
+ {
ob_start();
printf("[%s:%s\n", get_class($this), $this->getName());
print_r($this->getMetaData());
return $strval;
}
-
/**
* @access private
* @param integer_or_object $version_or_pagerevision
* object.
* @return integer The version number.
*/
- function _coerce_to_version($version_or_pagerevision) {
+ function _coerce_to_version($version_or_pagerevision)
+ {
if (method_exists($version_or_pagerevision, "getContent"))
$version = $version_or_pagerevision->getVersion();
else
- $version = (int) $version_or_pagerevision;
+ $version = (int)$version_or_pagerevision;
assert($version >= 0);
return $version;
}
- function isUserPage ($include_empty = true) {
+ function isUserPage($include_empty = true)
+ {
if (!$include_empty and !$this->exists()) return false;
return $this->get('pref') ? true : false;
}
// May be empty. Either the stored owner (/Chown), or the first authorized author
- function getOwner() {
+ function getOwner()
+ {
if ($owner = $this->get('owner'))
return $owner;
// check all revisions forwards for the first author_id
$backend = &$this->_wikidb->_backend;
$pagename = &$this->_pagename;
$latestversion = $backend->get_latest_version($pagename);
- for ($v=1; $v <= $latestversion; $v++) {
- $rev = $this->getRevision($v,false);
+ for ($v = 1; $v <= $latestversion; $v++) {
+ $rev = $this->getRevision($v, false);
if ($rev and $owner = $rev->get('author_id')) {
return $owner;
}
}
// The authenticated author of the first revision or empty if not authenticated then.
- function getCreator() {
- if ($current = $this->getRevision(1,false)) return $current->get('author_id');
+ function getCreator()
+ {
+ if ($current = $this->getRevision(1, false)) return $current->get('author_id');
else return '';
}
// The authenticated author of the current revision.
- function getAuthor() {
+ function getAuthor()
+ {
if ($current = $this->getCurrentRevision(false)) return $current->get('author_id');
else return '';
}
/* Semantic Web value, not stored in the links.
* todo: unify with some unit knowledge
*/
- function setAttribute($relation, $value) {
+ function setAttribute($relation, $value)
+ {
$attr = $this->get('attributes');
if (empty($attr))
$attr = array($relation => $value);
$this->set('attributes', $attr);
}
- function getAttribute($relation) {
+ function getAttribute($relation)
+ {
$meta = $this->get('attributes');
if (empty($meta))
return '';
return $meta[$relation];
}
-};
+}
/**
* This class represents a specific revision of a WikiDB_Page within
*/
class WikiDB_PageRevision
{
- //var $_transformedContent = false; // set by WikiDB_Page::save()
+ public $_transformedContent = false; // set by WikiDB_Page::save()
function WikiDB_PageRevision(&$wikidb, $pagename, $version,
$versiondata = false)
*
* @return WikiDB_Page The WikiDB_Page which this revision belongs to.
*/
- function getPage() {
+ function getPage()
+ {
return new WikiDB_Page($this->_wikidb, $this->_pagename);
}
*
* @return integer The version number of this revision.
*/
- function getVersion() {
+ function getVersion()
+ {
return $this->_version;
}
*
* @return boolean Returns true if the page has default content.
*/
- function hasDefaultContents() {
+ function hasDefaultContents()
+ {
$data = &$this->_data;
if (!isset($data['%content'])) return true;
if ($data['%content'] === true) return false;
* @return array An array of lines.
* The lines should contain no trailing white space.
*/
- function getContent() {
+ function getContent()
+ {
return explode("\n", $this->getPackedContent());
}
- /**
+ /**
* Get the pagename of the revision.
*
* @access public
*
* @return string pagename.
*/
- function getPageName() {
+ function getPageName()
+ {
return $this->_pagename;
}
- function getName() {
+
+ function getName()
+ {
return $this->_pagename;
}
*
* @return boolean True iff the revision is the latest (most recent) one.
*/
- function isCurrent() {
+ function isCurrent()
+ {
if (!isset($this->_iscurrent)) {
$page = $this->getPage();
$current = $page->getCurrentRevision(false);
* @return object An XmlContent-like object containing the page transformed
* contents.
*/
- function getTransformedContent($pagetype_override=false) {
- $backend = &$this->_wikidb->_backend;
+ function getTransformedContent($pagetype_override = false)
+ {
+ $backend = &$this->_wikidb->_backend;
- if ($pagetype_override) {
- // Figure out the normal page-type for this page.
+ if ($pagetype_override) {
+ // Figure out the normal page-type for this page.
$type = PageType::GetPageType($this->get('pagetype'));
- if ($type->getName() == $pagetype_override)
- $pagetype_override = false; // Not really an override...
- }
+ if ($type->getName() == $pagetype_override)
+ $pagetype_override = false; // Not really an override...
+ }
if ($pagetype_override) {
// Overriden page type, don't cache (or check cache).
- return new TransformedText($this->getPage(),
- $this->getPackedContent(),
- $this->getMetaData(),
- $pagetype_override);
+ return new TransformedText($this->getPage(),
+ $this->getPackedContent(),
+ $this->getMetaData(),
+ $pagetype_override);
}
$possibly_cache_results = true;
$page->set('_cached_html', ''); // ignored with !USECACHE
}
$possibly_cache_results = false;
- }
- elseif (USECACHE and !$this->_transformedContent) {
+ } elseif (USECACHE and !$this->_transformedContent) {
//$backend->lock();
if ($this->isCurrent()) {
$page = $this->getPage();
$this->_transformedContent = TransformedText::unpack($page->get('_cached_html'));
- }
- else {
+ } else {
$possibly_cache_results = false;
}
//$backend->unlock();
- }
+ }
if (!$this->_transformedContent) {
$this->_transformedContent
= new TransformedText($this->getPage(),
- $this->getPackedContent(),
- $this->getMetaData());
+ $this->getPackedContent(),
+ $this->getMetaData());
if ($possibly_cache_results and !WIKIDB_NOCACHE_MARKUP) {
// If we're still the current version, cache the transfomed page.
* @return string The page content.
* Lines are separated by new-lines.
*/
- function getPackedContent() {
+ function getPackedContent()
+ {
$data = &$this->_data;
if (empty($data['%content'])
|| (!$this->_wikidb->isWikiPage($this->_pagename)
- && $this->isCurrent())) {
+ && $this->isCurrent())
+ ) {
include_once 'lib/InlineParser.php';
// A feature similar to taglines at http://www.wlug.org.nz/
// Lib from http://www.aasted.org/quote/
if (defined('FORTUNE_DIR')
and is_dir(FORTUNE_DIR)
- and in_array($GLOBALS['request']->getArg('action'),
- array('create','edit')))
- {
+ and in_array($GLOBALS['request']->getArg('action'),
+ array('create', 'edit'))
+ ) {
include_once 'lib/fortune.php';
$fortune = new Fortune();
- $quote = $fortune->quoteFromDir(FORTUNE_DIR);
- if ($quote != -1)
- $quote = "<verbatim>\n"
- . str_replace("\n<br>","\n", $quote)
- . "</verbatim>\n\n";
- else
- $quote = "";
+ $quote = $fortune->quoteFromDir(FORTUNE_DIR);
+ if ($quote != -1)
+ $quote = "<verbatim>\n"
+ . str_replace("\n<br>", "\n", $quote)
+ . "</verbatim>\n\n";
+ else
+ $quote = "";
return $quote
- . sprintf(_("Describe %s here."),
- "[" . WikiEscape($this->_pagename) . "]");
+ . sprintf(_("Describe %s here."),
+ "[" . WikiEscape($this->_pagename) . "]");
}
// Replace empty content with default value.
return sprintf(_("Describe %s here."),
- "[" . WikiEscape($this->_pagename) . "]");
+ "[" . WikiEscape($this->_pagename) . "]");
}
// There is (non-default) content.
return $data['%content'];
}
- function _get_content() {
+ function _get_content()
+ {
$cache = &$this->_wikidb->_cache;
$pagename = $this->_pagename;
$version = $this->_version;
if ($newdata) {
assert(is_string($newdata['%content']));
return $newdata['%content'];
- }
- else {
+ } else {
// else revision has been deleted... What to do?
return __sprintf("Oops! Revision %s of %s seems to have been deleted!",
- $version, $pagename);
+ $version, $pagename);
}
}
* @return string The requested value, or false if the requested value
* is not defined.
*/
- function get($key) {
+ function get($key)
+ {
if (!$key || $key[0] == '%')
return false;
$data = &$this->_data;
*
* @return hash The revision meta-data.
*/
- function getMetaData() {
+ function getMetaData()
+ {
$meta = array();
foreach ($this->_data as $key => $val) {
if (!empty($val) && $key[0] != '%')
return $meta;
}
-
/**
* Return a string representation of the revision.
*
*
* @return string Printable representation of the WikiDB_Page.
*/
- function asString () {
+ function asString()
+ {
ob_start();
printf("[%s:%d\n", get_class($this), $this->get('version'));
print_r($this->_data);
ob_end_clean();
return $strval;
}
-};
-
+}
/**
* Class representing a sequence of WikiDB_Pages.
*/
class WikiDB_PageIterator
{
- function WikiDB_PageIterator(&$wikidb, &$iter, $options=false) {
+ function WikiDB_PageIterator(&$wikidb, &$iter, $options = false)
+ {
$this->_iter = $iter; // a WikiDB_backend_iterator
$this->_wikidb = &$wikidb;
$this->_options = $options;
- }
+ }
- function count () {
+ function count()
+ {
return $this->_iter->count();
}
- function limit () {
+
+ function limit()
+ {
return empty($this->_options['limit']) ? 0 : $this->_options['limit'];
}
*
* @return WikiDB_Page The next WikiDB_Page in the sequence.
*/
- function next () {
- if ( ! ($next = $this->_iter->next()) ) {
+ function next()
+ {
+ if (!($next = $this->_iter->next())) {
return false;
}
if (!$pagename) {
if (isset($next['linkrelation'])
- or isset($next['pagedata']['linkrelation'])) {
+ or isset($next['pagedata']['linkrelation'])
+ ) {
return false;
}
}
// (well not with file, cvs and dba)
if (isset($next['pagedata']) and count($next['pagedata']) > 1) {
$this->_wikidb->_cache->cache_data($next);
- // cache existing page id's since we iterate over all links in GleanDescription
- // and need them later for LinkExistingWord
+ // cache existing page id's since we iterate over all links in GleanDescription
+ // and need them later for LinkExistingWord
} elseif ($this->_options and array_key_exists('include_empty', $this->_options)
- and !$this->_options['include_empty'] and isset($next['id'])) {
+ and !$this->_options['include_empty'] and isset($next['id'])
+ ) {
$this->_wikidb->_cache->_id_cache[$next['pagename']] = $next['id'];
}
$page = new WikiDB_Page($this->_wikidb, $pagename);
*
* @access public
*/
- function free() {
+ function free()
+ {
$this->_iter->free();
}
- function reset() {
+
+ function reset()
+ {
$this->_iter->reset();
}
- function asArray() {
+
+ function asArray()
+ {
$result = array();
while ($page = $this->next())
$result[] = $page;
* Since iteration is usually destructive for SQL results,
* we have to generate a copy.
*/
- function applyFilters($options = false) {
+ function applyFilters($options = false)
+ {
if (!$options) $options = $this->_options;
if (isset($options['sortby'])) {
$array = array();
/* the rest is not destructive.
* reconstruct a new iterator
*/
- $pagenames = array(); $i = 0;
+ $pagenames = array();
+ $i = 0;
if (isset($options['limit']))
$limit = $options['limit'];
else
$exclude = $options['exclude'];
if (is_string($exclude) and !is_array($exclude))
$exclude = PageList::explodePageList($exclude, false, false, $limit);
- foreach($array as $pagename) {
+ foreach ($array as $pagename) {
if ($limit and $i++ > $limit)
return new WikiDB_Array_PageIterator($pagenames);
if (!empty($exclude) and !in_array($pagename, $exclude))
}
/* pagename only */
- function _doSort(&$array, $sortby) {
+ function _doSort(&$array, $sortby)
+ {
$sortby = PageList::sortby($sortby, 'init');
if ($sortby == '+pagename')
sort($array, SORT_STRING);
reset($array);
}
-};
+}
/**
* A class which represents a sequence of WikiDB_PageRevisions.
*/
class WikiDB_PageRevisionIterator
{
- function WikiDB_PageRevisionIterator(&$wikidb, &$revisions, $options=false) {
+ function WikiDB_PageRevisionIterator(&$wikidb, &$revisions, $options = false)
+ {
$this->_revisions = $revisions;
$this->_wikidb = &$wikidb;
$this->_options = $options;
}
- function count () {
+ function count()
+ {
return $this->_revisions->count();
}
* @return WikiDB_PageRevision
* The next WikiDB_PageRevision in the sequence.
*/
- function next () {
- if ( ! ($next = $this->_revisions->next()) )
+ function next()
+ {
+ if (!($next = $this->_revisions->next()))
return false;
//$this->_wikidb->_cache->cache_data($next);
$versiondata = $next['versiondata'];
if ((int)DEBUG) {
if (!(is_string($pagename) and $pagename != '')) {
- trigger_error("empty pagename",E_USER_WARNING);
+ trigger_error("empty pagename", E_USER_WARNING);
return false;
}
} else assert(is_string($pagename) and $pagename != '');
if ((int)DEBUG) {
if (!is_array($versiondata)) {
- trigger_error("empty versiondata",E_USER_WARNING);
+ trigger_error("empty versiondata", E_USER_WARNING);
return false;
}
} else assert(is_array($versiondata));
if ((int)DEBUG) {
if (!($version > 0)) {
- trigger_error("invalid version",E_USER_WARNING);
+ trigger_error("invalid version", E_USER_WARNING);
return false;
}
} else assert($version > 0);
return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
- $versiondata);
+ $versiondata);
}
/**
*
* @access public
*/
- function free() {
+ function free()
+ {
$this->_revisions->free();
}
- function asArray() {
+ function asArray()
+ {
$result = array();
while ($rev = $this->next())
$result[] = $rev;
$this->free();
return $result;
}
-};
+}
/** pseudo iterator
*/
class WikiDB_Array_PageIterator
{
- function WikiDB_Array_PageIterator($pagenames) {
+ function WikiDB_Array_PageIterator($pagenames)
+ {
global $request;
$this->_dbi = $request->getDbh();
$this->_pages = $pagenames;
reset($this->_pages);
}
- function next() {
+
+ function next()
+ {
$c = current($this->_pages);
next($this->_pages);
return $c !== false ? $this->_dbi->getPage($c) : false;
}
- function count() {
+
+ function count()
+ {
return count($this->_pages);
}
- function reset() {
+
+ function reset()
+ {
reset($this->_pages);
}
- function free() {}
- function asArray() {
+
+ function free()
+ {
+ }
+
+ function asArray()
+ {
reset($this->_pages);
return $this->_pages;
}
class WikiDB_Array_generic_iter
{
- function WikiDB_Array_generic_iter($result) {
+ function WikiDB_Array_generic_iter($result)
+ {
// $result may be either an array or a query result
if (is_array($result)) {
$this->_array = $result;
if (!empty($this->_array))
reset($this->_array);
}
- function next() {
+
+ function next()
+ {
$c = current($this->_array);
next($this->_array);
return $c !== false ? $c : false;
}
- function count() {
+
+ function count()
+ {
return count($this->_array);
}
- function reset() {
+
+ function reset()
+ {
reset($this->_array);
}
- function free() {}
- function asArray() {
+
+ function free()
+ {
+ }
+
+ function asArray()
+ {
if (!empty($this->_array))
reset($this->_array);
return $this->_array;
{
// FIXME: beautify versiondata cache. Cache only limited data?
- function WikiDB_cache (&$backend) {
+ function WikiDB_cache(&$backend)
+ {
$this->_backend = &$backend;
$this->_pagedata_cache = array();
$this->_versiondata_cache = array();
- array_push ($this->_versiondata_cache, array());
+ array_push($this->_versiondata_cache, array());
$this->_glv_cache = array();
$this->_id_cache = array(); // formerly ->_dbi->_iwpcache (nonempty pages => id)
$this->readonly = $GLOBALS['request']->_dbi->readonly;
}
- function close() {
+ function close()
+ {
$this->_pagedata_cache = array();
$this->_versiondata_cache = array();
$this->_glv_cache = array();
$this->_id_cache = array();
}
- function get_pagedata($pagename) {
+ function get_pagedata($pagename)
+ {
assert(is_string($pagename) && $pagename != '');
if (USECACHE) {
$cache = &$this->_pagedata_cache;
}
}
- function update_pagedata($pagename, $newdata) {
+ function update_pagedata($pagename, $newdata)
+ {
assert(is_string($pagename) && $pagename != '');
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$this->_backend->update_pagedata($pagename, $newdata);
if (USECACHE) {
if (!empty($this->_pagedata_cache[$pagename])
- and is_array($this->_pagedata_cache[$pagename]))
- {
+ and is_array($this->_pagedata_cache[$pagename])
+ ) {
$cachedata = &$this->_pagedata_cache[$pagename];
- foreach($newdata as $key => $val)
+ foreach ($newdata as $key => $val)
$cachedata[$key] = $val;
} else
$this->_pagedata_cache[$pagename] = $newdata;
}
}
- function invalidate_cache($pagename) {
+ function invalidate_cache($pagename)
+ {
unset ($this->_pagedata_cache[$pagename]);
unset ($this->_versiondata_cache[$pagename]);
unset ($this->_glv_cache[$pagename]);
//unset ($this->_backend->_page_data);
}
- function delete_page($pagename) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function delete_page($pagename)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$result = $this->_backend->delete_page($pagename);
$this->invalidate_cache($pagename);
return $result;
}
- function purge_page($pagename) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function purge_page($pagename)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$result = $this->_backend->purge_page($pagename);
$this->invalidate_cache($pagename);
return $result;
}
// FIXME: ugly and wrong. may overwrite full cache with partial cache
- function cache_data($data) {
+ function cache_data($data)
+ {
;
//if (isset($data['pagedata']))
// $this->_pagedata_cache[$data['pagename']] = $data['pagedata'];
}
- function get_versiondata($pagename, $version, $need_content = false) {
+ function get_versiondata($pagename, $version, $need_content = false)
+ {
// FIXME: Seriously ugly hackage
$readdata = false;
- if (USECACHE) { //temporary - for debugging
+ if (USECACHE) { //temporary - for debugging
assert(is_string($pagename) && $pagename != '');
// There is a bug here somewhere which results in an assertion failure at line 105
// of ArchiveCleaner.php It goes away if we use the next line.
//$need_content = true;
- $nc = $need_content ? '1':'0';
+ $nc = $need_content ? '1' : '0';
$cache = &$this->_versiondata_cache;
if (!isset($cache[$pagename][$version][$nc])
- || !(is_array ($cache[$pagename]))
- || !(is_array ($cache[$pagename][$version])))
- {
+ || !(is_array($cache[$pagename]))
+ || !(is_array($cache[$pagename][$version]))
+ ) {
$cache[$pagename][$version][$nc] =
$this->_backend->get_versiondata($pagename, $version, $need_content);
$readdata = true;
// If we have retrieved all data, we may as well set the cache for
// $need_content = false
- if ($need_content){
+ if ($need_content) {
$cache[$pagename][$version]['0'] =& $cache[$pagename][$version]['1'];
}
}
$vdata = $cache[$pagename][$version][$nc];
- } else {
+ } else {
$vdata = $this->_backend->get_versiondata($pagename, $version, $need_content);
$readdata = true;
- }
+ }
if ($readdata && is_array($vdata) && !empty($vdata['%pagedata'])) {
if (empty($this->_pagedata_cache))
$this->_pagedata_cache = array();
return $vdata;
}
- function set_versiondata($pagename, $version, $data) {
+ function set_versiondata($pagename, $version, $data)
+ {
//unset($this->_versiondata_cache[$pagename][$version]);
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$new = $this->_backend->set_versiondata($pagename, $version, $data);
// Update the cache
$this->_versiondata_cache[$pagename][$version]['1'] = $data;
unset($this->_glv_cache[$pagename]);
}
- function update_versiondata($pagename, $version, $data) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function update_versiondata($pagename, $version, $data)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$new = $this->_backend->update_versiondata($pagename, $version, $data);
// Update the cache
$this->_versiondata_cache[$pagename][$version]['1'] = $data;
unset($this->_glv_cache[$pagename]);
}
- function delete_versiondata($pagename, $version) {
- if (!empty($this->readonly)) { trigger_error("readonly database", E_USER_WARNING); return; }
+ function delete_versiondata($pagename, $version)
+ {
+ if (!empty($this->readonly)) {
+ trigger_error("readonly database", E_USER_WARNING);
+ return;
+ }
$new = $this->_backend->delete_versiondata($pagename, $version);
if (isset($this->_versiondata_cache[$pagename][$version]))
unset ($this->_versiondata_cache[$pagename][$version]);
unset ($this->_glv_cache[$pagename]);
}
- function get_latest_version($pagename) {
+ function get_latest_version($pagename)
+ {
if (USECACHE) {
- assert (is_string($pagename) && $pagename != '');
+ assert(is_string($pagename) && $pagename != '');
$cache = &$this->_glv_cache;
if (!isset($cache[$pagename])) {
$cache[$pagename] = $this->_backend->get_latest_version($pagename);
return $this->_backend->get_latest_version($pagename);
}
}
-};
+}
-function _sql_debuglog($msg, $newline=true, $shutdown=false) {
+function _sql_debuglog($msg, $newline = true, $shutdown = false)
+{
static $fp = false;
static $i = 0;
if (!$fp) {
$stamp = strftime("%y%m%d-%H%M%S");
- $fp = fopen(TEMP_DIR."/sql-$stamp.log", "a");
+ $fp = fopen(TEMP_DIR . "/sql-$stamp.log", "a");
register_shutdown_function("_sql_debuglog_shutdown_function");
} elseif ($shutdown) {
fclose($fp);
else fwrite($fp, $msg);
}
-function _sql_debuglog_shutdown_function() {
- _sql_debuglog('',false,true);
+function _sql_debuglog_shutdown_function()
+{
+ _sql_debuglog('', false, true);
}
// Local Variables: