diff --git a/lib/url_generator.rb b/lib/url_generator.rb
index 995742b7..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
@@ -19,14 +18,20 @@ class AbstractUrlGenerator
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
page_link(mode, name, text, web.address, known_page)
when :file
- file_link(mode, name, text, web.address, known_page, description)
+ file_link(mode, name, text, web.address, known_page)
when :pic
- pic_link(mode, name, text, web.address, known_page, description)
+ pic_link(mode, name, text, web.address, known_page)
else
raise "Unknown link type: #{link_type}"
end
@@ -38,12 +43,11 @@ class UrlGenerator < AbstractUrlGenerator
private
- def file_link(mode, name, text, web_address, known_file, description)
- title = CGI::escapeHTML(CGI::unescapeHTML( description || text))
+ def file_link(mode, name, text, web_address, known_file)
case mode
when :export
if known_file
- %{#{text}}
+ %{#{text}}
else
%{#{text}}
end
@@ -51,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
@@ -59,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
@@ -95,18 +99,17 @@ class UrlGenerator < AbstractUrlGenerator
end
end
- def pic_link(mode, name, text, web_address, known_pic, description)
- alt_text = CGI::escapeHTML(CGI::unescapeHTML( description || text))
+ def pic_link(mode, name, text, web_address, known_pic)
case mode
when :export
if known_pic
- %{}
+ %{}
else
%{}
end
when :publish
if known_pic
- %{}
+ %{}
else
%{#{text}}
end
@@ -114,7 +117,7 @@ class UrlGenerator < AbstractUrlGenerator
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
if known_pic
- %{}
+ %{}
else
%{#{text}?}
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f69767a3..d8b08a70 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -102,8 +102,7 @@ class StubUrlGenerator < AbstractUrlGenerator
super(:doesnt_need_controller)
end
- def file_link(mode, name, text, web_name, known_file, description)
- title = CGI::escapeHTML(CGI::unescapeHTML( description || text))
+ def file_link(mode, name, text, web_name, known_file)
link = CGI.escape(name)
case mode
when :export
@@ -143,18 +142,18 @@ class StubUrlGenerator < AbstractUrlGenerator
end
end
- def pic_link(mode, name, text, web_name, known_pic, description)
- alt_text = CGI::escapeHTML(CGI::unescapeHTML( description || text))
+ 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 %{}
+ if known_pic then %{}
else %{} end
when :publish
- if known_pic then %{}
+ if known_pic then %{}
else %{#{text}} end
else
- if known_pic then %{}
+ if known_pic then %{}
else %{#{text}?} end
end
end