Feature #2028 » patch_for_feature_2028_v2.diff
test/unit/wiki_page_test.rb (cópia de trabalho) | ||
---|---|---|
53 | 53 |
assert_nil page.parent_title |
54 | 54 |
|
55 | 55 |
page = WikiPage.find_by_title('Page_with_an_inline_image') |
56 |
assert_equal 'CookBook documentation', page.parent_title
|
|
56 |
assert_equal 'CookBook_documentation', page.parent_title
|
|
57 | 57 |
end |
58 | ||
59 |
def test_parent_pretty_title |
|
60 |
page = WikiPage.find_by_title('Another_page') |
|
61 |
assert_nil page.parent_title |
|
62 |
|
|
63 |
page = WikiPage.find_by_title('Page_with_an_inline_image') |
|
64 |
assert_equal 'CookBook documentation', page.parent_pretty_title |
|
65 |
end |
|
58 | 66 |
|
59 | 67 |
def test_assign_parent |
60 | 68 |
page = WikiPage.find_by_title('Another_page') |
app/helpers/application_helper.rb (cópia de trabalho) | ||
---|---|---|
197 | 197 |
|
198 | 198 |
def breadcrumb(*args) |
199 | 199 |
elements = args.flatten |
200 |
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil |
|
200 |
last_element = elements.pop |
|
201 |
last_element.nil? ? nil : content_tag('p', elements.join(' » ') + ' » ' + last_element, :class => 'breadcrumb') |
|
201 | 202 |
end |
202 | 203 |
|
203 | 204 |
def html_title(*args) |
... | ... | |
260 | 261 |
text = (Setting.text_formatting == 'textile') ? |
261 | 262 |
Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : |
262 | 263 |
simple_format(auto_link(h(text))) |
263 | ||
264 | 264 |
# different methods for formatting wiki links |
265 | 265 |
case options[:wiki_links] |
266 | 266 |
when :local |
... | ... | |
270 | 270 |
# used for single-file wiki export |
271 | 271 |
format_wiki_link = Proc.new {|project, title, anchor| "##{title}" } |
272 | 272 |
else |
273 |
format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
|
|
273 |
format_wiki_link = Proc.new {|project, title, anchor, parent| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor, :parent => parent && parent.title) }
|
|
274 | 274 |
end |
275 | 275 |
|
276 | 276 |
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
... | ... | |
303 | 303 |
end |
304 | 304 |
# check if page exists |
305 | 305 |
wiki_page = link_project.wiki.find_page(page) |
306 |
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), |
|
306 |
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor, obj && obj.page),
|
|
307 | 307 |
:class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
308 | 308 |
else |
309 | 309 |
# project or wiki doesn't exist |
app/models/wiki_page.rb (cópia de trabalho) | ||
---|---|---|
113 | 113 |
end |
114 | 114 |
|
115 | 115 |
def parent_title |
116 |
@parent_title || (self.parent && self.parent.pretty_title)
|
|
116 |
@parent_title || (self.parent && self.parent.title) |
|
117 | 117 |
end |
118 | 118 |
|
119 | 119 |
def parent_title=(t) |
120 |
return self.parent if (self.parent && (self.parent.title == t)) |
|
120 | 121 |
@parent_title = t |
121 | 122 |
parent_page = t.blank? ? nil : self.wiki.find_page(t) |
122 | 123 |
self.parent = parent_page |
123 | 124 |
end |
125 | ||
126 |
def parent_pretty_title |
|
127 |
@parent_pretty_title || (self.parent && self.parent.pretty_title) |
|
128 |
end |
|
124 | 129 |
|
125 | 130 |
protected |
126 | 131 |
|
app/controllers/wiki_controller.rb (cópia de trabalho) | ||
---|---|---|
52 | 52 |
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
53 | 53 |
return |
54 | 54 |
end |
55 |
@editable = editable?
|
|
55 |
@editable = editable?
|
|
56 | 56 |
render :action => 'show' |
57 | 57 |
end |
58 | 58 |
|
59 | 59 |
# edit an existing page or a new one |
60 | 60 |
def edit |
61 |
@page = @wiki.find_or_new_page(params[:page]) |
|
61 |
@page = @wiki.find_or_new_page(params[:page]) |
|
62 |
@page.parent_title = params[:parent] if params[:parent] |
|
62 | 63 |
return render_403 unless editable? |
64 | ||
63 | 65 |
@page.content = WikiContent.new(:page => @page) if @page.new_record? |
64 | 66 |
|
65 | 67 |
@content = @page.content_for_version(params[:version]) |
... | ... | |
70 | 72 |
# To prevent StaleObjectError exception when reverting to a previous version |
71 | 73 |
@content.version = @page.content.version |
72 | 74 |
else |
73 |
if !@page.new_record? && @content.text == params[:content][:text] |
|
74 |
# don't save if text wasn't changed |
|
75 |
redirect_to :action => 'index', :id => @project, :page => @page.title |
|
76 |
return |
|
77 |
end |
|
78 |
#@content.text = params[:content][:text] |
|
79 |
#@content.comments = params[:content][:comments] |
|
80 | 75 |
@content.attributes = params[:content] |
81 | 76 |
@content.author = User.current |
82 |
# if page is new @page.save will also save content, but not if page isn't a new record |
|
83 |
if (@page.new_record? ? @page.save : @content.save) |
|
84 |
redirect_to :action => 'index', :id => @project, :page => @page.title |
|
85 |
end |
|
77 |
@page.save if @page.changed? |
|
78 |
@content.save if @content.changed? |
|
79 |
redirect_to :action => 'index', :id => @project, :page => @page.title |
|
86 | 80 |
end |
87 | 81 |
rescue ActiveRecord::StaleObjectError |
88 | 82 |
# Optimistic locking exception |
app/views/wiki/show.rhtml (cópia de trabalho) | ||
---|---|---|
10 | 10 |
<%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> |
11 | 11 |
</div> |
12 | 12 | |
13 |
<%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %> |
|
13 |
<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
|
|
14 | 14 | |
15 | 15 |
<% if @content.version != @page.content.version %> |
16 | 16 |
<p> |
app/views/wiki/edit.rhtml (cópia de trabalho) | ||
---|---|---|
1 |
<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %> |
|
2 | ||
1 | 3 |
<h2><%= @page.pretty_title %></h2> |
2 | 4 | |
3 | 5 |
<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> |
... | ... | |
6 | 8 | |
7 | 9 |
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p> |
8 | 10 |
<p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p> |
11 |
<p><label><%= l(:field_parent_title) %></label><br /><%= select_tag 'parent', options_for_select(@wiki.pages.collect{|page| [page.pretty_title,page.title]}, @page.parent_title) %></p> |
|
9 | 12 |
<p><%= submit_tag l(:button_save) %> |
10 | 13 |
<%= link_to_remote l(:label_preview), |
11 | 14 |
{ :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, |
app/views/wiki/rename.rhtml (cópia de trabalho) | ||
---|---|---|
6 | 6 |
<div class="box"> |
7 | 7 |
<p><%= f.text_field :title, :required => true, :size => 100 %></p> |
8 | 8 |
<p><%= f.check_box :redirect_existing_links %></p> |
9 |
<p><%= f.text_field :parent_title, :size => 100 %></p>
|
|
9 |
<p><%= f.select :parent_title, @wiki.pages.collect{|page| [page.pretty_title,page.title]} %></p>
|
|
10 | 10 |
</div> |
11 | 11 |
<%= submit_tag l(:button_rename) %> |
12 | 12 |
<% end %> |
- « Previous
- 1
- 2
- Next »