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 @@
- + diff --git a/src/lib/views/wiki/WikiPageNewView.php b/src/lib/views/wiki/WikiPageNewView.php new file mode 100644 index 0000000..44bcf12 --- /dev/null +++ b/src/lib/views/wiki/WikiPageNewView.php @@ -0,0 +1,79 @@ +pageName = $pageName; + } + + /** + * Renders the view + * + * @author Tommy Montgomery + * @since 2008-10-20 + */ + public function send() { ?> + +

+ The page pageName; ?> has not + yet been created. Type some stuff into the textarea below, and then + press Create New Page to create the page. +

+ +
+ + + + + + +
+ + \ No newline at end of file diff --git a/src/lib/views/wiki/WikiPageView.php b/src/lib/views/wiki/WikiPageView.php index 915d958..7b3aa14 100644 --- a/src/lib/views/wiki/WikiPageView.php +++ b/src/lib/views/wiki/WikiPageView.php @@ -27,31 +27,37 @@ * * @author Tommy Montgomery * @since 2008-10-18 + * @uses addView() * * @param WikiPageObject $page The wiki page to display + * @param string $action The action to take * @param int $priority The priority of the view + * @param string $pageName The name of the page */ - public function __construct(WikiPageObject $page, $action = null, $priority = 0) { + public function __construct(WikiPageObject $page = null, $action = null, $pageName = '', $priority = 0) { parent::__construct($page, $action, $priority); $this->addView(new WikiPageMenuView($page, $action, 1)); - switch ($action) { + switch ($this->action) { + case 'new': + $this->addView(new WikiPageNewView($pageName, 2)); + break; case 'edit': - $this->addView(new WikiPageEditView($page, $action, 2)); + $this->addView(new WikiPageEditView($this->page, $this->action, 2)); break; case 'history': - $this->addView(new WikiPageHistoryView($page, $action, 2)); + $this->addView(new WikiPageHistoryView($this->page, $this->action, 2)); break; case 'stats': - $this->addView(new WikiPageStatsView($page, $action, 2)); + $this->addView(new WikiPageStatsView($this->page, $this->action, 2)); break; default: - $this->addView(new WikiPageContentView($page, $action, 2)); + $this->addView(new WikiPageContentView($this->page, $this->action, 2)); break; } - $this->addView(new WikiPageMenuView($page, $action, 3)); + $this->addView(new WikiPageMenuView($this->page, $this->action, 3)); } } diff --git a/src/media/css/global.css b/src/media/css/global.css index ab701c1..6118e91 100644 --- a/src/media/css/global.css +++ b/src/media/css/global.css @@ -94,12 +94,20 @@ ul.menu { } #main a { border-bottom: 1px dotted #000000; - color: #669966 ; + color: #000099; font-weight: bold; } +#main a.broken { + color: #CC6666; +} +#main a.broken:hover { + background-color: #CC6666; + color: #FFFFFF; +} #main a:hover { - color: #000000; - border-bottom: 2px solid #669966; + background-color: #000099; + color: #FFFFFF; + border-bottom: 1px solid transparent; } #foot {