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((wiki_categories.length==1)?(:label_wiki_category):(:label_wiki_category_plural)) %>

+ <% wiki_categories.sort.each do |category| %> + <%= link_to category, {:action => 'special', :page => 'category', :category => Wiki.titleize(category)} %>
+ <% end %> + <% end %> +<% end %> \ No newline at end of file diff -urNa redmine-0.8.3/app/views/wiki/special_category.rhtml redmine/app/views/wiki/special_category.rhtml --- redmine-0.8.3/app/views/wiki/special_category.rhtml 1970-01-01 01:00:00 +0100 +++ redmine/app/views/wiki/special_category.rhtml 2009-04-29 21:34:30 +0200 @@ -0,0 +1,23 @@ +

<%= l(:label_wiki_category) %>: <%= @category %>

+ +<% if @pages.empty? %> +

<%= l(:label_no_data) %>

+<% end %> + +<% content_for :sidebar do %> + <%= render :partial => 'sidebar' %> +<% end %> + +<% unless @pages.empty? %> +

+

<%= group = page.title[0,1].upcase %>

+

+<% end %> + diff -urNa redmine-0.8.3/config/routes.rb redmine/config/routes.rb --- redmine-0.8.3/config/routes.rb 2009-02-15 13:39:30 +0100 +++ redmine/config/routes.rb 2009-04-29 23:47:27 +0200 @@ -15,6 +15,7 @@ map.signin 'login', :controller => 'account', :action => 'login' map.signout 'logout', :controller => 'account', :action => 'logout' + map.connect 'wiki/:id/category/:category', :controller => 'wiki', :page => 'category', :action => 'special', :category => nil map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' map.connect 'help/:ctrl/:page', :controller => 'help' diff -urNa redmine-0.8.3/db/migrate/102_add_wiki_pages_categories.rb redmine/db/migrate/102_add_wiki_pages_categories.rb --- redmine-0.8.3/db/migrate/102_add_wiki_pages_categories.rb 1970-01-01 01:00:00 +0100 +++ redmine/db/migrate/102_add_wiki_pages_categories.rb 2009-04-19 19:40:12 +0200 @@ -0,0 +1,9 @@ +class AddWikiPagesCategories < ActiveRecord::Migration + def self.up + add_column :wiki_pages, :categories, :string + end + + def self.down + remove_column :wiki_pages, :categories + end +end diff -urNa redmine-0.8.3/lang/en.yml redmine/lang/en.yml --- redmine-0.8.3/lang/en.yml 2009-02-15 13:38:44 +0100 +++ redmine/lang/en.yml 2009-04-29 19:01:43 +0200 @@ -484,6 +484,8 @@ label_wiki_edit_plural: Wiki edits label_wiki_page: Wiki page label_wiki_page_plural: Wiki pages +label_wiki_category: Category +label_wiki_category_plural: Categories label_index_by_title: Index by title label_index_by_date: Index by date label_current_version: Current version diff -urNa redmine-0.8.3/lib/redmine/wiki_formatting/macros.rb redmine/lib/redmine/wiki_formatting/macros.rb --- redmine-0.8.3/lib/redmine/wiki_formatting/macros.rb 2009-02-15 13:39:30 +0100 +++ redmine/lib/redmine/wiki_formatting/macros.rb 2009-04-30 12:28:39 +0200 @@ -116,6 +116,29 @@ @included_wiki_pages.pop out end + + desc "Add the current wiki page to a category.\nExample: !{{category(Help)}}" + macro :category do |obj, args| + '' # categories are listed in the sidebar + end + + desc "Add the current wiki page to several categories.\nExample: !{{categories(Help, Snippets)}}" + macro :categories do |obj, args| + '' # categories are listed in the sidebar + end + + desc "Display a list of pages which belong to the specified category.\nExample: !{{pages_in_category(Help)}}" + macro :pages_in_category do |obj, args| + if !args.first.nil? + content_tag :ul, :class => :pages_in_category do + @wiki.find_pages_in_category(args.first).map do |p| + content_tag :li do + link_to p.pretty_title, {:action => 'index', :page => p.title} + end + end + end + end + end end end end