diff --git a/src/bootstrap.php b/src/bootstrap.php index 0524aec..ae031d0 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -28,11 +28,14 @@ case 'WikiViewFactory': case 'PanaceaDefaultController': case 'PanaceaViewFactory': + case 'PanaceaPostHandlerFactory': + case 'WikiPagePostHandler': $file = "$path/lib/$className.php"; break; case 'WikiPageView': case 'WikiPageEditView': + case 'WikiPageHistoryView': case 'WikiPageMenuView': case 'WikiPageContentView': case 'PanaceaWikiView': diff --git a/src/lib/PanaceaControllerFactory.php b/src/lib/PanaceaControllerFactory.php index 1859bee..92ba241 100644 --- a/src/lib/PanaceaControllerFactory.php +++ b/src/lib/PanaceaControllerFactory.php @@ -47,15 +47,12 @@ * Parses the URI fragments and determines which * {@link Controller} to instantiate * - * {@internal $section will be wiki, repo, tracker, etc. - * $page will be empty or the name of the page}} - * * @author Tommy Montgomery * @since 2008-10-05 * * @param array $uriFragments The URI fragments * @throws {@link ClassNotFoundException} - * @return PanaceaPageController + * @return PanaceaDefaultController */ public function getController(array $uriFragments) { if (empty($uriFragments)) { diff --git a/src/lib/PanaceaPostHandlerFactory.php b/src/lib/PanaceaPostHandlerFactory.php new file mode 100644 index 0000000..e616a15 --- /dev/null +++ b/src/lib/PanaceaPostHandlerFactory.php @@ -0,0 +1,66 @@ +Panacea application + * + * @package Panacea + * @subpackage Library + * @author Tommy Montgomery + * @since 2008-10-18 + */ + class PanaceaPostHandlerFactory implements PostHandlerFactory { + + /** + * The singleton instance + * + * @var PanaceaPostHandlerFactory + */ + private static $instance = null; + + protected function __construct() { + + } + + public final function __clone() { + throw new LogicException('Singletons cannot be cloned'); + } + + public static function getInstance() { + if (self::$instance === null) { + self::$instance = new self(); + } + + return new self(); + } + + public static function getPostHandler(array $postData) { + if (!isset($postData['handler'])) { + throw new InvalidPostDataException('handler', $postData); + } + + switch ($postData['handler']) { + case 'wikisource': + unset($postData['handler']); + return new WikiPagePostHandler($postData); + default: + throw new InvalidPostDataException('wikisource', $postData); + break; + } + } + + } + +?> \ No newline at end of file diff --git a/src/lib/PanaceaWikiController.php b/src/lib/PanaceaWikiController.php index 4ab7162..a342624 100644 --- a/src/lib/PanaceaWikiController.php +++ b/src/lib/PanaceaWikiController.php @@ -58,9 +58,16 @@ $request = Request::create(HttpUtil::getRequestMethod()); } + $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); + + //handle request metadata + if ($request->method === HttpUtil::HTTP_METHOD_POST) { + $postHandler = PanaceaPostHandlerFactory::getInstance()->getPostHandler($request->body); + $lastInsertId = $postHandler->execute($mysql); + } + try { $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); - $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); $wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); diff --git a/src/lib/WikiPagePostHandler.php b/src/lib/WikiPagePostHandler.php new file mode 100644 index 0000000..c727530 --- /dev/null +++ b/src/lib/WikiPagePostHandler.php @@ -0,0 +1,63 @@ +history table, + * at least until I think of something more for wiki pages + * to do that insert/update the database. + * + * @author Tommy Montgomery + * @since 2008-10-18 + * + * @param DatabaseVendor $vendor Database connection + * @throws {@link InvalidTypeException} + * @return int + */ + public function execute(DatabaseVendor $vendor = null) { + if (!($vendor instanceof DatabaseVendor)) { + throw new InvalidTypeException(1, 'DatabaseVendor', $vendor); + } + + $history = new WikiHistory(); + $fields = WikiHistory::getFields($vendor); + foreach ($this->data as $key => $value) { + if (!isset($fields[$key])) { + continue; + } + + settype($value, $fields[$key]['type']); + $history->$key = $value; + } + + + $history->created_user_id = 1; + + return $history->insert($vendor); + } + + } + +?> \ No newline at end of file diff --git a/src/lib/WikiPostHandler.php b/src/lib/WikiPostHandler.php new file mode 100644 index 0000000..6926269 --- /dev/null +++ b/src/lib/WikiPostHandler.php @@ -0,0 +1,41 @@ +data['wikisource'])) { + + } + } + + } + +?> \ No newline at end of file diff --git a/src/lib/views/wiki/WikiPageEditView.php b/src/lib/views/wiki/WikiPageEditView.php index eb7e816..8559de1 100644 --- a/src/lib/views/wiki/WikiPageEditView.php +++ b/src/lib/views/wiki/WikiPageEditView.php @@ -25,10 +25,19 @@ public function send() { ?>