added query string handling to controllers/views; added wiki edit page (no editing yet, though, just viewing wiki source)
This commit is contained in:
parent
0ffdd23172
commit
079ea35ca5
@ -32,6 +32,7 @@
|
||||
break;
|
||||
|
||||
case 'WikiPageView':
|
||||
case 'WikiPageEditView':
|
||||
case 'WikiPageMenuView':
|
||||
case 'WikiPageContentView':
|
||||
case 'PanaceaWikiView':
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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}<kbd>::VIEWTYPE_*</kbd> 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();
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,8 +28,14 @@
|
||||
* @author Tommy Montgomery
|
||||
* @since 2008-10-18
|
||||
*/
|
||||
public function send() {
|
||||
echo "\t\t" . $this->page;
|
||||
public function send() { ?>
|
||||
|
||||
<div class="wikicontent">
|
||||
<?php echo $this->page; ?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
35
src/lib/views/wiki/WikiPageEditView.php
Normal file
35
src/lib/views/wiki/WikiPageEditView.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* WikiPageEditView
|
||||
*
|
||||
* @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 WikiPageEditView extends PanaceaWikiView {
|
||||
|
||||
public function send() { ?>
|
||||
|
||||
<div class="wikicontent">
|
||||
<textarea rows="12" cols="80"><?php echo $this->page->getRevision()->wikitext; ?></textarea>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -34,7 +34,6 @@
|
||||
<ul class="menu">
|
||||
<li><a href="<?php echo $this->wikiPath; ?>/<?php echo $this->page->page->page_name; ?>?stats">Statistics</a></li>
|
||||
<li><a href="<?php echo $this->wikiPath; ?>/<?php echo $this->page->page->page_name; ?>?history">History</a></li>
|
||||
<li><a href="<?php echo $this->wikiPath; ?>/<?php echo $this->page->page->page_name; ?>?source">Source</a></li>
|
||||
<li><a href="<?php echo $this->wikiPath; ?>/<?php echo $this->page->page->page_name; ?>?edit">Edit</a></li>
|
||||
</ul>
|
||||
<div style="clear:right"></div>
|
||||
|
@ -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));
|
||||
}
|
||||
$this->addView(new WikiPageMenuView($page, $action, 1));
|
||||
|
||||
/**
|
||||
* Renders the view
|
||||
*
|
||||
* @author Tommy Montgomery
|
||||
* @since 2008-10-18
|
||||
*/
|
||||
public function send() {
|
||||
parent::send();
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ body {
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
}
|
||||
ul.menu {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
@ -143,3 +146,6 @@ ul.menu {
|
||||
float: right;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.wikicontent {
|
||||
margin: 10px auto;
|
||||
}
|
Loading…
Reference in New Issue
Block a user