Use exceptions.
authorJan Schneider <jan@horde.org>
Mon, 18 Oct 2010 11:01:33 +0000 (13:01 +0200)
committerJan Schneider <jan@horde.org>
Mon, 18 Oct 2010 11:01:33 +0000 (13:01 +0200)
32 files changed:
wicked/diff.php
wicked/display.php
wicked/history.php
wicked/lib/Api.php
wicked/lib/Application.php
wicked/lib/Driver.php
wicked/lib/Driver/sql.php
wicked/lib/Page.php
wicked/lib/Page/AddPage.php
wicked/lib/Page/AllPages.php
wicked/lib/Page/AttachedFiles.php
wicked/lib/Page/BackLinks.php
wicked/lib/Page/DeletePage.php
wicked/lib/Page/EditPage.php
wicked/lib/Page/LeastPopular.php
wicked/lib/Page/LikePages.php
wicked/lib/Page/MergeOrRename.php
wicked/lib/Page/MostPopular.php
wicked/lib/Page/NewPage.php
wicked/lib/Page/RecentChanges.php
wicked/lib/Page/RevertPage.php
wicked/lib/Page/Search.php
wicked/lib/Page/StandardPage.php
wicked/lib/Page/StandardPage/StdHistoryPage.php
wicked/lib/Page/SyncDiff.php
wicked/lib/Page/SyncPages.php
wicked/lib/Sync.php
wicked/lib/Sync/wicked.php
wicked/lib/tests/Driver.php
wicked/scripts/mail-filter.php
wicked/templates/display/title.inc
wicked/view.php

index 7bb87fb..479ac45 100644 (file)
@@ -31,9 +31,10 @@ if (!$v1 || ($v2 && version_compare($v1, $v2) > 0) || $v2 == '?') {
     $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();
 }
 
index d4e0de7..46d894b 100644 (file)
 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)) {
@@ -25,9 +27,10 @@ case 'lock':
                             '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;
@@ -37,13 +40,13 @@ case 'unlock':
         $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;
 
@@ -92,27 +95,29 @@ case 'export':
         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');
index 7e232f1..54565bc 100644 (file)
@@ -11,8 +11,9 @@
 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();
 }
index 9c16c6e..02ca8c1 100644 (file)
@@ -42,14 +42,11 @@ class Wicked_Api extends Horde_Registry_Api
      * @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'],
@@ -66,6 +63,7 @@ class Wicked_Api extends Horde_Registry_Api
      * @param array $pagenames Page names
      *
      * @return array  An array of arrays of page parameters.
+     * @throws Wicked_Exception
      */
     public function getMultiplePageInfo($pagenames = array())
     {
@@ -73,18 +71,12 @@ class Wicked_Api extends Horde_Registry_Api
 
         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'],
@@ -104,18 +96,12 @@ class Wicked_Api extends Horde_Registry_Api
      * @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']);
@@ -143,16 +129,12 @@ class Wicked_Api extends Horde_Registry_Api
      * @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);
     }
 
@@ -163,20 +145,12 @@ class Wicked_Api extends Horde_Registry_Api
      * @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;
     }
@@ -190,50 +164,43 @@ class Wicked_Api extends Horde_Registry_Api
      * @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()
     {
@@ -256,7 +223,8 @@ class Wicked_Api extends Horde_Registry_Api
      *
      * @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)
     {
@@ -269,7 +237,8 @@ class Wicked_Api extends Horde_Registry_Api
      * @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)
     {
@@ -278,11 +247,11 @@ class Wicked_Api extends Horde_Registry_Api
         $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();
@@ -295,11 +264,11 @@ class Wicked_Api extends Horde_Registry_Api
      * @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);
     }
 
     /**
@@ -307,17 +276,13 @@ class Wicked_Api extends Horde_Registry_Api
      *
      * @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'],
index 03250f8..a662302 100644 (file)
@@ -71,15 +71,15 @@ class Wicked_Application extends Horde_Registry_Application
             );
         }
 
-        $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;
     }
index 63bbe1b..5916edf 100644 (file)
@@ -25,7 +25,7 @@ define('WICKED_PAGE_MATCH_ANY', 4);
  * @author  Tyler Colbert <tyler@colberts.us>
  * @package Wicked
  */
