annotate .svn/pristine/1b/1b08ddf21a60c6f5d58afd83e4d47f0a83522899.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # encoding: utf-8
Chris@1517 2 #
Chris@1517 3 # Redmine - project management software
Chris@1517 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 5 #
Chris@1517 6 # This program is free software; you can redistribute it and/or
Chris@1517 7 # modify it under the terms of the GNU General Public License
Chris@1517 8 # as published by the Free Software Foundation; either version 2
Chris@1517 9 # of the License, or (at your option) any later version.
Chris@1517 10 #
Chris@1517 11 # This program is distributed in the hope that it will be useful,
Chris@1517 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 14 # GNU General Public License for more details.
Chris@1517 15 #
Chris@1517 16 # You should have received a copy of the GNU General Public License
Chris@1517 17 # along with this program; if not, write to the Free Software
Chris@1517 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 19
Chris@1517 20 require 'forwardable'
Chris@1517 21 require 'cgi'
Chris@1517 22
Chris@1517 23 module ApplicationHelper
Chris@1517 24 include Redmine::WikiFormatting::Macros::Definitions
Chris@1517 25 include Redmine::I18n
Chris@1517 26 include GravatarHelper::PublicMethods
Chris@1517 27 include Redmine::Pagination::Helper
Chris@1517 28
Chris@1517 29 extend Forwardable
Chris@1517 30 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
Chris@1517 31
Chris@1517 32 # Return true if user is authorized for controller/action, otherwise false
Chris@1517 33 def authorize_for(controller, action)
Chris@1517 34 User.current.allowed_to?({:controller => controller, :action => action}, @project)
Chris@1517 35 end
Chris@1517 36
Chris@1517 37 # Display a link if user is authorized
Chris@1517 38 #
Chris@1517 39 # @param [String] name Anchor text (passed to link_to)
Chris@1517 40 # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
Chris@1517 41 # @param [optional, Hash] html_options Options passed to link_to
Chris@1517 42 # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
Chris@1517 43 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
Chris@1517 44 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
Chris@1517 45 end
Chris@1517 46
Chris@1517 47 # Displays a link to user's account page if active
Chris@1517 48 def link_to_user(user, options={})
Chris@1517 49 if user.is_a?(User)
Chris@1517 50 name = h(user.name(options[:format]))
Chris@1517 51 if user.active? || (User.current.admin? && user.logged?)
Chris@1517 52 link_to name, user_path(user), :class => user.css_classes
Chris@1517 53 else
Chris@1517 54 name
Chris@1517 55 end
Chris@1517 56 else
Chris@1517 57 h(user.to_s)
Chris@1517 58 end
Chris@1517 59 end
Chris@1517 60
Chris@1517 61 # Displays a link to +issue+ with its subject.
Chris@1517 62 # Examples:
Chris@1517 63 #
Chris@1517 64 # link_to_issue(issue) # => Defect #6: This is the subject
Chris@1517 65 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
Chris@1517 66 # link_to_issue(issue, :subject => false) # => Defect #6
Chris@1517 67 # link_to_issue(issue, :project => true) # => Foo - Defect #6
Chris@1517 68 # link_to_issue(issue, :subject => false, :tracker => false) # => #6
Chris@1517 69 #
Chris@1517 70 def link_to_issue(issue, options={})
Chris@1517 71 title = nil
Chris@1517 72 subject = nil
Chris@1517 73 text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}"
Chris@1517 74 if options[:subject] == false
Chris@1517 75 title = issue.subject.truncate(60)
Chris@1517 76 else
Chris@1517 77 subject = issue.subject
Chris@1517 78 if truncate_length = options[:truncate]
Chris@1517 79 subject = subject.truncate(truncate_length)
Chris@1517 80 end
Chris@1517 81 end
Chris@1517 82 only_path = options[:only_path].nil? ? true : options[:only_path]
Chris@1517 83 s = link_to(text, issue_path(issue, :only_path => only_path),
Chris@1517 84 :class => issue.css_classes, :title => title)
Chris@1517 85 s << h(": #{subject}") if subject
Chris@1517 86 s = h("#{issue.project} - ") + s if options[:project]
Chris@1517 87 s
Chris@1517 88 end
Chris@1517 89
Chris@1517 90 # Generates a link to an attachment.
Chris@1517 91 # Options:
Chris@1517 92 # * :text - Link text (default to attachment filename)
Chris@1517 93 # * :download - Force download (default: false)
Chris@1517 94 def link_to_attachment(attachment, options={})
Chris@1517 95 text = options.delete(:text) || attachment.filename
Chris@1517 96 route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
Chris@1517 97 html_options = options.slice!(:only_path)
Chris@1517 98 url = send(route_method, attachment, attachment.filename, options)
Chris@1517 99 link_to text, url, html_options
Chris@1517 100 end
Chris@1517 101
Chris@1517 102 # Generates a link to a SCM revision
Chris@1517 103 # Options:
Chris@1517 104 # * :text - Link text (default to the formatted revision)
Chris@1517 105 def link_to_revision(revision, repository, options={})
Chris@1517 106 if repository.is_a?(Project)
Chris@1517 107 repository = repository.repository
Chris@1517 108 end
Chris@1517 109 text = options.delete(:text) || format_revision(revision)
Chris@1517 110 rev = revision.respond_to?(:identifier) ? revision.identifier : revision
Chris@1517 111 link_to(
Chris@1517 112 h(text),
Chris@1517 113 {:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev},
Chris@1517 114 :title => l(:label_revision_id, format_revision(revision))
Chris@1517 115 )
Chris@1517 116 end
Chris@1517 117
Chris@1517 118 # Generates a link to a message
Chris@1517 119 def link_to_message(message, options={}, html_options = nil)
Chris@1517 120 link_to(
Chris@1517 121 message.subject.truncate(60),
Chris@1517 122 board_message_path(message.board_id, message.parent_id || message.id, {
Chris@1517 123 :r => (message.parent_id && message.id),
Chris@1517 124 :anchor => (message.parent_id ? "message-#{message.id}" : nil)
Chris@1517 125 }.merge(options)),
Chris@1517 126 html_options
Chris@1517 127 )
Chris@1517 128 end
Chris@1517 129
Chris@1517 130 # Generates a link to a project if active
Chris@1517 131 # Examples:
Chris@1517 132 #
Chris@1517 133 # link_to_project(project) # => link to the specified project overview
Chris@1517 134 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
Chris@1517 135 # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
Chris@1517 136 #
Chris@1517 137 def link_to_project(project, options={}, html_options = nil)
Chris@1517 138 if project.archived?
Chris@1517 139 h(project.name)
Chris@1517 140 elsif options.key?(:action)
Chris@1517 141 ActiveSupport::Deprecation.warn "#link_to_project with :action option is deprecated and will be removed in Redmine 3.0."
Chris@1517 142 url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
Chris@1517 143 link_to project.name, url, html_options
Chris@1517 144 else
Chris@1517 145 link_to project.name, project_path(project, options), html_options
Chris@1517 146 end
Chris@1517 147 end
Chris@1517 148
Chris@1517 149 # Generates a link to a project settings if active
Chris@1517 150 def link_to_project_settings(project, options={}, html_options=nil)
Chris@1517 151 if project.active?
Chris@1517 152 link_to project.name, settings_project_path(project, options), html_options
Chris@1517 153 elsif project.archived?
Chris@1517 154 h(project.name)
Chris@1517 155 else
Chris@1517 156 link_to project.name, project_path(project, options), html_options
Chris@1517 157 end
Chris@1517 158 end
Chris@1517 159
Chris@1517 160 # Helper that formats object for html or text rendering
Chris@1517 161 def format_object(object, html=true)
Chris@1517 162 case object.class.name
Chris@1517 163 when 'Array'
Chris@1517 164 object.map {|o| format_object(o, html)}.join(', ').html_safe
Chris@1517 165 when 'Time'
Chris@1517 166 format_time(object)
Chris@1517 167 when 'Date'
Chris@1517 168 format_date(object)
Chris@1517 169 when 'Fixnum'
Chris@1517 170 object.to_s
Chris@1517 171 when 'Float'
Chris@1517 172 sprintf "%.2f", object
Chris@1517 173 when 'User'
Chris@1517 174 html ? link_to_user(object) : object.to_s
Chris@1517 175 when 'Project'
Chris@1517 176 html ? link_to_project(object) : object.to_s
Chris@1517 177 when 'Version'
Chris@1517 178 html ? link_to(object.name, version_path(object)) : object.to_s
Chris@1517 179 when 'TrueClass'
Chris@1517 180 l(:general_text_Yes)
Chris@1517 181 when 'FalseClass'
Chris@1517 182 l(:general_text_No)
Chris@1517 183 when 'Issue'
Chris@1517 184 object.visible? && html ? link_to_issue(object) : "##{object.id}"
Chris@1517 185 when 'CustomValue', 'CustomFieldValue'
Chris@1517 186 if object.custom_field
Chris@1517 187 f = object.custom_field.format.formatted_custom_value(self, object, html)
Chris@1517 188 if f.nil? || f.is_a?(String)
Chris@1517 189 f
Chris@1517 190 else
Chris@1517 191 format_object(f, html)
Chris@1517 192 end
Chris@1517 193 else
Chris@1517 194 object.value.to_s
Chris@1517 195 end
Chris@1517 196 else
Chris@1517 197 html ? h(object) : object.to_s
Chris@1517 198 end
Chris@1517 199 end
Chris@1517 200
Chris@1517 201 def wiki_page_path(page, options={})
Chris@1517 202 url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options))
Chris@1517 203 end
Chris@1517 204
Chris@1517 205 def thumbnail_tag(attachment)
Chris@1517 206 link_to image_tag(thumbnail_path(attachment)),
Chris@1517 207 named_attachment_path(attachment, attachment.filename),
Chris@1517 208 :title => attachment.filename
Chris@1517 209 end
Chris@1517 210
Chris@1517 211 def toggle_link(name, id, options={})
Chris@1517 212 onclick = "$('##{id}').toggle(); "
Chris@1517 213 onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
Chris@1517 214 onclick << "return false;"
Chris@1517 215 link_to(name, "#", :onclick => onclick)
Chris@1517 216 end
Chris@1517 217
Chris@1517 218 def image_to_function(name, function, html_options = {})
Chris@1517 219 html_options.symbolize_keys!
Chris@1517 220 tag(:input, html_options.merge({
Chris@1517 221 :type => "image", :src => image_path(name),
Chris@1517 222 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
Chris@1517 223 }))
Chris@1517 224 end
Chris@1517 225
Chris@1517 226 def format_activity_title(text)
Chris@1517 227 h(truncate_single_line_raw(text, 100))
Chris@1517 228 end
Chris@1517 229
Chris@1517 230 def format_activity_day(date)
Chris@1517 231 date == User.current.today ? l(:label_today).titleize : format_date(date)
Chris@1517 232 end
Chris@1517 233
Chris@1517 234 def format_activity_description(text)
Chris@1517 235 h(text.to_s.truncate(120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')
Chris@1517 236 ).gsub(/[\r\n]+/, "<br />").html_safe
Chris@1517 237 end
Chris@1517 238
Chris@1517 239 def format_version_name(version)
Chris@1517 240 if version.project == @project
Chris@1517 241 h(version)
Chris@1517 242 else
Chris@1517 243 h("#{version.project} - #{version}")
Chris@1517 244 end
Chris@1517 245 end
Chris@1517 246
Chris@1517 247 def due_date_distance_in_words(date)
Chris@1517 248 if date
Chris@1517 249 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
Chris@1517 250 end
Chris@1517 251 end
Chris@1517 252
Chris@1517 253 # Renders a tree of projects as a nested set of unordered lists
Chris@1517 254 # The given collection may be a subset of the whole project tree
Chris@1517 255 # (eg. some intermediate nodes are private and can not be seen)
Chris@1517 256 def render_project_nested_lists(projects)
Chris@1517 257 s = ''
Chris@1517 258 if projects.any?
Chris@1517 259 ancestors = []
Chris@1517 260 original_project = @project
Chris@1517 261 projects.sort_by(&:lft).each do |project|
Chris@1517 262 # set the project environment to please macros.
Chris@1517 263 @project = project
Chris@1517 264 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
Chris@1517 265 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
Chris@1517 266 else
Chris@1517 267 ancestors.pop
Chris@1517 268 s << "</li>"
Chris@1517 269 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
Chris@1517 270 ancestors.pop
Chris@1517 271 s << "</ul></li>\n"
Chris@1517 272 end
Chris@1517 273 end
Chris@1517 274 classes = (ancestors.empty? ? 'root' : 'child')
Chris@1517 275 s << "<li class='#{classes}'><div class='#{classes}'>"
Chris@1517 276 s << h(block_given? ? yield(project) : project.name)
Chris@1517 277 s << "</div>\n"
Chris@1517 278 ancestors << project
Chris@1517 279 end
Chris@1517 280 s << ("</li></ul>\n" * ancestors.size)
Chris@1517 281 @project = original_project
Chris@1517 282 end
Chris@1517 283 s.html_safe
Chris@1517 284 end
Chris@1517 285
Chris@1517 286 def render_page_hierarchy(pages, node=nil, options={})
Chris@1517 287 content = ''
Chris@1517 288 if pages[node]
Chris@1517 289 content << "<ul class=\"pages-hierarchy\">\n"
Chris@1517 290 pages[node].each do |page|
Chris@1517 291 content << "<li>"
Chris@1517 292 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
Chris@1517 293 :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
Chris@1517 294 content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
Chris@1517 295 content << "</li>\n"
Chris@1517 296 end
Chris@1517 297 content << "</ul>\n"
Chris@1517 298 end
Chris@1517 299 content.html_safe
Chris@1517 300 end
Chris@1517 301
Chris@1517 302 # Renders flash messages
Chris@1517 303 def render_flash_messages
Chris@1517 304 s = ''
Chris@1517 305 flash.each do |k,v|
Chris@1517 306 s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
Chris@1517 307 end
Chris@1517 308 s.html_safe
Chris@1517 309 end
Chris@1517 310
Chris@1517 311 # Renders tabs and their content
Chris@1517 312 def render_tabs(tabs, selected=params[:tab])
Chris@1517 313 if tabs.any?
Chris@1517 314 unless tabs.detect {|tab| tab[:name] == selected}
Chris@1517 315 selected = nil
Chris@1517 316 end
Chris@1517 317 selected ||= tabs.first[:name]
Chris@1517 318 render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected}
Chris@1517 319 else
Chris@1517 320 content_tag 'p', l(:label_no_data), :class => "nodata"
Chris@1517 321 end
Chris@1517 322 end
Chris@1517 323
Chris@1517 324 # Renders the project quick-jump box
Chris@1517 325 def render_project_jump_box
Chris@1517 326 return unless User.current.logged?
Chris@1517 327 projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq
Chris@1517 328 if projects.any?
Chris@1517 329 options =
Chris@1517 330 ("<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
Chris@1517 331 '<option value="" disabled="disabled">---</option>').html_safe
Chris@1517 332
Chris@1517 333 options << project_tree_options_for_select(projects, :selected => @project) do |p|
Chris@1517 334 { :value => project_path(:id => p, :jump => current_menu_item) }
Chris@1517 335 end
Chris@1517 336
Chris@1517 337 select_tag('project_quick_jump_box', options, :onchange => 'if (this.value != \'\') { window.location = this.value; }')
Chris@1517 338 end
Chris@1517 339 end
Chris@1517 340
Chris@1517 341 def project_tree_options_for_select(projects, options = {})
Chris@1517 342 s = ''
Chris@1517 343 project_tree(projects) do |project, level|
Chris@1517 344 name_prefix = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
Chris@1517 345 tag_options = {:value => project.id}
Chris@1517 346 if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
Chris@1517 347 tag_options[:selected] = 'selected'
Chris@1517 348 else
Chris@1517 349 tag_options[:selected] = nil
Chris@1517 350 end
Chris@1517 351 tag_options.merge!(yield(project)) if block_given?
Chris@1517 352 s << content_tag('option', name_prefix + h(project), tag_options)
Chris@1517 353 end
Chris@1517 354 s.html_safe
Chris@1517 355 end
Chris@1517 356
Chris@1517 357 # Yields the given block for each project with its level in the tree
Chris@1517 358 #
Chris@1517 359 # Wrapper for Project#project_tree
Chris@1517 360 def project_tree(projects, &block)
Chris@1517 361 Project.project_tree(projects, &block)
Chris@1517 362 end
Chris@1517 363
Chris@1517 364 def principals_check_box_tags(name, principals)
Chris@1517 365 s = ''
Chris@1517 366 principals.each do |principal|
Chris@1517 367 s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n"
Chris@1517 368 end
Chris@1517 369 s.html_safe
Chris@1517 370 end
Chris@1517 371
Chris@1517 372 # Returns a string for users/groups option tags
Chris@1517 373 def principals_options_for_select(collection, selected=nil)
Chris@1517 374 s = ''
Chris@1517 375 if collection.include?(User.current)
Chris@1517 376 s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
Chris@1517 377 end
Chris@1517 378 groups = ''
Chris@1517 379 collection.sort.each do |element|
Chris@1517 380 selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) || element.id.to_s == selected
Chris@1517 381 (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
Chris@1517 382 end
Chris@1517 383 unless groups.empty?
Chris@1517 384 s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
Chris@1517 385 end
Chris@1517 386 s.html_safe
Chris@1517 387 end
Chris@1517 388
Chris@1517 389 # Options for the new membership projects combo-box
Chris@1517 390 def options_for_membership_project_select(principal, projects)
Chris@1517 391 options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
Chris@1517 392 options << project_tree_options_for_select(projects) do |p|
Chris@1517 393 {:disabled => principal.projects.to_a.include?(p)}
Chris@1517 394 end
Chris@1517 395 options
Chris@1517 396 end
Chris@1517 397
Chris@1517 398 def option_tag(name, text, value, selected=nil, options={})
Chris@1517 399 content_tag 'option', value, options.merge(:value => value, :selected => (value == selected))
Chris@1517 400 end
Chris@1517 401
Chris@1517 402 # Truncates and returns the string as a single line
Chris@1517 403 def truncate_single_line(string, *args)
Chris@1517 404 ActiveSupport::Deprecation.warn(
Chris@1517 405 "ApplicationHelper#truncate_single_line is deprecated and will be removed in Rails 4 poring")
Chris@1517 406 # Rails 4 ActionView::Helpers::TextHelper#truncate escapes.
Chris@1517 407 # So, result is broken.
Chris@1517 408 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
Chris@1517 409 end
Chris@1517 410
Chris@1517 411 def truncate_single_line_raw(string, length)
Chris@1517 412 string.truncate(length).gsub(%r{[\r\n]+}m, ' ')
Chris@1517 413 end
Chris@1517 414
Chris@1517 415 # Truncates at line break after 250 characters or options[:length]
Chris@1517 416 def truncate_lines(string, options={})
Chris@1517 417 length = options[:length] || 250
Chris@1517 418 if string.to_s =~ /\A(.{#{length}}.*?)$/m
Chris@1517 419 "#{$1}..."
Chris@1517 420 else
Chris@1517 421 string
Chris@1517 422 end
Chris@1517 423 end
Chris@1517 424
Chris@1517 425 def anchor(text)
Chris@1517 426 text.to_s.gsub(' ', '_')
Chris@1517 427 end
Chris@1517 428
Chris@1517 429 def html_hours(text)
Chris@1517 430 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
Chris@1517 431 end
Chris@1517 432
Chris@1517 433 def authoring(created, author, options={})
Chris@1517 434 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
Chris@1517 435 end
Chris@1517 436
Chris@1517 437 def time_tag(time)
Chris@1517 438 text = distance_of_time_in_words(Time.now, time)
Chris@1517 439 if @project
Chris@1517 440 link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)}, :title => format_time(time))
Chris@1517 441 else
Chris@1517 442 content_tag('abbr', text, :title => format_time(time))
Chris@1517 443 end
Chris@1517 444 end
Chris@1517 445
Chris@1517 446 def syntax_highlight_lines(name, content)
Chris@1517 447 lines = []
Chris@1517 448 syntax_highlight(name, content).each_line { |line| lines << line }
Chris@1517 449 lines
Chris@1517 450 end
Chris@1517 451
Chris@1517 452 def syntax_highlight(name, content)
Chris@1517 453 Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
Chris@1517 454 end
Chris@1517 455
Chris@1517 456 def to_path_param(path)
Chris@1517 457 str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/")
Chris@1517 458 str.blank? ? nil : str
Chris@1517 459 end
Chris@1517 460
Chris@1517 461 def reorder_links(name, url, method = :post)
Chris@1517 462 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)),
Chris@1517 463 url.merge({"#{name}[move_to]" => 'highest'}),
Chris@1517 464 :method => method, :title => l(:label_sort_highest)) +
Chris@1517 465 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)),
Chris@1517 466 url.merge({"#{name}[move_to]" => 'higher'}),
Chris@1517 467 :method => method, :title => l(:label_sort_higher)) +
Chris@1517 468 link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)),
Chris@1517 469 url.merge({"#{name}[move_to]" => 'lower'}),
Chris@1517 470 :method => method, :title => l(:label_sort_lower)) +
Chris@1517 471 link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)),
Chris@1517 472 url.merge({"#{name}[move_to]" => 'lowest'}),
Chris@1517 473 :method => method, :title => l(:label_sort_lowest))
Chris@1517 474 end
Chris@1517 475
Chris@1517 476 def breadcrumb(*args)
Chris@1517 477 elements = args.flatten
Chris@1517 478 elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
Chris@1517 479 end
Chris@1517 480
Chris@1517 481 def other_formats_links(&block)
Chris@1517 482 concat('<p class="other-formats">'.html_safe + l(:label_export_to))
Chris@1517 483 yield Redmine::Views::OtherFormatsBuilder.new(self)
Chris@1517 484 concat('</p>'.html_safe)
Chris@1517 485 end
Chris@1517 486
Chris@1517 487 def page_header_title
Chris@1517 488 if @project.nil? || @project.new_record?
Chris@1517 489 h(Setting.app_title)
Chris@1517 490 else
Chris@1517 491 b = []
Chris@1517 492 ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
Chris@1517 493 if ancestors.any?
Chris@1517 494 root = ancestors.shift
Chris@1517 495 b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
Chris@1517 496 if ancestors.size > 2
Chris@1517 497 b << "\xe2\x80\xa6"
Chris@1517 498 ancestors = ancestors[-2, 2]
Chris@1517 499 end
Chris@1517 500 b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
Chris@1517 501 end
Chris@1517 502 b << h(@project)
Chris@1517 503 b.join(" \xc2\xbb ").html_safe
Chris@1517 504 end
Chris@1517 505 end
Chris@1517 506
Chris@1517 507 # Returns a h2 tag and sets the html title with the given arguments
Chris@1517 508 def title(*args)
Chris@1517 509 strings = args.map do |arg|
Chris@1517 510 if arg.is_a?(Array) && arg.size >= 2
Chris@1517 511 link_to(*arg)
Chris@1517 512 else
Chris@1517 513 h(arg.to_s)
Chris@1517 514 end
Chris@1517 515 end
Chris@1517 516 html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s}
Chris@1517 517 content_tag('h2', strings.join(' &#187; ').html_safe)
Chris@1517 518 end
Chris@1517 519
Chris@1517 520 # Sets the html title
Chris@1517 521 # Returns the html title when called without arguments
Chris@1517 522 # Current project name and app_title and automatically appended
Chris@1517 523 # Exemples:
Chris@1517 524 # html_title 'Foo', 'Bar'
Chris@1517 525 # html_title # => 'Foo - Bar - My Project - Redmine'
Chris@1517 526 def html_title(*args)
Chris@1517 527 if args.empty?
Chris@1517 528 title = @html_title || []
Chris@1517 529 title << @project.name if @project
Chris@1517 530 title << Setting.app_title unless Setting.app_title == title.last
Chris@1517 531 title.reject(&:blank?).join(' - ')
Chris@1517 532 else
Chris@1517 533 @html_title ||= []
Chris@1517 534 @html_title += args
Chris@1517 535 end
Chris@1517 536 end
Chris@1517 537
Chris@1517 538 # Returns the theme, controller name, and action as css classes for the
Chris@1517 539 # HTML body.
Chris@1517 540 def body_css_classes
Chris@1517 541 css = []
Chris@1517 542 if theme = Redmine::Themes.theme(Setting.ui_theme)
Chris@1517 543 css << 'theme-' + theme.name
Chris@1517 544 end
Chris@1517 545
Chris@1517 546 css << 'project-' + @project.identifier if @project && @project.identifier.present?
Chris@1517 547 css << 'controller-' + controller_name
Chris@1517 548 css << 'action-' + action_name
Chris@1517 549 css.join(' ')
Chris@1517 550 end
Chris@1517 551
Chris@1517 552 def accesskey(s)
Chris@1517 553 @used_accesskeys ||= []
Chris@1517 554 key = Redmine::AccessKeys.key_for(s)
Chris@1517 555 return nil if @used_accesskeys.include?(key)
Chris@1517 556 @used_accesskeys << key
Chris@1517 557 key
Chris@1517 558 end
Chris@1517 559
Chris@1517 560 # Formats text according to system settings.
Chris@1517 561 # 2 ways to call this method:
Chris@1517 562 # * with a String: textilizable(text, options)
Chris@1517 563 # * with an object and one of its attribute: textilizable(issue, :description, options)
Chris@1517 564 def textilizable(*args)
Chris@1517 565 options = args.last.is_a?(Hash) ? args.pop : {}
Chris@1517 566 case args.size
Chris@1517 567 when 1
Chris@1517 568 obj = options[:object]
Chris@1517 569 text = args.shift
Chris@1517 570 when 2
Chris@1517 571 obj = args.shift
Chris@1517 572 attr = args.shift
Chris@1517 573 text = obj.send(attr).to_s
Chris@1517 574 else
Chris@1517 575 raise ArgumentError, 'invalid arguments to textilizable'
Chris@1517 576 end
Chris@1517 577 return '' if text.blank?
Chris@1517 578 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
Chris@1517 579 only_path = options.delete(:only_path) == false ? false : true
Chris@1517 580
Chris@1517 581 text = text.dup
Chris@1517 582 macros = catch_macros(text)
Chris@1517 583 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
Chris@1517 584
Chris@1517 585 @parsed_headings = []
Chris@1517 586 @heading_anchors = {}
Chris@1517 587 @current_section = 0 if options[:edit_section_links]
Chris@1517 588
Chris@1517 589 parse_sections(text, project, obj, attr, only_path, options)
Chris@1517 590 text = parse_non_pre_blocks(text, obj, macros) do |text|
Chris@1517 591 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
Chris@1517 592 send method_name, text, project, obj, attr, only_path, options
Chris@1517 593 end
Chris@1517 594 end
Chris@1517 595 parse_headings(text, project, obj, attr, only_path, options)
Chris@1517 596
Chris@1517 597 if @parsed_headings.any?
Chris@1517 598 replace_toc(text, @parsed_headings)
Chris@1517 599 end
Chris@1517 600
Chris@1517 601 text.html_safe
Chris@1517 602 end
Chris@1517 603
Chris@1517 604 def parse_non_pre_blocks(text, obj, macros)
Chris@1517 605 s = StringScanner.new(text)
Chris@1517 606 tags = []
Chris@1517 607 parsed = ''
Chris@1517 608 while !s.eos?
Chris@1517 609 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
Chris@1517 610 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
Chris@1517 611 if tags.empty?
Chris@1517 612 yield text
Chris@1517 613 inject_macros(text, obj, macros) if macros.any?
Chris@1517 614 else
Chris@1517 615 inject_macros(text, obj, macros, false) if macros.any?
Chris@1517 616 end
Chris@1517 617 parsed << text
Chris@1517 618 if tag
Chris@1517 619 if closing
Chris@1517 620 if tags.last == tag.downcase
Chris@1517 621 tags.pop
Chris@1517 622 end
Chris@1517 623 else
Chris@1517 624 tags << tag.downcase
Chris@1517 625 end
Chris@1517 626 parsed << full_tag
Chris@1517 627 end
Chris@1517 628 end
Chris@1517 629 # Close any non closing tags
Chris@1517 630 while tag = tags.pop
Chris@1517 631 parsed << "</#{tag}>"
Chris@1517 632 end
Chris@1517 633 parsed
Chris@1517 634 end
Chris@1517 635
Chris@1517 636 def parse_inline_attachments(text, project, obj, attr, only_path, options)
Chris@1517 637 # when using an image link, try to use an attachment, if possible
Chris@1517 638 attachments = options[:attachments] || []
Chris@1517 639 attachments += obj.attachments if obj.respond_to?(:attachments)
Chris@1517 640 if attachments.present?
Chris@1517 641 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
Chris@1517 642 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
Chris@1517 643 # search for the picture in attachments
Chris@1517 644 if found = Attachment.latest_attach(attachments, filename)
Chris@1517 645 image_url = download_named_attachment_path(found, found.filename, :only_path => only_path)
Chris@1517 646 desc = found.description.to_s.gsub('"', '')
Chris@1517 647 if !desc.blank? && alttext.blank?
Chris@1517 648 alt = " title=\"#{desc}\" alt=\"#{desc}\""
Chris@1517 649 end
Chris@1517 650 "src=\"#{image_url}\"#{alt}"
Chris@1517 651 else
Chris@1517 652 m
Chris@1517 653 end
Chris@1517 654 end
Chris@1517 655 end
Chris@1517 656 end
Chris@1517 657
Chris@1517 658 # Wiki links
Chris@1517 659 #
Chris@1517 660 # Examples:
Chris@1517 661 # [[mypage]]
Chris@1517 662 # [[mypage|mytext]]
Chris@1517 663 # wiki links can refer other project wikis, using project name or identifier:
Chris@1517 664 # [[project:]] -> wiki starting page
Chris@1517 665 # [[project:|mytext]]
Chris@1517 666 # [[project:mypage]]
Chris@1517 667 # [[project:mypage|mytext]]
Chris@1517 668 def parse_wiki_links(text, project, obj, attr, only_path, options)
Chris@1517 669 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
Chris@1517 670 link_project = project
Chris@1517 671 esc, all, page, title = $1, $2, $3, $5
Chris@1517 672 if esc.nil?
Chris@1517 673 if page =~ /^([^\:]+)\:(.*)$/
Chris@1517 674 identifier, page = $1, $2
Chris@1517 675 link_project = Project.find_by_identifier(identifier) || Project.find_by_name(identifier)
Chris@1517 676 title ||= identifier if page.blank?
Chris@1517 677 end
Chris@1517 678
Chris@1517 679 if link_project && link_project.wiki
Chris@1517 680 # extract anchor
Chris@1517 681 anchor = nil
Chris@1517 682 if page =~ /^(.+?)\#(.+)$/
Chris@1517 683 page, anchor = $1, $2
Chris@1517 684 end
Chris@1517 685 anchor = sanitize_anchor_name(anchor) if anchor.present?
Chris@1517 686 # check if page exists
Chris@1517 687 wiki_page = link_project.wiki.find_page(page)
Chris@1517 688 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
Chris@1517 689 "##{anchor}"
Chris@1517 690 else
Chris@1517 691 case options[:wiki_links]
Chris@1517 692 when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
Chris@1517 693 when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
Chris@1517 694 else
Chris@1517 695 wiki_page_id = page.present? ? Wiki.titleize(page) : nil
Chris@1517 696 parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
Chris@1517 697 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
Chris@1517 698 :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent)
Chris@1517 699 end
Chris@1517 700 end
Chris@1517 701 link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
Chris@1517 702 else
Chris@1517 703 # project or wiki doesn't exist
Chris@1517 704 all
Chris@1517 705 end
Chris@1517 706 else
Chris@1517 707 all
Chris@1517 708 end
Chris@1517 709 end
Chris@1517 710 end
Chris@1517 711
Chris@1517 712 # Redmine links
Chris@1517 713 #
Chris@1517 714 # Examples:
Chris@1517 715 # Issues:
Chris@1517 716 # #52 -> Link to issue #52
Chris@1517 717 # Changesets:
Chris@1517 718 # r52 -> Link to revision 52
Chris@1517 719 # commit:a85130f -> Link to scmid starting with a85130f
Chris@1517 720 # Documents:
Chris@1517 721 # document#17 -> Link to document with id 17
Chris@1517 722 # document:Greetings -> Link to the document with title "Greetings"
Chris@1517 723 # document:"Some document" -> Link to the document with title "Some document"
Chris@1517 724 # Versions:
Chris@1517 725 # version#3 -> Link to version with id 3
Chris@1517 726 # version:1.0.0 -> Link to version named "1.0.0"
Chris@1517 727 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
Chris@1517 728 # Attachments:
Chris@1517 729 # attachment:file.zip -> Link to the attachment of the current object named file.zip
Chris@1517 730 # Source files:
Chris@1517 731 # source:some/file -> Link to the file located at /some/file in the project's repository
Chris@1517 732 # source:some/file@52 -> Link to the file's revision 52
Chris@1517 733 # source:some/file#L120 -> Link to line 120 of the file
Chris@1517 734 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
Chris@1517 735 # export:some/file -> Force the download of the file
Chris@1517 736 # Forum messages:
Chris@1517 737 # message#1218 -> Link to message with id 1218
Chris@1517 738 # Projects:
Chris@1517 739 # project:someproject -> Link to project named "someproject"
Chris@1517 740 # project#3 -> Link to project with id 3
Chris@1517 741 #
Chris@1517 742 # Links can refer other objects from other projects, using project identifier:
Chris@1517 743 # identifier:r52
Chris@1517 744 # identifier:document:"Some document"
Chris@1517 745 # identifier:version:1.0.0
Chris@1517 746 # identifier:source:some/file
Chris@1517 747 def parse_redmine_links(text, default_project, obj, attr, only_path, options)
Chris@1517 748 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-_]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
Chris@1517 749 leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $18, $14 || $19, $15, $17
Chris@1517 750 link = nil
Chris@1517 751 project = default_project
Chris@1517 752 if project_identifier
Chris@1517 753 project = Project.visible.find_by_identifier(project_identifier)
Chris@1517 754 end
Chris@1517 755 if esc.nil?
Chris@1517 756 if prefix.nil? && sep == 'r'
Chris@1517 757 if project
Chris@1517 758 repository = nil
Chris@1517 759 if repo_identifier
Chris@1517 760 repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
Chris@1517 761 else
Chris@1517 762 repository = project.repository
Chris@1517 763 end
Chris@1517 764 # project.changesets.visible raises an SQL error because of a double join on repositories
Chris@1517 765 if repository &&
Chris@1517 766 (changeset = Changeset.visible.
Chris@1517 767 find_by_repository_id_and_revision(repository.id, identifier))
Chris@1517 768 link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"),
Chris@1517 769 {:only_path => only_path, :controller => 'repositories',
Chris@1517 770 :action => 'revision', :id => project,
Chris@1517 771 :repository_id => repository.identifier_param,
Chris@1517 772 :rev => changeset.revision},
Chris@1517 773 :class => 'changeset',
Chris@1517 774 :title => truncate_single_line_raw(changeset.comments, 100))
Chris@1517 775 end
Chris@1517 776 end
Chris@1517 777 elsif sep == '#'
Chris@1517 778 oid = identifier.to_i
Chris@1517 779 case prefix
Chris@1517 780 when nil
Chris@1517 781 if oid.to_s == identifier &&
Chris@1517 782 issue = Issue.visible.includes(:status).find_by_id(oid)
Chris@1517 783 anchor = comment_id ? "note-#{comment_id}" : nil
Chris@1517 784 link = link_to(h("##{oid}#{comment_suffix}"),
Chris@1517 785 {:only_path => only_path, :controller => 'issues',
Chris@1517 786 :action => 'show', :id => oid, :anchor => anchor},
Chris@1517 787 :class => issue.css_classes,
Chris@1517 788 :title => "#{issue.subject.truncate(100)} (#{issue.status.name})")
Chris@1517 789 end
Chris@1517 790 when 'document'
Chris@1517 791 if document = Document.visible.find_by_id(oid)
Chris@1517 792 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
Chris@1517 793 :class => 'document'
Chris@1517 794 end
Chris@1517 795 when 'version'
Chris@1517 796 if version = Version.visible.find_by_id(oid)
Chris@1517 797 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
Chris@1517 798 :class => 'version'
Chris@1517 799 end
Chris@1517 800 when 'message'
Chris@1517 801 if message = Message.visible.includes(:parent).find_by_id(oid)
Chris@1517 802 link = link_to_message(message, {:only_path => only_path}, :class => 'message')
Chris@1517 803 end
Chris@1517 804 when 'forum'
Chris@1517 805 if board = Board.visible.find_by_id(oid)
Chris@1517 806 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
Chris@1517 807 :class => 'board'
Chris@1517 808 end
Chris@1517 809 when 'news'
Chris@1517 810 if news = News.visible.find_by_id(oid)
Chris@1517 811 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
Chris@1517 812 :class => 'news'
Chris@1517 813 end
Chris@1517 814 when 'project'
Chris@1517 815 if p = Project.visible.find_by_id(oid)
Chris@1517 816 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
Chris@1517 817 end
Chris@1517 818 end
Chris@1517 819 elsif sep == ':'
Chris@1517 820 # removes the double quotes if any
Chris@1517 821 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
Chris@1517 822 name = CGI.unescapeHTML(name)
Chris@1517 823 case prefix
Chris@1517 824 when 'document'
Chris@1517 825 if project && document = project.documents.visible.find_by_title(name)
Chris@1517 826 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
Chris@1517 827 :class => 'document'
Chris@1517 828 end
Chris@1517 829 when 'version'
Chris@1517 830 if project && version = project.versions.visible.find_by_name(name)
Chris@1517 831 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
Chris@1517 832 :class => 'version'
Chris@1517 833 end
Chris@1517 834 when 'forum'
Chris@1517 835 if project && board = project.boards.visible.find_by_name(name)
Chris@1517 836 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
Chris@1517 837 :class => 'board'
Chris@1517 838 end
Chris@1517 839 when 'news'
Chris@1517 840 if project && news = project.news.visible.find_by_title(name)
Chris@1517 841 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
Chris@1517 842 :class => 'news'
Chris@1517 843 end
Chris@1517 844 when 'commit', 'source', 'export'
Chris@1517 845 if project
Chris@1517 846 repository = nil
Chris@1517 847 if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$}
Chris@1517 848 repo_prefix, repo_identifier, name = $1, $2, $3
Chris@1517 849 repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
Chris@1517 850 else
Chris@1517 851 repository = project.repository
Chris@1517 852 end
Chris@1517 853 if prefix == 'commit'
Chris@1517 854 if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
Chris@1517 855 link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
Chris@1517 856 :class => 'changeset',
Chris@1517 857 :title => truncate_single_line_raw(changeset.comments, 100)
Chris@1517 858 end
Chris@1517 859 else
Chris@1517 860 if repository && User.current.allowed_to?(:browse_repository, project)
Chris@1517 861 name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$}
Chris@1517 862 path, rev, anchor = $1, $3, $5
Chris@1517 863 link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param,
Chris@1517 864 :path => to_path_param(path),
Chris@1517 865 :rev => rev,
Chris@1517 866 :anchor => anchor},
Chris@1517 867 :class => (prefix == 'export' ? 'source download' : 'source')
Chris@1517 868 end
Chris@1517 869 end
Chris@1517 870 repo_prefix = nil
Chris@1517 871 end
Chris@1517 872 when 'attachment'
Chris@1517 873 attachments = options[:attachments] || []
Chris@1517 874 attachments += obj.attachments if obj.respond_to?(:attachments)
Chris@1517 875 if attachments && attachment = Attachment.latest_attach(attachments, name)
Chris@1517 876 link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
Chris@1517 877 end
Chris@1517 878 when 'project'
Chris@1517 879 if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
Chris@1517 880 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
Chris@1517 881 end
Chris@1517 882 end
Chris@1517 883 end
Chris@1517 884 end
Chris@1517 885 (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
Chris@1517 886 end
Chris@1517 887 end
Chris@1517 888
Chris@1517 889 HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
Chris@1517 890
Chris@1517 891 def parse_sections(text, project, obj, attr, only_path, options)
Chris@1517 892 return unless options[:edit_section_links]
Chris@1517 893 text.gsub!(HEADING_RE) do
Chris@1517 894 heading = $1
Chris@1517 895 @current_section += 1
Chris@1517 896 if @current_section > 1
Chris@1517 897 content_tag('div',
Chris@1517 898 link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)),
Chris@1517 899 :class => 'contextual',
Chris@1517 900 :title => l(:button_edit_section),
Chris@1517 901 :id => "section-#{@current_section}") + heading.html_safe
Chris@1517 902 else
Chris@1517 903 heading
Chris@1517 904 end
Chris@1517 905 end
Chris@1517 906 end
Chris@1517 907
Chris@1517 908 # Headings and TOC
Chris@1517 909 # Adds ids and links to headings unless options[:headings] is set to false
Chris@1517 910 def parse_headings(text, project, obj, attr, only_path, options)
Chris@1517 911 return if options[:headings] == false
Chris@1517 912
Chris@1517 913 text.gsub!(HEADING_RE) do
Chris@1517 914 level, attrs, content = $2.to_i, $3, $4
Chris@1517 915 item = strip_tags(content).strip
Chris@1517 916 anchor = sanitize_anchor_name(item)
Chris@1517 917 # used for single-file wiki export
Chris@1517 918 anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
Chris@1517 919 @heading_anchors[anchor] ||= 0
Chris@1517 920 idx = (@heading_anchors[anchor] += 1)
Chris@1517 921 if idx > 1
Chris@1517 922 anchor = "#{anchor}-#{idx}"
Chris@1517 923 end
Chris@1517 924 @parsed_headings << [level, anchor, item]
Chris@1517 925 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
Chris@1517 926 end
Chris@1517 927 end
Chris@1517 928
Chris@1517 929 MACROS_RE = /(
Chris@1517 930 (!)? # escaping
Chris@1517 931 (
Chris@1517 932 \{\{ # opening tag
Chris@1517 933 ([\w]+) # macro name
Chris@1517 934 (\(([^\n\r]*?)\))? # optional arguments
Chris@1517 935 ([\n\r].*?[\n\r])? # optional block of text
Chris@1517 936 \}\} # closing tag
Chris@1517 937 )
Chris@1517 938 )/mx unless const_defined?(:MACROS_RE)
Chris@1517 939
Chris@1517 940 MACRO_SUB_RE = /(
Chris@1517 941 \{\{
Chris@1517 942 macro\((\d+)\)
Chris@1517 943 \}\}
Chris@1517 944 )/x unless const_defined?(:MACRO_SUB_RE)
Chris@1517 945
Chris@1517 946 # Extracts macros from text
Chris@1517 947 def catch_macros(text)
Chris@1517 948 macros = {}
Chris@1517 949 text.gsub!(MACROS_RE) do
Chris@1517 950 all, macro = $1, $4.downcase
Chris@1517 951 if macro_exists?(macro) || all =~ MACRO_SUB_RE
Chris@1517 952 index = macros.size
Chris@1517 953 macros[index] = all
Chris@1517 954 "{{macro(#{index})}}"
Chris@1517 955 else
Chris@1517 956 all
Chris@1517 957 end
Chris@1517 958 end
Chris@1517 959 macros
Chris@1517 960 end
Chris@1517 961
Chris@1517 962 # Executes and replaces macros in text
Chris@1517 963 def inject_macros(text, obj, macros, execute=true)
Chris@1517 964 text.gsub!(MACRO_SUB_RE) do
Chris@1517 965 all, index = $1, $2.to_i
Chris@1517 966 orig = macros.delete(index)
Chris@1517 967 if execute && orig && orig =~ MACROS_RE
Chris@1517 968 esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip)
Chris@1517 969 if esc.nil?
Chris@1517 970 h(exec_macro(macro, obj, args, block) || all)
Chris@1517 971 else
Chris@1517 972 h(all)
Chris@1517 973 end
Chris@1517 974 elsif orig
Chris@1517 975 h(orig)
Chris@1517 976 else
Chris@1517 977 h(all)
Chris@1517 978 end
Chris@1517 979 end
Chris@1517 980 end
Chris@1517 981
Chris@1517 982 TOC_RE = /<p>\{\{((<|&lt;)|(>|&gt;))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
Chris@1517 983
Chris@1517 984 # Renders the TOC with given headings
Chris@1517 985 def replace_toc(text, headings)
Chris@1517 986 text.gsub!(TOC_RE) do
Chris@1517 987 left_align, right_align = $2, $3
Chris@1517 988 # Keep only the 4 first levels
Chris@1517 989 headings = headings.select{|level, anchor, item| level <= 4}
Chris@1517 990 if headings.empty?
Chris@1517 991 ''
Chris@1517 992 else
Chris@1517 993 div_class = 'toc'
Chris@1517 994 div_class << ' right' if right_align
Chris@1517 995 div_class << ' left' if left_align
Chris@1517 996 out = "<ul class=\"#{div_class}\"><li>"
Chris@1517 997 root = headings.map(&:first).min
Chris@1517 998 current = root
Chris@1517 999 started = false
Chris@1517 1000 headings.each do |level, anchor, item|
Chris@1517 1001 if level > current
Chris@1517 1002 out << '<ul><li>' * (level - current)
Chris@1517 1003 elsif level < current
Chris@1517 1004 out << "</li></ul>\n" * (current - level) + "</li><li>"
Chris@1517 1005 elsif started
Chris@1517 1006 out << '</li><li>'
Chris@1517 1007 end
Chris@1517 1008 out << "<a href=\"##{anchor}\">#{item}</a>"
Chris@1517 1009 current = level
Chris@1517 1010 started = true
Chris@1517 1011 end
Chris@1517 1012 out << '</li></ul>' * (current - root)
Chris@1517 1013 out << '</li></ul>'
Chris@1517 1014 end
Chris@1517 1015 end
Chris@1517 1016 end
Chris@1517 1017
Chris@1517 1018 # Same as Rails' simple_format helper without using paragraphs
Chris@1517 1019 def simple_format_without_paragraph(text)
Chris@1517 1020 text.to_s.
Chris@1517 1021 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
Chris@1517 1022 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
Chris@1517 1023 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
Chris@1517 1024 html_safe
Chris@1517 1025 end
Chris@1517 1026
Chris@1517 1027 def lang_options_for_select(blank=true)
Chris@1517 1028 (blank ? [["(auto)", ""]] : []) + languages_options
Chris@1517 1029 end
Chris@1517 1030
Chris@1517 1031 def label_tag_for(name, option_tags = nil, options = {})
Chris@1517 1032 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
Chris@1517 1033 content_tag("label", label_text)
Chris@1517 1034 end
Chris@1517 1035
Chris@1517 1036 def labelled_form_for(*args, &proc)
Chris@1517 1037 args << {} unless args.last.is_a?(Hash)
Chris@1517 1038 options = args.last
Chris@1517 1039 if args.first.is_a?(Symbol)
Chris@1517 1040 options.merge!(:as => args.shift)
Chris@1517 1041 end
Chris@1517 1042 options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
Chris@1517 1043 form_for(*args, &proc)
Chris@1517 1044 end
Chris@1517 1045
Chris@1517 1046 def labelled_fields_for(*args, &proc)
Chris@1517 1047 args << {} unless args.last.is_a?(Hash)
Chris@1517 1048 options = args.last
Chris@1517 1049 options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
Chris@1517 1050 fields_for(*args, &proc)
Chris@1517 1051 end
Chris@1517 1052
Chris@1517 1053 def labelled_remote_form_for(*args, &proc)
Chris@1517 1054 ActiveSupport::Deprecation.warn "ApplicationHelper#labelled_remote_form_for is deprecated and will be removed in Redmine 2.2."
Chris@1517 1055 args << {} unless args.last.is_a?(Hash)
Chris@1517 1056 options = args.last
Chris@1517 1057 options.merge!({:builder => Redmine::Views::LabelledFormBuilder, :remote => true})
Chris@1517 1058 form_for(*args, &proc)
Chris@1517 1059 end
Chris@1517 1060
Chris@1517 1061 def error_messages_for(*objects)
Chris@1517 1062 html = ""
Chris@1517 1063 objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
Chris@1517 1064 errors = objects.map {|o| o.errors.full_messages}.flatten
Chris@1517 1065 if errors.any?
Chris@1517 1066 html << "<div id='errorExplanation'><ul>\n"
Chris@1517 1067 errors.each do |error|
Chris@1517 1068 html << "<li>#{h error}</li>\n"
Chris@1517 1069 end
Chris@1517 1070 html << "</ul></div>\n"
Chris@1517 1071 end
Chris@1517 1072 html.html_safe
Chris@1517 1073 end
Chris@1517 1074
Chris@1517 1075 def delete_link(url, options={})
Chris@1517 1076 options = {
Chris@1517 1077 :method => :delete,
Chris@1517 1078 :data => {:confirm => l(:text_are_you_sure)},
Chris@1517 1079 :class => 'icon icon-del'
Chris@1517 1080 }.merge(options)
Chris@1517 1081
Chris@1517 1082 link_to l(:button_delete), url, options
Chris@1517 1083 end
Chris@1517 1084
Chris@1517 1085 def preview_link(url, form, target='preview', options={})
Chris@1517 1086 content_tag 'a', l(:label_preview), {
Chris@1517 1087 :href => "#",
Chris@1517 1088 :onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|,
Chris@1517 1089 :accesskey => accesskey(:preview)
Chris@1517 1090 }.merge(options)
Chris@1517 1091 end
Chris@1517 1092
Chris@1517 1093 def link_to_function(name, function, html_options={})
Chris@1517 1094 content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
Chris@1517 1095 end
Chris@1517 1096
Chris@1517 1097 # Helper to render JSON in views
Chris@1517 1098 def raw_json(arg)
Chris@1517 1099 arg.to_json.to_s.gsub('/', '\/').html_safe
Chris@1517 1100 end
Chris@1517 1101
Chris@1517 1102 def back_url
Chris@1517 1103 url = params[:back_url]
Chris@1517 1104 if url.nil? && referer = request.env['HTTP_REFERER']
Chris@1517 1105 url = CGI.unescape(referer.to_s)
Chris@1517 1106 end
Chris@1517 1107 url
Chris@1517 1108 end
Chris@1517 1109
Chris@1517 1110 def back_url_hidden_field_tag
Chris@1517 1111 url = back_url
Chris@1517 1112 hidden_field_tag('back_url', url, :id => nil) unless url.blank?
Chris@1517 1113 end
Chris@1517 1114
Chris@1517 1115 def check_all_links(form_name)
Chris@1517 1116 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
Chris@1517 1117 " | ".html_safe +
Chris@1517 1118 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
Chris@1517 1119 end
Chris@1517 1120
Chris@1517 1121 def progress_bar(pcts, options={})
Chris@1517 1122 pcts = [pcts, pcts] unless pcts.is_a?(Array)
Chris@1517 1123 pcts = pcts.collect(&:round)
Chris@1517 1124 pcts[1] = pcts[1] - pcts[0]
Chris@1517 1125 pcts << (100 - pcts[1] - pcts[0])
Chris@1517 1126 width = options[:width] || '100px;'
Chris@1517 1127 legend = options[:legend] || ''
Chris@1517 1128 content_tag('table',
Chris@1517 1129 content_tag('tr',
Chris@1517 1130 (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) +
Chris@1517 1131 (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) +
Chris@1517 1132 (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe)
Chris@1517 1133 ), :class => "progress progress-#{pcts[0]}", :style => "width: #{width};").html_safe +
Chris@1517 1134 content_tag('p', legend, :class => 'percent').html_safe
Chris@1517 1135 end
Chris@1517 1136
Chris@1517 1137 def checked_image(checked=true)
Chris@1517 1138 if checked
Chris@1517 1139 image_tag 'toggle_check.png'
Chris@1517 1140 end
Chris@1517 1141 end
Chris@1517 1142
Chris@1517 1143 def context_menu(url)
Chris@1517 1144 unless @context_menu_included
Chris@1517 1145 content_for :header_tags do
Chris@1517 1146 javascript_include_tag('context_menu') +
Chris@1517 1147 stylesheet_link_tag('context_menu')
Chris@1517 1148 end
Chris@1517 1149 if l(:direction) == 'rtl'
Chris@1517 1150 content_for :header_tags do
Chris@1517 1151 stylesheet_link_tag('context_menu_rtl')
Chris@1517 1152 end
Chris@1517 1153 end
Chris@1517 1154 @context_menu_included = true
Chris@1517 1155 end
Chris@1517 1156 javascript_tag "contextMenuInit('#{ url_for(url) }')"
Chris@1517 1157 end
Chris@1517 1158
Chris@1517 1159 def calendar_for(field_id)
Chris@1517 1160 include_calendar_headers_tags
Chris@1517 1161 javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });")
Chris@1517 1162 end
Chris@1517 1163
Chris@1517 1164 def include_calendar_headers_tags
Chris@1517 1165 unless @calendar_headers_tags_included
Chris@1517 1166 tags = javascript_include_tag("datepicker")
Chris@1517 1167 @calendar_headers_tags_included = true
Chris@1517 1168 content_for :header_tags do
Chris@1517 1169 start_of_week = Setting.start_of_week
Chris@1517 1170 start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
Chris@1517 1171 # Redmine uses 1..7 (monday..sunday) in settings and locales
Chris@1517 1172 # JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
Chris@1517 1173 start_of_week = start_of_week.to_i % 7
Chris@1517 1174 tags << javascript_tag(
Chris@1517 1175 "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
Chris@1517 1176 "showOn: 'button', buttonImageOnly: true, buttonImage: '" +
Chris@1517 1177 path_to_image('/images/calendar.png') +
Chris@1517 1178 "', showButtonPanel: true, showWeek: true, showOtherMonths: true, " +
Chris@1517 1179 "selectOtherMonths: true, changeMonth: true, changeYear: true, " +
Chris@1517 1180 "beforeShow: beforeShowDatePicker};")
Chris@1517 1181 jquery_locale = l('jquery.locale', :default => current_language.to_s)
Chris@1517 1182 unless jquery_locale == 'en'
Chris@1517 1183 tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js")
Chris@1517 1184 end
Chris@1517 1185 tags
Chris@1517 1186 end
Chris@1517 1187 end
Chris@1517 1188 end
Chris@1517 1189
Chris@1517 1190 # Overrides Rails' stylesheet_link_tag with themes and plugins support.
Chris@1517 1191 # Examples:
Chris@1517 1192 # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults
Chris@1517 1193 # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets
Chris@1517 1194 #
Chris@1517 1195 def stylesheet_link_tag(*sources)
Chris@1517 1196 options = sources.last.is_a?(Hash) ? sources.pop : {}
Chris@1517 1197 plugin = options.delete(:plugin)
Chris@1517 1198 sources = sources.map do |source|
Chris@1517 1199 if plugin
Chris@1517 1200 "/plugin_assets/#{plugin}/stylesheets/#{source}"
Chris@1517 1201 elsif current_theme && current_theme.stylesheets.include?(source)
Chris@1517 1202 current_theme.stylesheet_path(source)
Chris@1517 1203 else
Chris@1517 1204 source
Chris@1517 1205 end
Chris@1517 1206 end
Chris@1517 1207 super sources, options
Chris@1517 1208 end
Chris@1517 1209
Chris@1517 1210 # Overrides Rails' image_tag with themes and plugins support.
Chris@1517 1211 # Examples:
Chris@1517 1212 # image_tag('image.png') # => picks image.png from the current theme or defaults
Chris@1517 1213 # image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
Chris@1517 1214 #
Chris@1517 1215 def image_tag(source, options={})
Chris@1517 1216 if plugin = options.delete(:plugin)
Chris@1517 1217 source = "/plugin_assets/#{plugin}/images/#{source}"
Chris@1517 1218 elsif current_theme && current_theme.images.include?(source)
Chris@1517 1219 source = current_theme.image_path(source)
Chris@1517 1220 end
Chris@1517 1221 super source, options
Chris@1517 1222 end
Chris@1517 1223
Chris@1517 1224 # Overrides Rails' javascript_include_tag with plugins support
Chris@1517 1225 # Examples:
Chris@1517 1226 # javascript_include_tag('scripts') # => picks scripts.js from defaults
Chris@1517 1227 # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets
Chris@1517 1228 #
Chris@1517 1229 def javascript_include_tag(*sources)
Chris@1517 1230 options = sources.last.is_a?(Hash) ? sources.pop : {}
Chris@1517 1231 if plugin = options.delete(:plugin)
Chris@1517 1232 sources = sources.map do |source|
Chris@1517 1233 if plugin
Chris@1517 1234 "/plugin_assets/#{plugin}/javascripts/#{source}"
Chris@1517 1235 else
Chris@1517 1236 source
Chris@1517 1237 end
Chris@1517 1238 end
Chris@1517 1239 end
Chris@1517 1240 super sources, options
Chris@1517 1241 end
Chris@1517 1242
Chris@1517 1243 # TODO: remove this in 2.5.0
Chris@1517 1244 def has_content?(name)
Chris@1517 1245 content_for?(name)
Chris@1517 1246 end
Chris@1517 1247
Chris@1517 1248 def sidebar_content?
Chris@1517 1249 content_for?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
Chris@1517 1250 end
Chris@1517 1251
Chris@1517 1252 def view_layouts_base_sidebar_hook_response
Chris@1517 1253 @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
Chris@1517 1254 end
Chris@1517 1255
Chris@1517 1256 def email_delivery_enabled?
Chris@1517 1257 !!ActionMailer::Base.perform_deliveries
Chris@1517 1258 end
Chris@1517 1259
Chris@1517 1260 # Returns the avatar image tag for the given +user+ if avatars are enabled
Chris@1517 1261 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
Chris@1517 1262 def avatar(user, options = { })
Chris@1517 1263 if Setting.gravatar_enabled?
Chris@1517 1264 options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default})
Chris@1517 1265 email = nil
Chris@1517 1266 if user.respond_to?(:mail)
Chris@1517 1267 email = user.mail
Chris@1517 1268 elsif user.to_s =~ %r{<(.+?)>}
Chris@1517 1269 email = $1
Chris@1517 1270 end
Chris@1517 1271 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
Chris@1517 1272 else
Chris@1517 1273 ''
Chris@1517 1274 end
Chris@1517 1275 end
Chris@1517 1276
Chris@1517 1277 def sanitize_anchor_name(anchor)
Chris@1517 1278 if ''.respond_to?(:encoding) || RUBY_PLATFORM == 'java'
Chris@1517 1279 anchor.gsub(%r{[^\s\-\p{Word}]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
Chris@1517 1280 else
Chris@1517 1281 # TODO: remove when ruby1.8 is no longer supported
Chris@1517 1282 anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
Chris@1517 1283 end
Chris@1517 1284 end
Chris@1517 1285
Chris@1517 1286 # Returns the javascript tags that are included in the html layout head
Chris@1517 1287 def javascript_heads
Chris@1517 1288 tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application')
Chris@1517 1289 unless User.current.pref.warn_on_leaving_unsaved == '0'
Chris@1517 1290 tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
Chris@1517 1291 end
Chris@1517 1292 tags
Chris@1517 1293 end
Chris@1517 1294
Chris@1517 1295 def favicon
Chris@1517 1296 "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe
Chris@1517 1297 end
Chris@1517 1298
Chris@1517 1299 # Returns the path to the favicon
Chris@1517 1300 def favicon_path
Chris@1517 1301 icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
Chris@1517 1302 image_path(icon)
Chris@1517 1303 end
Chris@1517 1304
Chris@1517 1305 # Returns the full URL to the favicon
Chris@1517 1306 def favicon_url
Chris@1517 1307 # TODO: use #image_url introduced in Rails4
Chris@1517 1308 path = favicon_path
Chris@1517 1309 base = url_for(:controller => 'welcome', :action => 'index', :only_path => false)
Chris@1517 1310 base.sub(%r{/+$},'') + '/' + path.sub(%r{^/+},'')
Chris@1517 1311 end
Chris@1517 1312
Chris@1517 1313 def robot_exclusion_tag
Chris@1517 1314 '<meta name="robots" content="noindex,follow,noarchive" />'.html_safe
Chris@1517 1315 end
Chris@1517 1316
Chris@1517 1317 # Returns true if arg is expected in the API response
Chris@1517 1318 def include_in_api_response?(arg)
Chris@1517 1319 unless @included_in_api_response
Chris@1517 1320 param = params[:include]
Chris@1517 1321 @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
Chris@1517 1322 @included_in_api_response.collect!(&:strip)
Chris@1517 1323 end
Chris@1517 1324 @included_in_api_response.include?(arg.to_s)
Chris@1517 1325 end
Chris@1517 1326
Chris@1517 1327 # Returns options or nil if nometa param or X-Redmine-Nometa header
Chris@1517 1328 # was set in the request
Chris@1517 1329 def api_meta(options)
Chris@1517 1330 if params[:nometa].present? || request.headers['X-Redmine-Nometa']
Chris@1517 1331 # compatibility mode for activeresource clients that raise
Chris@1517 1332 # an error when unserializing an array with attributes
Chris@1517 1333 nil
Chris@1517 1334 else
Chris@1517 1335 options
Chris@1517 1336 end
Chris@1517 1337 end
Chris@1517 1338
Chris@1517 1339 private
Chris@1517 1340
Chris@1517 1341 def wiki_helper
Chris@1517 1342 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
Chris@1517 1343 extend helper
Chris@1517 1344 return self
Chris@1517 1345 end
Chris@1517 1346
Chris@1517 1347 def link_to_content_update(text, url_params = {}, html_options = {})
Chris@1517 1348 link_to(text, url_params, html_options)
Chris@1517 1349 end
Chris@1517 1350 end