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