diff --git a/plugins/wiki/app/controllers/pages_controller.rb b/plugins/wiki/app/controllers/pages_controller.rb index 4abbd2655..eeea1bca5 100644 --- a/plugins/wiki/app/controllers/pages_controller.rb +++ b/plugins/wiki/app/controllers/pages_controller.rb @@ -130,6 +130,13 @@ def all end end + def diff + @page = Page.find(params[:id]) + @old_version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:old] + @new_version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:new] + @diff = Diffy::Diff.new(@old_version.body, @new_version.body).to_s(:html) + end + def version @page = Page.find(params[:id]) @version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:version] diff --git a/plugins/wiki/app/views/pages/diff.html.haml b/plugins/wiki/app/views/pages/diff.html.haml new file mode 100644 index 000000000..047aa08a1 --- /dev/null +++ b/plugins/wiki/app/views/pages/diff.html.haml @@ -0,0 +1,7 @@ +- title t('.title', title: @page.title, old: @old_version.lock_version, new: @new_version.lock_version) + +%style= Diffy::CSS += raw @diff + +%hr += link_to t('ui.back'), 'javascript:history.go(-1)', class: 'btn btn-primary' diff --git a/plugins/wiki/app/views/pages/show.html.haml b/plugins/wiki/app/views/pages/show.html.haml index 440488a5d..f73dcc2ce 100644 --- a/plugins/wiki/app/views/pages/show.html.haml +++ b/plugins/wiki/app/views/pages/show.html.haml @@ -12,12 +12,16 @@ %li= link_to t('.subpages'), "#subpages", 'data-toggle-this' => '#subpages' #versions.well.well-small{:style => "display:none"} - %h3= t '.title_versions' - %ul.unstyled - - @page.versions.reverse.each do |version| - %li - = link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version) - = "(#{show_user(User.find_by_id(version.updated_by))})" + = form_tag diff_page_path(@page), :method => :get do + %h3= t '.title_versions' + %ul.unstyled + - @page.versions.reverse.each_with_index do |version, index| + %li + = radio_button_tag :old, version.lock_version, index == 1 + = radio_button_tag :new, version.lock_version, index == 0 + = link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version) + = "(#{show_user(User.find_by_id(version.updated_by))})" + = submit_tag t('.diff'), class: 'btn' - unless @page.children.empty? #subpages.well.well-small{:style => "display:none"} diff --git a/plugins/wiki/config/locales/de.yml b/plugins/wiki/config/locales/de.yml new file mode 100644 index 000000000..d7455b097 --- /dev/null +++ b/plugins/wiki/config/locales/de.yml @@ -0,0 +1,6 @@ +de: + pages: + diff: + title: "%{title} - Ă„nderung von Version %{old} auf %{new}" + show: + diff: Versionen vergleichen diff --git a/plugins/wiki/config/locales/en.yml b/plugins/wiki/config/locales/en.yml index c41d67591..a930c08cb 100644 --- a/plugins/wiki/config/locales/en.yml +++ b/plugins/wiki/config/locales/en.yml @@ -32,6 +32,8 @@ en: redirect_notice: Redirected from %{page} ... destroy: notice: The page '%{page}' and all subpages have been deleted successfully. + diff: + title: "%{title} - changes from version %{old} to %{new}" edit: title: Edit page error_stale_object: Warning, the page has just been edited by someone else. Please try again. @@ -68,6 +70,7 @@ en: date_format: ! '%d-%m-%y %H:%M' delete: Delete page delete_confirm: ! 'Warning: all subpages will be deleted as well. Are you sure?' + diff: Compare versions edit: Edit page last_updated: Last updated by %{user} on %{when} subpages: subpages diff --git a/plugins/wiki/config/routes.rb b/plugins/wiki/config/routes.rb index 5eb866e8d..d579cd158 100644 --- a/plugins/wiki/config/routes.rb +++ b/plugins/wiki/config/routes.rb @@ -6,6 +6,7 @@ get :all, :on => :collection get :version, :on => :member get :revert, :on => :member + get :diff, :on => :member end get '/wiki/:permalink' => 'pages#show', :as => 'wiki_page' # , :constraints => {:permalink => /[^\s]+/} get '/wiki' => 'pages#show', :defaults => {:permalink => 'Home'}, :as => 'wiki'