Index: test/functional/wiki_controller_test.rb =================================================================== --- test/functional/wiki_controller_test.rb (revision 1270) +++ test/functional/wiki_controller_test.rb (working copy) @@ -147,7 +147,7 @@ assert_template 'special_page_index' pages = assigns(:pages) assert_not_nil pages - assert_equal 2, pages.size + assert_equal 3, pages.size assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, :content => /CookBook documentation/ end @@ -156,4 +156,20 @@ get :index, :id => 999 assert_response 404 end + + def test_wikilinks_use_headings_as_title + get :index, :id => 1, :page => 'Another_page' + assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, + :content => /CookBook documentation/ + assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/A_third_page' }, + :content => /Yet another page/ + end + + def test_wikilink_with_explicit_titles + get :index, :id => 1, :page => 'A_third_page' + assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, + :content => /Home page/ + + end + end Index: test/fixtures/wiki_contents.yml =================================================================== --- test/fixtures/wiki_contents.yml (revision 1270) +++ test/fixtures/wiki_contents.yml (working copy) @@ -1,9 +1,9 @@ --- wiki_contents_001: text: |- - h1. CookBook documentation + h1. CookBook documentation - + Some updated [[documentation]] here with gzipped history updated_on: 2007-03-07 00:10:51 +01:00 @@ -17,6 +17,10 @@ h1. Another page This is a link to a ticket: #2 + + This is a link back to the [[CookBook_documentation]] + + This is a link to [[A_third_page]] updated_on: 2007-03-08 00:18:07 +01:00 page_id: 2 id: 2 @@ -34,3 +38,14 @@ version: 1 author_id: 1 comments: +wiki_contents_004: + text: |- + h1. Yet another page + + Back to the [[CookBook_documentation|Home page]] + updated_on: 2007-03-08 00:18:07 +01:00 + page_id: 4 + id: 4 + version: 1 + author_id: 1 + comments: \ No newline at end of file Index: test/fixtures/wiki_pages.yml =================================================================== --- test/fixtures/wiki_pages.yml (revision 1270) +++ test/fixtures/wiki_pages.yml (working copy) @@ -14,4 +14,9 @@ title: Start_page id: 3 wiki_id: 2 +wiki_pages_004: + created_on: 2007-03-08 00:18:07 +01:00 + title: A_third_page + id: 4 + wiki_id: 1 \ No newline at end of file Index: test/fixtures/wiki_content_versions.yml =================================================================== --- test/fixtures/wiki_content_versions.yml (revision 1270) +++ test/fixtures/wiki_content_versions.yml (working copy) @@ -9,9 +9,9 @@ wiki_content_id: 1 compression: "" data: |- - h1. CookBook documentation + h1. CookBook documentation - + Some [[documentation]] here... wiki_content_versions_002: @@ -24,9 +24,9 @@ wiki_content_id: 1 compression: "" data: |- - h1. CookBook documentation + h1. CookBook documentation - + Some updated [[documentation]] here... wiki_content_versions_003: @@ -46,6 +46,10 @@ h1. Another page This is a link to a ticket: #2 + + This is a link back to the [[CookBook_documentation]] + + This is a link to [[A_third_page]] updated_on: 2007-03-08 00:18:07 +01:00 page_id: 2 wiki_content_id: 2 @@ -53,4 +57,19 @@ version: 1 author_id: 1 comments: - +wiki_content_versions_005: + data: |- + h1. Another page + + This is a link to a ticket: #2 + + This is a link back to the [[CookBook_documentation]] + + This is a link to [[A_third_page]] + updated_on: 2007-03-08 00:18:07 +01:00 + page_id: 4 + wiki_content_id: 4 + id: 5 + version: 1 + author_id: 1 + comments: Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 1270) +++ app/helpers/application_helper.rb (working copy) @@ -252,7 +252,8 @@ if link_project && link_project.wiki # check if page exists wiki_page = link_project.wiki.find_page(page) - link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), + link_to((title || (wiki_page ? wiki_page.content.first_heading : nil) || page), + format_wiki_link.call(link_project, Wiki.titleize(page)), :class => ('wiki-page' + (wiki_page ? '' : ' new'))) else # project or wiki doesn't exist Index: app/models/wiki_content.rb =================================================================== --- app/models/wiki_content.rb (revision 1270) +++ app/models/wiki_content.rb (working copy) @@ -23,6 +23,11 @@ belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :text + def first_heading + matches = text.match(/^h1.\s(.*)/) + matches ? matches[1] : nil + end + acts_as_versioned class Version belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'