added in ability to view diffs from the history page
This commit is contained in:
		
							parent
							
								
									cb39cca4fb
								
							
						
					
					
						commit
						649def05df
					
				| @ -58,6 +58,7 @@ | ||||
| 			case 'WikiPageContentView': | ||||
| 			case 'PanaceaWikiView': | ||||
| 			case 'WikiRevisionHistoryView': | ||||
| 			case 'WikiRevisionDiffView': | ||||
| 				$file = "$path/lib/views/wiki/$className.php"; | ||||
| 				break; | ||||
| 			 | ||||
|  | ||||
| @ -38,7 +38,7 @@ | ||||
| 		public function __construct(WikiPageObject $page, Collection $revisions, $action = null, $priority = 0)  { | ||||
| 			parent::__construct($page, $action, $priority); | ||||
| 			 | ||||
| 			$this->addView(new WikiRevisionHistoryView($revisions, 1)); | ||||
| 			$this->addView(new WikiRevisionHistoryView($revisions, $this->page->page->page_name, 1)); | ||||
| 		} | ||||
| 		 | ||||
| 		/** | ||||
|  | ||||
| @ -39,6 +39,8 @@ | ||||
| 			 | ||||
| 			$this->addView(new WikiPageMenuView($page, $action, 1)); | ||||
| 			 | ||||
| 			$vendor = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); | ||||
| 			 | ||||
| 			switch ($this->action) { | ||||
| 				case 'new': | ||||
| 					$this->addView(new WikiPageNewView($pageName, 2)); | ||||
| @ -48,7 +50,6 @@ | ||||
| 					break; | ||||
| 				case 'history': | ||||
| 					//get all revisions for the page
 | ||||
| 					$vendor    = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); | ||||
| 					$revisions = WikiHistory::getRevisionsForPage($vendor, $this->page->page); | ||||
| 					$this->addView(new WikiPageHistoryView($this->page, $revisions, $this->action, 2)); | ||||
| 					break; | ||||
| @ -56,7 +57,20 @@ | ||||
| 					$this->addView(new WikiPageStatsView($this->page, $this->action, 2)); | ||||
| 					break; | ||||
| 				default: | ||||
| 					$this->addView(new WikiPageContentView($this->page, $this->action, 2)); | ||||
| 					//check for diffs: WikiPage?diff[oldRev,newRev]
 | ||||
| 					if (preg_match('/^diff\[(\d+),(\d+)\]$/', $this->action, $matches)) { | ||||
| 						$oldRevision = (int)$matches[1]; | ||||
| 						$newRevision = (int)$matches[2]; | ||||
| 						 | ||||
| 						$diff = $this->page->compareRevisions($oldRevision, $newRevision, $vendor); | ||||
| 						//echo '<pre>'; var_dump($diff); echo '</pre>'; exit;
 | ||||
| 						 | ||||
| 						$this->addView(new WikiRevisionDiffView($this->page, $diff, $this->action, 2)); | ||||
| 					} | ||||
| 					else { | ||||
| 						//bogus/non-existent action, so just display the normal content
 | ||||
| 						$this->addView(new WikiPageContentView($this->page, $this->action, 2)); | ||||
| 					} | ||||
| 					break; | ||||
| 			} | ||||
| 			 | ||||
|  | ||||
							
								
								
									
										67
									
								
								src/lib/views/wiki/WikiRevisionDiffView.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/lib/views/wiki/WikiRevisionDiffView.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,67 @@ | ||||
| <?php | ||||
| 
 | ||||
| 	/** | ||||
| 	 * WikiPageHistoryView | ||||
| 	 * | ||||
| 	 * @package    Panacea | ||||
| 	 * @subpackage Views | ||||
| 	 * @author     Tommy Montgomery | ||||
| 	 * @since      2008-10-18 | ||||
| 	 */ | ||||
| 
 | ||||
