post handlers, and now you can edit wiki pages
This commit is contained in:
parent
edcd6127a9
commit
7f9c9e70d8
@ -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':
|
||||
|
@ -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)) {
|
||||
|
66
src/lib/PanaceaPostHandlerFactory.php
Normal file
66
src/lib/PanaceaPostHandlerFactory.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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);
|
||||
|
63
src/lib/WikiPagePostHandler.php
Normal file
63
src/lib/WikiPagePostHandler.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
41
src/lib/WikiPostHandler.php
Normal file
41
src/lib/WikiPostHandler.php
Normal 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'])) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -25,10 +25,19 @@
|
||||
public function send() { ?>
|
||||
|
||||
<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>
|
||||
|
||||
<?php }
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
35
src/lib/views/wiki/WikiPageHistoryView.php
Normal file
35
src/lib/views/wiki/WikiPageHistoryView.php
Normal 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user