From 4875037269702e9e4195d01e2711b489c40ad0e9 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 18 Feb 2011 00:12:12 -0600 Subject: allow viewing page history --- lib/Narwhal.pm | 7 +++++++ lib/Narwhal/Component/Wiki.pm | 37 +++++++++++++++++++++++++++++++++++++ root/templates/history.tt | 16 ++++++++++++++++ root/templates/page.tt | 5 +++++ 4 files changed, 65 insertions(+) create mode 100644 root/templates/history.tt diff --git a/lib/Narwhal.pm b/lib/Narwhal.pm index 4437027..9c0f099 100644 --- a/lib/Narwhal.pm +++ b/lib/Narwhal.pm @@ -42,6 +42,13 @@ router as { route '/edit/:page_name' => 'http-method:edit', ( page_name => { isa => 'Str' }, ); + route '/page/:page_name/:rev' => 'wiki.old_page', ( + page_name => { isa => 'Str' }, + rev => { isa => qr/^[0-9a-f]{40}$/ }, + ); + route '/history/:page_name' => 'wiki.history', ( + page_name => { isa => 'Str' }, + ); }, ( redirect => depends_on('/Component/Redirect'), wiki => depends_on('/Component/Wiki'), diff --git a/lib/Narwhal/Component/Wiki.pm b/lib/Narwhal/Component/Wiki.pm index 1139301..e3eb254 100644 --- a/lib/Narwhal/Component/Wiki.pm +++ b/lib/Narwhal/Component/Wiki.pm @@ -31,6 +31,43 @@ sub page { ); } +sub old_page { + my $self = shift; + my ($req, $page_name, $rev) = @_; + + my $page_rev = $self->lookup($rev); + return $req->new_response(404) + unless $page_rev; + + $self->render( + $req, + 'page.tt', + { + page => $page_name, + text => $page_rev->text, + author => $page_rev->author, + modified => $page_rev->modification_date, + historical => 1, + }, + ); +} + +sub history { + my $self = shift; + my ($req, $page_name) = @_; + + my $page = $self->lookup("page:$page_name"); + + $self->render( + $req, + 'history.tt', + { + page => $page_name, + head => $page->current_revision, + } + ); +} + __PACKAGE__->meta->make_immutable; no Moose; diff --git a/root/templates/history.tt b/root/templates/history.tt new file mode 100644 index 0000000..a50839b --- /dev/null +++ b/root/templates/history.tt @@ -0,0 +1,16 @@ + + +

[% page %]

+

View

+ +

+Last modified by [% author.id %] on [% modified %] +

+ + diff --git a/root/templates/page.tt b/root/templates/page.tt index 6e9ec31..754d4b7 100644 --- a/root/templates/page.tt +++ b/root/templates/page.tt @@ -1,7 +1,12 @@

[% page %]

+[% IF historical %] +

This is a historical view of this page

+[% ELSE %]

Edit

+[% END %] +

History

[% text %]

-- cgit v1.2.3