diff --git a/src/bootstrap.php b/src/bootstrap.php index 001ce41..b133619 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -58,6 +58,7 @@ case 'WikiPageContentView': case 'PanaceaWikiView': case 'WikiRevisionHistoryView': + case 'WikiRevisionDiffView': $file = "$path/lib/views/wiki/$className.php"; break; diff --git a/src/lib/views/wiki/WikiPageHistoryView.php b/src/lib/views/wiki/WikiPageHistoryView.php index 93f5341..da764c0 100644 --- a/src/lib/views/wiki/WikiPageHistoryView.php +++ b/src/lib/views/wiki/WikiPageHistoryView.php @@ -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)); } /** diff --git a/src/lib/views/wiki/WikiPageView.php b/src/lib/views/wiki/WikiPageView.php index f6ec5cc..0fd3208 100644 --- a/src/lib/views/wiki/WikiPageView.php +++ b/src/lib/views/wiki/WikiPageView.php @@ -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 '
'; var_dump($diff); echo '
'; 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; } diff --git a/src/lib/views/wiki/WikiRevisionDiffView.php b/src/lib/views/wiki/WikiRevisionDiffView.php new file mode 100644 index 0000000..87775e4 --- /dev/null +++ b/src/lib/views/wiki/WikiRevisionDiffView.php @@ -0,0 +1,67 @@ +diff = $diff; + } + + /** + * Renders the view + * + * @author Tommy Montgomery + * @since 2008-10-21 + */ + public function send() { ?> + +

Diff rdiff->oldRevision->revision; ?>/rdiff->newRevision->revision;?>

+ +
+
diff->getDiff(); ?>
+
+ + \ No newline at end of file diff --git a/src/lib/views/wiki/WikiRevisionHistoryView.php b/src/lib/views/wiki/WikiRevisionHistoryView.php index 5da8051..a2ea39f 100644 --- a/src/lib/views/wiki/WikiRevisionHistoryView.php +++ b/src/lib/views/wiki/WikiRevisionHistoryView.php @@ -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 @@ Date Message Author - Affected Lines + Diff revisions as $revision => $history) { ?> - - - revision; ?> - created; ?> - Not implemented yet - created_user_id; ?> - Not implemented yet - - + $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 = '' . $affectedBytes . ' bytes'; + } + + $previous = $history; + ?> + + + revision; ?> + created; ?> + message; ?> + created_user_id; ?> + + +