diff --git a/app/assets/javascripts/artists.js b/app/assets/javascripts/artists.js index 8a6f2bcfb..237d4f5fb 100644 --- a/app/assets/javascripts/artists.js +++ b/app/assets/javascripts/artists.js @@ -6,13 +6,15 @@ Danbooru.Artist.initialize_check_name_link(); if (Danbooru.meta("enable-auto-complete") === "true") { - Danbooru.Artist.initialize_auto_complete(); + Danbooru.Artist.initialize_autocomplete(); } } } - Danbooru.Artist.initialize_auto_complete = function() { - $("#quick_search_name").autocomplete({ + Danbooru.Artist.initialize_autocomplete = function() { + var $fields = $("#search_name,#quick_search_name"); + + $fields.autocomplete({ minLength: 1, source: function(req, resp) { $.ajax({ @@ -32,10 +34,16 @@ } }); } - }).data("uiAutocomplete")._renderItem = function(list, artist) { + }); + + var render_artist = function(list, artist) { var $link = $("").addClass("tag-type-1").text(artist.label); return $("
  • ").data("item.autocomplete", artist).append($link).appendTo(list); } + + $fields.each(function(i, field) { + $(field).data("uiAutocomplete")._renderItem = render_artist; + }); } Danbooru.Artist.initialize_check_name_link = function() { diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index ff1ff810e..998c2c7cd 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -36,22 +36,41 @@ } Danbooru.Post.initialize_tag_autocomplete = function() { - var $fields = $("#tags,#post_tag_string,#upload_tag_string"); + var $fields = $( + "#tags,#post_tag_string,#upload_tag_string,#tag-script-field," + + "#search_post_tags_match,#c-tags #search_name_matches,#c-tag-aliases #query,#c-tag-implications #query," + + "#wiki_page_title,#artist_name," + + "#tag_alias_request_antecedent_name,#tag_alias_request_consequent_name," + + "#tag_implication_request_antecedent_name,#tag_implication_request_consequent_name," + + "#tag_alias_antecedent_name,#tag_alias_consequent_name," + + "#tag_implication_antecedent_name,#tag_implication_consequent_name" + ); $fields.autocomplete({ focus: function() { return false; }, select: function(event, ui) { - this.value = this.value.replace(/\S+\s*$/g, ui.item.value + " "); + var before_caret_text = this.value.substring(0, this.selectionStart); + var after_caret_text = this.value.substring(this.selectionStart); + + this.value = before_caret_text.replace(/\S+\s*$/g, ui.item.value + " "); + + // Preserve original caret position to prevent it from jumping to the end + var original_start = this.selectionStart; + this.value += after_caret_text; + this.selectionStart = this.selectionEnd = original_start; + return false; }, source: function(req, resp) { - if (req.term.match(/ $/)) { + var before_caret_text = req.term.substring(0, this.element.get(0).selectionStart); + + if (before_caret_text.match(/ $/)) { return; } - var term = req.term.match(/\S+/g).pop(); + var term = before_caret_text.match(/\S+/g).pop(); $.ajax({ url: "/tags.json", data: { diff --git a/app/assets/javascripts/related_tag.js b/app/assets/javascripts/related_tag.js index 69e68ad60..931dfd017 100644 --- a/app/assets/javascripts/related_tag.js +++ b/app/assets/javascripts/related_tag.js @@ -105,8 +105,14 @@ var $dest = $("#related-tags"); $dest.empty(); - $dest.append(this.build_html("recent", this.other_tags(Danbooru.Cookie.get("recent_tags_with_categories")))); - $dest.append(this.build_html("frequent", this.other_tags(Danbooru.Cookie.get("favorite_tags_with_categories")))); + var recent_tags = Danbooru.Cookie.get("recent_tags_with_categories"); + var favorite_tags = Danbooru.Cookie.get("favorite_tags_with_categories"); + if (recent_tags.length) { + $dest.append(this.build_html("recent", this.other_tags(recent_tags))); + } + if (favorite_tags.length) { + $dest.append(this.build_html("frequent", this.other_tags(favorite_tags))); + } $dest.append(this.build_html(query, related_tags)); if (wiki_page_tags.length) { $dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags)); diff --git a/app/assets/javascripts/wiki_pages.js b/app/assets/javascripts/wiki_pages.js index 47a7e0f2f..c579e846c 100644 --- a/app/assets/javascripts/wiki_pages.js +++ b/app/assets/javascripts/wiki_pages.js @@ -9,7 +9,9 @@ Danbooru.WikiPage.initialize_typeahead = function() { if (Danbooru.meta("enable-auto-complete") === "true") { - $("#quick_search_title,#wiki_page_title").autocomplete({ + var $fields = $("#search_title,#quick_search_title"); + + $fields.autocomplete({ minLength: 1, source: function(req, resp) { $.ajax({ @@ -20,16 +22,26 @@ }, method: "get", success: function(data) { - resp($.map(data, function(tag) { + resp($.map(data, function(wiki_page) { return { - label: tag.title.replace(/_/g, " "), - value: tag.title + label: wiki_page.title.replace(/_/g, " "), + value: wiki_page.title, + category: wiki_page.category_name }; })); } }); } }); + + var render_wiki_page = function(list, wiki_page) { + var $link = $("").addClass("tag-type-" + wiki_page.category).text(wiki_page.label); + return $("
  • ").data("item.autocomplete", wiki_page).append($link).appendTo(list); + } + + $fields.each(function(i, field) { + $(field).data("uiAutocomplete")._renderItem = render_wiki_page; + }); } } })(); diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 65e571ff4..0f6b31a10 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -50,7 +50,7 @@ class ForumPostsController < ApplicationController @forum_post = ForumPost.find(params[:id]) check_privilege(@forum_post) @forum_post.update_attributes(params[:forum_post]) - respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page)) + respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page, :anchor => "forum_post_#{@forum_post.id}")) end def destroy diff --git a/app/controllers/post_versions_controller.rb b/app/controllers/post_versions_controller.rb index ddf634239..bc0ac7d20 100644 --- a/app/controllers/post_versions_controller.rb +++ b/app/controllers/post_versions_controller.rb @@ -16,7 +16,11 @@ class PostVersionsController < ApplicationController def undo @post_version = PostVersion.find(params[:id]) - @post_version.undo! + + if Danbooru.config.can_user_see_post?(CurrentUser.user, @post_version.post) + @post_version.undo! + end + respond_with(@post_version) do |format| format.js end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 219cf6608..7b995bcc2 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -69,7 +69,11 @@ class PostsController < ApplicationController def revert @post = Post.find(params[:id]) @version = PostVersion.find(params[:version_id]) - @post.revert_to!(@version) + + if Danbooru.config.can_user_see_post?(CurrentUser.user, @post) + @post.revert_to!(@version) + end + respond_with(@post) do |format| format.js end diff --git a/app/controllers/tag_corrections_controller.rb b/app/controllers/tag_corrections_controller.rb index 0c6511e1f..2f6303937 100644 --- a/app/controllers/tag_corrections_controller.rb +++ b/app/controllers/tag_corrections_controller.rb @@ -14,7 +14,7 @@ class TagCorrectionsController < ApplicationController if params[:commit] == "Fix" @correction.fix! - redirect_to tags_path(:search => {:name_matches => @correction.tag.name}), :notice => "Tag will be fixed in a few seconds" + redirect_to tags_path(:search => {:name_matches => @correction.tag.name, :hide_empty => "no"}), :notice => "Tag will be fixed in a few seconds" else redirect_to tags_path(:search => {:name_matches => @correction.tag.name}) end diff --git a/app/models/artist.rb b/app/models/artist.rb index a0c07d0dc..766b3534e 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -81,7 +81,7 @@ class Artist < ActiveRecord::Base def rename!(new_name) new_wiki_page = WikiPage.titled(new_name).first - if new_wiki_page + if new_wiki_page && wiki_page # Merge the old wiki page into the new one new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes) elsif wiki_page @@ -306,6 +306,24 @@ class Artist < ActiveRecord::Base end end + module ApiMethods + def hidden_attributes + super + [:other_names_index] + end + + def legacy_api_hash + return { + :id => id, + :name => name, + :other_names => other_names, + :group_name => group_name, + :urls => artist_urls.map {|x| x.url}, + :is_active => is_active?, + :updater_id => 0 + } + end + end + include UrlMethods include NameMethods include GroupMethods @@ -315,6 +333,7 @@ class Artist < ActiveRecord::Base include TagMethods include BanMethods extend SearchMethods + include ApiMethods def status if is_banned? && is_active? @@ -328,18 +347,6 @@ class Artist < ActiveRecord::Base end end - def legacy_api_hash - return { - :id => id, - :name => name, - :other_names => other_names, - :group_name => group_name, - :urls => artist_urls.map {|x| x.url}, - :is_active => is_active?, - :updater_id => 0 - } - end - def initialize_creator self.creator_id = CurrentUser.user.id end diff --git a/app/models/comment.rb b/app/models/comment.rb index a2973cf22..40a04c32e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -140,6 +140,10 @@ class Comment < ActiveRecord::Base def editable_by?(user) creator_id == user.id || user.is_janitor? end + + def hidden_attributes + super + [:body_index] + end end Comment.connection.extend(PostgresExtensions) diff --git a/app/models/dmail.rb b/app/models/dmail.rb index e79597bf4..dc7c6a065 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -188,4 +188,8 @@ class Dmail < ActiveRecord::Base def visible_to?(user) user.is_moderator? || owner_id == user.id end + + def hidden_attributes + super + [:message_index] + end end diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index db1efde41..9e2c308d4 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -161,4 +161,8 @@ class ForumPost < ActiveRecord::Base x.body = x.quoted_response end end + + def hidden_attributes + super + [:text_index] + end end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index e018552a9..b73a6a4a0 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -96,4 +96,8 @@ class ForumTopic < ActiveRecord::Base def presenter(forum_posts) @presenter ||= ForumTopicPresenter.new(self, forum_posts) end + + def hidden_attributes + super + [:text_index] + end end diff --git a/app/models/note.rb b/app/models/note.rb index 3ca9c5347..5a142f73f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -61,6 +61,10 @@ class Note < ActiveRecord::Base end module ApiMethods + def hidden_attributes + super + [:body_index] + end + def serializable_hash(options = {}) options ||= {} options[:except] ||= [] @@ -75,8 +79,8 @@ class Note < ActiveRecord::Base def to_xml(options = {}, &block) options ||= {} - options[:procs] ||= [] - options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} + options[:methods] ||= [] + options[:methods] += [:creator_name] super(options, &block) end end diff --git a/app/models/pool.rb b/app/models/pool.rb index c100fba90..6e126b3a4 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -168,7 +168,7 @@ class Pool < ActiveRecord::Base end def page_number(post_id) - post_id_array.find_index(post_id) + 1 + post_id_array.find_index(post_id).to_i + 1 end def deletable_by?(user) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 37fb24416..f049b829f 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -145,8 +145,7 @@ class TagAlias < ActiveRecord::Base if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank? CurrentUser.scoped(creator, creator_ip_addr) do antecedent_wiki.update_attributes( - :title => consequent_name, - :body => "[i]This page was automatically renamed from [[#{antecedent_name}]] by a tag alias.[/i]\n\n#{antecedent_wiki.body}" + :title => consequent_name ) end end diff --git a/app/models/upload.rb b/app/models/upload.rb index 28fc229e3..665405f21 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -396,8 +396,8 @@ class Upload < ActiveRecord::Base def to_xml(options = {}, &block) options ||= {} - options[:procs] ||= [] - options[:procs] << lambda {|options, record| options[:builder].tag!("uploader-name", record.uploader_name)} + options[:methods] ||= [] + options[:methods] += [:uploader_name] super(options, &block) end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 3d9174372..e997e17ca 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -58,13 +58,17 @@ class WikiPage < ActiveRecord::Base end module ApiMethods + def hidden_attributes + super + [:body_index] + end + def serializable_hash(options = {}) options ||= {} options[:except] ||= [] options[:except] += hidden_attributes unless options[:builder] options[:methods] ||= [] - options[:methods] += [:creator_name] + options[:methods] += [:creator_name, :category_name] end hash = super(options) hash @@ -72,8 +76,8 @@ class WikiPage < ActiveRecord::Base def to_xml(options = {}, &block) options ||= {} - options[:procs] ||= [] - options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} + options[:methods] ||= [] + options[:methods] += [:creator_name, :category_name] super(options, &block) end end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index fa40820df..f91fa7e14 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -1,6 +1,6 @@ class PostPresenter < Presenter def self.preview(post, options = {}) - if post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ + if post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ && !options[:raw] return "" end diff --git a/app/presenters/post_set_presenters/base.rb b/app/presenters/post_set_presenters/base.rb index 98976ca30..c06c1d69c 100644 --- a/app/presenters/post_set_presenters/base.rb +++ b/app/presenters/post_set_presenters/base.rb @@ -12,7 +12,7 @@ module PostSetPresenters end posts.each do |post| - html << PostPresenter.preview(post, :tags => @post_set.tag_string) + html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw) html << "\n" end diff --git a/app/views/admin/alias_and_implication_imports/new.html.erb b/app/views/admin/alias_and_implication_imports/new.html.erb index 592deda94..a1076a451 100644 --- a/app/views/admin/alias_and_implication_imports/new.html.erb +++ b/app/views/admin/alias_and_implication_imports/new.html.erb @@ -29,7 +29,7 @@ create implication aaa -> bbb
    diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 3662a7a98..a72285e99 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -9,7 +9,7 @@
    <%= format_text(comment.body) %> - <% if comment.updater_id.present? && (comment.updater_id != comment.creator_id || comment.created_at != comment.updated_at) %> + <% if comment.updated_at - comment.created_at > 5.minutes %>

    Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %>

    <% end %>
    diff --git a/app/views/notes/search.html.erb b/app/views/notes/search.html.erb index 8a8386c51..01a476127 100644 --- a/app/views/notes/search.html.erb +++ b/app/views/notes/search.html.erb @@ -5,8 +5,8 @@ <%= form_tag(notes_path, :method => :get, :class => "simple_form") do %> <%= hidden_field_tag "group_by", "note" %> <%= search_field "body_matches", :label => "Body" %> - <%= search_field "post_tags_match", :label => "Tags" %> <%= search_field "creator_name", :label => "Author" %> + <%= search_field "post_tags_match", :label => "Tags" %> <%= submit_tag "Search" %> <% end %> diff --git a/app/views/post_versions/_listing.html.erb b/app/views/post_versions/_listing.html.erb index fbb61dc26..a146a7d41 100644 --- a/app/views/post_versions/_listing.html.erb +++ b/app/views/post_versions/_listing.html.erb @@ -36,10 +36,12 @@ <%= post_version_diff(post_version) %> <% if CurrentUser.is_member? %> - <% if post_version.id != post_version.post.versions.first.id %> - <%= link_to "Undo", undo_post_version_path(post_version), :method => :put, :remote => true %> | + <% if Danbooru.config.can_user_see_post?(CurrentUser.user, post_version.post) %> + <% if post_version.id != post_version.post.versions.first.id %> + <%= link_to "Undo", undo_post_version_path(post_version), :method => :put, :remote => true %> | + <% end %> + <%= link_to "Revert to", revert_post_path(post_version.post_id, :version_id => post_version.id), :method => :put, :remote => true %> <% end %> - <%= link_to "Revert to", revert_post_path(post_version.post_id, :version_id => post_version.id), :method => :put, :remote => true %> <% end %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 3e4bbe2ff..3b9e3b69a 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -24,9 +24,7 @@

    History

      - <% if Danbooru.config.can_user_see_post?(CurrentUser.user, @post) %> -
    • <%= fast_link_to "Tags", post_versions_path(:search => {:post_id => @post.id}) %>
    • - <% end %> +
    • <%= fast_link_to "Tags", post_versions_path(:search => {:post_id => @post.id}) %>
    • <%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %>
    • <%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %>
    • <%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %>
    • diff --git a/config/deploy.rb b/config/deploy.rb index ee3d39aa1..a868261b6 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -64,6 +64,7 @@ namespace :data do run "mkdir -p #{release_path}/public/cache" run "mkdir -p #{deploy_to}/shared/system/cache" run "touch #{deploy_to}/shared/system/cache/tags.json" + run "ln -s #{deploy_to}/shared/system/cache/tags.json #{release_path}/public/cache/tags.json" run "touch #{deploy_to}/shared/system/cache/tags.json.gz" run "ln -s #{deploy_to}/shared/system/cache/tags.json.gz #{release_path}/public/cache/tags.json.gz" end diff --git a/config/routes.rb b/config/routes.rb index 1f3ed4dd0..a4f4cc3bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -312,7 +312,7 @@ Danbooru::Application.routes.draw do page = req.params[:before_id].present? ? "b#{req.params[:before_id]}" : req.params[:page] "/post_versions?page=#{page}&search[updater_id]=#{req.params[:user_id]}" end) - match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"} + match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}&search[post_id]=#{req.params[:post_id]}"} match "/tag/index.xml", :controller => "legacy", :action => "tags", :format => "xml" match "/tag/index.json", :controller => "legacy", :action => "tags", :format => "json" diff --git a/test/unit/alias_and_implication_importer_test.rb b/test/unit/alias_and_implication_importer_test.rb index ec4e58b6d..65a753c53 100644 --- a/test/unit/alias_and_implication_importer_test.rb +++ b/test/unit/alias_and_implication_importer_test.rb @@ -60,7 +60,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase @importer.process! artist.reload assert_equal("bbb", artist.name) - assert_match(/automatically renamed/, artist.notes) + assert_equal("testing", artist.notes) end end end