| 	/** Bootstraps the NowhereConcave framework */ | ||||
| 	require_once 'NowhereConcave/bootstrap.php'; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * View for a wiki page's history | ||||
| 	 * | ||||
| 	 * @package    Panacea | ||||
| 	 * @subpackage Views | ||||
| 	 * @author     Tommy Montgomery | ||||
| 	 * @since      2008-10-18 | ||||
| 	 */ | ||||
| 	class WikiRevisionDiffView extends PanaceaWikiView { | ||||
| 		 | ||||
| 		protected $diff; | ||||
| 		 | ||||
| 		/** | ||||
| 		 * Creates a new {@link WikiPageHistoryView} | ||||
| 		 * | ||||
| 		 * @author Tommy Montgomery | ||||
| 		 * @since  2008-10-21 | ||||
| 		 * @uses   addView() | ||||
| 		 * @uses   WikiRevisionHistoryView | ||||
| 		 * | ||||
| 		 * @param WikiPageObject $page      The wiki page to display | ||||
| 		 * @param WikiDiff       $diff      The diff between the two revisions | ||||
| 		 * @param string         $action    The action to take | ||||
| 		 * @param int            $priority  The priority of the view | ||||
| 		 */ | ||||
| 		public function __construct(WikiPageObject $page, WikiDiff $diff, $action = null, $priority = 0)  { | ||||
| 			parent::__construct($page, $action, $priority); | ||||
| 			 | ||||
| 			$this->diff = $diff; | ||||
| 		} | ||||
| 		 | ||||
| 		/** | ||||
| 		 * Renders the view | ||||
| 		 * | ||||
| 		 * @author Tommy Montgomery | ||||
| 		 * @since  2008-10-21 | ||||
| 		 */ | ||||
| 		public function send() { ?>
 | ||||
| 				 | ||||
| 				<h1>Diff r<?php echo $this->diff->oldRevision->revision; ?>/r<?php echo $this->diff->newRevision->revision;?></h1>
 | ||||
| 				 | ||||
| 				<div class="wikidiff"> | ||||
| 					<pre><?php echo $this->diff->getDiff(); ?></pre>
 | ||||
| 				</div> | ||||
| 				 | ||||
| 		<?php | ||||
| 			 | ||||
| 			parent::send(); | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 
 | ||||
| ?>
 | ||||
| @ -27,6 +27,13 @@ | ||||
| 		 */ | ||||
| 		protected $revisions; | ||||
| 		 | ||||
| 		/** | ||||
| 		 * Name of the page | ||||
| 		 * | ||||
| 		 * @var string | ||||
| 		 */ | ||||
| 		protected $pageName; | ||||
| 		 | ||||
| 		/** | ||||
| 		 * Creates a new {@link WikiRevisionHistoryView} | ||||
| 		 * | ||||
| @ -34,9 +41,10 @@ | ||||
| 		 * @since  2008-10-21 | ||||
| 		 * | ||||
| 		 * @param Collection $revisions The revisions to display | ||||
| 		 * @param string     $pageName  The name of the page | ||||
| 		 * @param int        $priority  The priority of the view | ||||
| 		 */ | ||||
| 		public function __construct(Collection $revisions, $priority = 0)  { | ||||
| 		public function __construct(Collection $revisions, $pageName, $priority = 0)  { | ||||
| 			parent::__construct($priority); | ||||
| 			 | ||||
| 			if ($revisions->type !== 'WikiHistory') { | ||||
| @ -44,6 +52,7 @@ | ||||
| 			} | ||||
| 			 | ||||
| 			$this->revisions = $revisions; | ||||
| 			$this->pageName  = $pageName; | ||||
| 		} | ||||
| 		 | ||||
| 		/** | ||||
| @ -60,21 +69,32 @@ | ||||
| 						<th>Date</th> | ||||
| 						<th>Message</th> | ||||
| 						<th>Author</th> | ||||
| 						<th>Affected Lines</th> | ||||
| 						<th>Diff</th> | ||||
| 					</tr> | ||||
| 					 | ||||
| 					<?php | ||||
| 						 | ||||
| 						foreach ($this->revisions as $revision => $history) { ?>
 | ||||
| 						 | ||||
| 						<tr> | ||||
| 							<td><?php echo $history->revision; ?></td>
 | ||||
| 							<td><?php echo $history->created; ?></td>
 | ||||
| 							<td>Not implemented yet</td> | ||||
| 							<td><?php echo $history->created_user_id; ?></td>
 | ||||
| 							<td>Not implemented yet</td> | ||||
| 						</tr> | ||||
| 						 | ||||
| 						$previous = null; | ||||
| 						foreach ($this->revisions as $revision => $history) {  | ||||
| 							$affectedBytes = 'n/a'; | ||||
| 							if ($previous !== null) { | ||||
| 								$link          = $this->wikiPath . '/' . $this->pageName; | ||||
| 								$link         .= '?diff[' . $previous->revision . ',' . $revision .']'; | ||||
| 								$affectedBytes = strlen($history->wikitext) - strlen($previous->wikitext); | ||||
| 								$affectedBytes = '<a href="' . $link .'">' . $affectedBytes . ' bytes</a>'; | ||||
| 							} | ||||
| 							 | ||||
| 							$previous = $history; | ||||
| 						?>
 | ||||
| 					 | ||||
| 					<tr> | ||||
| 						<td><?php echo $history->revision; ?></td>
 | ||||
| 						<td><?php echo $history->created; ?></td>
 | ||||
| 						<td><?php echo $history->message; ?></td>
 | ||||
| 						<td><?php echo $history->created_user_id; ?></td>
 | ||||
| 						<td><?php echo $affectedBytes; ?></td>
 | ||||
| 					</tr> | ||||
| 					 | ||||
| 						<?php  | ||||
| 						 | ||||
| 						} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user