diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-02-18 00:12:12 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-02-18 00:12:12 -0600 |
commit | 4875037269702e9e4195d01e2711b489c40ad0e9 (patch) | |
tree | 1f73708fa2b2cf8a6241ced5891749f846da8a67 | |
parent | 85de4ab2e5114c343cac8abd89a796d1bb48153a (diff) | |
download | narwhal-4875037269702e9e4195d01e2711b489c40ad0e9.tar.gz narwhal-4875037269702e9e4195d01e2711b489c40ad0e9.zip |
allow viewing page history
-rw-r--r-- | lib/Narwhal.pm | 7 | ||||
-rw-r--r-- | lib/Narwhal/Component/Wiki.pm | 37 | ||||
-rw-r--r-- | root/templates/history.tt | 16 | ||||
-rw-r--r-- | root/templates/page.tt | 5 |
4 files changed, 65 insertions, 0 deletions
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 @@ +<html> +<body> +<h1>[% page %]</h1> +<p><a href="[% uri_for('action', 'page', 'page_name', page) %]">View</a></p> +<ul> +[% SET cur = head %] +[% WHILE cur %] +<li><a href="[% uri_for('action', 'old_page', 'page_name', page, 'rev', cur.digest) %]">[% cur.author.id %] on [% cur.modification_date %]</a></li> +[% SET cur = cur.previous_revision %] +[% END %] +</ul> +<p style="font-size: small"> +Last modified by [% author.id %] on [% modified %] +</p> +</body> +</html> 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 @@ <html> <body> <h1>[% page %]</h1> +[% IF historical %] +<p>This is a historical view of this page</p> +[% ELSE %] <p><a href="[% uri_for('action', 'edit', 'page_name', page) %]">Edit</a></p> +[% END %] +<p><a href="[% uri_for('action', 'history', 'page_name', page) %]">History</a></p> <p> [% text %] </p> |