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  
    238238 
    239239  def test_locked 
    240240    @home.lock(Time.now, 'Locky') 
    241     r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage'
     241    r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage', 'attempted_action' => 'test'
    242242    assert_success 
    243243    assert_equal @home, r.template_objects['page'] 
    244244  end 
  • app/models/web.rb

    old new  
    4949     page.revise(content, created_at, author) 
    5050     @pages[page.name] = page 
    5151   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 
    5272   
    5373  def address=(the_address) 
    5474    if the_address != CGI.escape(the_address) 
  • app/models/revision.rb

    old new  
    124124    end 
    125125  end 
    126126 
     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 
    127136end 
  • app/models/wiki_service.rb

    old new  
    8888    page.revise(content, revised_on, author) 
    8989  end 
    9090 
     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 
    9195  def rollback_page(web_address, page_name, revision_number, created_at, author_id = nil) 
    9296    page = read_page(web_address, page_name) 
    9397    page.rollback(revision_number, created_at, author_id) 
  • app/models/page.rb

    old new  
    5151     
    5252  end 
    5353 
     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 
    5486  def rollback(revision_number, created_at, author_ip = nil) 
    5587    roll_back_revision = @revisions[revision_number].dup 
    5688    revise(roll_back_revision.content, created_at, Author.new(roll_back_revision.author, author_ip)) 
  • app/controllers/wiki_controller.rb

    old new  
    113113    end 
    114114  end 
    115115 
     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 
    116134  # Within a single page -------------------------------------------------------- 
    117135   
    118136  def cancel_edit 
     
    124142    if @page.nil? 
    125143      redirect_home 
    126144    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" 
    128146    else 
    129147      @page.lock(Time.now, @author) 
    130148    end 
    131149  end 
    132150   
     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   
    133162  def locked 
    134163    # 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 
    135168  end 
    136169   
    137170  def new 
  • app/views/wiki/locked.rhtml

    old new  
    1010</p> 
    1111 
    1212<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'} 
    1616  %> 
    1717 
    1818  <%= 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"> 
     28function cleanAuthorName() { 
     29  if (document.getElementById('authorName').value == "") { 
     30    document.getElementById('authorName').value = 'AnonymousCoward'; 
     31  } 
     32} 
     33</script> 
  • app/views/wiki/page.rhtml

    old new  
    3838          {:class => 'navlink', :accesskey => 'E', :name => 'edit'}) 
    3939    %> 
    4040    |  
     41    <%= link_to('Rename Page',  
     42          {:web => @web.address, :action => 'rename', :id => @page.name},  
     43          {:class => 'navlink', :name => 'rename'}) 
     44    %> 
     45    |  
    4146    <%= link_to('Edit Web',  
    4247            {:web => @web.address, :action => 'edit_web'},  
    4348            {:class => 'navlink', :name => 'edit_web'}) 
     
    4752          {:web => @web.address, :action => 'edit', :id => @page.name},  
    4853          {:class => 'navlink', :accesskey => 'E', :name => 'edit'}) 
    4954    %> 
     55    | 
     56    <%= link_to('Rename',  
     57          {:web => @web.address, :action => 'rename', :id => @page.name},  
     58          {:class => 'navlink', :name => 'rename'}) 
     59    %> 
    5060  <% end %> 
    5161 
    5262  <% if @page.revisions.length > 1 %>