From 079ea35ca51067108b705f2d0bdf0517786ffd48 Mon Sep 17 00:00:00 2001 From: tmont Date: Sun, 19 Oct 2008 05:48:30 +0000 Subject: [PATCH] added query string handling to controllers/views; added wiki edit page (no editing yet, though, just viewing wiki source) --- src/bootstrap.php | 1 + src/index.php | 11 ++++++- src/lib/PanaceaControllerFactory.php | 6 +++- src/lib/PanaceaDefaultController.php | 5 +++- src/lib/PanaceaWikiController.php | 15 +++++++--- src/lib/views/wiki/PanaceaWikiView.php | 7 +++-- src/lib/views/wiki/WikiPageContentView.php | 10 +++++-- src/lib/views/wiki/WikiPageEditView.php | 35 ++++++++++++++++++++++ src/lib/views/wiki/WikiPageMenuView.php | 1 - src/lib/views/wiki/WikiPageView.php | 35 ++++++++++++---------- src/media/css/global.css | 6 ++++ 11 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 src/lib/views/wiki/WikiPageEditView.php diff --git a/src/bootstrap.php b/src/bootstrap.php index e972335..0524aec 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -32,6 +32,7 @@ break; case 'WikiPageView': + case 'WikiPageEditView': case 'WikiPageMenuView': case 'WikiPageContentView': case 'PanaceaWikiView': diff --git a/src/index.php b/src/index.php index 5d2f40a..81af1ba 100644 --- a/src/index.php +++ b/src/index.php @@ -13,7 +13,16 @@ $uriRegex = str_replace(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']), '', dirname(__FILE__)); $uriRegex = str_replace('\\', '/', $uriRegex); - $uriRegex = '^' . $uriRegex . '/([^/]*)(?:/(.*))?'; + $uriRegex = '^' . $uriRegex . '/([^/]*)(?:/([^\?]*)(?:\?(.*))?)?'; + + /* + * $uriRegex: ^/webroot/([^/]*)(?:/(.*)(?:\?(.*))?)? + * + * ^/webroot/ - matches the webroot + * ([^/]*) - matches the section (this can be empty, hence the *) + * (?:/([^\?]*) - matches the page, if there is one + * (?:\?(.*)) - matches the query string, if there is one + */ Dispatcher::getInstance()->setUriRegex($uriRegex) ->setThrowExceptions(true) diff --git a/src/lib/PanaceaControllerFactory.php b/src/lib/PanaceaControllerFactory.php index d10f9cd..1859bee 100644 --- a/src/lib/PanaceaControllerFactory.php +++ b/src/lib/PanaceaControllerFactory.php @@ -64,10 +64,14 @@ $section = ''; $page = $uriFragments[0]; + $query = ''; if (isset($uriFragments[1])) { $section = ucfirst($uriFragments[0]); $page = ucfirst($uriFragments[1]); + if (isset($uriFragments[2])) { + $query = $uriFragments[2]; + } } if (empty($section)) { $section = 'Default'; @@ -85,7 +89,7 @@ } } - return new $controllerName($page); + return new $controllerName($page, $query); } } diff --git a/src/lib/PanaceaDefaultController.php b/src/lib/PanaceaDefaultController.php index cfd03f6..3582195 100644 --- a/src/lib/PanaceaDefaultController.php +++ b/src/lib/PanaceaDefaultController.php @@ -20,6 +20,8 @@ */ class PanaceaDefaultController extends Controller { + protected $queryString; + /** * Creates a new {@link PanaceaDefaultController} * @@ -31,8 +33,9 @@ * @param int $viewType One of the {@link View}::VIEWTYPE_* constants * @throws {@link InvalidTypeException} */ - public function __construct($page = '', $viewType = View::VIEWTYPE_HTML) { + public function __construct($page = '', $query = '', $viewType = View::VIEWTYPE_HTML) { parent::__construct($page, $viewType); + $this->queryString = $query; $this->viewFactory = PanaceaViewFactory::getInstance(); } diff --git a/src/lib/PanaceaWikiController.php b/src/lib/PanaceaWikiController.php index 4294393..4ab7162 100644 --- a/src/lib/PanaceaWikiController.php +++ b/src/lib/PanaceaWikiController.php @@ -20,9 +20,13 @@ */ class PanaceaWikiController extends PanaceaDefaultController { - public function __construct($page) { + protected $action; + + public function __construct($page, $action = null) { parent::__construct($page, View::VIEWTYPE_HTML); + $this->viewFactory = WikiViewFactory::getInstance(); + $this->action = $action; } /** @@ -44,6 +48,7 @@ * @since 2008-10-18 * @uses Request::create() * @uses HttpUtil::getRequestMethod() + * @todo Remove the hardcoded database connection * * @throws {@link InvalidRequestException} if a {@link View} cannot be created * @return PanaceaTemplateView @@ -55,10 +60,12 @@ try { $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); - $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); - $wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); + $wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); - $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject)); + $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $this->action)); + return $templateView; } catch (ClassNotFoundException $e) { diff --git a/src/lib/views/wiki/PanaceaWikiView.php b/src/lib/views/wiki/PanaceaWikiView.php index 6cad220..f2c3607 100644 --- a/src/lib/views/wiki/PanaceaWikiView.php +++ b/src/lib/views/wiki/PanaceaWikiView.php @@ -29,6 +29,8 @@ */ protected $page; + protected $action; + /** * Creates a new {@link WikiPageView} * @@ -38,10 +40,11 @@ * @param WikiPageObject $page The wiki page to display * @param int $priority The priority of the view */ - public function __construct(WikiPageObject $page, $priority = 0) { + public function __construct(WikiPageObject $page, $action = null, $priority = 0) { parent::__construct($priority); - $this->page = $page; + $this->page = $page; + $this->action = $action; } } diff --git a/src/lib/views/wiki/WikiPageContentView.php b/src/lib/views/wiki/WikiPageContentView.php index f84cc79..8551614 100644 --- a/src/lib/views/wiki/WikiPageContentView.php +++ b/src/lib/views/wiki/WikiPageContentView.php @@ -28,8 +28,14 @@ * @author Tommy Montgomery * @since 2008-10-18 */ - public function send() { - echo "\t\t" . $this->page; + public function send() { ?> + +
+ page; ?> + +
+ + +
+ +
+ + \ No newline at end of file diff --git a/src/lib/views/wiki/WikiPageMenuView.php b/src/lib/views/wiki/WikiPageMenuView.php index 6dc0e93..e5d4263 100644 --- a/src/lib/views/wiki/WikiPageMenuView.php +++ b/src/lib/views/wiki/WikiPageMenuView.php @@ -34,7 +34,6 @@
diff --git a/src/lib/views/wiki/WikiPageView.php b/src/lib/views/wiki/WikiPageView.php index 8f45760..915d958 100644 --- a/src/lib/views/wiki/WikiPageView.php +++ b/src/lib/views/wiki/WikiPageView.php @@ -31,22 +31,27 @@ * @param WikiPageObject $page The wiki page to display * @param int $priority The priority of the view */ - public function __construct(WikiPageObject $page, $priority = 0) { - parent::__construct($page, $priority); + public function __construct(WikiPageObject $page, $action = null, $priority = 0) { + parent::__construct($page, $action, $priority); - $this->addView(new WikiPageMenuView($page, 1)); - $this->addView(new WikiPageContentView($page, 2)); - $this->addView(new WikiPageMenuView($page, 3)); - } - - /** - * Renders the view - * - * @author Tommy Montgomery - * @since 2008-10-18 - */ - public function send() { - parent::send(); + $this->addView(new WikiPageMenuView($page, $action, 1)); + + switch ($action) { + case 'edit': + $this->addView(new WikiPageEditView($page, $action, 2)); + break; + case 'history': + $this->addView(new WikiPageHistoryView($page, $action, 2)); + break; + case 'stats': + $this->addView(new WikiPageStatsView($page, $action, 2)); + break; + default: + $this->addView(new WikiPageContentView($page, $action, 2)); + break; + } + + $this->addView(new WikiPageMenuView($page, $action, 3)); } } diff --git a/src/media/css/global.css b/src/media/css/global.css index 404094e..ab701c1 100644 --- a/src/media/css/global.css +++ b/src/media/css/global.css @@ -10,6 +10,9 @@ body { a { text-decoration: none; } +textarea { + width: 100%; +} ul.menu { list-style-type: none; margin: 0; @@ -142,4 +145,7 @@ ul.menu { .wikimenu ul li { float: right; margin-left: 10px; +} +.wikicontent { + margin: 10px auto; } \ No newline at end of file