Merge branch 'master' into amazon-ses

This commit is contained in:
albert
2013-03-09 11:45:54 -05:00
20 changed files with 143 additions and 67 deletions

View File

@@ -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);
}
});

View File

@@ -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();

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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?

View File

@@ -4,7 +4,7 @@ module PostAppealsHelper
html << '<ul>'
post.appeals.each do |appeal|
html << '<li>' + appeal.reason + ' - ' + link_to(appeal.creator.name, user_path(appeal.creator)) + ' ' + time_ago_in_words_tagged(appeal.created_at) + '</li>'
html << '<li>' + DText.parse_inline(appeal.reason).html_safe + ' - ' + link_to(appeal.creator.name, user_path(appeal.creator)) + ' ' + time_ago_in_words_tagged(appeal.created_at) + '</li>'
end
html << '</ul>'

View File

@@ -5,7 +5,7 @@ module PostFlagsHelper
post.flags.each do |flag|
html << '<li>'
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))

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -20,7 +20,7 @@
</tbody>
</table>
<%= sequential_paginator(@mod_actions) %>
<%= numbered_paginator(@mod_actions) %>
</div>
</div>

View File

@@ -7,12 +7,13 @@
<%= render "posts/partials/index/mode_menu" %>
<%= render "posts/partials/index/blacklist" %>
<section id="tag-box">
<h1>Tags</h1>
<%= @post_set.presenter.tag_list_html(self) %>
</section>
<%= render "posts/partials/index/blacklist" %>
<%= render "posts/partials/index/related" %>
</aside>

View File

@@ -13,7 +13,7 @@
This post is rating locked.
<% else %>
<%= f.label :blank, "Rating" %>
<fieldset class="ratings">
<%= f.radio_button :rating, :e %>
<%= f.label :rating_e, "Explicit" %>
@@ -26,18 +26,18 @@
</fieldset>
<% end %>
</div>
<% if CurrentUser.is_builder? %>
<div class="input">
<%= f.label :blank, "Lock" %>
<fieldset class="locks">
<%= 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 @@
</fieldset>
</div>
<% end %>
<div class="input">
<%= f.label :parent_id, "Parent" %>
<%= f.text_field :parent_id, :size => 5 %>
</div>
<div class="input">
<%= f.label :source %>
<%= f.text_field :source %>
<%= button_tag "Similar", :id => "similar-button", :type => "button" %>
<%= button_tag "Artist", :id => "find-artist-button", :type => "button" %>
</div>
<div class="input">
<div>
<%= f.label :tag_string, "Tags" %>
<%= f.text_area :tag_string , :size => "50x3" %>
</div>
<%= 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 @@
<div class="input">
<%= submit_tag "Submit" %>
</div>
<div id="related-tags-container">
<h1>Related Tags</h1>
<div id="related-tags">
</div>
</div>
<% end %>

View File

@@ -5,9 +5,9 @@
<section>
<h1>Listing</h1>
<ul>
<li><span class="key">&larr;</span> Previous page</li>
<li><span class="key">&rarr;</span> Next page</li>
<li><span class="key">/</span> Search</li>
<li><span class="key">a</span> Previous page</li>
<li><span class="key">d</span> Next page</li>
<li><span class="key">q</span> Search</li>
</ul>
</section>
@@ -16,10 +16,11 @@
<ul>
<li><span class="key">n</span> New note</li>
<li><span class="key">e</span> Edit tags</li>
<li><span class="key">/</span> Search</li>
<li><span class="key">space</span> Scroll down/next post</li>
<li><span class="key">&larr;</span> Previous post</li>
<li><span class="key">&rarr;</span> Next post</li>
<li><span class="key">q</span> Search</li>
<li><span class="key">w</span> Scroll up</li>
<li><span class="key">s</span> Scroll down</li>
<li><span class="key">a</span> Previous post</li>
<li><span class="key">d</span> Next post</li>
</ul>
</section>
</div>

View File

@@ -1 +1 @@
$("#favorite_tags").val(<%= raw @user.favorite_tags.to_json %>);
$("#user_favorite_tags").val(<%= raw @user.favorite_tags.to_json %>);

View File

@@ -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)

View File

@@ -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

View File

@@ -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