# File 'app/controllers/wiki_controller.rb', line 182defdestroyreturnrender_403unlesseditable?@descendants_count=@page.descendants.sizeif@descendants_count>0caseparams[:todo]when'nullify'# Nothing to do
when'destroy'# Removes all its descendants
@page.descendants.each(&:destroy)when'reassign'# Reassign children to another parent page
reassign_to=@wiki.pages.find_by_id(params[:reassign_to_id].to_i)returnunlessreassign_to@page.children.eachdo|child|child.update_attribute(:parent,reassign_to)endelse@reassignable_to=@wiki.pages-@page.self_and_descendantsreturnendend@page.destroyredirect_to:action=>'index',:project_id=>@projectend

#preview ⇒ Object

220
221
222
223
224
225
226
227
228
229
230

# File 'app/controllers/wiki_controller.rb', line 220defpreviewpage=@wiki.find_page(params[:id])# page is nil when previewing a new page
returnrender_403unlesspage.nil?||editable?(page)ifpage@attachements=page.attachments@previewed=page.contentend@text=params[:content][:text]render:partial=>'common/preview'end

#protect ⇒ Object

#rename ⇒ Object

rename a page

138
139
140
141
142
143
144
145
146
147

# File 'app/controllers/wiki_controller.rb', line 138defrenamereturnrender_403unlesseditable?@page.redirect_existing_links=true# used to display the *original* title if some AR validation errors occur
@original_title=@page.pretty_titleifrequest.post?&&@page.update_attributes(params[:wiki_page])flash[:notice]=l(:notice_successful_update)redirect_to:action=>'show',:project_id=>@project,:id=>@page.titleendend

#show ⇒ Object

# File 'app/controllers/wiki_controller.rb', line 53defshowpage_title=params[:id]@page=@wiki.find_or_new_page(page_title)if@page.new_record?ifUser.current.allowed_to?(:edit_wiki_pages,@project)&&editable?editrender:action=>'edit'elserender_404endreturnendifparams[:version]&&!User.current.allowed_to?(:view_wiki_edits,@project)# Redirects user to the current version if he's not allowed to view previous versions
redirect_to:version=>nilreturnend@content=@page.content_for_version(params[:version])ifUser.current.allowed_to?(:export_wiki_pages,@project)ifparams[:format]=='html'export=render_to_string:action=>'export',:layout=>falsesend_data(export,:type=>'text/html',:filename=>"#{@page.title}.html")returnelsifparams[:format]=='txt'send_data(@content.text,:type=>'text/plain',:filename=>"#{@page.title}.txt")returnendend@editable=editable?end

#update ⇒ Object

# File 'app/controllers/wiki_controller.rb', line 101defupdate@page=@wiki.find_or_new_page(params[:id])returnrender_403unlesseditable?@page.content=WikiContent.new(:page=>@page)if@page.new_record?@content=@page.content_for_version(params[:version])@content.text=initial_page_content(@page)if@content.text.blank?# don't keep previous comment
@content.comments=nilif!@page.new_record?&&params[:content].present?&&@content.text==params[:content][:text]attachments=Attachment.attach_files(@page,params[:attachments])render_attachment_warning_if_needed(@page)# don't save if text wasn't changed
redirect_to:action=>'show',:project_id=>@project,:id=>@page.titlereturnendparams[:content].delete(:version)# The version count is automatically increased
@content.attributes=params[:content]@content.author=User.current# if page is new @page.save will also save content, but not if page isn't a new record
if(@page.new_record??@page.save:@content.save)attachments=Attachment.attach_files(@page,params[:attachments])render_attachment_warning_if_needed(@page)call_hook(:controller_wiki_edit_after_save,{:params=>params,:page=>@page})redirect_to:action=>'show',:project_id=>@project,:id=>@page.titleelserender:action=>'edit'endrescueActiveRecord::StaleObjectError# Optimistic locking exception
flash.now[:error]=l(:notice_locking_conflict)render:action=>'edit'end