From 132bf9cb35dd47ebb083f677a409f55edcf7d49c Mon Sep 17 00:00:00 2001 From: tmont Date: Sat, 25 Oct 2008 20:56:26 +0000 Subject: [PATCH] implemented javascript-driven revision comparison (with the little radio buttons) --- src/lib/views/system/PanaceaTemplateView.php | 6 ++- .../views/wiki/WikiRevisionHistoryView.php | 38 +++++++++++++------ src/media/js/wiki.js | 36 ++++++++++++++++++ 3 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/media/js/wiki.js diff --git a/src/lib/views/system/PanaceaTemplateView.php b/src/lib/views/system/PanaceaTemplateView.php index 269fdaa..283a423 100644 --- a/src/lib/views/system/PanaceaTemplateView.php +++ b/src/lib/views/system/PanaceaTemplateView.php @@ -82,8 +82,10 @@ } } - return ViewMetaData::generate()->addMeta('revised', date('c', $revised)) - ->addCss($this->cssPath . '/global.css'); + $data = ViewMetaData::generate()->addMeta('revised', date('c', $revised)) + ->addCss($this->cssPath . '/global.css'); + + return parent::getMetaData()->merge($data); } /** diff --git a/src/lib/views/wiki/WikiRevisionHistoryView.php b/src/lib/views/wiki/WikiRevisionHistoryView.php index 5a5273f..627c830 100644 --- a/src/lib/views/wiki/WikiRevisionHistoryView.php +++ b/src/lib/views/wiki/WikiRevisionHistoryView.php @@ -47,14 +47,18 @@ public function __construct(Collection $revisions, $pageName, $priority = 0) { parent::__construct($priority); - if ($revisions->type !== 'WikiHistory') { - throw new InvalidTypeException(1, 'Collection with type "WikiHistory"', $revisions); + if ($revisions->type !== 'Registry') { + throw new InvalidTypeException(1, 'Collection with type "Registry"', $revisions); } $this->revisions = $revisions; $this->pageName = $pageName; } + public function getMetaData() { + return ViewMetaData::generate()->addJavaScript($this->jsPath . '/wiki.js'); + } + /** * Renders the view * @@ -69,31 +73,37 @@ Date Message Author - Diff + Diff revisions as $revision => $history) { + foreach ($this->revisions as $revision => $revisionData) { $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 >= 0) ? '+' : '') . $affectedBytes; - $affectedBytes = '' . $affectedBytes . ' bytes'; + $affectedBytes = strlen($revisionData->wikitext) - strlen($previous->wikitext); + $percentage = round(100 * $affectedBytes / strlen($revisionData->wikitext), 2); + $prefix = ($affectedBytes === 0) ? '±' : (($affectedBytes > 0) ? '+' : ''); + $suffix = (abs($affectedBytes) === 1) ? ' byte' : ' bytes'; + $affectedBytes = $prefix . $affectedBytes . $suffix . ' (' . $prefix . $percentage . '%)'; + + $affectedBytes = '' . $affectedBytes . ''; } - $previous = $history; + $previous = $revisionData; ?> - revision; ?> - created; ?> - message; ?> - created_user_id; ?> + revision; ?> + created; ?> + message; ?> + user_name; ?> + + + + + +