Wiki Redirects and Page Renaming
Added the ability to rename existing pages. [[!redirects Some Page Name]] redirects Wikilinks [[Some Page Name]] to the current page (assuming "Some Page Name" does not exist). Real pages trump redirects (though this may change, depending on user feedback).
This commit is contained in:
parent
634f635f16
commit
d7832ba262
|
@ -129,7 +129,7 @@ class FileController < ApplicationController
|
||||||
next
|
next
|
||||||
else
|
else
|
||||||
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
||||||
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
wiki.revise_page(@web.address, page_name, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||||
|
|
|
@ -22,8 +22,9 @@ class RevisionSweeper < ActionController::Caching::Sweeper
|
||||||
|
|
||||||
def expire_caches(page)
|
def expire_caches(page)
|
||||||
expire_cached_summary_pages(page.web)
|
expire_cached_summary_pages(page.web)
|
||||||
pages_to_expire = ([page.name] + WikiReference.pages_that_reference(page.web, page.name) +
|
pages_to_expire = ([page.name] + WikiReference.pages_that_reference(page.web, page.name)
|
||||||
WikiReference.pages_that_include(page.web, page.name)).uniq
|
+ WikiReference.pages_redirected_to(page.web, page.name)
|
||||||
|
+ WikiReference.pages_that_include(page.web, page.name)).uniq
|
||||||
pages_to_expire.each { |page_name| expire_cached_page(page.web, page_name) }
|
pages_to_expire.each { |page_name| expire_cached_page(page.web, page_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class WebSweeper < ActionController::Caching::Sweeper
|
||||||
web.pages.each { |page| expire_cached_page(web, page.name) }
|
web.pages.each { |page| expire_cached_page(web, page.name) }
|
||||||
expire_cached_summary_pages(web)
|
expire_cached_summary_pages(web)
|
||||||
elsif record.is_a?(WikiFile)
|
elsif record.is_a?(WikiFile)
|
||||||
record.web.pages_that_link_to(record.file_name).each do |page|
|
record.web.pages_that_link_to_file(record.file_name).each do |page|
|
||||||
expire_cached_page(record.web, page)
|
expire_cached_page(record.web, page)
|
||||||
end
|
end
|
||||||
expire_cached_summary_pages(record.web)
|
expire_cached_summary_pages(record.web)
|
||||||
|
|
|
@ -268,9 +268,13 @@ class WikiController < ApplicationController
|
||||||
raise Instiki::ValidationError.new('Your content was not valid utf-8.')
|
raise Instiki::ValidationError.new('Your content was not valid utf-8.')
|
||||||
end
|
end
|
||||||
if @page
|
if @page
|
||||||
wiki.revise_page(@web_name, @page_name, the_content, Time.now,
|
new_name = params['new_name'] || @page_name
|
||||||
|
raise Instiki::ValidationError.new('Your new title was not valid utf-8.') unless new_name.is_utf8?
|
||||||
|
raise Instiki::ValidationError.new('A page named "' + new_name.escapeHTML + '" already exists.') if @page_name != new_name && @web.has_page?(new_name)
|
||||||
|
wiki.revise_page(@web_name, @page_name, new_name, the_content, Time.now,
|
||||||
Author.new(author_name, remote_ip), PageRenderer.new)
|
Author.new(author_name, remote_ip), PageRenderer.new)
|
||||||
@page.unlock
|
@page.unlock
|
||||||
|
@page_name = new_name
|
||||||
else
|
else
|
||||||
wiki.write_page(@web_name, @page_name, the_content, Time.now,
|
wiki.write_page(@web_name, @page_name, the_content, Time.now,
|
||||||
Author.new(author_name, remote_ip), PageRenderer.new)
|
Author.new(author_name, remote_ip), PageRenderer.new)
|
||||||
|
|
|
@ -4,13 +4,14 @@ class Page < ActiveRecord::Base
|
||||||
has_many :wiki_references, :order => 'referenced_name'
|
has_many :wiki_references, :order => 'referenced_name'
|
||||||
has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
|
has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
|
||||||
|
|
||||||
def revise(content, time, author, renderer)
|
def revise(content, name, time, author, renderer)
|
||||||
revisions_size = new_record? ? 0 : revisions.size
|
revisions_size = new_record? ? 0 : revisions.size
|
||||||
if (revisions_size > 0) and content == current_revision.content
|
if (revisions_size > 0) and content == current_revision.content and name == self.name
|
||||||
raise Instiki::ValidationError.new(
|
raise Instiki::ValidationError.new(
|
||||||
"You have tried to save page '#{name}' without changing its content")
|
"You have tried to save page '#{name}' without changing its content")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.name = name
|
||||||
author = Author.new(author.to_s) unless author.is_a?(Author)
|
author = Author.new(author.to_s) unless author.is_a?(Author)
|
||||||
|
|
||||||
# Try to render content to make sure that markup engine can take it,
|
# Try to render content to make sure that markup engine can take it,
|
||||||
|
@ -37,7 +38,7 @@ class Page < ActiveRecord::Base
|
||||||
raise Instiki::ValidationError.new("Revision #{revision_number} not found")
|
raise Instiki::ValidationError.new("Revision #{revision_number} not found")
|
||||||
end
|
end
|
||||||
author = Author.new(roll_back_revision.author.name, author_ip)
|
author = Author.new(roll_back_revision.author.name, author_ip)
|
||||||
revise(roll_back_revision.content, time, author, renderer)
|
revise(roll_back_revision.content, self.name, time, author, renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def revisions?
|
def revisions?
|
||||||
|
@ -71,6 +72,10 @@ class Page < ActiveRecord::Base
|
||||||
web.select.pages_that_link_to(name)
|
web.select.pages_that_link_to(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirects_for
|
||||||
|
wiki_references.select { |ref| ref.redirected_page?}.map { |ref| ref.referenced_name }
|
||||||
|
end
|
||||||
|
|
||||||
def included_from
|
def included_from
|
||||||
web.select.pages_that_include(name)
|
web.select.pages_that_include(name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Web < ActiveRecord::Base
|
||||||
|
|
||||||
def add_page(name, content, time, author, renderer)
|
def add_page(name, content, time, author, renderer)
|
||||||
page = page(name) || Page.new(:web => self, :name => name)
|
page = page(name) || Page.new(:web => self, :name => name)
|
||||||
page.revise(content, time, author, renderer)
|
page.revise(content, name, time, author, renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authors
|
def authors
|
||||||
|
@ -43,6 +43,14 @@ class Web < ActiveRecord::Base
|
||||||
Page.count(:conditions => ['web_id = ? AND name = ?', id, name]) > 0
|
Page.count(:conditions => ['web_id = ? AND name = ?', id, name]) > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_redirect_for?(name)
|
||||||
|
WikiReference.page_that_redirects_for(self, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_that_redirects_for(name)
|
||||||
|
page(WikiReference.page_that_redirects_for(self, name))
|
||||||
|
end
|
||||||
|
|
||||||
def has_file?(file_name)
|
def has_file?(file_name)
|
||||||
WikiFile.find_by_file_name(file_name) != nil
|
WikiFile.find_by_file_name(file_name) != nil
|
||||||
end
|
end
|
||||||
|
@ -51,7 +59,11 @@ class Web < ActiveRecord::Base
|
||||||
WikiFile.all(:order => sort_order, :conditions => ['web_id = ?', id])
|
WikiFile.all(:order => sort_order, :conditions => ['web_id = ?', id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages_that_link_to(file_name)
|
def pages_that_link_to(page_name)
|
||||||
|
WikiReference.pages_that_link_to(self, page_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pages_that_link_to_file(file_name)
|
||||||
WikiReference.pages_that_link_to_file(self, file_name)
|
WikiReference.pages_that_link_to_file(self, file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ class Wiki
|
||||||
web.remove_pages(pages_in_category.orphaned_pages)
|
web.remove_pages(pages_in_category.orphaned_pages)
|
||||||
end
|
end
|
||||||
|
|
||||||
def revise_page(web_address, page_name, content, revised_at, author, renderer)
|
def revise_page(web_address, page_name, new_name, content, revised_at, author, renderer)
|
||||||
page = read_page(web_address, page_name)
|
page = read_page(web_address, page_name)
|
||||||
page.revise(content, revised_at, author, renderer)
|
page.revise(content, new_name, revised_at, author, renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback_page(web_address, page_name, revision_number, time, author_id = nil)
|
def rollback_page(web_address, page_name, revision_number, time, author_id = nil)
|
||||||
|
|
|
@ -2,6 +2,7 @@ class WikiReference < ActiveRecord::Base
|
||||||
|
|
||||||
LINKED_PAGE = 'L'
|
LINKED_PAGE = 'L'
|
||||||
WANTED_PAGE = 'W'
|
WANTED_PAGE = 'W'
|
||||||
|
REDIRECTED_PAGE = 'R'
|
||||||
INCLUDED_PAGE = 'I'
|
INCLUDED_PAGE = 'I'
|
||||||
CATEGORY = 'C'
|
CATEGORY = 'C'
|
||||||
AUTHOR = 'A'
|
AUTHOR = 'A'
|
||||||
|
@ -9,7 +10,7 @@ class WikiReference < ActiveRecord::Base
|
||||||
WANTED_FILE = 'E'
|
WANTED_FILE = 'E'
|
||||||
|
|
||||||
belongs_to :page
|
belongs_to :page
|
||||||
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR, FILE, WANTED_FILE]
|
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, REDIRECTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR, FILE, WANTED_FILE]
|
||||||
|
|
||||||
def self.link_type(web, page_name)
|
def self.link_type(web, page_name)
|
||||||
web.has_page?(page_name) ? LINKED_PAGE : WANTED_PAGE
|
web.has_page?(page_name) ? LINKED_PAGE : WANTED_PAGE
|
||||||
|
@ -51,6 +52,28 @@ class WikiReference < ActiveRecord::Base
|
||||||
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.pages_redirected_to(web, page_name)
|
||||||
|
names = []
|
||||||
|
if web.has_page?(page_name)
|
||||||
|
page = web.page(page_name)
|
||||||
|
redirected_names = page.redirects_for
|
||||||
|
redirected_names.each do |name|
|
||||||
|
names = names | self.pages_that_reference(web, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
names
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.page_that_redirects_for(web, page_name)
|
||||||
|
query = 'SELECT name FROM pages JOIN wiki_references ' +
|
||||||
|
'ON pages.id = wiki_references.page_id ' +
|
||||||
|
'WHERE wiki_references.referenced_name = ? ' +
|
||||||
|
"AND wiki_references.link_type = '#{REDIRECTED_PAGE}' " +
|
||||||
|
"AND pages.web_id = '#{web.id}'"
|
||||||
|
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
||||||
|
names[0]
|
||||||
|
end
|
||||||
|
|
||||||
def self.pages_in_category(web, category)
|
def self.pages_in_category(web, category)
|
||||||
query =
|
query =
|
||||||
"SELECT name FROM pages JOIN wiki_references " +
|
"SELECT name FROM pages JOIN wiki_references " +
|
||||||
|
@ -82,6 +105,10 @@ class WikiReference < ActiveRecord::Base
|
||||||
link_type == LINKED_PAGE
|
link_type == LINKED_PAGE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirected_page?
|
||||||
|
link_type == REDIRECTED_PAGE
|
||||||
|
end
|
||||||
|
|
||||||
def wanted_page?
|
def wanted_page?
|
||||||
link_type == WANTED_PAGE
|
link_type == WANTED_PAGE
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,16 @@
|
||||||
<% form_tag({ :action => 'save', :web => @web.address, :id => @page.name },
|
<% form_tag({ :action => 'save', :web => @web.address, :id => @page.name },
|
||||||
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
||||||
'accept-charset' => 'utf-8' }) do %>
|
'accept-charset' => 'utf-8' }) do %>
|
||||||
|
<% if @page_name != 'HomePage' -%>
|
||||||
|
<p>
|
||||||
|
<%= check_box_tag :alter_title, value = "1", checked=false,
|
||||||
|
'onchange' => "toggleVisibility();" %> <label for="alter_title">Change page name.</label><br/>
|
||||||
|
<span id="title_change" style="display:none"><label for="new_name">New name:</label> <%= text_field_tag :new_name, h(@page.name.purify),
|
||||||
|
:onblur => "addRedirect();" %></span>
|
||||||
|
</p>
|
||||||
|
<% else -%>
|
||||||
|
<%= hidden_field_tag 'new_name', @page_name %>
|
||||||
|
<% end%>
|
||||||
<div>
|
<div>
|
||||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] ||
|
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] ||
|
||||||
((params['content'] && params['content'].is_utf8?) ? params['content'] : @page.content).purify) %></textarea>
|
((params['content'] && params['content'].is_utf8?) ? params['content'] : @page.content).purify) %></textarea>
|
||||||
|
@ -31,10 +41,30 @@
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
function toggleVisibility() {
|
||||||
|
var span = document.getElementById('title_change');
|
||||||
|
if (span.style.display =='inline') {
|
||||||
|
span.style.display ='none';
|
||||||
|
document.getElementById('new_name').value = "<%= @page.name %>";
|
||||||
|
var content = document.getElementById('content').value
|
||||||
|
document.getElementById('content').value = content.replace(/\[\[!redirects <%= Regexp.escape(@page.name) %>\]\]\n/, '')
|
||||||
|
}
|
||||||
|
else
|
||||||
|
span.style.display ='inline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function addRedirect(){
|
||||||
|
if (document.getElementById('new_name').value != "<%= @page.name %>" ) {
|
||||||
|
var content = document.getElementById('content');
|
||||||
|
content.value = '[[!redirects <%= @page.name %>]]\n' + content.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function cleanAuthorName() {
|
function cleanAuthorName() {
|
||||||
if (document.getElementById('authorName').value == "") {
|
if (document.getElementById('authorName').value == "") {
|
||||||
document.getElementById('authorName').value = 'AnonymousCoward';
|
document.getElementById('authorName').value = 'AnonymousCoward';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.forms["editForm"].elements["content"].focus();
|
document.forms["editForm"].elements["content"].focus();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
<input type="checkbox" name="<%= file.file_name %>" value="delete"/>
|
<input type="checkbox" name="<%= file.file_name %>" value="delete"/>
|
||||||
<a href="<%= url_for :web => @web.address, :action => 'files',
|
<a href="<%= url_for :web => @web.address, :action => 'files',
|
||||||
:id => file.file_name %>"><%= file.file_name%></a> (<%= file.created_at.asctime %>) <span class="linked"><%= "Linked to by: " unless
|
:id => file.file_name %>"><%= file.file_name%></a> (<%= file.created_at.asctime %>) <span class="linked"><%= "Linked to by: " unless
|
||||||
@web.pages_that_link_to(file.file_name).empty? -%>
|
@web.pages_that_link_to_file(file.file_name).empty? -%>
|
||||||
<%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %></span>
|
<%= @web.pages_that_link_to_file(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %></span>
|
||||||
</li>
|
</li>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
21
lib/chunks/redirect.rb
Normal file
21
lib/chunks/redirect.rb
Normal 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
|
|
@ -173,6 +173,13 @@ class PageRenderer
|
||||||
:link_type => WikiReference::INCLUDED_PAGE
|
:link_type => WikiReference::INCLUDED_PAGE
|
||||||
end
|
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 = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
|
||||||
categories.each do |category|
|
categories.each do |category|
|
||||||
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
|
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
|
||||||
|
|
|
@ -10,23 +10,30 @@ class AbstractUrlGenerator
|
||||||
# Create a link for the given page (or file) name and link text based
|
# 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
|
# on the render mode in options and whether the page (file) exists
|
||||||
# in the web.
|
# 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
|
mode = (options[:mode] || :show).to_sym
|
||||||
link_type = (options[:link_type] || :show).to_sym
|
link_type = (options[:link_type] || :show).to_sym
|
||||||
|
|
||||||
if (link_type == :show)
|
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
|
else
|
||||||
|
name = asked_name
|
||||||
|
end
|
||||||
|
else
|
||||||
|
name = asked_name
|
||||||
known_page = web.has_file?(name)
|
known_page = web.has_file?(name)
|
||||||
description = web.description(name)
|
description = web.description(name)
|
||||||
description = description.unescapeHTML.escapeHTML if description
|
description = description.unescapeHTML.escapeHTML if description
|
||||||
end
|
end
|
||||||
if (text == name)
|
if (text == asked_name)
|
||||||
text = description || text
|
text = description || text
|
||||||
else
|
else
|
||||||
text = text || description
|
text = text || description
|
||||||
end
|
end
|
||||||
text = (text || WikiWords.separate(name)).unescapeHTML.escapeHTML
|
text = (text || WikiWords.separate(asked_name)).unescapeHTML.escapeHTML
|
||||||
|
|
||||||
case link_type
|
case link_type
|
||||||
when :show
|
when :show
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'cgi'
|
||||||
require 'chunks/engines'
|
require 'chunks/engines'
|
||||||
require 'chunks/category'
|
require 'chunks/category'
|
||||||
require_dependency 'chunks/include'
|
require_dependency 'chunks/include'
|
||||||
|
require_dependency 'chunks/redirect'
|
||||||
require_dependency 'chunks/wiki'
|
require_dependency 'chunks/wiki'
|
||||||
require_dependency 'chunks/literal'
|
require_dependency 'chunks/literal'
|
||||||
require 'chunks/nowiki'
|
require 'chunks/nowiki'
|
||||||
|
@ -38,7 +39,7 @@ require 'sanitizer'
|
||||||
module ChunkManager
|
module ChunkManager
|
||||||
attr_reader :chunks_by_type, :chunks_by_id, :chunks, :chunk_id
|
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 ]
|
WikiChunk::Word ]
|
||||||
|
|
||||||
HIDE_CHUNKS = [ Literal::Pre, Literal::Tags, Literal::Math ]
|
HIDE_CHUNKS = [ Literal::Pre, Literal::Tags, Literal::Math ]
|
||||||
|
|
|
@ -118,7 +118,7 @@ class FileControllerTest < ActionController::TestCase
|
||||||
# edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif'
|
# edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif'
|
||||||
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
||||||
renderer = PageRenderer.new
|
renderer = PageRenderer.new
|
||||||
@wiki.revise_page('wiki1', 'Oak', '[[rails-e2e.gif:pic]]',
|
@wiki.revise_page('wiki1', 'Oak', 'Oak', '[[rails-e2e.gif:pic]]',
|
||||||
Time.now, 'AnonymousBrave', renderer)
|
Time.now, 'AnonymousBrave', renderer)
|
||||||
assert_equal "<p><span class='newWikiWord'>rails-e2e.gif<a href='../file/rails-e2e.gif'>" +
|
assert_equal "<p><span class='newWikiWord'>rails-e2e.gif<a href='../file/rails-e2e.gif'>" +
|
||||||
"?</a></span></p>",
|
"?</a></span></p>",
|
||||||
|
@ -146,7 +146,7 @@ class FileControllerTest < ActionController::TestCase
|
||||||
assert @web.has_file?('rails-e2e.gif')
|
assert @web.has_file?('rails-e2e.gif')
|
||||||
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
|
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
|
||||||
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
||||||
@wiki.revise_page('wiki1', 'Oak', 'Try [[rails-e2e.gif:pic]] again.',
|
@wiki.revise_page('wiki1', 'Oak', 'Oak', 'Try [[rails-e2e.gif:pic]] again.',
|
||||||
Time.now, 'AnonymousBrave', renderer)
|
Time.now, 'AnonymousBrave', renderer)
|
||||||
assert_equal "<p>Try <img alt='Rails, end-to-end' src='../file/rails-e2e.gif'/> again.</p>",
|
assert_equal "<p>Try <img alt='Rails, end-to-end' src='../file/rails-e2e.gif'/> again.</p>",
|
||||||
renderer.display_content
|
renderer.display_content
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PageTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_revise
|
def test_revise
|
||||||
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55),
|
@page.revise('HisWay would be MyWay in kinda lame', @page.name, Time.local(2004, 4, 4, 16, 52),
|
||||||
'MarianneSyhler', test_renderer)
|
'MarianneSyhler', test_renderer)
|
||||||
@page.reload
|
@page.reload
|
||||||
|
|
||||||
|
@ -44,14 +44,14 @@ class PageTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_revise_continous_revision
|
def test_revise_continous_revision
|
||||||
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55),
|
@page.revise('HisWay would be MyWay in kinda lame', @page.name, Time.local(2004, 4, 4, 16, 55),
|
||||||
'MarianneSyhler', test_renderer)
|
'MarianneSyhler', test_renderer)
|
||||||
@page.reload
|
@page.reload
|
||||||
assert_equal 2, @page.revisions.length
|
assert_equal 2, @page.revisions.length
|
||||||
assert_equal 'HisWay would be MyWay in kinda lame', @page.content
|
assert_equal 'HisWay would be MyWay in kinda lame', @page.content
|
||||||
|
|
||||||
# consecutive revision by the same author within 30 minutes doesn't create a new revision
|
# consecutive revision by the same author within 30 minutes doesn't create a new revision
|
||||||
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57),
|
@page.revise('HisWay would be MyWay in kinda update', @page.name, Time.local(2004, 4, 4, 16, 57),
|
||||||
'MarianneSyhler', test_renderer)
|
'MarianneSyhler', test_renderer)
|
||||||
@page.reload
|
@page.reload
|
||||||
assert_equal 2, @page.revisions.length
|
assert_equal 2, @page.revisions.length
|
||||||
|
@ -59,7 +59,7 @@ class PageTest < ActiveSupport::TestCase
|
||||||
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revised_at
|
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revised_at
|
||||||
|
|
||||||
# but consecutive revision by another author results in a new revision
|
# but consecutive revision by another author results in a new revision
|
||||||
@page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58),
|
@page.revise('HisWay would be MyWay in the house', @page.name, Time.local(2004, 4, 4, 16, 58),
|
||||||
'DavidHeinemeierHansson', test_renderer)
|
'DavidHeinemeierHansson', test_renderer)
|
||||||
@page.reload
|
@page.reload
|
||||||
assert_equal 3, @page.revisions.length
|
assert_equal 3, @page.revisions.length
|
||||||
|
@ -67,18 +67,31 @@ class PageTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# consecutive update after 30 minutes since the last one also creates a new revision,
|
# consecutive update after 30 minutes since the last one also creates a new revision,
|
||||||
# even when it is by the same author
|
# even when it is by the same author
|
||||||
@page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30),
|
@page.revise('HisWay would be MyWay in my way', @page.name, Time.local(2004, 4, 4, 17, 30),
|
||||||
'DavidHeinemeierHansson', test_renderer)
|
'DavidHeinemeierHansson', test_renderer)
|
||||||
@page.reload
|
@page.reload
|
||||||
assert_equal 4, @page.revisions.length
|
assert_equal 4, @page.revisions.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_change_name
|
||||||
|
@page.revise('HisWay would be MyWay in my way', 'SecondPage', Time.local(2004, 4, 5, 17, 56),
|
||||||
|
'MarianneSyhler', test_renderer)
|
||||||
|
@page.reload
|
||||||
|
|
||||||
|
assert_equal "Second Page", @page.plain_name
|
||||||
|
assert_equal 2, @page.revisions.length, 'Should have two revisions'
|
||||||
|
assert_equal 'MarianneSyhler', @page.current_revision.author.to_s,
|
||||||
|
'Marianne should be the author now'
|
||||||
|
assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author.to_s,
|
||||||
|
'David was the first author'
|
||||||
|
end
|
||||||
|
|
||||||
def test_revise_content_unchanged
|
def test_revise_content_unchanged
|
||||||
last_revision_before = @page.current_revision
|
last_revision_before = @page.current_revision
|
||||||
revisions_number_before = @page.revisions.size
|
revisions_number_before = @page.revisions.size
|
||||||
|
|
||||||
assert_raises(Instiki::ValidationError) {
|
assert_raises(Instiki::ValidationError) {
|
||||||
@page.revise(@page.current_revision.content, Time.now, 'AlexeyVerkhovsky', test_renderer)
|
@page.revise(@page.current_revision.content, @page.name, Time.now, 'AlexeyVerkhovsky', test_renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_equal last_revision_before, @page.current_revision(true)
|
assert_equal last_revision_before, @page.current_revision(true)
|
||||||
|
@ -88,7 +101,7 @@ class PageTest < ActiveSupport::TestCase
|
||||||
def test_revise_changes_references_from_wanted_to_linked_for_new_pages
|
def test_revise_changes_references_from_wanted_to_linked_for_new_pages
|
||||||
web = Web.find(1)
|
web = Web.find(1)
|
||||||
new_page = Page.new(:web => web, :name => 'NewPage')
|
new_page = Page.new(:web => web, :name => 'NewPage')
|
||||||
new_page.revise('Reference to WantedPage, and to WantedPage2', Time.now, 'AlexeyVerkhovsky',
|
new_page.revise('Reference to WantedPage, and to WantedPage2', 'NewPage', Time.now, 'AlexeyVerkhovsky',
|
||||||
test_renderer)
|
test_renderer)
|
||||||
|
|
||||||
references = new_page.wiki_references(true)
|
references = new_page.wiki_references(true)
|
||||||
|
@ -99,7 +112,7 @@ class PageTest < ActiveSupport::TestCase
|
||||||
assert_equal WikiReference::WANTED_PAGE, references[1].link_type
|
assert_equal WikiReference::WANTED_PAGE, references[1].link_type
|
||||||
|
|
||||||
wanted_page = Page.new(:web => web, :name => 'WantedPage')
|
wanted_page = Page.new(:web => web, :name => 'WantedPage')
|
||||||
wanted_page.revise('And here it is!', Time.now, 'AlexeyVerkhovsky', test_renderer)
|
wanted_page.revise('And here it is!', 'WantedPage', Time.now, 'AlexeyVerkhovsky', test_renderer)
|
||||||
|
|
||||||
# link type stored for NewPage -> WantedPage reference should change from WANTED to LINKED
|
# link type stored for NewPage -> WantedPage reference should change from WANTED to LINKED
|
||||||
# reference NewPage -> WantedPage2 should remain the same
|
# reference NewPage -> WantedPage2 should remain the same
|
||||||
|
@ -112,8 +125,8 @@ class PageTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rollback
|
def test_rollback
|
||||||
@page.revise("spot two", Time.now, "David", test_renderer)
|
@page.revise("spot two", @page.name, Time.now, "David", test_renderer)
|
||||||
@page.revise("spot three", Time.now + 2000, "David", test_renderer)
|
@page.revise("spot three", @page.name, Time.now + 2000, "David", test_renderer)
|
||||||
assert_equal 3, @page.revisions(true).length, "Should have three revisions"
|
assert_equal 3, @page.revisions(true).length, "Should have three revisions"
|
||||||
@page.current_revision(true)
|
@page.current_revision(true)
|
||||||
@page.rollback(0, Time.now, '127.0.0.1', test_renderer)
|
@page.rollback(0, Time.now, '127.0.0.1', test_renderer)
|
||||||
|
|
Loading…
Reference in a new issue