Wiki: allows single section edit (#2222).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7829 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -100,6 +100,13 @@ class WikiController < ApplicationController
|
||||
|
||||
# To prevent StaleObjectError exception when reverting to a previous version
|
||||
@content.version = @page.content.version
|
||||
|
||||
@text = @content.text
|
||||
if params[:section].present?
|
||||
@section = params[:section].to_i
|
||||
@text, @section_hash = Redmine::WikiFormatting.formatter.new(@text).get_section(@section)
|
||||
render_404 if @text.blank?
|
||||
end
|
||||
end
|
||||
|
||||
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
@@ -120,7 +127,17 @@ class WikiController < ApplicationController
|
||||
redirect_to :action => 'show', :project_id => @project, :id => @page.title
|
||||
return
|
||||
end
|
||||
@content.attributes = params[:content]
|
||||
|
||||
@content.comments = params[:content][:comments]
|
||||
@text = params[:content][:text]
|
||||
if params[:section].present?
|
||||
@section = params[:section].to_i
|
||||
@section_hash = params[:section_hash]
|
||||
@content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
|
||||
else
|
||||
@content.version = params[:content][:version]
|
||||
@content.text = @text
|
||||
end
|
||||
@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)
|
||||
@@ -132,7 +149,7 @@ class WikiController < ApplicationController
|
||||
render :action => 'edit'
|
||||
end
|
||||
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
|
||||
# Optimistic locking exception
|
||||
flash.now[:error] = l(:notice_locking_conflict)
|
||||
render :action => 'edit'
|
||||
|
||||
@@ -486,11 +486,11 @@ module ApplicationHelper
|
||||
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
||||
only_path = options.delete(:only_path) == false ? false : true
|
||||
|
||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
|
||||
|
||||
@parsed_headings = []
|
||||
text = parse_non_pre_blocks(text) do |text|
|
||||
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
|
||||
[:parse_sections, :parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_macros, :parse_headings].each do |method_name|
|
||||
send method_name, text, project, obj, attr, only_path, options
|
||||
end
|
||||
end
|
||||
@@ -728,7 +728,23 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
|
||||
HEADING_RE = /(<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>)/i unless const_defined?(:HEADING_RE)
|
||||
|
||||
def parse_sections(text, project, obj, attr, only_path, options)
|
||||
return unless options[:edit_section_links]
|
||||
section = 0
|
||||
text.gsub!(HEADING_RE) do
|
||||
section += 1
|
||||
if section > 1
|
||||
content_tag('div',
|
||||
link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => section)),
|
||||
:class => 'contextual',
|
||||
:title => l(:button_edit_section)) + $1
|
||||
else
|
||||
$1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Headings and TOC
|
||||
# Adds ids and links to headings unless options[:headings] is set to false
|
||||
@@ -736,7 +752,7 @@ module ApplicationHelper
|
||||
return if options[:headings] == false
|
||||
|
||||
text.gsub!(HEADING_RE) do
|
||||
level, attrs, content = $1.to_i, $2, $3
|
||||
level, attrs, content = $2.to_i, $3, $4
|
||||
item = strip_tags(content).strip
|
||||
anchor = sanitize_anchor_name(item)
|
||||
# used for single-file wiki export
|
||||
@@ -746,6 +762,33 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
MACROS_RE = /
|
||||
(!)? # escaping
|
||||
(
|
||||
\{\{ # opening tag
|
||||
([\w]+) # macro name
|
||||
(\(([^\}]*)\))? # optional arguments
|
||||
\}\} # closing tag
|
||||
)
|
||||
/x unless const_defined?(:MACROS_RE)
|
||||
|
||||
# Macros substitution
|
||||
def parse_macros(text, project, obj, attr, only_path, options)
|
||||
text.gsub!(MACROS_RE) do
|
||||
esc, all, macro = $1, $2, $3.downcase
|
||||
args = ($5 || '').split(',').each(&:strip)
|
||||
if esc.nil?
|
||||
begin
|
||||
exec_macro(macro, obj, args)
|
||||
rescue => e
|
||||
"<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
|
||||
end || all
|
||||
else
|
||||
all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
||||
|
||||
# Renders the TOC with given headings
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<div class="wiki">
|
||||
<%= textilizable content, :text, :attachments => content.page.attachments %>
|
||||
<div class="wiki wiki-page">
|
||||
<%= textilizable content, :text, :attachments => content.page.attachments,
|
||||
:edit_section_links => (content.is_a?(WikiContent) && @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && {:controller => 'wiki', :action => 'edit', :project_id => @page.project, :id => @page.title}) %>
|
||||
</div>
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
|
||||
<% form_for :content, @content, :url => {:action => 'update', :id => @page.title}, :html => {:method => :put, :multipart => true, :id => 'wiki_form'} do |f| %>
|
||||
<%= f.hidden_field :version %>
|
||||
<% if @section %>
|
||||
<%= hidden_field_tag 'section', @section %>
|
||||
<%= hidden_field_tag 'section_hash', @section_hash %>
|
||||
<% end %>
|
||||
<%= error_messages_for 'content' %>
|
||||
|
||||
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
|
||||
<p><%= text_area_tag 'content[text]', @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(:label_attachment_plural)%></label><br /><%= render :partial => 'attachments/form' %></p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user