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; | 				break; | ||||||
| 			 | 			 | ||||||
| 			case 'WikiPageView': | 			case 'WikiPageView': | ||||||
|  | 			case 'WikiPageEditView': | ||||||
| 			case 'WikiPageMenuView': | 			case 'WikiPageMenuView': | ||||||
| 			case 'WikiPageContentView': | 			case 'WikiPageContentView': | ||||||
| 			case 'PanaceaWikiView': | 			case 'PanaceaWikiView': | ||||||
|  | |||||||
| @ -13,7 +13,16 @@ | |||||||
| 	 | 	 | ||||||
| 	$uriRegex = str_replace(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']), '', dirname(__FILE__)); | 	$uriRegex = str_replace(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']), '', dirname(__FILE__)); | ||||||
| 	$uriRegex = str_replace('\\', '/', $uriRegex); | 	$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) | 	Dispatcher::getInstance()->setUriRegex($uriRegex) | ||||||
| 	                         ->setThrowExceptions(true) | 	                         ->setThrowExceptions(true) | ||||||
|  | |||||||
| @ -64,10 +64,14 @@ | |||||||
| 			 | 			 | ||||||
| 			$section = ''; | 			$section = ''; | ||||||
| 			$page    = $uriFragments[0]; | 			$page    = $uriFragments[0]; | ||||||
|  | 			$query   = ''; | ||||||
| 			 | 			 | ||||||
| 			if (isset($uriFragments[1])) { | 			if (isset($uriFragments[1])) { | ||||||
| 				$section = ucfirst($uriFragments[0]); | 				$section = ucfirst($uriFragments[0]); | ||||||
| 				$page    = ucfirst($uriFragments[1]); | 				$page    = ucfirst($uriFragments[1]); | ||||||
|  | 				if (isset($uriFragments[2])) { | ||||||
|  | 					$query = $uriFragments[2]; | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			if (empty($section)) { | 			if (empty($section)) { | ||||||
| 				$section = 'Default'; | 				$section = 'Default'; | ||||||
| @ -85,7 +89,7 @@ | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			return new $controllerName($page); | 			return new $controllerName($page, $query); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -20,6 +20,8 @@ | |||||||
| 	 */ | 	 */ | ||||||
| 	class PanaceaDefaultController extends Controller { | 	class PanaceaDefaultController extends Controller { | ||||||
| 		 | 		 | ||||||
|  | 		protected $queryString; | ||||||
|  | 		 | ||||||
| 		/** | 		/** | ||||||
| 		 * Creates a new {@link PanaceaDefaultController} | 		 * Creates a new {@link PanaceaDefaultController} | ||||||
| 		 * | 		 * | ||||||
| @ -31,8 +33,9 @@ | |||||||
| 		 * @param  int    $viewType One of the {@link View}<kbd>::VIEWTYPE_*</kbd> constants | 		 * @param  int    $viewType One of the {@link View}<kbd>::VIEWTYPE_*</kbd> constants | ||||||
| 		 * @throws {@link InvalidTypeException} | 		 * @throws {@link InvalidTypeException} | ||||||
| 		 */ | 		 */ | ||||||
| 		public function __construct($page = '', $viewType = View::VIEWTYPE_HTML) { | 		public function __construct($page = '', $query = '', $viewType = View::VIEWTYPE_HTML) { | ||||||
| 			parent::__construct($page, $viewType); | 			parent::__construct($page, $viewType); | ||||||
|  | 			$this->queryString = $query; | ||||||
| 			$this->viewFactory = PanaceaViewFactory::getInstance(); | 			$this->viewFactory = PanaceaViewFactory::getInstance(); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|  | |||||||
| @ -20,9 +20,13 @@ | |||||||
| 	 */ | 	 */ | ||||||
| 	class PanaceaWikiController extends PanaceaDefaultController { | 	class PanaceaWikiController extends PanaceaDefaultController { | ||||||
| 		 | 		 | ||||||
| 		public function __construct($page) { | 		protected $action; | ||||||
|  | 		 | ||||||
|  | 		public function __construct($page, $action = null) { | ||||||
| 			parent::__construct($page, View::VIEWTYPE_HTML); | 			parent::__construct($page, View::VIEWTYPE_HTML); | ||||||
|  | 			 | ||||||
| 			$this->viewFactory = WikiViewFactory::getInstance(); | 			$this->viewFactory = WikiViewFactory::getInstance(); | ||||||
|  | 			$this->action      = $action; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		/** | 		/** | ||||||
| @ -44,6 +48,7 @@ | |||||||
| 		 * @since  2008-10-18 | 		 * @since  2008-10-18 | ||||||
| 		 * @uses   Request::create() | 		 * @uses   Request::create() | ||||||
| 		 * @uses   HttpUtil::getRequestMethod() | 		 * @uses   HttpUtil::getRequestMethod() | ||||||
|  | 		 * @todo   Remove the hardcoded database connection | ||||||
| 		 * | 		 * | ||||||
| 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | ||||||
| 		 * @return PanaceaTemplateView | 		 * @return PanaceaTemplateView | ||||||
| @ -55,10 +60,12 @@ | |||||||
| 			 | 			 | ||||||
| 			try { | 			try { | ||||||
| 				$templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); | 				$templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); | ||||||
| 				$mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); | 				$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); | ||||||
| 				$templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject)); | 				$templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $this->action)); | ||||||
|  | 				 | ||||||
| 				return $templateView; | 				return $templateView; | ||||||
| 			} | 			} | ||||||
| 			catch (ClassNotFoundException $e) { | 			catch (ClassNotFoundException $e) { | ||||||
|  | |||||||
| @ -29,6 +29,8 @@ | |||||||
| 		 */ | 		 */ | ||||||
| 		protected $page; | 		protected $page; | ||||||
| 		 | 		 | ||||||
|  | 		protected $action; | ||||||
|  | 		 | ||||||
| 		/** | 		/** | ||||||
| 		 * Creates a new {@link WikiPageView} | 		 * Creates a new {@link WikiPageView} | ||||||
| 		 * | 		 * | ||||||
| @ -38,10 +40,11 @@ | |||||||
| 		 * @param WikiPageObject $page     The wiki page to display | 		 * @param WikiPageObject $page     The wiki page to display | ||||||
| 		 * @param int            $priority The priority of the view | 		 * @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); | 			parent::__construct($priority); | ||||||
| 			 | 			 | ||||||
| 			$this->page  = $page; | 			$this->page   = $page; | ||||||
|  | 			$this->action = $action; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -28,8 +28,14 @@ | |||||||
| 		 * @author Tommy Montgomery | 		 * @author Tommy Montgomery | ||||||
| 		 * @since  2008-10-18 | 		 * @since  2008-10-18 | ||||||
| 		 */ | 		 */ | ||||||
| 		public function send() { | 		public function send() { ?>
 | ||||||
| 			echo "\t\t" . $this->page; | 				 | ||||||
|  | 				<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"> | 					<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; ?>?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; ?>?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> | 						<li><a href="<?php echo $this->wikiPath; ?>/<?php echo $this->page->page->page_name; ?>?edit">Edit</a></li> | ||||||
| 					</ul> | 					</ul> | ||||||
| 					<div style="clear:right"></div> | 					<div style="clear:right"></div> | ||||||
|  | |||||||
| @ -31,22 +31,27 @@ | |||||||
| 		 * @param WikiPageObject $page     The wiki page to display | 		 * @param WikiPageObject $page     The wiki page to display | ||||||
| 		 * @param int            $priority The priority of the view | 		 * @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($page, $priority); | 			parent::__construct($page, $action, $priority); | ||||||
| 			 | 			 | ||||||
| 			$this->addView(new WikiPageMenuView($page, 1)); | 			$this->addView(new WikiPageMenuView($page, $action, 1)); | ||||||
| 			$this->addView(new WikiPageContentView($page, 2)); |  | ||||||
| 			$this->addView(new WikiPageMenuView($page, 3)); |  | ||||||
| 		} |  | ||||||
| 			 | 			 | ||||||
| 		/** | 			switch ($action) { | ||||||
| 		 * Renders the view | 				case 'edit': | ||||||
| 		 * | 					$this->addView(new WikiPageEditView($page, $action, 2)); | ||||||
| 		 * @author Tommy Montgomery | 					break; | ||||||
| 		 * @since  2008-10-18 | 				case 'history': | ||||||
| 		 */ | 					$this->addView(new WikiPageHistoryView($page, $action, 2)); | ||||||
| 		public function send() { | 					break; | ||||||
| 			parent::send(); | 				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 { | a { | ||||||
| 	text-decoration: none; | 	text-decoration: none; | ||||||
| } | } | ||||||
|  | textarea { | ||||||
|  | 	width: 100%; | ||||||
|  | } | ||||||
| ul.menu { | ul.menu { | ||||||
| 	list-style-type: none; | 	list-style-type: none; | ||||||
| 	margin: 0; | 	margin: 0; | ||||||
| @ -143,3 +146,6 @@ ul.menu { | |||||||
| 	float: right; | 	float: right; | ||||||
| 	margin-left: 10px; | 	margin-left: 10px; | ||||||
| } | } | ||||||
|  | .wikicontent { | ||||||
|  | 	margin: 10px auto; | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user