now you can edit/create wiki pages

This commit is contained in:
tmont 2008-10-22 04:25:17 +00:00
parent f90dd02210
commit bb2acc1ce1
10 changed files with 206 additions and 22 deletions

View File

@ -39,6 +39,7 @@
//handlers
case 'PanaceaPostHandlerFactory':
case 'WikiEditPagePostHandler':
case 'WikiNewPagePostHandler':
$file = "$path/lib/controllers/handlers/$className.php";
break;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* WikiPagePostHandler
* WikiEditPagePostHandler
*
* @package Panacea
* @subpackage Wiki
@ -20,7 +20,7 @@
* @author Tommy Montgomery
* @since 2008-10-18
*/
class WikiPagePostHandler extends PostHandler {
class WikiEditPagePostHandler extends PostHandler {
/**
* {@inheritdoc}

View File

@ -0,0 +1,74 @@
<?php
/**
* WikiNewPagePostHandler
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-21
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* Object for handling POST requests for creating a new page
*
* @package Panacea
* @subpackage Wiki
* @author Tommy Montgomery
* @since 2008-10-21
*/
class WikiNewPagePostHandler extends PostHandler {
/**
* {@inheritdoc}
*
* Creates a new wiki page and a its first revision.
*
* @author Tommy Montgomery
* @since 2008-10-21
*
* @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);
}
if (!isset($this->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);
}
}
?>

View File

@ -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;

View File

@ -26,7 +26,7 @@
<div class="wikicontent">
<form action="<?php echo $this->wikiPath . '/' . $this->page->page->page_name; ?>" method="post">
<input type="hidden" name="handler" value="wikisource"/>
<input type="hidden" name="handler" value="wikiedit"/>
<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>

View File

@ -0,0 +1,79 @@
<?php
/**
* WikiPageNewView
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-20
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* View for creating a new wiki page
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-20
*/
class WikiPageNewView extends PanaceaWikiView {
/**
* The name of the new page
*
* @var string
*/
protected $pageName;
/**
* Creates a new {@link WikiPageNewView} for the specified page name
*
* @author Tommy Montgomery
* @since 2008-10-20
*
* @param string $pageName The name of the new page
*/
public function __construct($pageName, $priority = 0) {
if (!is_string($pageName)) {
throw new InvalidTypeException(1, 'string', $pageName);
}
parent::__construct(null, null, $priority);
$this->pageName = $pageName;
}
/**
* Renders the view
*
* @author Tommy Montgomery
* @since 2008-10-20
*/
public function send() { ?>
<p>
The page <b><tt><?php echo $this->pageName; ?></tt></b> has not
yet been created. Type some stuff into the textarea below, and then
press <i>Create New Page</i> to create the page.
</p>
<div class="wikicontent">
<form action="<?php echo $this->wikiPath . '/' . $this->pageName; ?>" method="post">
<input type="hidden" name="handler" value="wikinew"/>
<input type="hidden" name="page_name" value="<?php echo $this->pageName; ?>"/>
<textarea name="wikitext" rows="12" cols="80"></textarea>
<input type="submit" name="submit" value="Create New Page"/>
</form>
</div>
<?php
}
}
?>

View File

@ -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));
}
}

View File

@ -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 {