Class: WikiController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- WikiController
- Defined in:
- app/controllers/wiki_controller.rb
Constant Summary
Constants inherited from ApplicationController
ApplicationController::FILE_TYPES
Instance Method Summary collapse
-
#authenticate ⇒ Object
Outside a single web ——————————————————–.
-
#authors ⇒ Object
Within a single web ———————————————————.
-
#cancel_edit ⇒ Object
Within a single page ——————————————————–.
- #edit ⇒ Object
- #export_html ⇒ Object
- #export_markup ⇒ Object
- #export_pdf ⇒ Object
- #export_tex ⇒ Object
- #feeds ⇒ Object
- #index ⇒ Object
- #list ⇒ Object
- #locked ⇒ Object
- #login ⇒ Object
- #new ⇒ Object
- #pdf ⇒ Object
- #print ⇒ Object
- #published ⇒ Object
- #recently_revised ⇒ Object
- #revision ⇒ Object
- #rollback ⇒ Object
- #rss_with_content ⇒ Object
- #rss_with_headlines ⇒ Object
- #save ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #tex ⇒ Object
- #web_list ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#authenticate ⇒ Object
Outside a single web ——————————————————–
24 25 26 27 28 29 30 31 |
# File 'app/controllers/wiki_controller.rb', line 24 def authenticate if password_check(@params['password']) redirect_home else flash[:info] = password_error(@params['password']) redirect_to :action => 'login', :web => @web_name end end |
#authors ⇒ Object
Within a single web ———————————————————
44 45 46 |
# File 'app/controllers/wiki_controller.rb', line 44 def @authors = @web.select..sort end |
#cancel_edit ⇒ Object
Within a single page ——————————————————–
118 119 120 121 |
# File 'app/controllers/wiki_controller.rb', line 118 def cancel_edit @page.unlock redirect_to_page(@page_name) end |
#edit ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/wiki_controller.rb', line 123 def edit if @page.nil? redirect_home elsif @page.locked?(Time.now) and not @params['break_lock'] redirect_to :web => @web_name, :action => 'locked', :id => @page_name else @page.lock(Time.now, @author) end end |
#export_html ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/wiki_controller.rb', line 48 def export_html export_pages_as_zip('html') do |page| @page = page @link_mode = :export render_to_string('wiki/print', use_layout = (@params['layout'] != 'no')) end end |
#export_markup ⇒ Object
56 57 58 |
# File 'app/controllers/wiki_controller.rb', line 56 def export_markup export_pages_as_zip(@web.markup) { |page| page.content } end |
#export_pdf ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/controllers/wiki_controller.rb', line 60 def export_pdf file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}" file_path = File.join(@wiki.storage_path, file_name) export_web_to_tex "#{file_path}.tex" unless FileTest.exists? "#{file_path}.tex" convert_tex_to_pdf "#{file_path}.tex" send_file "#{file_path}.pdf" end |
#export_tex ⇒ Object
69 70 71 72 73 74 |
# File 'app/controllers/wiki_controller.rb', line 69 def export_tex file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}.tex" file_path = File.join(@wiki.storage_path, file_name) export_web_to_tex(file_path) unless FileTest.exists?(file_path) send_file file_path end |
#feeds ⇒ Object
76 77 78 79 |
# File 'app/controllers/wiki_controller.rb', line 76 def feeds @rss_with_content_allowed = rss_with_content_allowed? # show the template end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/wiki_controller.rb', line 10 def index if @web_name redirect_home elsif not @wiki.setup? redirect_to :controller => 'admin', :action => 'create_system' elsif @wiki.webs.length == 1 redirect_home @wiki.webs.values.first.address else redirect_to :action => 'web_list' end end |
#list ⇒ Object
81 82 83 84 85 86 |
# File 'app/controllers/wiki_controller.rb', line 81 def list parse_category @pages_by_name = @pages_in_category.by_name @page_names_that_are_wanted = @pages_in_category.wanted_pages @pages_that_are_orphaned = @pages_in_category.orphaned_pages end |
#locked ⇒ Object
133 134 135 |
# File 'app/controllers/wiki_controller.rb', line 133 def locked # to template end |
#login ⇒ Object
33 34 35 |
# File 'app/controllers/wiki_controller.rb', line 33 def login # to template end |
#new ⇒ Object
137 138 139 |
# File 'app/controllers/wiki_controller.rb', line 137 def new # to template end |
#pdf ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/controllers/wiki_controller.rb', line 141 def pdf page = wiki.read_page(@web_name, @page_name) safe_page_name = @page.name.gsub(/\W/, '') file_name = "#{safe_page_name}-#{@web.address}-#{@page.created_at.strftime('%Y-%m-%d-%H-%M-%S')}" file_path = File.join(@wiki.storage_path, file_name) export_page_to_tex("#{file_path}.tex") unless FileTest.exists?("#{file_path}.tex") # NB: this is _very_ slow convert_tex_to_pdf("#{file_path}.tex") send_file "#{file_path}.pdf" end |
#print ⇒ Object
153 154 155 156 |
# File 'app/controllers/wiki_controller.rb', line 153 def print @link_mode ||= :show # to template end |
#published ⇒ Object
158 159 160 161 162 163 164 |
# File 'app/controllers/wiki_controller.rb', line 158 def published if @web.published @page = wiki.read_page(@web_name, @page_name || 'HomePage') else redirect_home end end |
#recently_revised ⇒ Object
88 89 90 91 |
# File 'app/controllers/wiki_controller.rb', line 88 def recently_revised parse_category @pages_by_revision = @pages_in_category.by_revision end |
#revision ⇒ Object
166 167 168 |
# File 'app/controllers/wiki_controller.rb', line 166 def revision get_page_and_revision end |
#rollback ⇒ Object
170 171 172 |
# File 'app/controllers/wiki_controller.rb', line 170 def rollback get_page_and_revision end |
#rss_with_content ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'app/controllers/wiki_controller.rb', line 93 def rss_with_content if rss_with_content_allowed? render_rss(hide_description = false, *parse_rss_params) else render_text 'RSS feed with content for this web is blocked for security reasons. ' + 'The web is password-protected and not published', '403 Forbidden' end end |
#rss_with_headlines ⇒ Object
102 103 104 |
# File 'app/controllers/wiki_controller.rb', line 102 def rss_with_headlines render_rss(hide_description = true, *parse_rss_params) end |
#save ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/controllers/wiki_controller.rb', line 174 def save redirect_home if @page_name.nil? ['author'] = @params['author'] begin if @page wiki.revise_page(@web_name, @page_name, @params['content'], Time.now, Author.new(@params['author'], remote_ip)) @page.unlock else wiki.write_page(@web_name, @page_name, @params['content'], Time.now, Author.new(@params['author'], remote_ip)) end redirect_to_page @page_name rescue => e flash[:error] = e flash[:content] = @params['content'] if @page @page.unlock redirect_to :action => 'edit', :web => @web_name, :id => @page_name else redirect_to :action => 'new', :web => @web_name, :id => @page_name end end end |
#search ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/wiki_controller.rb', line 106 def search @query = @params['query'] @title_results = @web.select { |page| page.name =~ /#{@query}/i }.sort @results = @web.select { |page| page.content =~ /#{@query}/i }.sort all_pages_found = (@results + @title_results).uniq if all_pages_found.size == 1 redirect_to_page(all_pages_found.first.name) end end |
#show ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/controllers/wiki_controller.rb', line 200 def show if @page begin render_action 'page' # TODO this rescue should differentiate between errors due to rendering and errors in # the application itself (for application errors, it's better not to rescue the error at all) rescue => e logger.error e flash[:error] = e. if in_a_web? redirect_to :action => 'edit', :web => @web_name, :id => @page_name else raise e end end else if not @page_name.nil? and not @page_name.empty? redirect_to :web => @web_name, :action => 'new', :id => @page_name else render_text 'Page name is not specified', '404 Not Found' end end end |
#tex ⇒ Object
224 225 226 |
# File 'app/controllers/wiki_controller.rb', line 224 def tex @tex_content = RedClothForTex.new(@page.content).to_tex end |
#web_list ⇒ Object
37 38 39 |
# File 'app/controllers/wiki_controller.rb', line 37 def web_list @webs = wiki.webs.values.sort_by { |web| web.name } end |