| Class | PagesController |
| In: |
app/controllers/pages_controller.rb
|
| Parent: | ApplicationController |
| FLASH_CHECKIN_SUCCESS | = | "Check-in succesfull, please add or update the version note!" |
Action checkin to checkin a page that is checked-out TODO force post method
# File app/controllers/pages_controller.rb, line 150
150: def checkin
151: if params[:checkout_id]
152: logger.info("Finding checkout with id #{params[:checkout_id]}")
153: co = Checkout.find(params[:checkout_id])
154: @version = co.version
155: @wiki = co.site
156: @page = co.page
157: co.checkin(session['user'], params[:html])
158: raise "Failed to checkin #{checkout.id}" if Checkout.exists?(co.id)
159: flash.now['success'] = FLASH_CHECKIN_SUCCESS
160: users = (User.find(:all, :conditions => ['notify_immediate=?', 1]) + Notification.find_all_users(@page, Page.name)).uniq
161: unless users.empty?
162: subject = "New version created of #{@version.page.presentation_name}"
163: introduction = "User #{@version.user.name} created a version of <a href=\"#{@version.page.url(true, request.host + (request.port == 80 ? '' : ':' + request.port.to_s))}\">#{@version.page.presentation_name}</a> in site #{@version.wiki.title}<br>"
164: Notifier::deliver_notification(users,subject,introduction, @version.note, request.host + (request.port == 80 ? '' : ':' + request.port.to_s))
165: end
166: #redirect_to :controller => 'versions', :action => 'edit', :id => version.id
167: if @version.template?
168: # Because we use note field to cache the brief description of a template
169: # the field should be empty. Maybe we should rethink this use of the note field
170: @version.note = ''
171: @version.save!
172: redirect_to '/' + @version.wiki.rel_path + '/' + @version.page.rel_path
173: end
174: else
175: logger.debug("Updating version note using params #{params.inspect}")
176: @version = Version.find(params[:version][:id])
177: @wiki = @version.wiki
178: @page = @version.page
179: if mine?(@version) || cadmin?
180: #@version.note = params[:version][:note]
181: if @version.update_attributes(params[:version])
182: flash['notice'] = ::FLASH_RECORD_UPDATED
183: #redirect_to :action => 'list', :site_id => @version.site_id, :page_id => @version.page_id
184: redirect_to '/' + @version.wiki.rel_path + '/' + @version.page.rel_path
185: end
186: else
187: flash.now['error'] = ::FLASH_NOT_OWNER
188: end
189: end
190: end
Action checkout to create a new checkout
# File app/controllers/pages_controller.rb, line 99
99: def checkout
100: if request.get?
101: @version = UserVersion.new
102: @page = Page.find(params[:id])
103: @wiki = @page.site
104: #--
105: #@wiki = Wiki.find_by_folder(params[:site_folder])
106: # TODO these kind of statement are no longer necessary,
107: # do global search and replace
108: #++
109: @version.wiki = @wiki
110: co = @page.checkout
111: if co
112: redirect_to :action => 'edit', :checkout_id => co.id
113: else
114: @version.source_version = @page.current_version
115: end
116: else
117: logger.info("Creating new checkout using params #{params[:version].inspect}")
118: @version = UserVersion.new(params[:version])
119: @page = @version.source_version.page
120: @wiki = @page.site
121: co = Checkout.new(:note => @version.note, :page => @page, :site => @wiki, :source_version => @version.source_version, :user => session['user'], :version => @version )
122: if co.save
123: redirect_to :action => 'edit', :checkout_id => co.id
124: else
125: logger.info("Failed to save checkout #{co.inspect}")
126: end
127: end
128: @versions = @page.versions
129: end
TODO Implement test
# File app/controllers/pages_controller.rb, line 244
244: def destroy
245: @page = Page.find(params[:id])
246: #paths.each {|path| File.delete(path) if File.exists?(path)} # decided not to delete the files
247: Checkout.destroy_all(['page_id=?', @page.id])
248: Comment.destroy_all(['page_id=?', @page.id])
249: Notification.destroy_all(['page_id=?', @page.id])
250: Version.destroy_all(['page_id=?', @page.id])
251: @page.destroy
252: flash['success'] = "Page #{@page.presentation_name}deleted!"
253: redirect_to request.referer
254: end
# File app/controllers/pages_controller.rb, line 63
63: def discussion
64: if request.get?
65: @wiki = Wiki.find_by_folder(params[:site_folder])
66: @page = Page.find(params[:id])
67: @comment = Comment.new(:site => @wiki, :page => @page)
68: else
69: @comment = Comment.new(params[:comment].merge(:user => session['user']))
70: @page = @comment.page
71: @wiki = @page.site
72: @comment.version = @page.current_version
73: if @comment.save
74: redirect_to :controller => 'pages', :site_folder => @wiki.folder, :id => @page.id, :action => 'discussion'
75: users = (User.find(:all, :conditions => ['notify_immediate=?', 1]) + Notification.find_all_users(@page, Page.name)).uniq
76: unless users.empty?
77: subject = "New comment about #{@page.presentation_name}"
78: introduction = "User #{@comment.user.name} created a comment about <a href=\"#{@comment.page.url(true, request.host + (request.port == 80 ? '' : ':' + request.port.to_s))}\">#{@comment.page.presentation_name}</a> in site #{@comment.site.title}<br>"
79: Notifier::deliver_notification(users,subject,introduction, @comment.text, request.host + (request.port == 80 ? '' : ':' + request.port.to_s))
80: end
81: end
82: end
83: @comments = Comment.find(:all, :conditions => ["page_id=? and site_id=?", @page.id, @wiki.id], :order => 'created_on ASC')
84: end
# File app/controllers/pages_controller.rb, line 86
86: def edit
87: if params[:checkout_id]
88: @checkout = Checkout.find(params[:checkout_id])
89: @page = @checkout.page
90: @wiki = @checkout.site
91: render :layout => false
92: else
93: # TODO this is not used?
94: redirect_to :action => 'checkout', :id => params[:id], :site_folder => params[:site_folder]
95: end
96: end
# File app/controllers/pages_controller.rb, line 256
256: def history
257: @page = Page.find(params[:id])
258: @wiki = Wiki.find_by_folder(params[:site_folder])
259: @versions = @page.versions
260: @versions << @page.checkout.version unless @page.checkout.nil?
261: @other_versions = Version.find(:all, :conditions => ['wiki_id<>? and page_id=?', @wiki.id, @page.id], :order=> 'wiki_id, version ASC')
262: end
Action new to create a new Page based on a template or based on another page.
# File app/controllers/pages_controller.rb, line 193
193: def new
194: if request.get?
195: @wiki = Wiki.find_by_folder(params[:site_folder])
196: @page = Page.find(params[:id])
197: version = @page.current_version
198: version.save! if version.version == 0
199: @new_page = Page.new
200: @new_page.source_version = version.id # TODO a better name would be source_version_id?
201: else
202: logger.info("Creating new page with #{params.inspect}")
203: @page = Page.find(params[:id])
204: @wiki = Wiki.find_by_folder(params[:site_folder])
205: @templates = []
206: version = Version.find(params[:page][:source_version])
207: @new_page, @checkout = WikiPage.new_using_template(params[:page].merge(:user=> session['user'], :site => @wiki, :source_version => version))
208: if @new_page.save
209: if @checkout
210: redirect_to :action => 'edit', :checkout_id => @checkout.id
211: end
212: end
213: # TODO his will cause an error in new.rhtml. Implement test
214: end
215: @templates = Site.templates
216: @templates = [version] + @templates
217:
218: end
# File app/controllers/pages_controller.rb, line 264
264: def rollback
265: unless params[:version].nil?
266: to = Version.find(params[:version][:version_id])
267: if to.page.checkout.nil?
268: co = Checkout.new(:user => session['user'], :page => to.page, :site => to.wiki, :source_version => to, :note => "Rollback to version #{to.version}")
269: if co.save
270: co.checkin(session['user'])
271: flash['success'] = 'Rollback complete'
272: else
273: flash['error'] = 'Rollback failed'
274: end
275: else
276: flash['error'] = 'Cannot rollback checked out page'
277: end
278: redirect_to :action => 'history', :id => to.page.id, :site_folder => to.wiki.folder
279: end
280: end
save the HTML after checking that the User is the owner. The Page remains checked-out.
# File app/controllers/pages_controller.rb, line 132
132: def save
133: @checkout = Checkout.find(params[:checkout_id])
134: raise LoginController::FLASH_UNOT_CADMIN if !mine?(@checkout) && !cadmin?
135: @checkout.version.html = params[:html]
136: @checkout.version.save
137: if params[:action] == 'save'
138: redirect_to :action => 'edit', :checkout_id => @checkout.id
139: else
140: redirect_to(url_for('/' + @checkout.version.rel_path_root))
141: end
142: end
# File app/controllers/pages_controller.rb, line 282
282: def text
283: @page = Page.find(params[:id])
284: render :inline => "<%= (simple_format(strip_tags(@page.html))) %>", :layout => false
285: end
# File app/controllers/pages_controller.rb, line 223
223: def undocheckout
224: co = Checkout.find(params[:checkout_id])
225: page = co.page
226: wiki = co.site
227: if mine?(co) || cadmin?
228: co.undo
229: if Checkout.exists?(co.id)
230: raise "Failed to undo checkout #{co.id} of page #{co.page.presentation_name}"
231: else
232: if Page.exists?(page.id)
233: redirect_to page.url
234: else
235: redirect_to wiki.pages[0].url
236: end
237: end
238: else
239: raise "This checkout is owned by #{co.user.name}. You cannot undo a checkout that belongs to another user"
240: end
241: end
# File app/controllers/pages_controller.rb, line 31
31: def view
32: #--
33: # TODO add 'Compare with previous' link
34: #++
35: logger.debug("params[:url]:" + params[:url])
36: s3,s4,s5 = params[:url].split('/').values_at(2,3,4)
37: @rel_path = params[:url].sub("http://#{s3}/#{s4}/#{s5}/", '').split('?')[0] # url sometimes contains a parameter!
38: logger.debug("Finding wiki by folder #{s4}")
39: @wiki = Wiki.find_by_folder(s5)
40: @page = WikiPage.find_by_rel_path_and_site_id(@rel_path, @wiki.id)
41: if @page
42: logger.debug("Page found")
43: @version = @page.current_version
44: @comments = Comment.find(:all, :conditions => ["page_id=? and site_id=?", @page.id, @wiki.id], :order => 'created_on ASC')
45: @checkout = @page.checkout
46: logger.debug("@version: #{@version.inspect}")
47: @contributor_names = @page.contributors
48: end
49: headers["Content-Type"] = 'text/javascript'
50: render :update do |page|
51: page.replace_html 'epfwiki_header', :partial => 'header'
52: page.replace_html 'epfwiki_footer', :partial => 'footer'
53: if @checkout
54: if @version
55: page.replace_html 'checkout_text', :inline => "<%= image_tag('notice.png', :align => 'middle') %> This page is currently being modified by <%= @checkout.user.name %>"
56: else
57: page.replace_html 'checkout_text', :inline => "<%= image_tag('notice.png', :align => 'middle') %> This page is currently being created by <%= @checkout.user.name %>"
58: end
59: end
60: end
61: end