diff --git a/app/models/page.rb b/app/models/page.rb index 2ce6feb3..c799792a 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -72,6 +72,10 @@ class Page < ActiveRecord::Base wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name } end + def categories + wiki_references.select { |ref| ref.category? }.map { |ref| ref.referenced_name } + end + def linked_from web.select.pages_that_link_to(name) end diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index 6277195b..d4d624aa 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -81,16 +81,6 @@ class WikiReference < ActiveRecord::Base row['name'].as_utf8 if row end - def self.page_categories(web, page_name) - query = - "SELECT referenced_name FROM wiki_references JOIN pages " + - "ON wiki_references.page_id = pages.id " + - "WHERE pages.name = ? " + - "AND wiki_references.link_type = '#{CATEGORY}' " + - "AND pages.web_id = '#{web.id}'" - names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['referenced_name'].as_utf8 } - end - def self.pages_in_category(web, category) query = "SELECT name FROM pages JOIN wiki_references " + @@ -142,4 +132,8 @@ class WikiReference < ActiveRecord::Base link_type == WANTED_FILE end + def category? + link_type == CATEGORY + end + end diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index b9239251..c273a4f1 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -69,8 +69,7 @@ function cleanAuthorName() { } document.forms["editForm"].elements["content"].focus(); -<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) and - !WikiReference.page_categories(@web, @page.name).include?('S5-slideshow') -%> +<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) and !@page.categories.include?('S5-slideshow') -%> addS5button('<%= CGI.escapeHTML(@page.name) %>'); <%- end -%> //-->