Commit c259ada6 authored by Eric Davis's avatar Eric Davis

Refactor: rename WikiController#index to #show, it's a single resource action

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4266 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent d3381fb5
......@@ -22,14 +22,14 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :show }
helper :attachments
include AttachmentsHelper
helper :watchers
# display a page (in editing mode if it doesn't exist)
def index
def show
page_title = params[:page]
@page = @wiki.find_or_new_page(page_title)
if @page.new_record?
......@@ -79,7 +79,7 @@ class WikiController < ApplicationController
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
# don't save if text wasn't changed
redirect_to :action => 'index', :project_id => @project, :page => @page.title
redirect_to :action => 'show', :project_id => @project, :page => @page.title
return
end
#@content.text = params[:content][:text]
......@@ -91,7 +91,7 @@ class WikiController < ApplicationController
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
redirect_to :action => 'index', :project_id => @project, :page => @page.title
redirect_to :action => 'show', :project_id => @project, :page => @page.title
end
end
rescue ActiveRecord::StaleObjectError
......@@ -107,13 +107,13 @@ class WikiController < ApplicationController
@original_title = @page.pretty_title
if request.post? && @page.update_attributes(params[:wiki_page])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index', :project_id => @project, :page => @page.title
redirect_to :action => 'show', :project_id => @project, :page => @page.title
end
end
def protect
@page.update_attribute :protected, params[:protected]
redirect_to :action => 'index', :project_id => @project, :page => @page.title
redirect_to :action => 'show', :project_id => @project, :page => @page.title
end
# show page history
......@@ -176,7 +176,7 @@ class WikiController < ApplicationController
export = render_to_string :action => 'export_multiple', :layout => false
send_data(export, :type => 'text/html', :filename => "wiki.html")
else
redirect_to :action => 'index', :project_id => @project, :page => nil
redirect_to :action => 'show', :project_id => @project, :page => nil
end
end
......@@ -204,7 +204,7 @@ class WikiController < ApplicationController
return render_403 unless editable?
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
redirect_to :action => 'index', :page => @page.title
redirect_to :action => 'show', :page => @page.title
end
private
......
......@@ -182,7 +182,7 @@ module ApplicationHelper
content << "<ul class=\"pages-hierarchy\">\n"
pages[node].each do |page|
content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :project_id => page.project, :page => page.title},
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :page => page.title},
:title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
content << "</li>\n"
......@@ -551,7 +551,7 @@ module ApplicationHelper
when :local; "#{title}.html"
when :anchor; "##{title}" # used for single-file wiki export
else
url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :project_id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
end
link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
else
......
......@@ -4,6 +4,6 @@
<h3><%= l(:label_wiki) %></h3>
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
<%= link_to l(:field_start_page), {:action => 'show', :page => nil} %><br />
<%= link_to l(:label_index_by_title), {:action => 'page_index'} %><br />
<%= link_to l(:label_index_by_date), {:action => 'date_index'} %><br />
......@@ -6,7 +6,7 @@
<h2><%= @page.pretty_title %></h2>
<p>
<%= l(:label_version) %> <%= link_to @annotate.content.version, :action => 'index', :page => @page.title, :version => @annotate.content.version %>
<%= l(:label_version) %> <%= link_to @annotate.content.version, :action => 'show', :page => @page.title, :version => @annotate.content.version %>
<em>(<%= @annotate.content.author ? @annotate.content.author.name : "anonyme" %>, <%= format_time(@annotate.content.updated_on) %>)</em>
</p>
......@@ -18,7 +18,7 @@
<% @annotate.lines.each do |line| -%>
<tr class="bloc-<%= colors[line[0]] %>">
<th class="line-num"><%= line_num %></th>
<td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title, :version => line[0] %></td>
<td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'show', :project_id => @project, :page => @page.title, :version => line[0] %></td>
<td class="author"><%= h(line[1]) %></td>
<td class="line-code"><pre><%=h line[2] %></pre></td>
</tr>
......
......@@ -12,7 +12,7 @@
<h3><%= format_date(date) %></h3>
<ul>
<% @pages_by_date[date].each do |page| %>
<li><%= link_to page.pretty_title, :action => 'index', :page => page.title %></li>
<li><%= link_to page.pretty_title, :action => 'show', :page => page.title %></li>
<% end %>
</ul>
<% end %>
......@@ -23,11 +23,11 @@
<% unless @pages.empty? %>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
<%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
<% end %>
<% end %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
<% end %>
......@@ -15,5 +15,5 @@
</div>
<%= submit_tag l(:button_apply) %>
<%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title %>
<%= link_to l(:button_cancel), :controller => 'wiki', :action => 'show', :project_id => @project, :page => @page.title %>
<% end %>
......@@ -5,10 +5,10 @@
<h2><%= @page.pretty_title %></h2>
<p>
<%= l(:label_version) %> <%= link_to @diff.content_from.version, :action => 'index', :page => @page.title, :version => @diff.content_from.version %>
<%= l(:label_version) %> <%= link_to @diff.content_from.version, :action => 'show', :page => @page.title, :version => @diff.content_from.version %>
<em>(<%= @diff.content_from.author ? @diff.content_from.author.name : "anonyme" %>, <%= format_time(@diff.content_from.updated_on) %>)</em>
&#8594;
<%= l(:label_version) %> <%= link_to @diff.content_to.version, :action => 'index', :page => @page.title, :version => @diff.content_to.version %>/<%= @page.content.version %>
<%= l(:label_version) %> <%= link_to @diff.content_to.version, :action => 'show', :page => @page.title, :version => @diff.content_to.version %>/<%= @page.content.version %>
<em>(<%= @diff.content_to.author ? @diff.content_to.author.name : "anonyme" %>, <%= format_time(@diff.content_to.updated_on) %>)</em>
</p>
......
......@@ -19,7 +19,7 @@
<% line_num = 1 %>
<% @versions.each do |ver| %>
<tr class="<%= cycle("odd", "even") %>">
<td class="id"><%= link_to ver.version, :action => 'index', :page => @page.title, :version => ver.version %></td>
<td class="id"><%= link_to ver.version, :action => 'show', :page => @page.title, :version => ver.version %></td>
<td class="checkbox"><%= radio_button_tag('version', ver.version, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < @versions.size) %></td>
<td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}") if show_diff && (line_num > 1) %></td>
<td align="center"><%= format_time(ver.updated_on) %></td>
......
......@@ -16,11 +16,11 @@
<% unless @pages.empty? %>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
<%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
<% end %>
<% end %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
<%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
<% end %>
......@@ -15,11 +15,11 @@
<% if @content.version != @page.content.version %>
<p>
<%= link_to(('&#171; ' + l(:label_previous)), :action => 'index', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
<%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
<%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
<%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :page => @page.title, :version => @content.version) + ')' if @content.version > 1 %> -
<%= link_to((l(:label_next) + ' &#187;'), :action => 'index', :page => @page.title, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
<%= link_to(l(:label_current_version), :action => 'index', :page => @page.title) %>
<%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :page => @page.title, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
<%= link_to(l(:label_current_version), :action => 'show', :page => @page.title) %>
<br />
<em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
<%=h @content.comments %>
......
......@@ -32,7 +32,7 @@ ActionController::Routing::Routes.draw do |map|
wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
wiki_views.connect 'projects/:project_id/wiki/page_index', :action => 'page_index'
wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'index', :page => nil
wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'show', :page => nil
wiki_views.connect 'projects/:project_id/wiki/:page/edit', :action => 'edit'
wiki_views.connect 'projects/:project_id/wiki/:page/rename', :action => 'rename'
wiki_views.connect 'projects/:project_id/wiki/:page/history', :action => 'history'
......
......@@ -111,7 +111,7 @@ Redmine::AccessControl.map do |map|
map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
map.permission :view_wiki_pages, :wiki => [:index, :special, :page_index, :date_index]
map.permission :view_wiki_pages, :wiki => [:show, :special, :page_index, :date_index]
map.permission :export_wiki_pages, :wiki => [:export]
map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment]
......@@ -195,7 +195,7 @@ Redmine::MenuManager.map :project_menu do |menu|
menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :param => :project_id,
menu.push :wiki, { :controller => 'wiki', :action => 'show', :page => nil }, :param => :project_id,
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
......
......@@ -32,7 +32,7 @@ class WikiControllerTest < ActionController::TestCase
end
def test_show_start_page
get :index, :project_id => 'ecookbook'
get :show, :project_id => 'ecookbook'
assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /CookBook documentation/
......@@ -45,7 +45,7 @@ class WikiControllerTest < ActionController::TestCase
end
def test_show_page_with_name
get :index, :project_id => 1, :page => 'Another_page'
get :show, :project_id => 1, :page => 'Another_page'
assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /Another page/
......@@ -60,20 +60,20 @@ class WikiControllerTest < ActionController::TestCase
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
page.save!
get :index, :project_id => 1, :page => 'Another_page'
get :show, :project_id => 1, :page => 'Another_page'
assert_response :success
assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
:content => /Side bar content for test_show_with_sidebar/
end
def test_show_unexistent_page_without_edit_right
get :index, :project_id => 1, :page => 'Unexistent page'
get :show, :project_id => 1, :page => 'Unexistent page'
assert_response 404
end
def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2
get :index, :project_id => 1, :page => 'Unexistent page'
get :show, :project_id => 1, :page => 'Unexistent page'
assert_response :success
assert_template 'edit'
end
......@@ -85,7 +85,7 @@ class WikiControllerTest < ActionController::TestCase
:content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page",
:version => 0}
assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'New_page'
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'New_page'
page = Project.find(1).wiki.find_page('New page')
assert !page.new_record?
assert_not_nil page.content
......@@ -176,7 +176,7 @@ class WikiControllerTest < ActionController::TestCase
post :rename, :project_id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => 1 }
assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
wiki = Project.find(1).wiki
# Check redirects
assert_not_nil wiki.find_page('Another page')
......@@ -188,7 +188,7 @@ class WikiControllerTest < ActionController::TestCase
post :rename, :project_id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => "0" }
assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
wiki = Project.find(1).wiki
# Check that there's no redirects
assert_nil wiki.find_page('Another page')
......@@ -280,7 +280,7 @@ class WikiControllerTest < ActionController::TestCase
get :export, :project_id => 'ecookbook'
should_respond_with :redirect
should_redirect_to('wiki index') { {:action => 'index', :project_id => @project, :page => nil} }
should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :page => nil} }
end
end
end
......@@ -298,7 +298,7 @@ class WikiControllerTest < ActionController::TestCase
end
def test_not_found
get :index, :project_id => 999
get :show, :project_id => 999
assert_response 404
end
......@@ -307,7 +307,7 @@ class WikiControllerTest < ActionController::TestCase
assert !page.protected?
@request.session[:user_id] = 2
post :protect, :project_id => 1, :page => page.title, :protected => '1'
assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_page'
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_page'
assert page.reload.protected?
end
......@@ -316,13 +316,13 @@ class WikiControllerTest < ActionController::TestCase
assert page.protected?
@request.session[:user_id] = 2
post :protect, :project_id => 1, :page => page.title, :protected => '0'
assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'CookBook_documentation'
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'CookBook_documentation'
assert !page.reload.protected?
end
def test_show_page_with_edit_link
@request.session[:user_id] = 2
get :index, :project_id => 1
get :show, :project_id => 1
assert_response :success
assert_template 'show'
assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
......@@ -330,7 +330,7 @@ class WikiControllerTest < ActionController::TestCase
def test_show_page_without_edit_link
@request.session[:user_id] = 4
get :index, :project_id => 1
get :show, :project_id => 1
assert_response :success
assert_template 'show'
assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
......
......@@ -311,8 +311,8 @@ class RoutingTest < ActionController::IntegrationTest
end
context "wiki (singular, project's pages)" do
should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :project_id => '567'
should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :project_id => '567', :page => 'lalala'
should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'show', :project_id => '567'
should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'show', :project_id => '567', :page => 'lalala'
should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :project_id => '1', :page => 'CookBook_documentation'
should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :project_id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment