Merge pull request #166 from arr2036/mediawiki_compat

Gollum doesn't play nice with un-canonicalized filenames, and breaks offsite links when replacing mediawiki
This commit is contained in:
Corey Donohoe
2012-04-10 16:04:09 -07:00
19 changed files with 202 additions and 34 deletions
+31 -9
View File
@@ -76,11 +76,20 @@ module Gollum
end
# Reusable filter to turn a filename (without path) into a canonical name.
# Strips extension, converts spaces to dashes.
# Strips extension, converts dashes to spaces.
#
# Returns the filtered String.
def self.canonicalize_filename(filename)
filename.split('.')[0..-2].join('.').gsub('-', ' ')
strip_filename(filename).gsub('-', ' ')
end
# Reusable filter to strip extension and path from filename
#
# filename - The string path or filename to strip
#
# Returns the stripped String.
def self.strip_filename(filename)
::File.basename(filename, ::File.extname(filename))
end
# Public: Initialize a page.
@@ -100,6 +109,13 @@ module Gollum
@blob && @blob.name
end
# Public: The on-disk filename of the page with extension stripped.
#
# Returns the String name.
def filename_stripped
self.class.strip_filename(filename)
end
# Public: The canonical page name without extension, and dashes converted
# to spaces.
#
@@ -246,17 +262,22 @@ module Gollum
# Convert a human page name into a canonical page name.
#
# name - The String human page name.
# name - The String human page name.
# char_white_sub - Substitution for whitespace
# char_other_sub - Substitution for other special chars
#
# Examples
#
# Page.cname("Bilbo Baggins")
# # => 'Bilbo-Baggins'
#
# Page.cname("Bilbo Baggins",'_')
# # => 'Bilbo_Baggins'
#
# Returns the String canonical name.
def self.cname(name)
name.respond_to?(:gsub) ?
name.gsub(%r{[ /<>]}, '-') :
def self.cname(name, char_white_sub = '-', char_other_sub = '-')
name.respond_to?(:gsub) ?
name.gsub(%r{\s},char_white_sub).gsub(%r{[/<>+]}, char_other_sub) :
''
end
@@ -370,10 +391,11 @@ module Gollum
# Returns a Boolean.
def page_match(name, filename)
if match = self.class.valid_filename?(filename)
Page.cname(name).downcase == Page.cname(match).downcase
else
false
@wiki.ws_subs.each do |sub|
return true if Page.cname(name).downcase == Page.cname(match, sub).downcase
end
end
false
end
# Loads a sub page. Sub page nanes (footers) are prefixed with