diff --git a/app/models/web.rb b/app/models/web.rb
index 59129120..1e1d5585 100644
--- a/app/models/web.rb
+++ b/app/models/web.rb
@@ -47,6 +47,11 @@ class Web < ActiveRecord::Base
WikiFile.find_by_file_name(file_name) != nil
end
+ def description(file_name)
+ file = WikiFile.find_by_file_name(file_name)
+ file.description if file
+ end
+
def markup
read_attribute('markup').to_sym
end
diff --git a/app/views/file/file.rhtml b/app/views/file/file.rhtml
index cbdf0325..37c490b7 100644
--- a/app/views/file/file.rhtml
+++ b/app/views/file/file.rhtml
@@ -9,7 +9,7 @@
{ 'multipart' => true , 'accept-charset' => 'utf-8' }) do %>
<%= hidden_field 'file', 'file_name' %>
-
+
@@ -18,7 +18,7 @@
<%= link_to :back %> and edit the wiki page that refers to the file.
-
+
<%= text_field "file", "description", "size" => 40 %>
diff --git a/lib/url_generator.rb b/lib/url_generator.rb
index b5415e63..dbc68dd3 100644
--- a/lib/url_generator.rb
+++ b/lib/url_generator.rb
@@ -9,7 +9,6 @@ class AbstractUrlGenerator
# on the render mode in options and whether the page (file) exists
# in the web.
def make_link(name, web, text = nil, options = {})
- text = CGI.escapeHTML(text || WikiWords.separate(name))
mode = (options[:mode] || :show).to_sym
link_type = (options[:link_type] || :show).to_sym
@@ -17,7 +16,14 @@ class AbstractUrlGenerator
known_page = web.has_page?(name)
else
known_page = web.has_file?(name)
+ description = web.description(name)
end
+ if (text == name)
+ text = description || text
+ else
+ text = text || description
+ end
+ text = CGI.escapeHTML(CGI.unescapeHTML(text || WikiWords.separate(name)))
case link_type
when :show
@@ -41,7 +47,7 @@ class UrlGenerator < AbstractUrlGenerator
case mode
when :export
if known_file
- %{#{text}}
+ %{#{text}}
else
%{#{text}}
end
@@ -49,7 +55,7 @@ class UrlGenerator < AbstractUrlGenerator
if known_file
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
- %{#{text}}
+ %{#{text}}
else
%{#{text}}
end
@@ -57,7 +63,7 @@ class UrlGenerator < AbstractUrlGenerator
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
if known_file
- %{#{text}}
+ %{#{text}}
else
%{#{text}?}
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 9be06248..d8b08a70 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -106,14 +106,14 @@ class StubUrlGenerator < AbstractUrlGenerator
link = CGI.escape(name)
case mode
when :export
- if known_file then %{#{text}}
+ if known_file then %{#{text}}
else %{#{text}} end
when :publish
- if known_file then %{#{text}}
+ if known_file then %{#{text}}
else %{#{text}} end
else
if known_file
- %{#{text}}
+ %{#{text}}
else
%{#{text}?}
end
@@ -144,6 +144,7 @@ class StubUrlGenerator < AbstractUrlGenerator
def pic_link(mode, name, text, web_name, known_pic)
link = CGI.escape(name)
+ text = CGI.escapeHTML(CGI.unescapeHTML(text || :description))
case mode.to_sym
when :export
if known_pic then %{}
diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb
index 29cad167..17ea2fa8 100644
--- a/test/unit/page_renderer_test.rb
+++ b/test/unit/page_renderer_test.rb
@@ -305,10 +305,10 @@ class PageRendererTest < Test::Unit::TestCase
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
assert_markup_parsed_as(
- '',
- '[[square.jpg|Square:pic]]')
+ '',
+ '[[square.jpg|Blue Square:pic]]')
assert_markup_parsed_as(
- '',
+ '',
'[[square.jpg:pic]]')
end