post handlers, and now you can edit wiki pages

This commit is contained in:
tmont 2008-10-20 03:49:01 +00:00
parent edcd6127a9
commit 7f9c9e70d8
8 changed files with 228 additions and 7 deletions

View File

@ -28,11 +28,14 @@
case 'WikiViewFactory': case 'WikiViewFactory':
case 'PanaceaDefaultController': case 'PanaceaDefaultController':
case 'PanaceaViewFactory': case 'PanaceaViewFactory':
case 'PanaceaPostHandlerFactory':
case 'WikiPagePostHandler':
$file = "$path/lib/$className.php"; $file = "$path/lib/$className.php";
break; break;
case 'WikiPageView': case 'WikiPageView':
case 'WikiPageEditView': case 'WikiPageEditView':
case 'WikiPageHistoryView':
case 'WikiPageMenuView': case 'WikiPageMenuView':
case 'WikiPageContentView': case 'WikiPageContentView':
case 'PanaceaWikiView': case 'PanaceaWikiView':

View File

@ -47,15 +47,12 @@
* Parses the URI fragments and determines which * Parses the URI fragments and determines which
* {@link Controller} to instantiate * {@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 * @author Tommy Montgomery
* @since 2008-10-05 * @since 2008-10-05
* *
* @param array $uriFragments The URI fragments * @param array $uriFragments The URI fragments
* @throws {@link ClassNotFoundException} * @throws {@link ClassNotFoundException}
* @return PanaceaPageController * @return PanaceaDefaultController
*/ */
public function getController(array $uriFragments) { public function getController(array $uriFragments) {
if (empty($uriFragments)) { if (empty($uriFragments)) {

View File

@ -0,0 +1,66 @@
<?php
/**
* PanaceaPostHandlerFactory
*
* @package Panacea
* @subpackage Library
* @author Tommy Montgomery
* @since 2008-10-18
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* Factory implementation that retrieves a {@link PostHandler}
* for the <i>Panacea</i> 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;
}
}
}
?>

View File

@ -58,9 +58,16 @@
$request = Request::create(HttpUtil::getRequestMethod()); $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 { try {
$templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page);
$mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki');
$wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); $wikiObject = new WikiPageObject(WikiPage::loadByPageName($mysql, $this->page));
$wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql);

View File

@ -0,0 +1,63 @@
<?php
/**
* WikiPagePostHandler
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-18
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* Object for handling wiki-related POST requests
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-18
*/
class WikiPagePostHandler extends PostHandler {
/**
* {@inheritdoc}
*
* This always inserts into the <kbd>history</kbd> 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);
}
}
?>

View File

@ -0,0 +1,41 @@
<?php
/**
* WikiPostHandler
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-18
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* Object for handling wiki-related POST requests
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-18
*/
class WikiPostHandler extends PostHandler {
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @since 2008-10-18
*
* @return mixed
*/
public function execute() {
if (isset($this->data['wikisource'])) {
}
}
}
?>

View File

@ -25,10 +25,19 @@
public function send() { ?> public function send() { ?>
<div class="wikicontent"> <div class="wikicontent">
<textarea rows="12" cols="80"><?php echo $this->page->getRevision()->wikitext; ?></textarea> <form action="<?php echo $this->wikiPath . '/' . $this->page->page->page_name; ?>" method="post">
<input type="hidden" name="handler" value="wikisource"/>
<input type="hidden" name="page_id" value="<?php echo $this->page->page->page_id ?>"/>
<textarea name="wikitext" rows="12" cols="80"><?php echo $this->page->getRevision()->wikitext; ?></textarea>
<a href="<?php echo $this->wikiPath .'/' . $this->page->page->page_name; ?>"><input class="cancel" type="button" value="Cancel"/></a>
<input type="submit" name="submit" value="Submit Changes"/>
</form>
</div> </div>
<?php } <?php
}
} }

View File

@ -0,0 +1,35 @@
<?php
/**
* WikiPageHistoryView
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-18
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* View for wiki source
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-18
*/
class WikiPageHistoryView extends PanaceaWikiView {
public function send() { ?>
<?php
}
}
?>