Patch #3274 » wiki_page_categories.patch
| redmine/app/controllers/wiki_controller.rb 2009-04-30 13:18:51 +0200 | ||
|---|---|---|
|
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
|
||
| redmine/app/helpers/application_helper.rb 2009-04-30 13:13:41 +0200 | ||
|---|---|---|
|
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:
|
||
| redmine/app/models/wiki.rb 2009-04-30 13:19:23 +0200 | ||
|---|---|---|
|
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"
|
||
| ... | ... | |
|
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
|
||
| redmine/app/models/wiki_content.rb 2009-04-30 12:23:33 +0200 | ||
|---|---|---|
|
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
|
||
| redmine/app/views/wiki/_sidebar.rhtml 2009-04-30 12:30:47 +0200 | ||
|---|---|---|
|
<%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
|
||
|
<%= link_to l(:label_index_by_title), {:action => 'special', :page => 'Page_index'} %><br />
|
||
|
<%= link_to l(:label_index_by_date), {:action => 'special', :page => 'Date_index'} %><br />
|
||
|
<% if wiki_categories = @page.categories.sub(/^\|(.*)\|$/, '\1').split('|') rescue nil %>
|
||
|
<% if (!wiki_categories.empty?) %>
|
||
|
<h3><%= l((wiki_categories.length==1)?(:label_wiki_category):(:label_wiki_category_plural)) %></h3>
|
||
|
<% wiki_categories.sort.each do |category| %>
|
||
|
<%= link_to category, {:action => 'special', :page => 'category', :category => Wiki.titleize(category)} %><br />
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
| redmine/app/views/wiki/special_category.rhtml 2009-04-29 21:34:30 +0200 | ||
|---|---|---|
|
<h2><%= l(:label_wiki_category) %>: <%= @category %></h2>
|
||
|
<% if @pages.empty? %>
|
||
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||
|
<% end %>
|
||
|
<% content_for :sidebar do %>
|
||
|
<%= render :partial => 'sidebar' %>
|
||
|
<% end %>
|
||
|
<% unless @pages.empty? %>
|
||
|
<p>
|
||
|
<ul>
|
||
|
<% @pages.each do |page| %>
|
||
|
<% if page.title[0,1].upcase != (group rescue nil) %>
|
||
|
</ul><h4><%= group = page.title[0,1].upcase %></h4><ul>
|
||
|
<% end %>
|
||
|
<li><%= link_to page.pretty_title, {:action => 'index', :page => page.title} %></li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
</p>
|
||
|
<% end %>
|
||
| redmine/config/routes.rb 2009-04-29 23:47:27 +0200 | ||
|---|---|---|
|
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'
|
||
| redmine/db/migrate/102_add_wiki_pages_categories.rb 2009-04-19 19:40:12 +0200 | ||
|---|---|---|
|
class AddWikiPagesCategories < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
add_column :wiki_pages, :categories, :string
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :wiki_pages, :categories
|
||
|
end
|
||
|
end
|
||
| redmine/lang/en.yml 2009-04-29 19:01:43 +0200 | ||
|---|---|---|
|
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
|
||
| redmine/lib/redmine/wiki_formatting/macros.rb 2009-04-30 12:28:39 +0200 | ||
|---|---|---|
|
@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
|
||