From 69bfc1028b035e76ee207f229587dd473dc9e56d Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Tue, 31 Mar 2009 15:54:41 -0500 Subject: [PATCH] Cache Revisions Fix config/routes.rb to make revisions cacheable. Cache revisions. Modify the history page so that it links to the current page (and diff). --- app/controllers/wiki_controller.rb | 2 +- app/helpers/application_helper.rb | 7 ++++++- app/views/wiki/history.html.erb | 5 ++++- config/routes.rb | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 5cda325e..c2bfad42 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -9,7 +9,7 @@ class WikiController < ApplicationController before_filter :load_page before_filter :dnsbl_check, :only => [:edit, :new, :save, :export_html, :export_markup] caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, :file_list, - :history, :atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) } + :history, :revision, :atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) } cache_sweeper :revision_sweeper layout 'default', :except => [:atom_with_content, :atom_with_headlines, :atom, :tex, :s5, :export_html] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6d09c910..f6662834 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -54,7 +54,12 @@ module ApplicationHelper # 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( + revision_number == page.revisions.length ? + link_to( + text || page.plain_name, + {:web => @web.address, :action => 'show', :id => page.name, + :mode => mode}, 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) diff --git a/app/views/wiki/history.html.erb b/app/views/wiki/history.html.erb index 4b24be38..94b3e9b2 100644 --- a/app/views/wiki/history.html.erb +++ b/app/views/wiki/history.html.erb @@ -7,7 +7,10 @@ <%- for rev in @revisions_by_day[day] -%>
  • <%= link_to_revision(rev.page, @revision_numbers[rev.id], - text="Revision #{@revision_numbers[rev.id]}") %> + text= (rev.page.revisions.length == @revision_numbers[rev.id] ? + "Current" : + "Revision #{@revision_numbers[rev.id]}" ) + ) %> <%- if @revision_numbers[rev.id] > 1 -%> (<%= link_to_revision(rev.page, @revision_numbers[rev.id], text="diff", mode='diff') %>) diff --git a/config/routes.rb b/config/routes.rb index d98f88d2..7d19313c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,7 +26,8 @@ ActionController::Routing::Routes.draw do |map| connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login' connect_to_web map, ':web/web_list', :controller => 'wiki', :action => 'web_list' connect_to_web map, ':web/show/diff/:id', :controller => 'wiki', :action => 'show', :mode => 'diff' - connect_to_web map, ':web/revision/diff/:id', :controller => 'wiki', :action => 'revision', :mode => 'diff' + connect_to_web map, ':web/revision/diff/:id/:rev', :controller => 'wiki', :action => 'revision', :mode => 'diff', :requirements => { :rev => /\d*/} + connect_to_web map, ':web/revision/:id/:rev', :controller => 'wiki', :action => 'revision', :requirements => { :rev => /\d*/} connect_to_web map, ':web/list/:category', :controller => 'wiki', :action => 'list', :requirements => { :category => /.*/}, :category => nil connect_to_web map, ':web/recently_revised/:category', :controller => 'wiki', :action => 'recently_revised', :requirements => { :category => /.*/}, :category => nil connect_to_web map, ':web/:action/:id', :controller => 'wiki'