diff --git a/src/bootstrap.php b/src/bootstrap.php index 677bd8c..11801af 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -39,6 +39,7 @@ //handlers case 'PanaceaPostHandlerFactory': case 'WikiEditPagePostHandler': + case 'WikiNewPagePostHandler': $file = "$path/lib/controllers/handlers/$className.php"; break; diff --git a/src/lib/controllers/PanaceaWikiController.php b/src/lib/controllers/PanaceaWikiController.php index c6f74d4..7f5ef86 100644 --- a/src/lib/controllers/PanaceaWikiController.php +++ b/src/lib/controllers/PanaceaWikiController.php @@ -67,11 +67,18 @@ } try { - $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); - $wikiObject = new PanaceaWikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + try { + $wikiObject = new PanaceaWikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); + } + catch (DomainException $e) { + //the page doesn't exist, so we don't need to pass the wiki object or action along + $wikiObject = null; + $this->action = 'new'; + } - $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); - $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $this->action)); + $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); + $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $this->action, $this->page)); return $templateView; } diff --git a/src/lib/controllers/handlers/PanaceaPostHandlerFactory.php b/src/lib/controllers/handlers/PanaceaPostHandlerFactory.php index e616a15..92fb618 100644 --- a/src/lib/controllers/handlers/PanaceaPostHandlerFactory.php +++ b/src/lib/controllers/handlers/PanaceaPostHandlerFactory.php @@ -48,15 +48,18 @@ public static function getPostHandler(array $postData) { if (!isset($postData['handler'])) { - throw new InvalidPostDataException('handler', $postData); + throw new InvalidPostDataException($postData, array('handler')); } switch ($postData['handler']) { - case 'wikisource': + case 'wikiedit': unset($postData['handler']); - return new WikiPagePostHandler($postData); + return new WikiEditPagePostHandler($postData); + case 'wikinew': + unset($postData['handler']); + return new WikiNewPagePostHandler($postData); default: - throw new InvalidPostDataException('wikisource', $postData); + throw new Exception(); break; } } diff --git a/src/lib/controllers/handlers/WikiEditPagePostHandler.php b/src/lib/controllers/handlers/WikiEditPagePostHandler.php index c727530..666884e 100644 --- a/src/lib/controllers/handlers/WikiEditPagePostHandler.php +++ b/src/lib/controllers/handlers/WikiEditPagePostHandler.php @@ -1,7 +1,7 @@ data['wikitext'])) { + throw new InvalidPostDataException('wikitext', $this->data); + } + + //create row in wiki.pages + $page = new WikiPage(); + $fields = WikiPage::getFields($vendor); + foreach ($this->data as $key => $value) { + if (!isset($fields[$key])) { + continue; + } + + settype($value, $fields[$key]['type']); + $page->$key = $value; + } + + $page->created_user_id = 1; + $page->category_id = 1; + $pageId = $page->insert($vendor); + + //create first revision in wiki.history + $history = new WikiHistory(); + WikiHistory::getFields($vendor); + $history->page_id = $pageId; + $history->revision = 1; + $history->wikitext = $this->data['wikitext']; + $history->created_user_id = 1; + return $history->insert($vendor); + } + + } + +?> \ No newline at end of file diff --git a/src/lib/views/wiki/PanaceaWikiView.php b/src/lib/views/wiki/PanaceaWikiView.php index f2c3607..b367cf2 100644 --- a/src/lib/views/wiki/PanaceaWikiView.php +++ b/src/lib/views/wiki/PanaceaWikiView.php @@ -29,6 +29,11 @@ */ protected $page; + /** + * The action to take on the page (e.g. edit) + * + * @var string + */ protected $action; /** @@ -38,9 +43,10 @@ * @since 2008-10-18 * * @param WikiPageObject $page The wiki page to display + * @param string $action The action to perform on the page (e.g. edit) * @param int $priority The priority of the view */ - public function __construct(WikiPageObject $page, $action = null, $priority = 0) { + public function __construct(WikiPageObject $page = null, $action = null, $priority = 0) { parent::__construct($priority); $this->page = $page; diff --git a/src/lib/views/wiki/WikiPageEditView.php b/src/lib/views/wiki/WikiPageEditView.php index 8559de1..e6dc8fa 100644 --- a/src/lib/views/wiki/WikiPageEditView.php +++ b/src/lib/views/wiki/WikiPageEditView.php @@ -26,7 +26,7 @@