Ticket #69: patch.69.diff
| File patch.69.diff, 8.7 kB (added by anonymous, 3 years ago) |
|---|
-
test/functional/wiki_controller_test.rb
old new 238 238 239 239 def test_locked 240 240 @home.lock(Time.now, 'Locky') 241 r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage' )241 r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage', 'attempted_action' => 'test') 242 242 assert_success 243 243 assert_equal @home, r.template_objects['page'] 244 244 end -
app/models/web.rb
old new 49 49 page.revise(content, created_at, author) 50 50 @pages[page.name] = page 51 51 end 52 53 def rename_page(old_name, new_name, renamed_at, author) 54 # Ensures we are not overwriting another page 55 if @pages.has_key?(new_name) 56 raise Instiki::ValidationError.new("A page named #{new_name} already exists") 57 end 58 59 page = @pages[old_name] 60 61 page.references.each { |referencing_page| 62 referencing_page.change_all_references(old_name, new_name) 63 } 64 65 page.rename(new_name, renamed_at, author) 66 67 @pages[new_name] = page 68 @pages.delete(old_name) 69 refresh_pages_with_references(old_name) 70 refresh_pages_with_references(new_name) 71 end 52 72 53 73 def address=(the_address) 54 74 if the_address != CGI.escape(the_address) -
app/models/revision.rb
old new 124 124 end 125 125 end 126 126 127 def change_all_references(old_name, new_name) 128 new_name = "[[" + new_name + "]]" 129 @content.gsub!( /\[\[#{old_name}\]\]/, new_name ) 130 131 #if do_not_only_use_bracketted_names 132 @content.gsub!( /\b#{old_name}\b/, new_name ) 133 #end 134 end 135 127 136 end -
app/models/wiki_service.rb
old new 88 88 page.revise(content, revised_on, author) 89 89 end 90 90 91 def rename_page(web_address, page_name, new_page_name, renamed_on, author) 92 @webs[web_address].rename_page(page_name, new_page_name, renamed_on, author) 93 end 94 91 95 def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) 92 96 page = read_page(web_address, page_name) 93 97 page.rollback(revision_number, created_at, author_id) -
app/models/page.rb
old new 51 51 52 52 end 53 53 54 def rename(new_name, renamed_at, author) 55 56 if new_name == @name 57 raise Instiki::ValidationError.new( 58 "The new name '#{new_name}' is the same as the old name") 59 end 60 61 # If there exists such a thing as an "invalid name," here would be the place to check 62 63 # Renames are not included in the revision history, so only the current revision need be changed 64 old_name = @name 65 @name = new_name 66 67 @revisions.last.created_at = created_at 68 @revisions.last.clear_display_cache 69 70 self.revisions.last.force_rendering 71 # at this point the page may not be inserted in the web yet, and therefore 72 # references to the page itself are rendered as "unresolved". Clearing the cache allows 73 # the page to re-render itself once again, hopefully _after_ it is inserted in the web 74 self.revisions.last.clear_display_cache 75 76 self 77 78 end 79 80 def change_all_references(old_name, new_name) 81 revisions.each { |rev| 82 rev.change_all_references(old_name, new_name) 83 } 84 end 85 54 86 def rollback(revision_number, created_at, author_ip = nil) 55 87 roll_back_revision = @revisions[revision_number].dup 56 88 revise(roll_back_revision.content, created_at, Author.new(roll_back_revision.author, author_ip)) -
app/controllers/wiki_controller.rb
old new 113 113 end 114 114 end 115 115 116 def perform_rename 117 redirect_home if @page_name.nil? 118 redirect_home if @page.nil? 119 cookies['author'] = @params['author'] 120 121 begin 122 wiki.rename_page(@web_name, @page_name, @params['newPageName'], 123 Time.now, Author.new(@params['author'], remote_ip)) 124 @page.unlock 125 redirect_to_page @params['newPageName'] 126 rescue => e 127 flash[:error] = e 128 flash[:newPageName] = @params['newPageName'] 129 @page.unlock 130 redirect_to :action => 'rename', :web => @web_name, :id => @page_name 131 end 132 end 133 116 134 # Within a single page -------------------------------------------------------- 117 135 118 136 def cancel_edit … … 124 142 if @page.nil? 125 143 redirect_home 126 144 elsif @page.locked?(Time.now) and not @params['break_lock'] 127 redirect_to :web => @web_name, :action => 'locked', :id => @page_name 145 redirect_to :web => @web_name, :action => 'locked', :id => @page_name, :attempted_action => "edit" 128 146 else 129 147 @page.lock(Time.now, @author) 130 148 end 131 149 end 132 150 151 def rename 152 if @page.nil? 153 redirect_home 154 elsif @page.locked?(Time.now) and not @params['break_lock'] 155 # This bit needs to be fixed up to support multiple locks on each referring page 156 redirect_to :web => @web_name, :action => 'locked', :id => @page_name, :attempted_action => "rename" 157 else 158 @page.lock(Time.now, @author) 159 end 160 end 161 133 162 def locked 134 163 # to template 164 @attempted_action = @params['attempted_action'] 165 if @attempted_action.nil? or @attempted_action.empty? 166 redirect_to :web => @web_name, :action => 'show', :id => @page_name 167 end 135 168 end 136 169 137 170 def new -
app/views/wiki/locked.rhtml
old new 10 10 </p> 11 11 12 12 <p> 13 <%= link_to 'Edit the page anyway',14 {:web => @web_name, :action => 'edit', :id => @page.name, :params => {'break_lock' => '1'} },15 {:accesskey => ' E'}13 <%= link_to "#{@attempted_action.capitalize} the page anyway", 14 {:web => @web_name, :action => @attempted_action, :id => @page.name, :params => {'break_lock' => '1'} }, 15 {:accesskey => 'F'} 16 16 %> 17 17 18 18 <%= link_to 'Cancel', -
app/views/wiki/rename.rhtml
old new 1 <% 2 @title = "Renaming #{@page.name}" 3 @content_width = 720 4 @hide_navigation = true 5 %> 6 7 <%= form_tag({ :action => 'perform_rename', :web => @web.address, :id => @page.name}, 8 {'id' => 'renameForm', 'method' => 'post', 'onSubmit' => 'cleanAuthorName()'}) 9 %> 10 11 <p> 12 Please choose a new title: 13 <input type="text" name="newPageName" value="<%= @page.name %>" /> 14 </p> 15 <p> 16 <input type="submit" value="Submit" accesskey="s"/> as 17 <input type="text" name="author" id="authorName" value="<%= @author %>" 18 onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> 19 | 20 <%= link_to('Cancel', {:web => @web.address, :action => 'cancel_edit', :id => @page.name}, 21 {:accesskey => 'c'}) 22 %> 23 <small>(unlocks page)</small> 24 </p> 25 <%= end_form_tag %> 26 27 <script language="JavaScript1.2"> 28 function cleanAuthorName() { 29 if (document.getElementById('authorName').value == "") { 30 document.getElementById('authorName').value = 'AnonymousCoward'; 31 } 32 } 33 </script> -
app/views/wiki/page.rhtml
old new 38 38 {:class => 'navlink', :accesskey => 'E', :name => 'edit'}) 39 39 %> 40 40 | 41 <%= link_to('Rename Page', 42 {:web => @web.address, :action => 'rename', :id => @page.name}, 43 {:class => 'navlink', :name => 'rename'}) 44 %> 45 | 41 46 <%= link_to('Edit Web', 42 47 {:web => @web.address, :action => 'edit_web'}, 43 48 {:class => 'navlink', :name => 'edit_web'}) … … 47 52 {:web => @web.address, :action => 'edit', :id => @page.name}, 48 53 {:class => 'navlink', :accesskey => 'E', :name => 'edit'}) 49 54 %> 55 | 56 <%= link_to('Rename', 57 {:web => @web.address, :action => 'rename', :id => @page.name}, 58 {:class => 'navlink', :name => 'rename'}) 59 %> 50 60 <% end %> 51 61 52 62 <% if @page.revisions.length > 1 %>