-class Wicked_Driver {
+abstract class Wicked_Driver {
 
     /**
      * Hash containing connection parameters.
@@ -54,7 +54,7 @@ class Wicked_Driver {
     /**
      * Accessor to manage a VFS instance.
      *
-     * @throws VFS_Exception
+     * @throws Wicked_Exception
      */
     function getVFS()
     {
@@ -62,7 +62,7 @@ class Wicked_Driver {
             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);
             }
         }
 
@@ -74,12 +74,8 @@ class Wicked_Driver {
      *
      * @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.
@@ -88,24 +84,15 @@ class Wicked_Driver {
      * @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.
@@ -114,30 +101,16 @@ class Wicked_Driver {
      *
      * @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;
     }
@@ -185,27 +158,18 @@ class Wicked_Driver {
         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.
@@ -214,12 +178,9 @@ class Wicked_Driver {
      *
      * @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.
@@ -228,12 +189,9 @@ class Wicked_Driver {
      *
      * @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.
@@ -242,22 +200,13 @@ class Wicked_Driver {
      *
      * @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.
@@ -269,13 +218,10 @@ class Wicked_Driver {
      * @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.
@@ -293,23 +239,15 @@ class Wicked_Driver {
      *                         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. */
@@ -317,7 +255,7 @@ class Wicked_Driver {
         try {
             $vfs->writeData($path, $file['attachment_name'] . ';' . $result, $data, true);
         } catch (VFS_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
+            throw new Wicked_Exception($e);
         }
     }
 
@@ -330,15 +268,11 @@ class Wicked_Driver {
      * @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);
@@ -354,12 +288,10 @@ class Wicked_Driver {
                 try {
                     $vfs->deleteFile($path, $attachment . ';' . $fileversion);
                 } catch (VFS_Exception $e) {
-                    return PEAR::raiseError($result->getMessage());
+                    throw new Wicked_Exception($e);
                 }
             }
         }
-
-        return true;
     }
 
     /**
@@ -367,24 +299,19 @@ class Wicked_Driver {
      *
      * @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);
         }
     }
 
@@ -400,13 +327,10 @@ class Wicked_Driver {
      *
      * @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.
@@ -416,44 +340,30 @@ class Wicked_Driver {
      * @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.
@@ -473,8 +383,8 @@ class Wicked_Driver {
      * @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)
     {
@@ -494,15 +404,10 @@ class Wicked_Driver {
         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.');
     }
 
 }
index 093aed6..8878b00 100644 (file)
@@ -38,7 +38,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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)
     {
@@ -50,7 +51,7 @@ class Wicked_Driver_sql extends Wicked_Driver {
             return $pages[0];
         }
 
-        return PEAR::raiseError($pagename . ' not found');
+        throw new Wicked_Exception($pagename . ' not found');
     }
 
     /**
@@ -59,12 +60,13 @@ class Wicked_Driver_sql extends Wicked_Driver {
      * @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);
@@ -106,7 +108,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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)
     {
@@ -125,7 +128,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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)
     {
@@ -137,7 +141,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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)
     {
@@ -160,7 +165,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *                                     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)
     {
@@ -169,13 +175,13 @@ class Wicked_Driver_sql extends Wicked_Driver {
 
         $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 . ')';
@@ -291,8 +297,9 @@ class Wicked_Driver_sql extends Wicked_Driver {
      * @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)
     {
@@ -335,14 +342,13 @@ class Wicked_Driver_sql extends Wicked_Driver {
      * @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'] .
@@ -378,15 +384,12 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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'] .
@@ -417,8 +420,8 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @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)
     {
@@ -479,7 +482,7 @@ class Wicked_Driver_sql extends Wicked_Driver {
      *
      * @param string $pagename  The page that was viewed.
      *
-     * @return mixed  True or PEAR_Error on failure.
+     * @throws Wicked_Exception
      */
     function logPageView($pagename)
     {
@@ -498,16 +501,16 @@ class Wicked_Driver_sql extends Wicked_Driver {
      * @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();
@@ -550,7 +553,7 @@ class Wicked_Driver_sql extends Wicked_Driver {
      * @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)
     {
@@ -572,9 +575,6 @@ class Wicked_Driver_sql extends Wicked_Driver {
 
         $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. */
@@ -665,56 +665,58 @@ class Wicked_Driver_sql extends Wicked_Driver {
 
         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);
     }
 
     /**
@@ -830,14 +832,14 @@ class Wicked_Driver_sql extends Wicked_Driver {
     /**
      * 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(
index cc8c421..6c5bc38 100644 (file)
@@ -50,7 +50,7 @@ class Wicked_Page {
      */
     function isValid()
     {
-        return !empty($this->_page) && !is_a($this->_page, 'PEAR_Error');
+        return !empty($this->_page);
     }
 
     /**
@@ -180,9 +180,10 @@ class Wicked_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()
     {
@@ -192,9 +193,10 @@ class Wicked_Page {
     }
 
     /**
-     * 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)
     {
@@ -235,18 +237,18 @@ class Wicked_Page {
 
     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()
@@ -268,33 +270,27 @@ class Wicked_Page {
 
     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;
@@ -330,17 +326,16 @@ class Wicked_Page {
     }
 
     /**
-     * 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;
     }
@@ -360,10 +355,12 @@ class Wicked_Page {
     }
 
     /**
-     * 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()
     {
@@ -372,37 +369,31 @@ class Wicked_Page {
 
     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')
@@ -507,7 +498,7 @@ class Wicked_Page {
             return $this->diff($params);
 
         default:
-            return PEAR::raiseError(_("Unsupported"));
+            throw new Wicked_Exception(_("Unsupported"));
         }
     }
 
@@ -518,22 +509,22 @@ class Wicked_Page {
 
     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()
@@ -573,7 +564,7 @@ class Wicked_Page {
 
     function handleAction()
     {
-        return PEAR::raiseError(_("Unsupported"));
+        throw new Wicked_Exception(_("Unsupported"));
     }
 
 }
index a03ac69..27cba55 100644 (file)
@@ -54,17 +54,18 @@ class AddPage extends Wicked_Page {
     }
 
     /**
-     * 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;
@@ -91,7 +92,6 @@ class AddPage extends Wicked_Page {
         }
 
         require WICKED_TEMPLATES . '/edit/create.inc';
-        return true;
     }
 
     function pageName()
index 000da21..cd8d830 100644 (file)
@@ -23,36 +23,26 @@ class AllPages extends Wicked_Page {
         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(),
index 2904603..c61eda3 100644 (file)
@@ -53,27 +53,21 @@ class AttachedFiles extends Wicked_Page {
     }
 
     /**
-     * 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',
@@ -98,18 +92,19 @@ class AttachedFiles extends Wicked_Page {
     /**
      * 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');
@@ -152,7 +147,6 @@ class AttachedFiles extends Wicked_Page {
 
         Horde::addScriptFile('stripe.js', 'horde', true);
         echo $template->fetch(WICKED_TEMPLATES . '/display/AttachedFiles.html');
-        return true;
     }
 
     function pageName()
@@ -191,16 +185,15 @@ class AttachedFiles extends Wicked_Page {
                 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;
         }
@@ -244,10 +237,11 @@ class AttachedFiles extends Wicked_Page {
         }
 
         $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;
         }
@@ -285,11 +279,12 @@ class AttachedFiles extends Wicked_Page {
                       '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) {
index f8504eb..07dbda8 100644 (file)
@@ -36,23 +36,15 @@ class BackLinks extends Wicked_Page {
     }
 
     /**
-     * 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) {
@@ -64,7 +56,6 @@ class BackLinks extends Wicked_Page {
             require WICKED_TEMPLATES . '/pagelist/summary.inc';
         }
         require WICKED_TEMPLATES . '/pagelist/footer.inc';
-
         return ob_get_clean();
     }
 
index 53617ce..0490787 100644 (file)
@@ -65,7 +65,7 @@ class DeletePage extends Wicked_Page {
     /**
      * Render this page in Display mode.
      *
-     * @return mixed True or PEAR_Error.
+     * @throws Wicked_Exception
      */
     function display()
     {
@@ -103,7 +103,6 @@ class DeletePage extends Wicked_Page {
 
 </form>
 <?php
-        return true;
     }
 
     function pageName()
index a2935ef..55dc5ee 100644 (file)
@@ -90,17 +90,18 @@ class EditPage extends Wicked_Page {
             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()
     {
@@ -109,9 +110,7 @@ class EditPage extends Wicked_Page {
         if (is_null($page_text)) {
             $page_text = $page->getText();
         }
-
         require WICKED_TEMPLATES . '/edit/standard.inc';
-        return true;
     }
 
     function pageName()
@@ -174,20 +173,12 @@ class EditPage extends Wicked_Page {
             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();
             }
         }
 
index e402e7a..45afea1 100644 (file)
@@ -25,37 +25,28 @@ class LeastPopular extends Wicked_Page {
         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(),
index 3743c7b..9a66c55 100644 (file)
@@ -36,25 +36,16 @@ class LikePages extends Wicked_Page {
     }
 
     /**
-     * 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) {
@@ -66,7 +57,6 @@ class LikePages extends Wicked_Page {
             require WICKED_TEMPLATES . '/pagelist/summary.inc';
         }
         require WICKED_TEMPLATES . '/pagelist/footer.inc';
-
         return ob_get_clean();
     }
 
index ea2314b..e6d84f7 100644 (file)
@@ -78,9 +78,9 @@ class MergeOrRename extends Wicked_Page {
     }
 
     /**
-     * Render this page in Display mode.
+     * Renders this page in display mode.
      *
-     * @return mixed                Returns true or PEAR_Error.
+     * @throws Wicked_Exception
      */
     function display()
     {
@@ -100,11 +100,6 @@ class MergeOrRename extends Wicked_Page {
         $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']));
@@ -179,50 +174,30 @@ class MergeOrRename extends Wicked_Page {
         }
 
         $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);
@@ -231,13 +206,7 @@ class MergeOrRename extends Wicked_Page {
                 '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);
@@ -261,10 +230,11 @@ class MergeOrRename extends Wicked_Page {
                 $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;
             }
@@ -288,13 +258,7 @@ class MergeOrRename extends Wicked_Page {
             }
 
             $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();
index b4d70a0..d36beb8 100644 (file)
@@ -25,37 +25,28 @@ class MostPopular extends Wicked_Page {
         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(),
index 1016f9c..101e5b9 100644 (file)
@@ -77,9 +77,9 @@ class NewPage extends Wicked_Page {
     }
 
     /**
-     * Render this page in Display mode.
+     * Renders this page in display mode.
      *
-     * @return mixed Returns true or PEAR_Error.
+     * @throws Wicked_Exception
      */
     function display()
     {
@@ -127,12 +127,12 @@ class NewPage extends Wicked_Page {
                 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');
             }
         }
 
index c9cb9c7..28c4f5d 100644 (file)
@@ -25,9 +25,10 @@ class RecentChanges extends Wicked_Page {
         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()
     {
@@ -81,23 +82,15 @@ class RecentChanges extends Wicked_Page {
     }
 
     /**
-     * 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');
     }
 
index 8242950..b3a3fa9 100644 (file)
@@ -57,9 +57,9 @@ class RevertPage extends Wicked_Page {
     }
 
     /**
-     * Render this page in Display mode.
+     * Renders this page in display mode.
      *
-     * @return mixed True or PEAR_Error.
+     * @throws Wicked_Exception
      */
     function display()
     {
@@ -88,7 +88,6 @@ class RevertPage extends Wicked_Page {
 
 </form>
 <?php
-        return true;
     }
 
     function pageName()
index 44c125a..ad2eaf8 100644 (file)
@@ -26,27 +26,26 @@ class Search extends Wicked_Page {
 
     /**
      * 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));
     }
 
     /**
@@ -65,22 +64,16 @@ class Search extends Wicked_Page {
     }
 
     /**
-     * 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';
index 182769d..4bf143d 100644 (file)
@@ -43,15 +43,41 @@ class StandardPage extends Wicked_Page {
      *
      * @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.
@@ -80,31 +106,6 @@ class StandardPage extends Wicked_Page {
             $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');
@@ -158,23 +159,18 @@ class StandardPage extends Wicked_Page {
         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');
@@ -191,16 +187,18 @@ class StandardPage extends Wicked_Page {
 
     /**
      * 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.
@@ -240,6 +238,9 @@ class StandardPage extends Wicked_Page {
         return $owner != $this->_lock['lock_owner'];
     }
 
+    /**
+     * @throws Wicked_Exception
+     */
     function lock()
     {
         if ($this->_locks) {
@@ -247,7 +248,7 @@ class StandardPage extends Wicked_Page {
             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."));
             }
         }
     }
@@ -281,15 +282,15 @@ class StandardPage extends Wicked_Page {
         $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());
index 4c77346..f976432 100644 (file)
@@ -27,11 +27,13 @@ class StdHistoryPage extends StandardPage {
      *
      * @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;
         }
 
@@ -39,13 +41,11 @@ class StdHistoryPage extends StandardPage {
         $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()
index 0b7a2dd..0fe86db 100644 (file)
@@ -40,30 +40,19 @@ class SyncDiff extends SyncPages {
     }
 
     /**
-     * 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);
@@ -95,20 +84,12 @@ class SyncDiff extends SyncPages {
     }
 
     /**
-     * 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();
     }
 
     /**
@@ -128,31 +109,18 @@ class SyncDiff extends SyncPages {
     }
 
     /**
-     * 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();
index 51a2f45..0f56a9b 100644 (file)
@@ -29,13 +29,12 @@ class SyncPages extends Wicked_Page {
 
     /**
      * 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')) {
@@ -50,9 +49,10 @@ class SyncPages extends Wicked_Page {
     }
 
     /**
-     * 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()
     {
@@ -92,9 +92,6 @@ class SyncPages extends Wicked_Page {
                 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'],
@@ -116,9 +113,7 @@ class SyncPages extends Wicked_Page {
 
             // 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;
             }
 
@@ -135,20 +130,14 @@ class SyncPages extends Wicked_Page {
     }
 
     /**
-     * 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();
     }
 
     /**
@@ -181,6 +170,8 @@ class SyncPages extends Wicked_Page {
 
     /**
      * Get and process sync info form
+     *
+     * @throws Wicked_Exception
      */
     function _syncForm()
     {
@@ -269,15 +260,10 @@ class SyncPages extends Wicked_Page {
                 // 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;
@@ -317,10 +303,6 @@ class SyncPages extends Wicked_Page {
     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'],
@@ -335,58 +317,43 @@ class SyncPages extends Wicked_Page {
      * 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');
@@ -401,23 +368,8 @@ class SyncPages extends Wicked_Page {
     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.
index 4122870..9008999 100644 (file)
@@ -11,7 +11,7 @@
  * @author  Duck <duck@obala.net>
  * @package Wicked
  */
-class Wicked_Sync {
+abstract class Wicked_Sync {
 
     /**
      * Hash containing connection parameters.
@@ -70,47 +70,39 @@ class Wicked_Sync {
      * 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.
@@ -118,11 +110,9 @@ class Wicked_Sync {
      * @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
@@ -133,11 +123,7 @@ class Wicked_Sync {
      * @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);
 }
index a6000e4..60eb392 100644 (file)
@@ -42,7 +42,8 @@ class Wicked_Sync_wicked extends Wicked_Sync {
      *
      * @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)
     {
@@ -54,7 +55,8 @@ class Wicked_Sync_wicked extends Wicked_Sync {
      *
      * @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)
     {
@@ -66,7 +68,8 @@ class Wicked_Sync_wicked extends Wicked_Sync {
      *
      * @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())
     {
@@ -94,11 +97,11 @@ class Wicked_Sync_wicked extends Wicked_Sync {
      * @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));
     }
 
     /**
@@ -107,17 +110,21 @@ class Wicked_Sync_wicked extends Wicked_Sync {
      * @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);
+        }
     }
-
 }
index 850a91f..c921d2e 100644 (file)
@@ -18,7 +18,6 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
         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()
@@ -27,39 +26,29 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
 
         $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];
@@ -69,7 +58,6 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
     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);
@@ -77,11 +65,8 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
         $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) {
@@ -95,49 +80,33 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
     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));
     }
@@ -145,10 +114,7 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
     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();
@@ -162,41 +128,33 @@ class Wicked_Driver_TC extends HordeUnitTestCase {
 
     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"));
     }
 
index dab60a8..40e20ab 100755 (executable)
@@ -6,6 +6,26 @@
  * 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));
 
@@ -17,17 +37,12 @@ while (!feof(STDIN)) {
     $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.
@@ -102,29 +117,6 @@ if (is_null($pageName)) {
     $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;
-}
index 2352967..d59fa91 100644 (file)
@@ -1,13 +1,11 @@
 <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' => '?',
@@ -17,7 +15,8 @@ if (!is_a($v, 'PEAR_Error') && $this->allows(Wicked::MODE_DIFF)) {
     $right .= '&nbsp;' .
         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>';
 }
index d42781d..d6ecd05 100644 (file)
@@ -24,8 +24,9 @@ if ($id !== false) {
 
 $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');
@@ -47,8 +48,9 @@ if (empty($version)) {
     }
 }
 
-$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');