diff -urNa redmine-0.8.3/app/controllers/wiki_controller.rb redmine/app/controllers/wiki_controller.rb
--- redmine-0.8.3/app/controllers/wiki_controller.rb 2009-02-15 13:38:43 +0100
+++ redmine/app/controllers/wiki_controller.rb 2009-04-30 13:18:51 +0200
@@ -156,6 +156,9 @@
export = render_to_string :action => 'export_multiple', :layout => false
send_data(export, :type => 'text/html', :filename => "wiki.html")
return
+ when 'category'
+ @category = params[:category].gsub(/_/, ' ')
+ @pages = @wiki.find_pages_in_category(@category)
else
# requested special page doesn't exist, redirect to default page
redirect_to :action => 'index', :id => @project, :page => nil and return
diff -urNa redmine-0.8.3/app/helpers/application_helper.rb redmine/app/helpers/application_helper.rb
--- redmine-0.8.3/app/helpers/application_helper.rb 2009-04-18 11:54:06 +0200
+++ redmine/app/helpers/application_helper.rb 2009-04-30 13:13:41 +0200
@@ -320,6 +320,32 @@
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
+ # Wiki category links
+ #
+ # Examples:
+ # [[category:mycategory]]
+ # [[category:mycategory|mytext]]
+ # wiki links can refer other project wikis, using project name or identifier:
+ # [[myproject:category:mycategory]]
+ # [[myproject:category:mycategory|mytext]]
+ text = text.gsub(/(!)?(\[\[(?:(.+?):)?category:(.+?)(?:\|(.+?))?\]\])/) do |m|
+ esc, all, link_project, category, title = $1, $2, $3, $4, $5
+ if esc.nil?
+ if link_project.nil?
+ link_project = project
+ else
+ link_project = Project.find_by_name(link_project) || Project.find_by_identifier(link_project)
+ end
+ if link_project && link_project.wiki
+ link_to((title || category), :only_path => only_path, :controller => 'wiki', :id => project, :action => 'special', :page => 'category', :category => Wiki.titleize(category))
+ else
+ title || category
+ end
+ else
+ '!' + all
+ end
+ end
+
# Wiki links
#
# Examples:
diff -urNa redmine-0.8.3/app/models/wiki.rb redmine/app/models/wiki.rb
--- redmine-0.8.3/app/models/wiki.rb 2009-02-15 13:38:43 +0100
+++ redmine/app/models/wiki.rb 2009-04-30 13:19:23 +0200
@@ -42,6 +42,11 @@
end
page
end
+
+ # find pages which belong to a certain category
+ def find_pages_in_category(category)
+ pages.find :all, :conditions => [ "LOWER(categories) LIKE LOWER(?)", "%|#{category.downcase}|%"], :order=> 'title'
+ end
# Finds a page by title
# The given string can be of one of the forms: "title" or "project:title"
@@ -62,12 +67,16 @@
end
end
+ def self.upcase_first(title)
+ title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
+ end
+
# turn a string into a valid page title
def self.titleize(title)
# replace spaces with _ and remove unwanted caracters
title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
# upcase the first letter
- title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
+ title = self.upcase_first(title)
title
end
end
diff -urNa redmine-0.8.3/app/models/wiki_content.rb redmine/app/models/wiki_content.rb
--- redmine-0.8.3/app/models/wiki_content.rb 2009-02-15 13:38:43 +0100
+++ redmine/app/models/wiki_content.rb 2009-04-30 12:23:33 +0200
@@ -22,6 +22,20 @@
belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id'
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :text
+
+ def after_save
+ page.categories = categories.join('|')
+ page.categories = '|' + page.categories + '|' if !categories.empty?
+ page.save!
+ end
+
+ def categories
+ if text.match(/\{\{categor(?:y|ies)\((.+?)\)\}\}/)
+ $1.split(/\s*,\s*/).map { |c| Wiki.upcase_first(c) }
+ else
+ []
+ end
+ end
acts_as_versioned
class Version
diff -urNa redmine-0.8.3/app/views/wiki/_sidebar.rhtml redmine/app/views/wiki/_sidebar.rhtml
--- redmine-0.8.3/app/views/wiki/_sidebar.rhtml 2008-04-24 21:13:04 +0200
+++ redmine/app/views/wiki/_sidebar.rhtml 2009-04-30 12:30:47 +0200
@@ -3,3 +3,12 @@
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %>
<%= link_to l(:label_index_by_title), {:action => 'special', :page => 'Page_index'} %>
<%= link_to l(:label_index_by_date), {:action => 'special', :page => 'Date_index'} %>
+
+<% if wiki_categories = @page.categories.sub(/^\|(.*)\|$/, '\1').split('|') rescue nil %>
+ <% if (!wiki_categories.empty?) %>
+
<%= l(:label_no_data) %>
+<% end %> + +<% content_for :sidebar do %> + <%= render :partial => 'sidebar' %> +<% end %> + +<% unless @pages.empty? %> ++