@@ -1,111 +1,111 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class WikiController < ApplicationController |
|
18 | class WikiController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :find_wiki, :check_project_privacy, :except => [:preview] |
|
20 | before_filter :find_wiki, :check_project_privacy, :except => [:preview] | |
21 |
|
21 | |||
22 | # display a page (in editing mode if it doesn't exist) |
|
22 | # display a page (in editing mode if it doesn't exist) | |
23 | def index |
|
23 | def index | |
24 | page_title = params[:page] |
|
24 | page_title = params[:page] | |
25 | @page = @wiki.find_or_new_page(page_title) |
|
25 | @page = @wiki.find_or_new_page(page_title) | |
26 | if @page.new_record? |
|
26 | if @page.new_record? | |
27 | edit |
|
27 | edit | |
28 | render :action => 'edit' and return |
|
28 | render :action => 'edit' and return | |
29 | end |
|
29 | end | |
30 | @content = (params[:version] ? @page.content.versions.find_by_version(params[:version]) : @page.content) |
|
30 | @content = (params[:version] ? @page.content.versions.find_by_version(params[:version]) : @page.content) | |
31 | if params[:export] == 'html' |
|
31 | if params[:export] == 'html' | |
32 | export = render_to_string :action => 'export', :layout => false |
|
32 | export = render_to_string :action => 'export', :layout => false | |
33 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") |
|
33 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") | |
34 | return |
|
34 | return | |
35 | elsif params[:export] == 'txt' |
|
35 | elsif params[:export] == 'txt' | |
36 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
|
36 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") | |
37 | return |
|
37 | return | |
38 | end |
|
38 | end | |
39 | render :action => 'show' |
|
39 | render :action => 'show' | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | # edit an existing page or a new one |
|
42 | # edit an existing page or a new one | |
43 | def edit |
|
43 | def edit | |
44 | @page = @wiki.find_or_new_page(params[:page]) |
|
44 | @page = @wiki.find_or_new_page(params[:page]) | |
45 | @page.content = WikiContent.new(:page => @page) if @page.new_record? |
|
45 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
46 | @content = @page.content |
|
46 | @content = @page.content | |
47 |
@content.text = "h1. #{@page.pretty_title}" if @content.text. |
|
47 | @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? | |
48 | # don't keep previous comment |
|
48 | # don't keep previous comment | |
49 | @content.comment = nil |
|
49 | @content.comment = nil | |
50 | if request.post? |
|
50 | if request.post? | |
51 | if @content.text == params[:content][:text] |
|
51 | if @content.text == params[:content][:text] | |
52 | # don't save if text wasn't changed |
|
52 | # don't save if text wasn't changed | |
53 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
53 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
54 | return |
|
54 | return | |
55 | end |
|
55 | end | |
56 | @content.text = params[:content][:text] |
|
56 | @content.text = params[:content][:text] | |
57 | @content.comment = params[:content][:comment] |
|
57 | @content.comment = params[:content][:comment] | |
58 | @content.author = logged_in_user |
|
58 | @content.author = logged_in_user | |
59 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
59 | # if page is new @page.save will also save content, but not if page isn't a new record | |
60 | if (@page.new_record? ? @page.save : @content.save) |
|
60 | if (@page.new_record? ? @page.save : @content.save) | |
61 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
61 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
62 | end |
|
62 | end | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | # show page history |
|
66 | # show page history | |
67 | def history |
|
67 | def history | |
68 | @page = @wiki.find_page(params[:page]) |
|
68 | @page = @wiki.find_page(params[:page]) | |
69 | # don't load text |
|
69 | # don't load text | |
70 | @versions = @page.content.versions.find :all, |
|
70 | @versions = @page.content.versions.find :all, | |
71 | :select => "id, author_id, comment, updated_on, version", |
|
71 | :select => "id, author_id, comment, updated_on, version", | |
72 | :order => 'version DESC' |
|
72 | :order => 'version DESC' | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | # display special pages |
|
75 | # display special pages | |
76 | def special |
|
76 | def special | |
77 | page_title = params[:page].downcase |
|
77 | page_title = params[:page].downcase | |
78 | case page_title |
|
78 | case page_title | |
79 | # show pages index, sorted by title |
|
79 | # show pages index, sorted by title | |
80 | when 'page_index' |
|
80 | when 'page_index' | |
81 | # eager load information about last updates, without loading text |
|
81 | # eager load information about last updates, without loading text | |
82 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", |
|
82 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
83 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", |
|
83 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", | |
84 | :order => 'title' |
|
84 | :order => 'title' | |
85 | # export wiki to a single html file |
|
85 | # export wiki to a single html file | |
86 | when 'export' |
|
86 | when 'export' | |
87 | @pages = @wiki.pages.find :all, :order => 'title' |
|
87 | @pages = @wiki.pages.find :all, :order => 'title' | |
88 | export = render_to_string :action => 'export_multiple', :layout => false |
|
88 | export = render_to_string :action => 'export_multiple', :layout => false | |
89 | send_data(export, :type => 'text/html', :filename => "wiki.html") |
|
89 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
90 | return |
|
90 | return | |
91 | else |
|
91 | else | |
92 | # requested special page doesn't exist, redirect to default page |
|
92 | # requested special page doesn't exist, redirect to default page | |
93 | redirect_to :action => 'index', :id => @project, :page => nil and return |
|
93 | redirect_to :action => 'index', :id => @project, :page => nil and return | |
94 | end |
|
94 | end | |
95 | render :action => "special_#{page_title}" |
|
95 | render :action => "special_#{page_title}" | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def preview |
|
98 | def preview | |
99 | @text = params[:content][:text] |
|
99 | @text = params[:content][:text] | |
100 | render :partial => 'preview' |
|
100 | render :partial => 'preview' | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | private |
|
103 | private | |
104 |
|
104 | |||
105 | def find_wiki |
|
105 | def find_wiki | |
106 | @project = Project.find(params[:id]) |
|
106 | @project = Project.find(params[:id]) | |
107 | @wiki = @project.wiki |
|
107 | @wiki = @project.wiki | |
108 | rescue ActiveRecord::RecordNotFound |
|
108 | rescue ActiveRecord::RecordNotFound | |
109 | render_404 |
|
109 | render_404 | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end |
General Comments 0
You need to be logged in to leave comments.
Login now