Feature #2028 » patch_for_feature_2028_v2.diff
| test/unit/wiki_page_test.rb (cópia de trabalho) | ||
|---|---|---|
|
assert_nil page.parent_title
|
||
|
|
||
|
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||
|
assert_equal 'CookBook documentation', page.parent_title
|
||
|
assert_equal 'CookBook_documentation', page.parent_title
|
||
|
end
|
||
|
def test_parent_pretty_title
|
||
|
page = WikiPage.find_by_title('Another_page')
|
||
|
assert_nil page.parent_title
|
||
|
|
||
|
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||
|
assert_equal 'CookBook documentation', page.parent_pretty_title
|
||
|
end
|
||
|
|
||
|
def test_assign_parent
|
||
|
page = WikiPage.find_by_title('Another_page')
|
||
| app/helpers/application_helper.rb (cópia de trabalho) | ||
|---|---|---|
|
|
||
|
def breadcrumb(*args)
|
||
|
elements = args.flatten
|
||
|
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
||
|
last_element = elements.pop
|
||
|
last_element.nil? ? nil : content_tag('p', elements.join(' » ') + ' » ' + last_element, :class => 'breadcrumb')
|
||
|
end
|
||
|
|
||
|
def html_title(*args)
|
||
| ... | ... | |
|
text = (Setting.text_formatting == 'textile') ?
|
||
|
Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
|
||
|
simple_format(auto_link(h(text)))
|
||
|
# different methods for formatting wiki links
|
||
|
case options[:wiki_links]
|
||
|
when :local
|
||
| ... | ... | |
|
# used for single-file wiki export
|
||
|
format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
|
||
|
else
|
||
|
format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
|
||
|
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) }
|
||
|
end
|
||
|
|
||
|
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
||
| ... | ... | |
|
end
|
||
|
# check if page exists
|
||
|
wiki_page = link_project.wiki.find_page(page)
|
||
|
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
|
||
|
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor, obj && obj.page),
|
||
|
:class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||
|
else
|
||
|
# project or wiki doesn't exist
|
||
| app/models/wiki_page.rb (cópia de trabalho) | ||
|---|---|---|
|
end
|
||
|
|
||
|
def parent_title
|
||
|
@parent_title || (self.parent && self.parent.pretty_title)
|
||
|
@parent_title || (self.parent && self.parent.title)
|
||
|
end
|
||
|
|
||
|
def parent_title=(t)
|
||
|
return self.parent if (self.parent && (self.parent.title == t))
|
||
|
@parent_title = t
|
||
|
parent_page = t.blank? ? nil : self.wiki.find_page(t)
|
||
|
self.parent = parent_page
|
||
|
end
|
||
|
def parent_pretty_title
|
||
|
@parent_pretty_title || (self.parent && self.parent.pretty_title)
|
||
|
end
|
||
|
|
||
|
protected
|
||
|
|
||
| app/controllers/wiki_controller.rb (cópia de trabalho) | ||
|---|---|---|
|
send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
|
||
|
return
|
||
|
end
|
||
|
@editable = editable?
|
||
|
@editable = editable?
|
||
|
render :action => 'show'
|
||
|
end
|
||
|
|
||
|
# edit an existing page or a new one
|
||
|
def edit
|
||
|
@page = @wiki.find_or_new_page(params[:page])
|
||
|
@page = @wiki.find_or_new_page(params[:page])
|
||
|
@page.parent_title = params[:parent] if params[:parent]
|
||
|
return render_403 unless editable?
|
||
|
@page.content = WikiContent.new(:page => @page) if @page.new_record?
|
||
|
|
||
|
@content = @page.content_for_version(params[:version])
|
||
| ... | ... | |
|
# To prevent StaleObjectError exception when reverting to a previous version
|
||
|
@content.version = @page.content.version
|
||
|
else
|
||
|
if !@page.new_record? && @content.text == params[:content][:text]
|
||
|
# don't save if text wasn't changed
|
||
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||
|
return
|
||
|
end
|
||
|
#@content.text = params[:content][:text]
|
||
|
#@content.comments = params[:content][:comments]
|
||
|
@content.attributes = params[:content]
|
||
|
@content.author = User.current
|
||
|
# if page is new @page.save will also save content, but not if page isn't a new record
|
||
|
if (@page.new_record? ? @page.save : @content.save)
|
||
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||
|
end
|
||
|
@page.save if @page.changed?
|
||
|
@content.save if @content.changed?
|
||
|
redirect_to :action => 'index', :id => @project, :page => @page.title
|
||
|
end
|
||
|
rescue ActiveRecord::StaleObjectError
|
||
|
# Optimistic locking exception
|
||
| app/views/wiki/show.rhtml (cópia de trabalho) | ||
|---|---|---|
|
<%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %>
|
||
|
</div>
|
||
|
<%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
|
||
|
<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
|
||
|
<% if @content.version != @page.content.version %>
|
||
|
<p>
|
||
| app/views/wiki/edit.rhtml (cópia de trabalho) | ||
|---|---|---|
|
<%= breadcrumb(@page.ancestors.reverse.push(@page).collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
|
||
|
<h2><%= @page.pretty_title %></h2>
|
||
|
<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %>
|
||
| ... | ... | |
|
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
|
||
|
<p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p>
|
||
|
<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>
|
||
|
<p><%= submit_tag l(:button_save) %>
|
||
|
<%= link_to_remote l(:label_preview),
|
||
|
{ :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title },
|
||
| app/views/wiki/rename.rhtml (cópia de trabalho) | ||
|---|---|---|
|
<div class="box">
|
||
|
<p><%= f.text_field :title, :required => true, :size => 100 %></p>
|
||
|
<p><%= f.check_box :redirect_existing_links %></p>
|
||
|
<p><%= f.text_field :parent_title, :size => 100 %></p>
|
||
|
<p><%= f.select :parent_title, @wiki.pages.collect{|page| [page.pretty_title,page.title]} %></p>
|
||
|
</div>
|
||
|
<%= submit_tag l(:button_rename) %>
|
||
|
<% end %>
|
||
- « Previous
- 1
- 2
- Next »