From f3a1b4e38c25fd34ef19d9b04567d327c34f6713 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 5 Apr 2007 14:45:44 +0000 Subject: [PATCH] Added the ability to easily rollback to a previous version of a wiki page. git-svn-id: http://redmine.rubyforge.org/svn/trunk@424 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 5 +++-- app/models/wiki_page.rb | 6 ++++++ app/views/wiki/show.rhtml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fr.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/zh.yml | 1 + 10 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 552565668..5931a93ad 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -27,7 +27,7 @@ class WikiController < ApplicationController edit render :action => 'edit' and return end - @content = (params[:version] ? @page.content.versions.find_by_version(params[:version]) : @page.content) + @content = @page.content_for_version(params[:version]) if params[:export] == 'html' export = render_to_string :action => 'export', :layout => false send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") @@ -43,7 +43,8 @@ class WikiController < ApplicationController def edit @page = @wiki.find_or_new_page(params[:page]) @page.content = WikiContent.new(:page => @page) if @page.new_record? - @content = @page.content + + @content = @page.content_for_version(params[:version]) @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? # don't keep previous comment @content.comment = nil diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 19961cb0b..f2ea8fd59 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -32,6 +32,12 @@ class WikiPage < ActiveRecord::Base WikiPage.pretty_title(title) end + def content_for_version(version=nil) + result = content.versions.find_by_version(version.to_i) if version + result ||= content + result + end + def self.pretty_title(str) (str && str.is_a?(String)) ? str.tr('_', ' ') : str end diff --git a/app/views/wiki/show.rhtml b/app/views/wiki/show.rhtml index 2e8ee4089..e4e1bc38d 100644 --- a/app/views/wiki/show.rhtml +++ b/app/views/wiki/show.rhtml @@ -1,5 +1,6 @@
<%= link_to(l(:button_edit), {:action => 'edit', :page => @page.title}, :class => 'icon icon-edit') if @content.version == @page.content.version %> +<%= link_to(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> <%= link_to(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> <%= link_to(l(:label_page_index), {:action => 'special', :page => 'Page_index'}, :class => 'icon icon-index') %>
diff --git a/lang/de.yml b/lang/de.yml index c08b4af40..c8d0aedd2 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -380,6 +380,7 @@ button_cancel: Abbrechen button_activate: Aktivieren button_sort: Sortieren button_log_time: Log time +button_rollback: Rollback to this version status_active: aktiv status_registered: angemeldet diff --git a/lang/en.yml b/lang/en.yml index 4ce8bcb27..8c56811b3 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -380,6 +380,7 @@ button_cancel: Cancel button_activate: Activate button_sort: Sort button_log_time: Log time +button_rollback: Rollback to this version status_active: active status_registered: registered diff --git a/lang/es.yml b/lang/es.yml index a2014845e..8272cfea2 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -380,6 +380,7 @@ button_cancel: Cancelar button_activate: Activar button_sort: Clasificar button_log_time: Log time +button_rollback: Rollback to this version status_active: active status_registered: registered diff --git a/lang/fr.yml b/lang/fr.yml index 8b52ac5de..b3efeebb1 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -380,6 +380,7 @@ button_cancel: Annuler button_activate: Activer button_sort: Trier button_log_time: Saisir temps +button_rollback: Revenir à cette version status_active: actif status_registered: enregistré diff --git a/lang/it.yml b/lang/it.yml index daaed6b79..0900a2a7a 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -380,6 +380,7 @@ button_cancel: Annulla button_activate: Attiva button_sort: Ordina button_log_time: Log time +button_rollback: Rollback to this version status_active: active status_registered: registered diff --git a/lang/ja.yml b/lang/ja.yml index bbeb6d453..babb212e0 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -381,6 +381,7 @@ button_cancel: キャンセル button_activate: 有効にする button_sort: ソート button_log_time: 時間を記録 +button_rollback: Rollback to this version status_active: 有効 status_registered: 登録 diff --git a/lang/zh.yml b/lang/zh.yml index 6301b8235..42d69759d 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -383,6 +383,7 @@ button_cancel: 取消 button_activate: 激活 button_sort: 排序 button_log_time: 登记工时 +button_rollback: Rollback to this version status_active: 激活 status_registered: 已注册 -- 2.39.5