From d5a65e6ac8ba30a56ffea10e83d696d942e353d4 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 30 Mar 2009 23:50:06 -0500 Subject: [PATCH] History Pages From Jason Blevins: Create a "History" page for each wiki page. Link to it, and to the "Diff" page from "Recently Revised". Also, correct a bug in listing/deleting links to uploaded video and audio files. --- app/controllers/wiki_controller.rb | 21 +++++++++++++++++++++ app/helpers/application_helper.rb | 16 ++++++++++++++++ app/helpers/wiki_helper.rb | 7 +++++++ app/views/wiki/history.html.erb | 23 +++++++++++++++++++++++ app/views/wiki/recently_revised.rhtml | 5 +++++ lib/page_renderer.rb | 4 ++-- 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 app/views/wiki/history.html.erb diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 5df3ee56..1f59a00e 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -314,6 +314,27 @@ class WikiController < ApplicationController end end + def history + if @page + @revisions_by_day = Hash.new { |h, day| h[day] = [] } + @revision_numbers = Hash.new { |h, id| h[id] = [] } + revision_number = @page.revisions.length + @page.revisions.reverse.each do |rev| + day = Date.new(rev.revised_at.year, rev.revised_at.month, rev.revised_at.day) + @revisions_by_day[day] << rev + @revision_numbers[rev.id] = revision_number + revision_number = revision_number - 1 + end + render :action => 'history' + else + if not @page_name.nil? and @page_name.is_utf8? and not @page_name.empty? + redirect_to :web => @web_name, :action => 'new', :id => @page_name + else + render :text => 'Page name is not specified', :status => 404, :layout => 'error' + end + end + end + def tex if @web.markup == :markdownMML or @web.markup == :markdownPNG or @web.markup == :markdown @tex_content = Maruku.new(@page.content).to_latex diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9553504e..6d09c910 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -52,6 +52,22 @@ module ApplicationHelper UrlGenerator.new(@controller).make_link(page.author.name, page.web, nil, options) end + # Create a hyperlink to a particular revision of a Wiki page + def link_to_revision(page, revision_number, text = nil, mode = nil, html_options = {}) + link_to( + text || page.plain_name + "(rev # #{revision_number})", + {:web => @web.address, :action => 'revision', :id => page.name, + :rev => revision_number, :mode => mode}, html_options) + end + + # Create a hyperlink to the history of a particular Wiki page + def link_to_history(page, text = nil, html_options = {}) + link_to( + text || page.plain_name + "(history)", + {:web => @web.address, :action => 'history', :id => page.name}, + html_options) + end + def base_url home_page_url = url_for :controller => 'admin', :action => 'create_system', :only_path => true home_page_url.sub(%r-/create_system/?$-, '') diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 07d614a8..eeb103f2 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -6,6 +6,7 @@ module WikiHelper menu << back_for_revision if @revision_number > 1 menu << current_revision menu << see_or_hide_changes_for_revision if @revision_number > 1 + menu << history if @page.revisions.length > 1 menu << rollback menu end @@ -18,6 +19,7 @@ module WikiHelper menu << back_for_page menu << see_or_hide_changes_for_page end + menu << history if @page.revisions.length > 1 menu end @@ -31,6 +33,11 @@ module WikiHelper link_to('Edit Web', {:web => @web.address, :action => 'edit_web'}, {:class => 'navlink', :accesskey => 'W', :id => 'edit_web', :rel => 'nofollow'}) end + + def history + link_to_history(@page, 'History', + {:class => 'navlink', :accesskey => 'S', :id => 'history', :rel => 'nofollow'}) + end def forward if @revision_number < @page.revisions.length - 1 diff --git a/app/views/wiki/history.html.erb b/app/views/wiki/history.html.erb new file mode 100644 index 00000000..4b24be38 --- /dev/null +++ b/app/views/wiki/history.html.erb @@ -0,0 +1,23 @@ +<%- @title = @page.plain_name + " (history)" -%> +<%- @show_footer = true -%> + +<%- @revisions_by_day.keys.sort.reverse.each do |day| -%> +

<%= format_date(day, include_time = false) %>

+ +<%- end -%> diff --git a/app/views/wiki/recently_revised.rhtml b/app/views/wiki/recently_revised.rhtml index dd633915..22dc9f64 100644 --- a/app/views/wiki/recently_revised.rhtml +++ b/app/views/wiki/recently_revised.rhtml @@ -8,6 +8,11 @@ <%- for page in @pages_by_day[day] -%>
  • <%= link_to_existing_page page %> + <%- if page.revisions.length > 1 %> + (<%= link_to_revision(page, page.revisions.length, text='diff', + mode='diff') %>) + (<%= link_to_history(page, text='history') %>) + <%- end -%>