Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2009-06-02 22:24:50 -05:00
commit 3d626dae30
16 changed files with 161 additions and 33 deletions

21
lib/chunks/redirect.rb Normal file
View file

@ -0,0 +1,21 @@
require 'chunks/wiki'
# [[!redirects Foo]]
# redirects Wikilinks for the (nonexistent) page "Foo" to this page.
# If "Foo" exists, then the Redirect has no effect. But if "Foo"
# does not exist, then a Wikilink [[Foo]] will produce a link to this
# page, rather than produce a create-a-new-page link.
class Redirect < WikiChunk::WikiReference
REDIRECT_PATTERN = /\[\[!redirects\s+([^\]\s][^\]]*?)\s*\]\]/i
def self.pattern() REDIRECT_PATTERN end
def initialize(match_data, content)
super
@page_name = match_data[1].strip
@link_type = :redirect
@unmask_text = ''
end
end

View file

@ -173,6 +173,13 @@ class PageRenderer
:link_type => WikiReference::INCLUDED_PAGE
end
redirect_chunks = rendering_result.find_chunks(Redirect)
redirects = redirect_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
redirects.each do |redirected_page_name|
references.build :referenced_name => redirected_page_name,
:link_type => WikiReference::REDIRECTED_PAGE
end
categories = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
categories.each do |category|
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY

View file

@ -10,23 +10,30 @@ class AbstractUrlGenerator
# Create a link for the given page (or file) name and link text based
# on the render mode in options and whether the page (file) exists
# in the web.
def make_link(name, web, text = nil, options = {})
def make_link(asked_name, web, text = nil, options = {})
mode = (options[:mode] || :show).to_sym
link_type = (options[:link_type] || :show).to_sym
if (link_type == :show)
known_page = web.has_page?(name)
page_exists = web.has_page?(asked_name)
known_page = page_exists || web.has_redirect_for?(asked_name)
if known_page && !page_exists
name = web.page_that_redirects_for(asked_name)
else
name = asked_name
end
else
name = asked_name
known_page = web.has_file?(name)
description = web.description(name)
description = description.unescapeHTML.escapeHTML if description
end
if (text == name)
if (text == asked_name)
text = description || text
else
text = text || description
end
text = (text || WikiWords.separate(name)).unescapeHTML.escapeHTML
text = (text || WikiWords.separate(asked_name)).unescapeHTML.escapeHTML
case link_type
when :show

View file

@ -2,6 +2,7 @@ require 'cgi'
require 'chunks/engines'
require 'chunks/category'
require_dependency 'chunks/include'
require_dependency 'chunks/redirect'
require_dependency 'chunks/wiki'
require_dependency 'chunks/literal'
require 'chunks/nowiki'
@ -38,7 +39,7 @@ require 'sanitizer'
module ChunkManager
attr_reader :chunks_by_type, :chunks_by_id, :chunks, :chunk_id
ACTIVE_CHUNKS = [ NoWiki, Category, WikiChunk::Link,
ACTIVE_CHUNKS = [ NoWiki, Category, Redirect, WikiChunk::Link,
WikiChunk::Word ]
HIDE_CHUNKS = [ Literal::Pre, Literal::Tags, Literal::Math ]