diff --git a/app/assets/javascripts/paginator.js b/app/assets/javascripts/paginator.js index 14969a601..c9c0a294e 100644 --- a/app/assets/javascripts/paginator.js +++ b/app/assets/javascripts/paginator.js @@ -18,8 +18,8 @@ $(function() { if ($(".paginator").length && (Danbooru.meta("enable-js-navigation") === "true")) { - $(document).bind("keydown.right", Danbooru.Paginator.next_page); - $(document).bind("keydown.left", Danbooru.Paginator.prev_page); + $(document).bind("keydown.d", Danbooru.Paginator.next_page); + $(document).bind("keydown.a", Danbooru.Paginator.prev_page); } }); diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index e3859b2d3..c3ce93ab5 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -33,7 +33,6 @@ Danbooru.Post.initialize_similar = function() { $("#similar-button").click(function(e) { var old_source_name = $("#post_source").attr("name"); - var old_target = $("#form").attr("target"); var old_action = $("#form").attr("action"); $("#post_source").attr("name", "url"); @@ -43,14 +42,14 @@ $("#form").trigger("submit"); $("#post_source").attr("name", old_source_name); - $("#form").attr("target", old_target); + $("#form").attr("target", ""); $("#form").attr("action", old_action); e.preventDefault(); }); } - Danbooru.Post.nav_pool_prev = function() { + Danbooru.Post.nav_prev = function() { if ($("#search-seq-nav").length) { var href = $("#search-seq-nav a[rel=prev]").attr("href"); if (href) { @@ -64,7 +63,7 @@ } } - Danbooru.Post.nav_pool_next = function() { + Danbooru.Post.nav_next = function() { if ($("#search-seq-nav").length) { var href = $("#search-seq-nav a[rel=next]").attr("href"); location.href = href; @@ -76,17 +75,21 @@ } } - Danbooru.Post.nav_pool_scroll = function() { - var scroll_top = $(window).scrollTop() + $(window).height(); - - if (scroll_top > $("#image").height() + $("#image").offset().top + ($("#image").height() / 2)) { - Danbooru.Post.nav_pool_next(); - return; + Danbooru.Post.nav_scroll_down = function() { + var scroll_top = $(window).scrollTop() + ($(window).height() * 0.85); + Danbooru.scroll_to(scroll_top); + } + + Danbooru.Post.nav_scroll_up = function() { + var scroll_top = $(window).scrollTop() - ($(window).height() * 0.85); + if (scroll_top < 0) { + scroll_top = 0; } + Danbooru.scroll_to(scroll_top); } Danbooru.Post.initialize_shortcuts = function() { - $(document).bind("keydown./", function(e) { + $(document).bind("keydown.q", function(e) { $("#tags").trigger("focus"); e.preventDefault(); }); @@ -98,20 +101,24 @@ e.preventDefault(); }); - $(document).bind("keydown.left", function(e) { - Danbooru.Post.nav_pool_prev(); + $(document).bind("keydown.a", function(e) { + Danbooru.Post.nav_prev(); e.preventDefault(); }); - $(document).bind("keydown.right", function(e) { - Danbooru.Post.nav_pool_next(); + $(document).bind("keydown.d", function(e) { + Danbooru.Post.nav_next(); e.preventDefault(); }); - - $(document).bind("keydown.space", function(e) { - Danbooru.Post.nav_pool_scroll(); - }) } + + $(document).bind("keydown.s", function(e) { + Danbooru.Post.nav_scroll_down(); + }) + + $(document).bind("keydown.w", function(e) { + Danbooru.Post.nav_scroll_up(); + }) } Danbooru.Post.initialize_links = function() { @@ -229,9 +236,7 @@ $("#comments").hide(); $("#share").hide(); $("#post_tag_string").focus(); - if (Danbooru.meta("favorite-tags")) { - $("#related-tags-button").trigger("click"); - } + $("#related-tags-button").trigger("click"); } else { $("#edit").hide(); $("#comments").hide(); diff --git a/app/assets/javascripts/uploads.js b/app/assets/javascripts/uploads.js index 4a04df794..be2915af7 100644 --- a/app/assets/javascripts/uploads.js +++ b/app/assets/javascripts/uploads.js @@ -10,6 +10,7 @@ this.initialize_image(); this.initialize_info(); this.initialize_similar(); + $("#related-tags-button").trigger("click"); } } @@ -25,7 +26,6 @@ $("#similar-button").click(function(e) { var old_source_name = $("#upload_source").attr("name"); var old_file_name = $("#upload_file").attr("name") - var old_target = $("#form").attr("target"); var old_action = $("#form").attr("action"); $("#upload_source").attr("name", "url"); @@ -37,7 +37,7 @@ $("#upload_source").attr("name", old_source_name); $("#upload_file").attr("name", old_file_name); - $("#form").attr("target", old_target); + $("#form").attr("target", ""); $("#form").attr("action", old_action); e.preventDefault(); diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index b3cf2fa3c..ab70c6fc3 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -4,9 +4,15 @@ } Danbooru.scroll_to = function(element) { + var top = null; + if (typeof(element) === "number") { + top = element; + } else { + top = element.offset().top - 10; + } $('html, body').animate({ - scrollTop: element.offset().top - 10 - }, 250); + scrollTop: top + }, 0); } Danbooru.notice = function(msg) { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index cdedc4f84..fb53acc41 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -16,6 +16,12 @@ class PostsController < ApplicationController def show @post = Post.find(params[:id]) + + if !Danbooru.config.can_user_see_post?(CurrentUser.user, @post) + redirect_to(:back, :notice => "Post #{@post.id} is not available") + return + end + @post_flag = PostFlag.new(:post_id => @post.id) @post_appeal = PostAppeal.new(:post_id => @post.id) respond_with(@post) @@ -32,7 +38,11 @@ class PostsController < ApplicationController def update @post = Post.find(params[:id]) - @post.update_attributes(params[:post], :as => CurrentUser.role) + + if Danbooru.config.can_user_see_post?(CurrentUser.user, @post) + @post.update_attributes(params[:post], :as => CurrentUser.role) + end + respond_with(@post) do |format| format.html do if @post.errors.any? diff --git a/app/helpers/post_appeals_helper.rb b/app/helpers/post_appeals_helper.rb index 6274fc86c..c01d84914 100644 --- a/app/helpers/post_appeals_helper.rb +++ b/app/helpers/post_appeals_helper.rb @@ -4,7 +4,7 @@ module PostAppealsHelper html << '' diff --git a/app/helpers/post_flags_helper.rb b/app/helpers/post_flags_helper.rb index 4e65d869a..8a6751358 100644 --- a/app/helpers/post_flags_helper.rb +++ b/app/helpers/post_flags_helper.rb @@ -5,7 +5,7 @@ module PostFlagsHelper post.flags.each do |flag| html << '
  • ' - html << flag.reason + html << DText.parse_inline(flag.reason).html_safe if CurrentUser.is_janitor? html << ' - ' + link_to(flag.creator.name, user_path(flag.creator)) diff --git a/app/models/post.rb b/app/models/post.rb index f2719454b..bc6a54ae6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -32,7 +32,7 @@ class Post < ActiveRecord::Base validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?} # validate :validate_parent_does_not_have_a_parent attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :builder, :privileged, :platinum, :contributor, :janitor, :moderator, :admin, :default] - attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :janitor, :moderator, :admin] + attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin] attr_accessible :is_status_locked, :as => [:admin] module FileMethods diff --git a/app/models/tag.rb b/app/models/tag.rb index d3e1e170e..d621ad5c5 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -87,6 +87,7 @@ class Tag < ActiveRecord::Base def update_category_cache_for_all(force = false) if category_changed? || force update_category_cache + delay(:queue => "default").update_category_post_counts if category_changed? Danbooru.config.other_server_hosts.each do |host| delay(:queue => host).update_category_cache @@ -94,6 +95,14 @@ class Tag < ActiveRecord::Base end end + def update_category_post_counts + old_field = "tag_count_#{Danbooru.config.reverse_tag_category_mapping[category_was]}".downcase + new_field = "tag_count_#{category_name}".downcase + Post.without_timeout do + Post.raw_tag_match(name).update_all("#{old_field} = #{old_field} - 1, #{new_field} = #{new_field} + 1") + end + end + def update_category_cache Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour) end diff --git a/app/models/upload.rb b/app/models/upload.rb index 489f968ba..4d598f897 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -77,7 +77,11 @@ class Upload < ActiveRecord::Base validate_md5_uniqueness validate_md5_confirmation calculate_file_size(file_path) - calculate_dimensions(file_path) if has_dimensions? + add_file_size_tags!(file_path) + if has_dimensions? + calculate_dimensions(file_path) + add_dimension_tags! + end generate_resizes(file_path) move_file post = convert_to_post @@ -172,7 +176,17 @@ class Upload < ActiveRecord::Base self.image_width = image_size.get_width self.image_height = image_size.get_height end - + + def add_dimension_tags! + if image_width >= 10_000 || image_height >= 10_000 + self.tag_string = "#{tag_string} insanely_absurdres".strip + elsif image_width >= 3200 || image_height >= 2400 + self.tag_string = "#{tag_string} absurdres".strip + elsif image_width >= 1600 && image_height >= 1200 + self.tag_string = "#{tag_string} highres".strip + end + end + # Does this file have image dimensions? def has_dimensions? %w(jpg gif png swf).include?(file_ext) @@ -363,6 +377,12 @@ class Upload < ActiveRecord::Base include UploaderMethods extend SearchMethods + def add_file_size_tags!(file_path) + if file_size >= 10.megabytes + self.tag_string = "#{tag_string} huge_filesize".strip + end + end + def presenter @presenter ||= UploadPresenter.new(self) end diff --git a/app/models/user.rb b/app/models/user.rb index 51a8177d5..556f2d509 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -443,10 +443,6 @@ class User < ActiveRecord::Base limit = 10 + (approved_count / 10) - (deleted_count / 4) - pending_count end - if limit > 20 - limit = 20 - end - if limit < 0 limit = 0 end diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index dfc657e9b..8d1729288 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -50,12 +50,9 @@ class UserPresenter string = "base:10 + approved:(#{approved_count} / 10) - deleted:(#{deleted_count}) / 4 - pending:#{pending_count}" end - if limit >= 20 - limit = 20 - string += " = capped:20" - elsif limit < 0 + if limit < 0 limit = 0 - string += " = capped:0" + string += " = 0" else string += " = #{limit}" end diff --git a/app/views/mod_actions/index.html.erb b/app/views/mod_actions/index.html.erb index 8fd0e0792..f17c971b3 100644 --- a/app/views/mod_actions/index.html.erb +++ b/app/views/mod_actions/index.html.erb @@ -20,7 +20,7 @@ - <%= sequential_paginator(@mod_actions) %> + <%= numbered_paginator(@mod_actions) %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 6f4bbfea1..1b8ee299b 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -7,12 +7,13 @@ <%= render "posts/partials/index/mode_menu" %> + <%= render "posts/partials/index/blacklist" %> +

    Tags

    <%= @post_set.presenter.tag_list_html(self) %>
    - <%= render "posts/partials/index/blacklist" %> <%= render "posts/partials/index/related" %> diff --git a/app/views/posts/partials/show/_edit.html.erb b/app/views/posts/partials/show/_edit.html.erb index 4e4e574a0..b0da1e22a 100644 --- a/app/views/posts/partials/show/_edit.html.erb +++ b/app/views/posts/partials/show/_edit.html.erb @@ -13,7 +13,7 @@ This post is rating locked. <% else %> <%= f.label :blank, "Rating" %> - +
    <%= f.radio_button :rating, :e %> <%= f.label :rating_e, "Explicit" %> @@ -26,18 +26,18 @@
    <% end %> - + <% if CurrentUser.is_builder? %>
    <%= f.label :blank, "Lock" %> - +
    <%= f.check_box :is_note_locked %> <%= f.label :is_note_locked, "Notes" %> <%= f.check_box :is_rating_locked %> <%= f.label :is_rating_locked, "Rating" %> - + <% if CurrentUser.is_admin? %> <%= f.check_box :is_status_locked %> <%= f.label :is_status_locked, "Status" %> @@ -45,25 +45,25 @@
    <% end %> - +
    <%= f.label :parent_id, "Parent" %> <%= f.text_field :parent_id, :size => 5 %>
    - +
    <%= f.label :source %> <%= f.text_field :source %> <%= button_tag "Similar", :id => "similar-button", :type => "button" %> <%= button_tag "Artist", :id => "find-artist-button", :type => "button" %>
    - +
    <%= f.label :tag_string, "Tags" %> <%= f.text_area :tag_string , :size => "50x3" %>
    - + <%= button_tag "Related tags", :id => "related-tags-button", :type => "button" %> <%= button_tag "Artists", :id => "related-artists-button", :type => "button" %> <%= button_tag "Characters", :id => "related-characters-button", :type => "button" %> @@ -73,11 +73,11 @@
    <%= submit_tag "Submit" %>
    - + - + <% end %> diff --git a/app/views/static/keyboard_shortcuts.html.erb b/app/views/static/keyboard_shortcuts.html.erb index 6523c0438..8f24e20dd 100644 --- a/app/views/static/keyboard_shortcuts.html.erb +++ b/app/views/static/keyboard_shortcuts.html.erb @@ -5,9 +5,9 @@

    Listing

      -
    • Previous page
    • -
    • Next page
    • -
    • / Search
    • +
    • a Previous page
    • +
    • d Next page
    • +
    • q Search
    @@ -16,10 +16,11 @@
    diff --git a/app/views/users/restore_uploaded_tags.js.erb b/app/views/users/restore_uploaded_tags.js.erb index cc3d6d145..75f478ea2 100644 --- a/app/views/users/restore_uploaded_tags.js.erb +++ b/app/views/users/restore_uploaded_tags.js.erb @@ -1 +1 @@ -$("#favorite_tags").val(<%= raw @user.favorite_tags.to_json %>); +$("#user_favorite_tags").val(<%= raw @user.favorite_tags.to_json %>); diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 048d6a885..bf14f67ae 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -80,7 +80,7 @@ class CommentTest < ActiveSupport::TestCase comment_vote = c1.vote!("up") assert_equal([], comment_vote.errors.full_messages) comment_vote = c1.vote!("up") - assert_equal(["User has already voted for this comment"], comment_vote.errors.full_messages) + assert_equal(["You have already voted for this comment"], comment_vote.errors.full_messages) assert_equal(1, CommentVote.count) assert_equal(1, CommentVote.last.score) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index bd5758f2b..6a713aa3e 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -373,6 +373,12 @@ class PostTest < ActiveSupport::TestCase should "update the category cache of the tag" do assert_equal(Tag.categories.copyright, Cache.get("tc:abc")) end + + should "update the tag counts of the posts" do + assert_equal(0, @post.tag_count_artist) + assert_equal(1, @post.tag_count_copyright) + assert_equal(0, @post.tag_count_general) + end end context "tagged with a metatag" do diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 44518811c..7b43ec9ae 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -22,6 +22,31 @@ class UploadTest < ActiveSupport::TestCase teardown do FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*")) end + + context "that has insanely absurd res dimensions" do + setup do + @upload = FactoryGirl.build(:jpg_upload, :tag_string => "") + @upload.image_width = 10_000 + @upload.image_height = 10 + @upload.add_dimension_tags! + end + + should "have the insanely_absurdres tag" do + assert_match(/insanely_absurdres/, @upload.tag_string) + end + end + + context "that has a large flie size" do + setup do + @upload = FactoryGirl.build(:jpg_upload, :tag_string => "") + @upload.file_size = 11.megabytes + @upload.add_file_size_tags!(@upload.file_path) + end + + should "have the huge_filesize tag" do + assert_match(/huge_filesize/, @upload.tag_string) + end + end context "image size calculator" do should "discover the dimensions for a JPG" do @@ -81,17 +106,17 @@ class UploadTest < ActiveSupport::TestCase context "determining if a file is downloadable" do should "classify HTTP sources as downloadable" do - @upload = FactoryGirl.create(:source_upload, source: "http://www.example.com/1.jpg") + @upload = FactoryGirl.create(:source_upload, :source => "http://www.example.com/1.jpg") assert_not_nil(@upload.is_downloadable?) end should "classify HTTPS sources as downloadable" do - @upload = FactoryGirl.create(:source_upload, source: "https://www.example.com/1.jpg") + @upload = FactoryGirl.create(:source_upload, :source => "https://www.example.com/1.jpg") assert_not_nil(@upload.is_downloadable?) end should "classify non-HTTP/HTTPS sources as not downloadable" do - @upload = FactoryGirl.create(:source_upload, source: "ftp://www.example.com/1.jpg") + @upload = FactoryGirl.create(:source_upload, :source => "ftp://www.example.com/1.jpg") assert_nil(@upload.is_downloadable?) end end