$v2 = $tmp;
}
-$page = Wicked_Page::getPage(Horde_Util::getFormData('page'), $v2);
-if (is_a($page, 'PEAR_Error')) {
- $notification->push(sprintf(_("Internal error viewing requested page: %s"), $page->getMessage()), 'horde.error');
+try {
+ $page = Wicked_Page::getPage(Horde_Util::getFormData('page'), $v2);
+} catch (Wicked_Exception $e) {
+ $notification->push(sprintf(_("Internal error viewing requested page: %s"), $e->getMessage()), 'horde.error');
Wicked::url('WikiHome', true)->redirect();
}
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('wicked');
-$page = Wicked_Page::getCurrentPage();
-if (is_a($page, 'PEAR_Error')) {
- $notification->push(_("Internal error viewing requested page"),
- 'horde.error');
+$actionID = Horde_Util::getFormData('actionID');
+try {
+ $page = Wicked_Page::getCurrentPage();
+} catch (Wicked_Exception $e) {
+ $notification->push(_("Internal error viewing requested page"), 'horde.error');
+ $page = Wicked_Page::getPage('');
+ $actionID = null;
}
-$actionID = Horde_Util::getFormData('actionID');
switch ($actionID) {
case 'lock':
if (!$page->allows(Wicked::MODE_LOCKING)) {
'horde.error');
break;
}
- $result = $page->lock();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Page failed to lock: %s"), $result->getMessage()),
+ try {
+ $result = $page->lock();
+ } catch (Wicked_Exception $e) {
+ $notification->push(sprintf(_("Page failed to lock: %s"), $e->getMessage()),
'horde.error');
}
break;
$notification->push(_("You are not allowed to unlock this page"),
'horde.error');
}
- $result = $page->unlock();
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $result = $page->unlock();
+ $notification->push(_("Page unlocked"), 'horde.success');
+ } catch (Wicked_Exception $e) {
$notification->push(
- sprintf(_("Page failed to unlock: %s"), $result->getMessage()),
+ sprintf(_("Page failed to unlock: %s"), $e->getMessage()),
'horde.error');
- } else {
- $notification->push(_("Page unlocked"), 'horde.success');
}
break;
break;
}
- $wiki = &$page->getProcessor($format);
- $text = $wiki->transform($page->getText(), $format);
- if (is_a($text, 'PEAR_Error')) {
- echo $text->getMessage();
- } else {
+ $wiki = $page->getProcessor($format);
+ try {
+ $text = $wiki->transform($page->getText(), $format);
$browser->downloadHeaders($page->pageTitle() . $ext, $mime, false, strlen($text));
echo $text;
+ exit;
+ } catch (Wicked_Exception $e) {
+ $notification->push($e);
}
- exit(0);
+ break;
default:
$wicked->logPageView($page->pageName());
+ break;
}
if (!$page->allows(Wicked::MODE_DISPLAY)) {
- $notification->push(_("You don't have permission to view this page."),
- 'horde.error');
if ($page->pageName() == 'WikiHome') {
- throw new Horde_Exception(_("You don't have permission to view this page."));
+ Horde::fatal(_("You don't have permission to view this page."));
}
- Wicked::url('WikiHome', true)->redirect();
+ $notification->push(_("You don't have permission to view this page."),
+ 'horde.error');
+ $page = Wicked_Page::getPage('');
}
$params = Horde_Util::getFormData('params');
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('wicked');
-$page = Wicked_Page::getCurrentPage();
-if (is_a($page, 'PEAR_Error')) {
+try {
+ $page = Wicked_Page::getCurrentPage();
+} catch (Wicked_Exception $e) {
$notification->push(_("Internal error viewing requested page"), 'horde.error');
Wicked::url('WikiHome', true)->redirect();
}
* @param string $pagename Page name
*
* @return array An array of page parameters.
+ * @throws Wicked_Exception
*/
public function getPageInfo($pagename)
{
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
return array(
'page_majorversion' => $page->_page['page_majorversion'],
'page_minorversion' => $page->_page['page_minorversion'],
* @param array $pagenames Page names
*
* @return array An array of arrays of page parameters.
+ * @throws Wicked_Exception
*/
public function getMultiplePageInfo($pagenames = array())
{
if (empty($pagenames)) {
$pagenames = $GLOBALS['wicked']->getPages(false);
- if (is_a($pagenames, 'PEAR_Error')) {
- return $pagenames;
- }
}
$info = array();
foreach ($pagenames as $pagename) {
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
$info[$pagename] = array(
'page_majorversion' => $page->_page['page_majorversion'],
'page_minorversion' => $page->_page['page_minorversion'],
* @param string $pagename Page name
*
* @return array An array of page parameters.
+ * @throws Wicked_Exception
*/
public function getPageHistory($pagename)
{
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
$summaries = $GLOBALS['wicked']->getHistory($pagename);
- if (is_a($summaries, 'PEAR_Error')) {
- return $summaries;
- }
foreach ($summaries as $i => $summary) {
$summaries[$i]['page_checksum'] = md5($summary['page_text']);
* @param string $pagename Page to display
*
* @return array Page without CSS link
+ * @throws Wicked_Exception
*/
public function display($pagename)
{
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
$GLOBALS['wicked']->logPageView($page->pageName());
-
return $page->displayContents(false);
}
* @param string $format Format to render page to (Plain, XHtml)
*
* @return array Rendered page
+ * @throws Wicked_Exception
*/
public function renderPage($pagename, $format = 'Plain')
{
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
- $wiki = &$page->getProcessor();
- $content = $wiki->transform($page->getText(), $format);
- if (is_a($content, 'PEAR_Error')) {
- return $content;
- }
-
+ $content = $page->getProcessor()->transform($page->getText(), $format);
$GLOBALS['wicked']->logPageView($page->pageName());
return $content;
}
* @param string $changelog Description of the change
* @param boolean $minorchange True if this is a minor change
*
- * @return boolean | PEAR_Error True on success, PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
public function edit($pagename, $text, $changelog = '',
$minorchange = false)
{
$page = Wicked_Page::getPage($pagename);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
if (!$page->allows(Wicked::MODE_EDIT)) {
- return PEAR::RaiseError(sprintf(_("You don't have permission to edit \"%s\"."), $pagename));
+ throw new Wicked_Exception(sprintf(_("You don't have permission to edit \"%s\"."), $pagename));
}
if ($GLOBALS['conf']['wicked']['require_change_log'] &&
empty($changelog)) {
- return PEAR::raiseError(_("You must provide a change log."));
- }
+ throw new Wicked_Exception(_("You must provide a change log."));
+ }
- $content = $page->getText();
- if (is_a($content, 'PEAR_Error')) {
+ try {
+ $content = $page->getText();
+ } catch (Wicked_Exception $e) {
// Maybe the page does not exists, if not create it
if ($GLOBALS['wicked']->pageExists($pagename)) {
- return $content;
- } else {
- return $GLOBALS['wicked']->newPage($pagename, $text);
+ throw $e;
}
+ $GLOBALS['wicked']->newPage($pagename, $text);
}
if (trim($text) == trim($content)) {
- return PEAR::raiseError(_("No changes made"));
+ throw new Wicked_Exception(_("No changes made"));
}
- $result = $page->updateText($text, $changelog, $minorchange);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- } else {
- return true;
- }
+ $page->updateText($text, $changelog, $minorchange);
}
/**
* Get a list of templates provided by Wicked. A template is any page
* whose name begins with "Template"
*
- * @return mixed Array on success; PEAR_Error on failure
+ * @return arrary Array on success.
+ * @throws Wicked_Exception
*/
public function listTemplates()
{
*
* @param string $name The name of the template to fetch
*
- * @return mixed String of template data on success; PEAR_Error on fail.
+ * @return string Template data.
+ * @throws Wicked_Exception
*/
public function getTemplate($name)
{
* @param string $name The name of the page to fetch
* @param string $version Page version
*
- * @return mixed String of page data on success; PEAR_Error on fail
+ * @return string Page data.
+ * @throws Wicked_Exception
*/
public function getPageSource($pagename, $version = null)
{
$page = Wicked_Page::getPage($pagename, $version);
if (!$page->allows(Wicked::MODE_CONTENT)) {
- return PEAR::raiseError(_("Permission denied."));
+ throw new Wicked_Exception(_("Permission denied."));
}
if (!$page->isValid()) {
- return PEAR::raiseError(_("Invalid page requested."));
+ throw new Wicked_Exception(_("Invalid page requested."));
}
return $page->getText();
* @param string $name Name of the new or modified page
* @param string $data Text content of the populated template
*
- * @return mixed True on success; PEAR_Error on failure
+ * @throws Wicked_Exception
*/
public function saveTemplate($name, $data)
{
- return $this->edit($name, $data, 'Template Auto-fill', false);
+ $this->edit($name, $data, 'Template Auto-fill', false);
}
/**
*
* @param integer $days The number of days to look back.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
+ * @throws Wicked_Exception
*/
public function getRecentChanges($days = 3)
{
- $summaries = $GLOBALS['wicked']->getRecentChanges($days);
- if (is_a($summaries, 'PEAR_Error')) {
- return $summaries;
- }
-
$info = array();
- foreach ($summaries as $page) {
+ foreach ($GLOBALS['wicked']->getRecentChanges($days) as $page) {
$info[$page['page_name']] = array(
'page_majorversion' => $page['page_majorversion'],
'page_minorversion' => $page['page_minorversion'],
);
}
- $pages = $GLOBALS['wicked']->getPages();
- if (!($pages instanceof PEAR_Error)) {
+ try {
+ $pages = $GLOBALS['wicked']->getPages();
sort($pages);
foreach ($pages as $pagename) {
$perms['pages:' .$GLOBALS['wicked']->getPageId($pagename)] = array(
'title' => $pagename
);
}
- }
+ } catch (Wicked_Exception $e) {}
return $perms;
}
* @author Tyler Colbert <tyler@colberts.us>
* @package Wicked
*/
-class Wicked_Driver {
+abstract class Wicked_Driver {
/**
* Hash containing connection parameters.
/**
* Accessor to manage a VFS instance.
*
- * @throws VFS_Exception
+ * @throws Wicked_Exception
*/
function getVFS()
{
try {
$this->_vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
} catch (VFS_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Wicked_Exception($e);
}
}
*
* @param string $pagename The name of the page to retrieve
*
- * @return boolean True on success, PEAR_Error on failure.
*/
- function retrieveByName($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function retrieveByName($pagename);
/**
* Retrieves a historic version of a page.
* @param string $pagename The name of the page to retrieve.
* @param string $version The version to retrieve.
*
- * @return array The page hash, or PEAR_Error on failure.
*/
- function retrieveHistory($pagename, $version)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function retrieveHistory($pagename, $version);
/**
* Logs a hit to $pagename.
*
* @param string $pagename The page that was viewed.
- *
- * @return boolean True or PEAR_Error on failure.
*/
- function logPageView($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function logPageView($pagename);
/**
* Creates a new page.
*
* @param string $pagename The new page's name.
* @param string $text The new page's text.
- *
- * @return mixed True, or PEAR_Error on failure.
*/
- function newPage($pagename, $text)
- {
- return PEAR::raiseError(_("Not implemented."));
- }
+ abstract function newPage($pagename, $text);
- function updateText($pagename, $text, $changelog, $minorchange)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function updateText($pagename, $text, $changelog, $minorchange);
- function renamePage($pagename, $newname)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function renamePage($pagename, $newname);
function getPageId($pagename)
{
$pages = $this->getPages();
- if (is_a($pages, 'PEAR_Error')) {
- return $pages;
- }
$ids = array_flip($pages);
return isset($ids[$pagename]) ? $ids[$pagename] : false;
}
return in_array($pagename, $this->getPages());
}
- function getAllPages()
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getAllPages();
- function getHistory($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getHistory($pagename);
/**
* Returns the most recently changed pages.
*
* @param integer $days The number of days to look back.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
*/
- function getRecentChanges($days = 3)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getRecentChanges($days = 3);
/**
* Returns the most popular pages.
*
* @param integer $limit The number of most popular pages to return.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
*/
- function mostPopular($limit = 10)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function mostPopular($limit = 10);
/**
* Returns the least popular pages.
*
* @param integer $limit The number of least popular pages to return.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
*/
- function leastPopular($limit = 10)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function leastPopular($limit = 10);
/**
* Finds pages with matches in text or title.
*
* @param string $searchtext The search expression (Google-like).
*
- * @return array A list of pages, or PEAR_Error on failure.
+ * @return array A list of pages
*/
- function searchText($searchtext)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function searchText($searchtext);
- function getBackLinks($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getBackLinks($pagename);
- function getLikePages($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getLikePages($pagename);
/**
* Retrieves data on files attached to a page.
* @param boolean $allversions Whether to include all versions. If false
* or omitted, only the most recent version
* of each attachment is returned.
- * @return mixed An array of key/value arrays describing the attached
- * files or a PEAR_Error:: instance on failure.
+ * @return array An array of key/value arrays describing the attached
+ * files.
*/
- function getAttachedFiles($pageId, $allversions = false)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getAttachedFiles($pageId, $allversions = false);
/**
* Attaches a file to a page or update an attachment.
* the currently logged-in user is assumed.</pre>
* @param string $data This is the contents of the file to be attached.
*
- * @return boolean True or PEAR_Error:: instance on failure.
+ * @throws Wicked_Exception
*/
function attachFile($file, $data)
{
- $vfs =& $this->getVFS();
- if (is_a($vfs, 'PEAR_Error')) {
- return $vfs;
- }
-
+ $vfs = $this->getVFS();
if (!isset($file['change_author'])) {
$file['change_author'] = $GLOBALS['registry']->getAuth();
}
-
$result = $this->_attachFile($file);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
/* We encode the path quoted printable so we won't get any nasty
* characters the filesystem might reject. */
try {
$vfs->writeData($path, $file['attachment_name'] . ';' . $result, $data, true);
} catch (VFS_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Wicked_Exception($e);
}
}
* @param string $version If specified, the version to delete. If null,
* then all versions of $attachment will be removed.
*
- * @return boolean|PEAR_Error Either true or a PEAR_Error describing failure.
+ * @throws Wicked_Exception
*/
function removeAttachment($pageId, $attachment, $version = null)
{
- $vfs =& $this->getVFS();
- if (is_a($vfs, 'PEAR_Error')) {
- return $vfs;
- }
-
+ $vfs = $this->getVFS();
$path = WICKED_VFS_ATTACH_PATH . '/' . $pageId;
$fileList = $this->getAttachedFiles($pageId, true);
try {
$vfs->deleteFile($path, $attachment . ';' . $fileversion);
} catch (VFS_Exception $e) {
- return PEAR::raiseError($result->getMessage());
+ throw new Wicked_Exception($e);
}
}
}
-
- return true;
}
/**
*
* @param integer $pageId The Id of the page to remove attachments from.
*
- * @return boolean|PEAR_Error Either true or a PEAR_Error describing failure.
+ * @throws Wicked_Exception
*/
function removeAllAttachments($pageId)
{
- $vfs =& $this->getVFS();
- if (is_a($vfs, 'PEAR_Error')) {
- return $vfs;
- }
-
+ $vfs = $this->getVFS();
if (!$vfs->isFolder(WICKED_VFS_ATTACH_PATH, $pageId)) {
- return true;
+ return;
}
try {
$vfs->deleteFolder(WICKED_VFS_ATTACH_PATH, $pageId, true);
- return true;
} catch (VFS_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Wicked_Exception($e);
}
}
*
* @param array $file See Wicked_Driver::attachFile().
*
- * @return boolean The new version of the file attached, or a PEAR_Error::
- * instance on failure.
+ * @return boolean The new version of the file attached
+ * @throws Wicked_Exception
*/
- function _attachFile($file)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function _attachFile($file);
/**
* Retrieves the contents of an attachment.
* @param string $filename This is the name of the attachment.
* @param string $version This is the version of the attachment.
*
- * @return string The file's contents or a PEAR_Error on error.
+ * @return string The file's contents.
+ * @throws Wicked_Exception
*/
function getAttachmentContents($pageId, $filename, $version)
{
- $vfs =& $this->getVFS();
- if (is_a($vfs, 'PEAR_Error')) {
- return $vfs;
- }
-
+ $vfs = $this->getVFS();
$path = WICKED_VFS_ATTACH_PATH . '/' . $pageId;
try {
return $vfs->read($path, $filename . ';' . $version);
} catch (VFS_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Wicked_Exception($e);
}
}
- function removeVersion($pagename, $version)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function removeVersion($pagename, $version);
function removeAllVersions($pagename)
{
/* When deleting a page, also delete all its attachments. */
- $result = $this->removeAllAttachments($this->getPageId($pagename));
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- return true;
+ $this->removeAllAttachments($this->getPageId($pagename));
}
- function searchTitles($searchtext)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function searchTitles($searchtext);
/**
* Returns the charset used by the backend.
* @param array $params A hash containing any additional configuration or
* connection parameters a subclass might need.
*
- * @return mixed The newly created concrete Wicked_Driver instance, or
- * false on an error.
+ * @return Wicked_Driver The newly created concrete Wicked_Driver instance.
+ * @throws Wicked_Exception
*/
function factory($driver = null, $params = null)
{
if (class_exists($class)) {
$wicked = new $class($params);
$result = $wicked->connect();
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
return $wicked;
- } else {
- return PEAR::raiseError('Definition of ' . $class . ' not found.');
}
- return $wicked;
+ throw new Wicked_Exception('Definition of ' . $class . ' not found.');
}
}
*
* @param string $pagename The name of the page to retrieve.
*
- * @return mixed True on success, PEAR_Error on failure.
+ * @return array
+ * @throws Wicked_Exception
*/
function retrieveByName($pagename)
{
return $pages[0];
}
- return PEAR::raiseError($pagename . ' not found');
+ throw new Wicked_Exception($pagename . ' not found');
}
/**
* @param string $pagename The name of the page to retrieve.
* @param string $version The version to retrieve.
*
- * @return array The page hash, or PEAR_Error on failure.
+ * @return array The page hash.
+ * @throws Wicked_Exception
*/
function retrieveHistory($pagename, $version)
{
if (empty($version) or !preg_match('/^[0-9]+\.[0-9]+$/', $version)) {
- return PEAR::raiseError('invalid version number');
+ throw new Wicked_Exception('invalid version number');
}
list($major, $minor) = explode('.', $version);
*
* @param integer $days The number of days to look back.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
+ * @throws Wicked_Exception
*/
function getRecentChanges($days = 3)
{
*
* @param integer $limit The number of most popular pages to return.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
+ * @throws Wicked_Exception
*/
function mostPopular($limit = 10)
{
*
* @param integer $limit The number of least popular pages to return.
*
- * @return mixed An array of pages, or PEAR_Error on failure.
+ * @return array Pages.
+ * @throws Wicked_Exception
*/
function leastPopular($limit = 10)
{
* are searched. If false, only page
* text is searched.
*
- * @return array A list of pages, or PEAR_Error on failure.
+ * @return array A list of pages.
+ * @throws Wicked_Exception
*/
function searchText($searchtext, $title = true)
{
$textClause = Horde_SQL_Keywords::parse('page_text', $searchtext);
if (is_a($textClause, 'PEAR_Error')) {
- return $textClause;
+ throw new Wicked_Exception($textClause);
}
if ($title) {
$nameClause = Horde_SQL_Keywords::parse('page_name', $searchtext);
if (is_a($nameClause, 'PEAR_Error')) {
- return $nameClause;
+ throw new Wicked_Exception($nameClause);
}
$where = '(' . $nameClause . ') OR (' . $textClause . ')';
* @param boolean $allversions Whether to include all versions. If false
* or omitted, only the most recent version
* of each attachment is returned.
- * @return mixed An array of key/value arrays describing the attached
- * files or a PEAR_Error:: instance on failure.
+ * @return array An array of key/value arrays describing the attached
+ * files.
+ * @throws Wicked_Exception
*/
function getAttachedFiles($pageId, $allversions = false)
{
* @param string $attachment The name of the file.
* @param string $version If specified, the version to delete. If null,
* then all versions of $attachment will be removed.
+ *
+ * @throws Wicked_Exception
*/
function removeAttachment($pageId, $attachment, $version = null)
{
/* Try to delete from the VFS first. */
- $result = parent::removeAttachment($pageId, $attachment, $version);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
+ parent::removeAttachment($pageId, $attachment, $version);
/* First try against the current attachments table. */
$sql = 'DELETE FROM ' . $this->_params['attachmenttable'] .
*
* @param integer $pageId The Id of the page to remove attachments from.
*
- * @return boolean|PEAR_Error Either true or a PEAR_Error describing failure.
+ * @throws Wicked_Exception
*/
function removeAllAttachments($pageId)
{
/* Try to delete from the VFS first. */
$result = parent::removeAllAttachments($pageId);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
/* First try against the current attachments table. */
$sql = 'DELETE FROM ' . $this->_params['attachmenttable'] .
*
* @param array $file See Wicked_Driver::attachFile().
*
- * @return boolean The new version of the file attached, or a PEAR_Error::
- * instance on failure.
+ * @return string The new version of the file attached.
+ * @throws Wicked_Exception
*/
function _attachFile($file)
{
*
* @param string $pagename The page that was viewed.
*
- * @return mixed True or PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
function logPageView($pagename)
{
* @param string $pagename The new page's name.
* @param string $text The new page's text.
*
- * @return mixed True, or PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
function newPage($pagename, $text)
{
if (!strlen($pagename)) {
- return PEAR::raiseError(_("Page name must not be empty"));
+ throw new Wicked_Exception(_("Page name must not be empty"));
}
if ($GLOBALS['browser']->isRobot()) {
- return PEAR::raiseError(_("Robots are not allowed to create pages"));
+ throw new Wicked_Exception(_("Robots are not allowed to create pages"));
}
$author = $GLOBALS['registry']->getAuth();
* @param string $pagename The name of the page to rename.
* @param string $newname The page's new name.
*
- * @return mixed True or PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
function renamePage($pagename, $newname)
{
$changelog = sprintf(_("Renamed page from %s"), $pagename);
$newPage = $this->retrieveByName($newname);
- if (is_a($newPage, 'PEAR_Error')) {
- return $newPage;
- }
/* Call getPages with no caching so that the new list of pages is
* read in. */
Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
- $result = $this->_db->selectValue($query, $values);
- if ($result && !is_a($result, 'PEAR_Error')) {
- /* We're deleting the current version. Have to promote the
- * next-most revision from the history table. */
- $query = 'SELECT * FROM ' . $this->_params['historytable'] .
- ' WHERE page_name = ? ORDER BY page_majorversion DESC, page_minorversion DESC';
- $query = $this->_db->addLimitOffset($query, array('limit' => 1));
+ try {
+ $result = $this->_db->selectValue($query, $values);
+ } catch (Horde_Db_Exception $e) {
+ $result = false;
+ }
+ if (!$result) {
+ /* Removing a historical revision - we can just slice it out of the
+ * history table. $values is unchanged. */
+ $query = 'DELETE FROM ' . $this->_params['historytable'] .
+ ' WHERE page_name = ? and page_majorversion = ? and page_minorversion = ?';
Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
+ $this->_db->delete($query, $values);
+ return;
+ }
- $revision = $this->_db->selectOne($query, array($this->_convertToDriver($pagename)), DB_FETCHMODE_ASSOC);
-
- /* Replace the current version of the page with the
- * version being promoted. */
- $query = 'UPDATE ' . $this->_params['table'] . ' SET' .
- ' page_text = ?, page_majorversion = ?, page_minorversion = ?,' .
- ' version_created = ?, change_author = ?, change_log = ?' .
- ' WHERE page_name = ?';
- $values = array($revision['page_text'],
- $revision['page_majorversion'],
- $revision['page_minorversion'],
- $revision['version_created'],
- $revision['change_author'],
- $revision['change_log'],
- $this->_convertToDriver($pagename));
-
- Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
- $this->_db->update($query, $values);
+ /* We're deleting the current version. Have to promote the
+ * next-most revision from the history table. */
+ $query = 'SELECT * FROM ' . $this->_params['historytable'] .
+ ' WHERE page_name = ? ORDER BY page_majorversion DESC, page_minorversion DESC';
+ $query = $this->_db->addLimitOffset($query, array('limit' => 1));
- /* Finally, remove the version that we promoted from the
- * history table. */
- $query = 'DELETE FROM ' . $this->_params['historytable'] .
- ' WHERE page_name = ? and page_majorversion = ? and page_minorversion = ?';
- $values = array($this->_convertToDriver($pagename), $revision['page_majorversion'], $revision['page_minorversion']);
+ Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
- Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
+ $revision = $this->_db->selectOne($query, array($this->_convertToDriver($pagename)), DB_FETCHMODE_ASSOC);
+
+ /* Replace the current version of the page with the
+ * version being promoted. */
+ $query = 'UPDATE ' . $this->_params['table'] . ' SET' .
+ ' page_text = ?, page_majorversion = ?, page_minorversion = ?,' .
+ ' version_created = ?, change_author = ?, change_log = ?' .
+ ' WHERE page_name = ?';
+ $values = array($revision['page_text'],
+ $revision['page_majorversion'],
+ $revision['page_minorversion'],
+ $revision['version_created'],
+ $revision['change_author'],
+ $revision['change_log'],
+ $this->_convertToDriver($pagename));
- $this->_db->delete($query, $values);
- } else {
- /* Removing a historical revision - we can just slice it
- * out of the history table. $values is unchanged. */
- $query = 'DELETE FROM ' . $this->_params['historytable'] .
- ' WHERE page_name = ? and page_majorversion = ? and page_minorversion = ?';
+ Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
+ $this->_db->update($query, $values);
- Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
+ /* Finally, remove the version that we promoted from the
+ * history table. */
+ $query = 'DELETE FROM ' . $this->_params['historytable'] .
+ ' WHERE page_name = ? and page_majorversion = ? and page_minorversion = ?';
+ $values = array($this->_convertToDriver($pagename), $revision['page_majorversion'], $revision['page_minorversion']);
- $this->_db->delete($query, $values);
- }
+ Horde::logMessage('Wicked_Driver_sql::removeVersion(): ' . $query, 'DEBUG');
- return true;
+ $this->_db->delete($query, $values);
}
/**
/**
* Attempts to open a persistent connection to the SQL server.
*
- * @return boolean True on success, PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
function connect()
{
try {
$this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter');
} catch (Horde_Exception $e) {
- return PEAR::raiseError($e->getMessage());
+ throw new Wicked_Exception($e);
}
$this->_params = array_merge(array(
*/
function isValid()
{
- return !empty($this->_page) && !is_a($this->_page, 'PEAR_Error');
+ return !empty($this->_page);
}
/**
}
/**
- * Get the page we are currently on.
+ * Returns the page we are currently on.
*
- * @return Returns a Page or PEAR_Error.
+ * @return Wicked_Page The current page.
+ * @throws Wicked_Exception
*/
function getCurrentPage()
{
}
/**
- * Get the page we are currently on.
+ * Returns the requested page.
*
- * @return mixed Returns a Page or PEAR_Error.
+ * @return Wicked_Page The requested page.
+ * @throws Wicked_Exception
*/
function getPage($pagename, $pagever = null, $referrer = null)
{
function versionCreated()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function formatVersionCreated()
{
- global $prefs;
- $v = $this->versionCreated();
- if (is_a($v, 'PEAR_Error') || !$v) {
- return _("Never");
- } else {
- return strftime($prefs->getValue('date_format'), $v);
- }
+ try {
+ $v = $this->versionCreated();
+ if ($v) {
+ return strftime($GLOBALS['prefs']->getValue('date_format'), $v);
+ }
+ } catch (Wicked_Exception $e) {}
+ return _("Never");
}
function author()
function hits()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function version()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
/**
- * Retrieve the previous version number for this page
+ * Returns the previous version number for this page.
*
- * @return mixed A string containing the previous version or null if this
- * is the first version.
+ * @return string A string containing the previous version or null if this
+ * is the first version.
+ * @throws Wicked_Exception
*/
function previousVersion()
{
global $wicked;
- $res = $this->version();
- if (is_a($res, 'PEAR_Error')) {
- return $res;
- }
-
+ $this->version();
$history = $wicked->getHistory($this->pageName());
- if (is_a($history, 'PEAR_Error')) {
- return $history;
- }
if (count($history) == 0) {
return null;
}
/**
- * Render this page in Display mode. You really must override this
- * function if your page is to be anything like a real page.
+ * Renders this page in display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * This must be overridden if the page is to be anything like a real page.
+ *
+ * @throws Wicked_Exception
*/
function display()
{
+ // Get content first, it might throw an exception.
$inner = $this->displayContents(false);
- if (is_a($inner, 'PEAR_Error')) {
- return $inner;
- }
require WICKED_TEMPLATES . '/display/title.inc';
echo $inner;
}
}
/**
- * Render this page for displaying in a block. You really must override
- * this function if your page is to be anything like a real page.
+ * Renders this page for displaying in a block.
+ *
+ * This must be overridden if the page is to be anything like a real page.
*
- * @return mixed Returns true or PEAR_Error.
+ * @return string The content.
+ * @throws Wicked_Exception
*/
function block()
{
function displayContents($isBlock)
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
/**
- * Render this page in Remove mode.
- *
- * @return mixed Returns true or PEAR_Error.
+ * Renders this page in remove mode.
*/
function remove()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
/**
- * Render this page in History mode.
- *
- * @return mixed Returns true or PEAR_Error.
+ * Renders this page in history mode.
*/
function history()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
/**
- * Render this page in Diff mode.
- *
- * @return mixed Returns true or PEAR_Error.
+ * Renders this page in diff mode.
*/
function diff()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function &getProcessor($output_format = 'Xhtml')
return $this->diff($params);
default:
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
}
function lock()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function unlock()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function updateText($newtext, $changelog, $minorchange)
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function getText()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
function pageName()
function handleAction()
{
- return PEAR::raiseError(_("Unsupported"));
+ throw new Wicked_Exception(_("Unsupported"));
}
}
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
- $templates = $GLOBALS['wicked']->getMatchingPages('Template', WICKED_PAGE_MATCH_ENDS);
- if (is_a($templates, 'PEAR_Error')) {
+ try {
+ $templates = $GLOBALS['wicked']->getMatchingPages('Template', WICKED_PAGE_MATCH_ENDS);
+ } catch (Wicked_Exception $e) {
$GLOBALS['notification']->push(sprintf(_("Error retrieving templates: %s"),
- $templates->getMessage()), 'horde.error');
- return $templates;
+ $e->getMessage()), 'horde.error');
+ throw $e;
}
$search_results = null;
}
require WICKED_TEMPLATES . '/edit/create.inc';
- return true;
}
function pageName()
Wicked::MODE_DISPLAY => true);
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page content.
*/
function content()
{
- global $wicked;
-
- return $wicked->getAllPages();
+ return $GLOBALS['wicked']->getAllPages();
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns page contents or PEAR_Error
+ * @return string The page contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $summaries = $this->content();
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving summaries : ' .
- $summaries->getMessage(), 'horde.error');
- return $summaries;
- }
-
$template = $GLOBALS['injector']->createInstance('Horde_Template');
$pages = array();
- foreach ($summaries as $page) {
+ foreach ($this->content() as $page) {
$page = new StandardPage($page);
$pages[] = array('author' => $page->author(),
'created' => $page->formatVersionCreated(),
}
/**
- * Returns this page rendered in Content mode.
+ * Returns this page rendered in content mode.
*
- * @return string The page content, or PEAR_Error.
+ * @throws Wicked_Exception
*/
function content()
{
global $wicked, $notification;
if (!$wicked->pageExists($this->referrer())) {
- $error = sprintf(_("Referrer \"%s\" does not exist."),
- $this->referrer());
- $notification->push($error, 'horde.error');
- return PEAR::raiseError($error);
+ throw new Wicked_Exception(sprintf(_("Referrer \"%s\" does not exist."),
+ $this->referrer()));
}
$referrer_id = $wicked->getPageId($this->referrer());
-
$attachments = $wicked->getAttachedFiles($referrer_id, true);
- if (is_a($attachments, 'PEAR_Error')) {
- return $attachments;
- }
foreach ($attachments as $idx => $attach) {
$attachments[$idx]['date'] = date('M j, Y g:ia',
/**
* Returns this page rendered in Display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
global $registry, $wicked, $notification, $conf;
- $attachments = $this->content();
- if (is_a($attachments, 'PEAR_Error')) {
+ try {
+ $attachments = $this->content();
+ } catch (Wicked_Exception $e) {
$notification->push(sprintf(_("Error retrieving attachments: %s"),
- $attachments->getMessage()),
+ $e->getMessage()),
'horde.error');
- return $attachments;
+ throw $e;
}
$template = $GLOBALS['injector']->createInstance('Horde_Template');
Horde::addScriptFile('stripe.js', 'horde', true);
echo $template->fetch(WICKED_TEMPLATES . '/display/AttachedFiles.html');
- return true;
}
function pageName()
return;
}
- $result = $wicked->removeAttachment(
- $wicked->getPageId($this->referrer()),
- $filename, $version);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result->getMessage(), 'horde.error');
- } else {
+ try {
+ $wicked->removeAttachment($wicked->getPageId($this->referrer()),
+ $filename, $version);
$notification->push(
sprintf(_("Successfully deleted version %s of \"%s\" from \"%s\""),
$version, $filename, $this->referrer()),
'horde.success');
+ } catch (Wicked_Exception $e) {
+ $notification->push($result->getMessage(), 'horde.error');
}
return;
}
}
$referrer_id = $wicked->getPageId($this->referrer());
- $attachments = $wicked->getAttachedFiles($referrer_id);
- if (is_a($attachments, 'PEAR_Error')) {
+ try {
+ $attachments = $wicked->getAttachedFiles($referrer_id);
+ } catch (Wicked_Exception $e) {
$notification->push(sprintf(_("Error retrieving attachments: %s"),
- $attachments->getMessage()),
+ $e->getMessage()),
'horde.error');
return;
}
'minor' => $minor_change,
'change_log' => $change_log);
- $result = $wicked->attachFile($file, $data);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- Horde::logMessage($result, 'ERR');
- return $result;
+ try {
+ $wicked->attachFile($file, $data);
+ } catch (Wicked_Exception $e) {
+ $notification->push($e);
+ Horde::logMessage($e);
+ throw $e;
}
if ($is_update) {
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns contents or PEAR_Error.
+ * @return string The contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $wicked, $notification;
-
- $summaries = $wicked->getBackLinks($this->_referrer);
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving summaries: ' .
- $summaries->getMessage(), 'horde.error');
- return $summaries;
- }
-
+ $summaries = $GLOBALS['wicked']->getBackLinks($this->_referrer);
Horde::addScriptFile('tables.js', 'horde', true);
-
ob_start();
require WICKED_TEMPLATES . '/pagelist/header.inc';
foreach ($summaries as $page) {
require WICKED_TEMPLATES . '/pagelist/summary.inc';
}
require WICKED_TEMPLATES . '/pagelist/footer.inc';
-
return ob_get_clean();
}
/**
* Render this page in Display mode.
*
- * @return mixed True or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
</form>
<?php
- return true;
}
function pageName()
if ($page->isLocked()) {
$page->unlock();
}
- $result = $page->lock();
- if (is_a($result, 'PEAR_Error')) {
- $GLOBALS['notification']->push(sprintf(_("Page failed to lock: %s"), $result->getMessage()), 'horde.error');
+ try {
+ $page->lock();
+ } catch (Wicked_Exception $e) {
+ $GLOBALS['notification']->push(sprintf(_("Page failed to lock: %s"), $e->getMessage()), 'horde.error');
}
}
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
if (is_null($page_text)) {
$page_text = $page->getText();
}
-
require WICKED_TEMPLATES . '/edit/standard.inc';
- return true;
}
function pageName()
if (trim($text) == trim($page->getText())) {
$notification->push(_("No changes made"), 'horde.warning');
} else {
- $result = $page->updateText($text, $changelog, $minorchange);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Save Failed: %s"),
- $result->getMessage()), 'horde.error');
- } else {
- $notification->push(_("Page Saved"), 'horde.success');
- }
+ $page->updateText($text, $changelog, $minorchange);
+ $notification->push(_("Page Saved"), 'horde.success');
}
if ($page->allows(Wicked::MODE_UNLOCKING)) {
- $result = $page->unlock();
- if (is_a($result, 'PEAR_Error')) {
- $GLOBALS['notification']->push(sprintf(_("Page failed to unlock: %s"), $result->getMessage()), 'horde.error');
- }
+ $page->unlock();
}
}
Wicked::MODE_DISPLAY => true);
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
* @param integer $numPages How many (at most) pages should we return?
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page contents.
*/
function content($numPages = 10)
{
- global $wicked;
-
- return $wicked->leastPopular($numPages);
+ return $GLOBALS['wicked']->leastPopular($numPages);
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns content or PEAR_Error.
+ * @return string The content.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $summaries = $this->content(10);
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving LeastPopular: ' . $summaries->getMessage(), 'horde.error');
- return $summaries;
- }
-
$template = $GLOBALS['injector']->createInstance('Horde_Template');
$pages = array();
- foreach ($summaries as $page) {
+ foreach ($this->content(10) as $page) {
$page = new StandardPage($page);
$pages[] = array('author' => $page->author(),
'created' => $page->formatVersionCreated(),
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns contents or PEAR_Error.
+ * @return string The contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $wicked, $notification;
-
$referrer = $this->referrer();
-
- $summaries = $wicked->getLikePages($referrer);
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving summaries: ' .
- $summaries->getMessage(), 'horde.error');
- return $summaries;
- }
-
+ $summaries = $GLOBALS['wicked']->getLikePages($referrer);
Horde::addScriptFile('tables.js', 'horde', true);
-
ob_start();
require WICKED_TEMPLATES . '/pagelist/header.inc';
foreach ($summaries as $page) {
require WICKED_TEMPLATES . '/pagelist/summary.inc';
}
require WICKED_TEMPLATES . '/pagelist/footer.inc';
-
return ob_get_clean();
}
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
$template->set('requiredMarker', $requiredMarker);
$references = $wicked->getBackLinks($referrer);
- if (is_a($references, 'PEAR_Error')) {
- $notification->push('Error retrieving back links: ' .
- $references->getMessage(), 'horde.error');
- return $references;
- }
foreach ($references as $key => $page) {
$references[$key]['page_url'] = htmlspecialchars(Wicked::url($page['page_name']));
}
$sourcePage = Wicked_Page::getPage($referrer);
- if (is_a($sourcePage, 'PEAR_Error')) {
- $notification->push(sprintf(_("Failed to retrieve \"%s\": %s"),
- $referrer, $sourcePage->getMessage()),
- 'horde.error');
- return;
- } elseif (!$this->allows(Wicked::MODE_EDIT)) {
- $notification->push(sprintf(_("You do not have permission to edit \"%s\""),
- $referrer), 'horde.error');
- return;
+ if (!$this->allows(Wicked::MODE_EDIT)) {
+ throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""),
+ $referrer));
}
$destPage = Wicked_Page::getPage($new_name);
- if (!is_a($destPage, 'PEAR_Error') && !is_a($destPage, 'AddPage')) {
+ if (!is_a($destPage, 'AddPage')) {
// Destination page exists.
if ($collision != 'merge') {
// We don't want to overwrite.
- $notification->push(sprintf(_("Page \"%s\" already exists."),
- $new_name), 'horde.error');
- return;
+ throw new Wicked_Exception(sprintf(_("Page \"%s\" already exists."),
+ $new_name));
}
if (!$destPage->allows(Wicked::MODE_EDIT)) {
- $notification->push(sprintf(_("You do not have permission to edit \"%s\""),
- $new_name), 'horde.error');
- return;
+ throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""),
+ $new_name));
}
// Merge the two pages.
$newText = $destPage->getText() . "\n----\n" . $sourcePage->getText();
$changelog = sprintf(_("Merged from %s"), $referrer);
- $result = $wicked->updateText($new_name, $newText, $changelog, true);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Error updating %s: %s"),
- $new_name, $result->getMessage()),
- 'horde.error');
- return;
- }
+ $wicked->updateText($new_name, $newText, $changelog, true);
+ $wicked->removeAllVersions($referrer);
- $result = $wicked->removeAllVersions($referrer);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Error deleting %s: %s"),
- $referrer, $result->getMessage()),
- 'horde.error');
- return;
- }
$notification->push(sprintf(_("Merged \"%s\" into \"%s\"."), $referrer, $new_name), 'horde.success');
$url = Wicked::url($new_name, true, -1);
'Subject' => '[' . $registry->get('name') . '] merged: ' . $referrer . ', ' . $new_name));
} else {
// Rename the page.
- $result = $wicked->renamePage($referrer, $new_name);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Error renaming \"%s\": %s"),
- $referrer, $result->getMessage()),
- 'horde.error');
- return;
- }
+ $wicked->renamePage($referrer, $new_name);
$notification->push(sprintf(_("Renamed \"%s\" to \"%s\"."), $referrer, $new_name), 'horde.success');
$url = Wicked::url($new_name, true, -1);
$page_name = $new_name;
}
- $refPage = $wicked->retrieveByName($page_name);
- if (is_a($refPage, 'PEAR_Error')) {
+ try {
+ $refPage = $wicked->retrieveByName($page_name);
+ } catch (Wicked_Exception $e) {
$notification->push(sprintf(_("Error retrieving %s: %s"),
- $page_name, $refPage->getMessage()),
+ $page_name, $e->getMessage()),
'horde.error');
continue;
}
}
$newText = preg_replace($from, $to, $refPage['page_text']);
- $result = $wicked->updateText($page_name, $newText, $changelog, true);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Error updating %s: %s"),
- $page_name, $result->getMessage()),
- 'horde.warning');
- return;
- }
+ $wicked->updateText($page_name, $newText, $changelog, true);
}
Wicked::url($new_name, true)->redirect();
Wicked::MODE_DISPLAY => true);
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
* @param integer $numPages How many (at most) pages should we return?
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page content.
*/
function content($numPages = 10)
{
- global $wicked;
-
- return $wicked->mostPopular($numPages);
+ return $GLOBALS['wicked']->mostPopular($numPages);
}
/**
- * Render this page in Display mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @return string The content.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $summaries = $this->content(10);
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving MostPopular: ' . $summaries->getMessage(), 'horde.error');
- return $summaries;
- }
-
$template = $GLOBALS['injector']->createInstance('Horde_Template');
$pages = array();
- foreach ($summaries as $page) {
+ foreach ($this->content(10) as $page) {
$page = new StandardPage($page);
$pages[] = array('author' => $page->author(),
'created' => $page->formatVersionCreated(),
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
return;
}
- $result = $wicked->newPage($this->referrer(), $text);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("Create Failed: %s"),
- $result->getMessage()), 'horde.error');
- } else {
+ try {
+ $result = $wicked->newPage($this->referrer(), $text);
$notification->push(_("Page Created"), 'horde.success');
+ } catch (Wicked_Exception $e) {
+ $notification->push(sprintf(_("Create Failed: %s"),
+ $e->getMessage()), 'horde.error');
}
}
Wicked::MODE_DISPLAY => true);
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page content.
+ * @throws Wicked_Exception
*/
function content()
{
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns contents or PEAR_Error.
+ * @return string The contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $changes = $this->content();
- if (is_a($changes, 'PEAR_Error')) {
- $notification->push('Error retrieving histories: ' . $summaries->getMessage(), 'horde.error');
- return $changes;
- }
-
$template = $GLOBALS['injector']->createInstance('Horde_Template');
- $template->set('changes', $changes);
-
+ $template->set('changes', $this->content());
return $template->fetch(WICKED_TEMPLATES . '/display/RecentChanges.html');
}
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
- * @return mixed True or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display()
{
</form>
<?php
- return true;
}
function pageName()
/**
* Cached search results.
+ *
* @var array
*/
- var $_results;
+ var $_results = array();
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
* @param string $searchtext The title to search for.
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page content.
*/
function content($searchtext = '')
{
if (empty($searchtext)) {
return array();
}
-
- $titles = $GLOBALS['wicked']->searchTitles($searchtext);
- $pages = $GLOBALS['wicked']->searchText($searchtext, false);
-
- return array('titles' => $titles, 'pages' => $pages);
+ return array(
+ 'titles' => $GLOBALS['wicked']->searchTitles($searchtext),
+ 'pages' => $GLOBALS['wicked']->searchText($searchtext, false));
}
/**
}
/**
- * Render this page in Display mode.
+ * Renders this page in display mode.
*
* @param string $searchtext The title to search for.
*
- * @return mixed Returns true or PEAR_Error.
+ * @throws Wicked_Exception
*/
function display($searchtext)
{
global $notification;
- if (is_a($this->_results, 'PEAR_Error')) {
- $notification->push('Error retrieving search results: ' .
- $this->_results->getMessage(), 'horde.error');
- return $this->_results;
- }
-
if (!$searchtext) {
require WICKED_TEMPLATES . '/pagelist/search.inc';
require WICKED_TEMPLATES . '/pagelist/footer.inc';
*
* @param string $pagename The name of the page to represent.
*/
- function StandardPage($pagename)
+ function __construct($pagename)
{
if (is_array($pagename)) {
$this->_page = $pagename;
return;
}
- global $wicked, $notification;
- $page = $wicked->retrieveByName($pagename);
+ $page = null;
+ try {
+ $page = $GLOBALS['wicked']->retrieveByName($pagename);
+ } catch (Wicked_Exception $e) {
+ // If we can't load $pagename, see if there's default data for it.
+ $pagefile = WICKED_BASE . '/scripts/data/' . basename($pagename);
+ if ($pagename == basename($pagename) &&
+ file_exists($pagefile)) {
+ $text = file_get_contents($pagefile);
+ try {
+ $GLOBALS['wicked']->newPage($pagename, $text);
+ try {
+ $page = $GLOBALS['wicked']->retrieveByName($pagename);
+ } catch (Wicked_Exception $e) {
+ $GLOBALS['notification']->push(sprintf(_("Unable to create %s"), $pagename), 'horde.error');
+ }
+ } catch (Wicked_Exception $e) {}
+ }
+ }
+
+ if ($page) {
+ $this->_page = $page;
+ } else {
+ if ($pagename == 'WikiHome') {
+ $GLOBALS['notification']->push(_("Unable to create WikiHome. The wiki is not configured."), 'horde.error');
+ }
+ $this->_page = array();
+ }
// Make sure 'wicked' permission exists. Set reasonable defaults if
// necessary.
$perms->addPermission($perm);
}
- // If we can't load $pagename, see if there's default data for it.
- if (is_a($page, 'PEAR_Error')) {
- $pagefile = WICKED_BASE . '/scripts/data/' . basename($pagename);
- if ($pagename == basename($pagename) &&
- file_exists($pagefile)) {
- $text = file_get_contents($pagefile);
- $result = $wicked->newPage($pagename, $text);
- if (!is_a($result, 'PEAR_Error')) {
- $page = $wicked->retrieveByName($pagename);
- if (is_a($page, 'PEAR_Error')) {
- $notification->push(sprintf(_("Unable to create %s"), $pagename), 'horde.error');
- }
- }
- }
- }
-
- if (is_a($page, 'PEAR_Error')) {
- if ($pagename == 'WikiHome') {
- $notification->push(_("Unable to create WikiHome. The wiki is not configured."), 'horde.error');
- }
- $this->_page = array();
- } else {
- $this->_page = $page;
- }
-
if ($GLOBALS['conf']['lock']['driver'] != 'none') {
$this->supportedModes[Wicked::MODE_LOCKING] = $this->supportedModes[Wicked::MODE_UNLOCKING] = true;
$this->_locks = $GLOBALS['injector']->getInstance('Horde_Lock');
return parent::allows($mode);
}
+ /**
+ * @throws Wicked_Exception
+ */
function displayContents($isBlock)
{
- global $wicked;
-
$wiki = $this->getProcessor();
$text = $wiki->transform($this->getText());
$attachments = array();
if (!$isBlock) {
- $pageId = $wicked->getPageId($this->pageName());
- if (!is_a($pageId, 'PEAR_Error')) {
- $attachments = $wicked->getAttachedFiles($wicked->getPageId($this->pageName()));
- if (is_a($attachments, 'PEAR_Error')) {
- $attachments = array();
- }
- }
-
+ $pageId = $GLOBALS['wicked']->getPageId($this->pageName());
+ $attachments = $GLOBALS['wicked']->getAttachedFiles($pageId);
if (count($attachments)) {
global $mime_drivers, $mime_drivers_map;
$result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'horde');
/**
* Renders this page in History mode.
+ *
+ * @throws Wicked_Exception
*/
function history()
{
- global $wicked, $notification;
require_once WICKED_BASE . '/lib/Page/StandardPage/StdHistoryPage.php';
- $summaries = $wicked->getHistory($this->pageName());
- if (is_a($summaries, 'PEAR_Error')) {
- $notification->push('Error retrieving histories : ' . $summaries->getMessage(), 'horde.error');
- return $summaries;
+ try {
+ $summaries = $GLOBALS['wicked']->getHistory($this->pageName());
+ } catch (Wicked_Exception $e) {
+ $GLOBALS['notification']->push('Error retrieving histories : ' . $e->getMessage(), 'horde.error');
+ throw $e;
}
// Header.
return $owner != $this->_lock['lock_owner'];
}
+ /**
+ * @throws Wicked_Exception
+ */
function lock()
{
if ($this->_locks) {
if ($id) {
$this->_lock = $this->_locks->getLockInfo($id);
} else {
- return PEAR::raiseError(_("The page is already locked."));
+ throw new Wicked_Exception(_("The page is already locked."));
}
}
}
$time = ceil(($this->_lock['lock_expiry_timestamp'] - time()) / 60);
return sprintf(ngettext("%d minute", "%d minutes", $time), $time);
}
-
+
+ /**
+ * @throws Wicked_Exception
+ */
function updateText($newtext, $changelog, $minorchange)
{
$version = $this->version();
$result = $GLOBALS['wicked']->updateText($this->pageName(), $newtext,
$changelog, $minorchange);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
$url = Wicked::url($this->pageName(), true, -1);
$new_page = $this->getPage($this->pageName());
*
* @param string $pagename The name of the page to load.
* @param integer $version The version of the page to load.
+ *
+ * @throws Wicked_Exception
*/
- function StdHistoryPage($pagename, $version = null)
+ function __construct($pagename, $version = null)
{
if (empty($version)) {
- parent::StandardPage($pagename);
+ parent::__construct($pagename);
return;
}
$pages = $GLOBALS['wicked']->retrieveHistory($pagename, $version);
// If it didnt find one, return an error.
- if (is_a($pages, 'PEAR_Error')) {
- $GLOBALS['notification']->push($pages);
- } elseif (empty($pages[0])) {
- $GLOBALS['notification']->push(_("History page not found"));
- } else {
- $this->_page = $pages[0];
+ if (empty($pages[0])) {
+ throw new Wicked_Exception(_("History page not found"));
}
+
+ $this->_page = $pages[0];
}
function isOld()
}
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
- * @return string The page content, or PEAR_Error.
+ * @throws Wicked_Exception
*/
function content()
{
if (!$this->_loadSyncDriver()) {
- return PEAR::raiseError(_("Synchronization is disabled"));
+ throw new Wicked_Exception(_("Synchronization is disabled"));
}
$remote = $this->_sync->getPageSource($this->_pageName);
- if (is_a($remote, 'PEAR_Error')) {
- return $remote;
- }
-
$page = Wicked_Page::getPage($this->_pageName);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
$local = $page->getText();
- if (is_a($local, 'PEAR_Error')) {
- return $local;
- }
$renderer = 'inline';
$inverse = Horde_Util::getGet('inverse', 1);
}
/**
- * Render this page in display or block mode.
- *
- * @return mixed Returns page contents or PEAR_Error
+ * @return string The page contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $content = $this->content();
- if (is_a($content, 'PEAR_Error')) {
- $notification->push($content);
- }
-
- return $content;
+ return $this->content();
}
/**
}
/**
- * Try to find out if any version's content is same on the local and remote
- * servers.
+ * Tries to find out if any version's content is the same on the local and
+ * remote servers.
+ *
+ * @throws Wicked_Exception
*/
function _getSameVersion()
{
$local = $GLOBALS['wicked']->getHistory($this->_pageName);
- if (is_a($local, 'PEAR_Error')) {
- return $local;
- }
-
$info = $this->getLocalPageInfo($this->_pageName);
- if (is_a($info, 'PEAR_Error')) {
- return $info;
- }
$local[] = $info;
-
$remote = $this->_sync->getPageHistory($this->_pageName);
- if (is_a($remote, 'PEAR_Error')) {
- return $remote;
- }
-
$info = $this->getRemotePageInfo($this->_pageName);
- if (is_a($info, 'PEAR_Error')) {
- return $info;
- }
$remote[] = $info;
$checksums = array();
/**
* Constructor
+ *
+ * @throws Wicked_Exception
*/
function SyncPages()
{
$this->_loadSyncDriver();
- if (is_a($this->_sync, 'PEAR_Error')) {
- return $this->_sync;
- }
// Do we need to perform any action?
switch (Horde_Util::getGet('actionID')) {
}
/**
- * Render this page in Content mode.
+ * Renders this page in content mode.
*
- * @return string The page content, or PEAR_Error.
+ * @return string The page content.
+ * @throws Wicked_Exception
*/
function content()
{
continue;
}
$page = Wicked_Page::getPage($pageName);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
$new_local[$pageName] = array(
'page_majorversion' => $page->_page['page_majorversion'],
'page_minorversion' => $page->_page['page_minorversion'],
// Compare checksum
$page = Wicked_Page::getPage($pageName);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- } elseif (md5($page->getText()) == $_SESSION['wicked']['sync']['pages'][$pageName]['page_checksum']) {
+ if (md5($page->getText()) == $_SESSION['wicked']['sync']['pages'][$pageName]['page_checksum']) {
continue;
}
}
/**
- * Render this page in display or block mode.
+ * Renders this page in display or block mode.
*
- * @return mixed Returns page contents or PEAR_Error
+ * @return string The contents.
+ * @throws Wicked_Exception
*/
function displayContents($isBlock)
{
- global $notification;
-
- $content = $this->content();
- if (is_a($content, 'PEAR_Error')) {
- $notification->push($content);
- }
-
- return $content;
+ return $this->content();
}
/**
/**
* Get and process sync info form
+ *
+ * @throws Wicked_Exception
*/
function _syncForm()
{
// Load driver
$_SESSION['wicked']['sync'] = $info;
$this->_loadSyncDriver();
- if (is_a($this->_sync, 'PEAR_Error')) {
- return $this->_sync;
- }
// We submitted the form so we should fetch pages
$pages = $this->_sync->getMultiplePageInfo();
- if (is_a($pages, 'PEAR_Error')) {
- $GLOBALS['notification']->push($pages);
- } elseif (!empty($pages)) {
+ if (!empty($pages)) {
$_SESSION['wicked']['sync']['pages'] = $pages;
}
break;
function getLocalPageInfo($pageName)
{
$page = Wicked_Page::getPage($pageName);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
return array(
'page_majorversion' => $page->_page['page_majorversion'],
'page_minorversion' => $page->_page['page_minorversion'],
* Get page info
*
* @param boolean $local Get local or remote info
+ *
+ * @throws Wicked_Exception
*/
function getRemotePageInfo($pageName)
{
- if (isset($_SESSION['wicked']['sync']['pages'][$pageName])) {
- return $_SESSION['wicked']['sync']['pages'][$pageName];
- } else {
- $info = $this->_sync->getPageInfo($pageName);
- if (!is_a($info, 'PEAR_Error')) {
- $_SESSION['wicked']['sync']['pages'][$pageName] = $info;
- }
- return $info;
+ if (!isset($_SESSION['wicked']['sync']['pages'][$pageName])) {
+ $_SESSION['wicked']['sync']['pages'][$pageName] = $this->_sync->getPageInfo($pageName);
}
+ return $_SESSION['wicked']['sync']['pages'][$pageName];
}
/**
* Download remote page to local server
+ *
+ * @throws Wicked_Exception
*/
function download($pageName)
{
$text = $this->_sync->getPageSource($pageName);
- if (is_a($text, 'PEAR_Error')) {
- return $text;
- }
-
$page = Wicked_Page::getPage($pageName);
- if (is_a($page, 'PEAR_Error')) {
- return $page;
- }
-
if (!$page->allows(Wicked::MODE_EDIT)) {
- return PEAR::RaiseError(sprintf(_("You don't have permission to edit \"%s\"."), $pageName));
+ throw new Wicked_Exception(sprintf(_("You don't have permission to edit \"%s\"."), $pageName));
}
- $content = $page->getText();
- if (is_a($content, 'PEAR_Error')) {
- // Maybe the page does not exists, if not create it
- if ($GLOBALS['wicked']->pageExists($pageName)) {
- return $content;
- } else {
- $result = $GLOBALS['wicked']->newPage($pageName, $text);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
- }
- } else {
+ try {
+ $content = $page->getText();
if (trim($text) == trim($content)) {
- return PEAR::raiseError(_("No changes made"));
+ $GLOBALS['notification']->push(_("No changes made"), 'horde.message');
+ return;
}
- $result = $page->updateText($text, _("Downloaded from remote server"), true);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ $page->updateText($text, _("Downloaded from remote server"), true);
+ } catch (Wicked_Exception $e) {
+ // Maybe the page does not exists, if not create it
+ if ($GLOBALS['wicked']->pageExists($pageName)) {
+ throw $e;
}
+ $GLOBALS['wicked']->newPage($pageName, $text);
}
$GLOBALS['notification']->push(sprintf(_("Page \"%s\" was sucessfuly downloaded from remote to local wiki."), $pageName), 'horde.success');
function upload($pageName)
{
$page = Wicked_Page::getPage($pageName);
- if (is_a($page, 'PEAR_Error')) {
- $GLOBALS['notification']->push($page);
- return $page;
- }
-
$content = $page->getText();
- if (is_a($content, 'PEAR_Error')) {
- $GLOBALS['notification']->push($content);
- return $content;
- }
-
- $result = $this->_sync->editPage($pageName, $content, _("Uploaded from remote server"), true);
- if (is_a($result, 'PEAR_Error')) {
- $GLOBALS['notification']->push($result);
- return $content;
- }
-
+ $this->_sync->editPage($pageName, $content, _("Uploaded from remote server"), true);
$GLOBALS['notification']->push(sprintf(_("Page \"%s\" was sucessfully uploaded from local to remote wiki."), $pageName), 'horde.success');
// Show the newly updated page.
* @author Duck <duck@obala.net>
* @package Wicked
*/
-class Wicked_Sync {
+abstract class Wicked_Sync {
/**
* Hash containing connection parameters.
* Returns a list of available pages.
*
* @return array An array of all available pages.
+ * @throws Wicked_Exception
*/
- function listPages()
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function listPages();
/**
* Get the wiki source of a page specified by its name.
*
* @param string $name The name of the page to fetch
*
- * @return mixed Array of page data on success; PEAR_Error on failure
+ * @return array Page data.
+ * @throws Wicked_Exception
*/
- function getPageSource($pageName)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getPageSource($pageName);
/**
* Return basic page information.
*
* @param string $pageName Page name
*
- * @return mixed Array of page data on success; PEAR_Error on failure
+ * @return array Page data.
+ * @throws Wicked_Exception
*/
- function getPageInfo($pageName)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getPageInfo($pageName);
/**
* Return basic information of .multiple pages
*
* @param array $pages Page names to get info for
*
- * @return mixed Array of pages data on success; PEAR_Error on failure
+ * @return array Pages data.
+ * @throws Wicked_Exception
*/
- function getMultiplePageInfo($pages = array())
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getMultiplePageInfo($pages = array());
/**
* Return page history.
* @param string $pagename Page name
*
* @return array An array of page parameters.
+ * @throws Wicked_Exception
*/
- function getPageHistory($pagename)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
+ abstract function getPageHistory($pagename);
/**
* Updates content of a wiki page. If the page does not exist it is
* @param string $changelog Description of the change
* @param boolean $minorchange True if this is a minor change
*
- * @return boolean | PEAR_Error True on success, PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
- function editPage($pagename, $text, $changelog = '', $minorchange = false)
- {
- return PEAR::raiseError(_("Unsupported"));
- }
-
+ abstract function editPage($pagename, $text, $changelog = '', $minorchange = false);
}
*
* @param string $name The name of the page to fetch
*
- * @return mixed String of page data on success; PEAR_Error on fail
+ * @return string Page data.
+ * @throws Wicked_Exception
*/
function getPageSource($pageName)
{
*
* @param string $pageName Page name
*
- * @return mixed Array of page data on success; PEAR_Error on failure
+ * @return array Page data.
+ * @throws Wicked_Exception
*/
function getPageInfo($pageName)
{
*
* @param array $pages Page names to get info for
*
- * @return mixed Array of pages data on success; PEAR_Error on failure
+ * @return array Pages data.
+ * @throws Wicked_Exception
*/
function getMultiplePageInfo($pages = array())
{
* @param string $changelog Description of the change
* @param boolean $minorchange True if this is a minor change
*
- * @return boolean | PEAR_Error True on success, PEAR_Error on failure.
+ * @throws Wicked_Exception
*/
function editPage($pagename, $text, $changelog = '', $minorchange = false)
{
- return $this->_getData('edit', array($pagename, $text, $changelog, $minorchange));
+ $this->_getData('edit', array($pagename, $text, $changelog, $minorchange));
}
/**
* @param string $method Method name to call
* @param array $params Array of parameters
*
- * @return mixed Array of pages data on success; PEAR_Error on failure
+ * @return mixed
+ * @throws Wicked_Exception
*/
function _getData($method, $params = array())
{
- return Horde_RPC::request(
- 'xmlrpc',
- $this->_params['url'],
- $this->_params['prefix'] . '.' . $method,
- $params,
- array('user' => $this->_params['user'],
- 'pass' => $this->_params['password']));
+ try {
+ return Horde_RPC::request(
+ 'xmlrpc',
+ $this->_params['url'],
+ $this->_params['prefix'] . '.' . $method,
+ $params,
+ array('user' => $this->_params['user'],
+ 'pass' => $this->_params['password']));
+ } catch (Horde_Exception $e) {
+ throw new Wicked_Exception($e);
+ }
}
-
}
require_once WICKED_BASE . '/lib/Wicked.php';
$this->wicked = Wicked_Driver::factory('sql', $this->getTestDatabaseSQLDriverConfig());
- $this->assertNotA($this->wicked, 'PEAR_Error');
}
function test_Driver_newPage_should_successfully_create_a_page()
$this->assertFalse($this->wicked->pageExists(TEST_PAGE_1));
- $res = $this->wicked->newPage(TEST_PAGE_1, 'This is a test.');
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->newPage(TEST_PAGE_1, 'This is a test.');
$this->assertTrue($this->wicked->pageExists(TEST_PAGE_1));
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertEqual('This is a test.', $page['page_text']);
}
function test_updateText_should_also_update_history()
{
- $res = $this->wicked->updateText(TEST_PAGE_1, 'Here\'s the new page text.',
- 'Test change.', true);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->updateText(TEST_PAGE_1, 'Here\'s the new page text.',
+ 'Test change.', true);
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertEqual('Here\'s the new page text.', $page['page_text']);
$last_version = sprintf('%d.%d', $page['page_majorversion'],
$page['page_minorversion']);
-
- $res = $this->wicked->updateText(TEST_PAGE_1, 'Here\'s the second change.',
- 'Test change 2.', false);
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->updateText(TEST_PAGE_1, 'Here\'s the second change.',
+ 'Test change 2.', false);
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertEqual('Here\'s the second change.', $page['page_text']);
$res = $this->wicked->retrieveHistory(TEST_PAGE_1, $last_version);
- $this->assertNotA($res, 'PEAR_Error');
-
$this->assertNotEqual(0, count($res),
"no results from retrieveHistory()");
$page = $res[0];
function testGetHistoryAndRemoveVersion()
{
$history = $this->wicked->getHistory(TEST_PAGE_1);
- $this->assertNotA($history, 'PEAR_Error');
$this->assertFalse(count($history) < 2, "need more history to test");
$nvers = count($history);
$item_1_ver = sprintf('%d.%d', $item_1['page_majorversion'],
$item_1['page_minorversion']);
- $res = $this->wicked->removeVersion(TEST_PAGE_1, $item_1_ver);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->removeVersion(TEST_PAGE_1, $item_1_ver);
$history = $this->wicked->getHistory(TEST_PAGE_1);
- $this->assertNotA($history, 'PEAR_Error');
$this->assertEqual(count($history), ($nvers - 1));
foreach ($history as $page) {
function testLock()
{
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertFalse($page['locked']);
- $res = $this->wicked->lock(TEST_PAGE_1, true);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->lock(TEST_PAGE_1, true);
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertTrue($page['locked']);
- $res = $this->wicked->lock(TEST_PAGE_1, false);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->lock(TEST_PAGE_1, false);
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
$this->assertFalse($page['locked']);
}
function test_logPageView_should_increment_hit_counter()
{
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
-
$hits = $page['page_hits'];
-
- $res = $this->wicked->logPageView(TEST_PAGE_1);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->logPageView(TEST_PAGE_1);
$page = $this->wicked->retrieveByName(TEST_PAGE_1);
- $this->assertNotA($page, 'PEAR_Error');
-
$this->assertEqual($page['page_hits'], $hits + 1);
}
function testRenamePage()
{
- $res = $this->wicked->renamePage(TEST_PAGE_1, TEST_PAGE_2);
- $this->assertNotA($res, 'PEAR_Error');
-
+ $this->wicked->renamePage(TEST_PAGE_1, TEST_PAGE_2);
$this->assertFalse($this->wicked->pageExists(TEST_PAGE_1));
$this->assertTrue($this->wicked->pageExists(TEST_PAGE_2));
- $res = $this->wicked->renamePage(TEST_PAGE_2, TEST_PAGE_1);
+ $this->wicked->renamePage(TEST_PAGE_2, TEST_PAGE_1);
$this->assertTrue($this->wicked->pageExists(TEST_PAGE_1));
$this->assertFalse($this->wicked->pageExists(TEST_PAGE_2));
}
function testGetPagesAndGetAllPages()
{
$pages = $this->wicked->getPages(false);
- $this->assertNotA($pages, 'PEAR_Error');
-
$allPages = $this->wicked->getAllPages();
- $this->assertNotA($allPages, 'PEAR_Error');
$this->assertEqual(count($allPages), count($pages));
$allPageNames = array();
function test_mostPopular_call_should_not_fail()
{
- $res = $this->wicked->mostPopular();
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->mostPopular();
}
function test_leastPopular_call_should_not_fail()
{
- $res = $this->wicked->leastPopular();
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->leastPopular();
}
function test_recentChanges_call_should_not_fail()
{
- $res = $this->wicked->getRecentChanges();
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->getRecentChanges();
}
function testSearches()
{
$res = $this->wicked->searchTitles('.phpt');
- $this->assertNotA($res, 'PEAR_Error');
-
$this->assertFalse(count($res) < 1, "didn't find all the pages.");
$res = $this->wicked->searchText('second change');
- $this->assertNotA($res, 'PEAR_Error');
$this->assertFalse(count($res) < 1, "didn't find all the pages.");
- $res = $this->wicked->getLikePages('Wiki');
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->getLikePages('Wiki');
}
function test_removeAllVersions_should_not_leave_any_versions()
{
- $res = $this->wicked->removeAllVersions(TEST_PAGE_1);
- $this->assertNotA($res, 'PEAR_Error');
+ $this->wicked->removeAllVersions(TEST_PAGE_1);
$this->assertFalse($this->wicked->pageExists("TEXT_PAGE_1"));
}
* page.
*/
+function headerValue($headers, $name)
+{
+ $val = null;
+ foreach ($headers as $headerName => $headerVal) {
+ if (!strcasecmp($name, $headerName)) {
+ if (is_array($headerVal)) {
+ $thisVal = join(', ', $headerVal);
+ } else {
+ $thisVal = $headerVal;
+ }
+ if (is_null($val)) {
+ $val = $thisVal;
+ } else {
+ $val .= ", " . $thisVal;
+ }
+ }
+ }
+ return $val;
+}
+
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('wicked', array('authentication' => 'none', 'cli' => true));
$text .= fgets(STDIN, 512);
}
-$message = Horde_Mime_Part::parseMessage($text);
-if (is_a($message, 'PEAR_Error')) {
- $cli->fatal(sprintf(_("Error parsing MIME message: %s\n"),
- $message->getMessage()));
-}
-
if (preg_match("/^(.*?)\r?\n\r?\n/s", $text, $matches)) {
$hdrText = $matches[1];
} else {
$hdrText = $text;
}
+$message = Horde_Mime_Part::parseMessage($text);
$headers = Horde_Mime_Headers::parseHeaders($hdrText);
// Format the message into a pageBody.
$pageName = "EmailMessage" . ucfirst(md5(uniqid('wicked')));
}
-$res = $wicked->newPage($pageName, $pageBody);
-if (is_a($res, 'PEAR_Error')) {
- $cli->fatal(sprintf(_("Error creating new page: %s"), $res->getMessage()));
-}
+$wicked->newPage($pageName, $pageBody);
exit(0);
-
-function headerValue($headers, $name)
-{
- $val = null;
- foreach ($headers as $headerName => $headerVal) {
- if (!strcasecmp($name, $headerName)) {
- if (is_array($headerVal)) {
- $thisVal = join(', ', $headerVal);
- } else {
- $thisVal = $headerVal;
- }
- if (is_null($val)) {
- $val = $thisVal;
- } else {
- $val .= ", " . $thisVal;
- }
- }
- }
- return $val;
-}
<div class="header">
<?php
$right = '';
-$v = $this->versionCreated();
-if (!is_a($v, 'PEAR_Error')) {
+try {
+ $v = $this->versionCreated();
$right .= sprintf(_("Last Modified %s by %s"), $this->formatVersionCreated(), $this->author());
-}
-$v = $this->version();
-if (!is_a($v, 'PEAR_Error') && $this->allows(Wicked::MODE_DIFF)) {
+ $v = $this->version();
$diff_url = Horde_Util::addParameter(Horde::url('diff.php'),
array('page' => $this->pageName(),
'v1' => '?',
$right .= ' ' .
Horde::link($diff_url, $diff_alt) .
Horde::img('diff.png', $diff_alt) . '</a>';
-}
+} catch (Wicked_Exception $e) {}
+
if ($right) {
echo '<div class="smallheader rightFloat">' . $right . '</div>';
}
$version = Horde_Util::getFormData('version');
if (empty($version)) {
- $attachments = $wicked->getAttachedFiles($page_id);
- if (is_a($attachments, 'PEAR_Error')) {
+ try {
+ $attachments = $wicked->getAttachedFiles($page_id);
+ } catch (Wicked_Exception $e) {
// If we redirect here, we cause an infinite loop with inline
// attachments.
header('HTTP/1.1 404 Not Found');
}
}
-$data = $wicked->getAttachmentContents($page_id, $file, $version);
-if (is_a($data, 'PEAR_Error')) {
+try {
+ $data = $wicked->getAttachmentContents($page_id, $file, $version);
+} catch (Wicked_Exception $e) {
// If we redirect here, we cause an infinite loop with inline
// attachments.
header('HTTP/1.1 404 Not Found');