From 12207bc01c208330d28c94b93a7260169a533223 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 6 Jun 2009 12:37:00 -0500 Subject: [PATCH] Redirect Targets are not Orphaned A pages that is linked-to, via a redirect, is not orphaned. --- app/models/page.rb | 4 ++++ app/models/page_set.rb | 4 ++-- app/models/wiki_reference.rb | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index 370a2ca7..e66e0415 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -72,6 +72,10 @@ class Page < ActiveRecord::Base web.select.pages_that_link_to(name) end + def redirects + wiki_references.select { |ref| ref.redirected_page? }.map { |ref| ref.referenced_name } + end + def included_from web.select.pages_that_include(name) end diff --git a/app/models/page_set.rb b/app/models/page_set.rb index fb0ecf46..f39d927a 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -67,8 +67,8 @@ class PageSet < Array if never_orphans.include? page.name false else -# references = pages_that_reference(page.name) - references = WikiReference.pages_that_reference(@web, page.name) + references = WikiReference.pages_that_reference(@web, page.name) + + WikiReference.pages_redirected_to(@web, page.name) references.empty? or references == [page.name] end } diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index d4db97f0..421489f1 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -60,9 +60,12 @@ class WikiReference < ActiveRecord::Base def self.pages_redirected_to(web, page_name) names = [] + redirected_pages = [] page = web.page(page_name) - redirected_pages = Thread.current[:page_redirects][page.name] - redirected_pages.each { |name| names = names + self.pages_that_reference(web, name) } if redirected_pages + redirected_pages.concat page.redirects + redirected_pages.concat Thread.current[:page_redirects][page.name] if + Thread.current[:page_redirects] && Thread.current[:page_redirects][page.name] + redirected_pages.uniq.each { |name| names = names + self.pages_that_reference(web, name) } names.uniq end