From 817880012c1a73fd4ba71e15299e08ff301b6458 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 20:47:00 -0400 Subject: [PATCH 01/13] Band-aid fix for bulleted list rendering (#1803) --- app/logical/d_text.rb | 10 +++++++--- test/unit/dtext_test.rb | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 67bfe6298..fd776ba5b 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -109,7 +109,11 @@ class DText end end - html += "
  • #{content}
  • " + if nest > 0 + html += "
  • #{content}
  • " + else + html += "

    #{content}

    " + end end while layout.any? @@ -187,7 +191,7 @@ class DText else "" end - + when /\[code\](?!\])/ flags[:code] = true '
    '
    @@ -208,7 +212,7 @@ class DText
             if stack.last == "expandable"
               stack.pop
               ''
    -        end 
    +        end
     
           else
             if flags[:code]
    diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb
    index aa6860e6b..f737446a6 100644
    --- a/test/unit/dtext_test.rb
    +++ b/test/unit/dtext_test.rb
    @@ -100,7 +100,7 @@ class DTextTest < ActiveSupport::TestCase
       def test_auto_urls_in_parentheses
         assert_equal('

    a (http://test.com) b

    ', p('a (http://test.com) b')) end - + def test_old_syle_links assert_equal('

    test

    ', p('"test":http://test.com')) end @@ -125,6 +125,10 @@ class DTextTest < ActiveSupport::TestCase assert_equal('', p("* post #1").gsub(/\n/, "")) end + def test_lists_not_preceded_by_newline + assert_equal('

    a

    ', p("a\n* b\n* c").gsub(/\n/, "")) + end + def test_inline_tags assert_equal('

    tag

    ', p("{{tag}}")) end From c6f79df22c6c5d61a4525490ba94598031582261 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 21:07:23 -0400 Subject: [PATCH 02/13] More complete fix for #1803 When a list is prefixed by more than one non-list line, output those prefix lines as part of the same paragraph, not as separate ones. Treat other lines not beginning with a "*" as continuations of the previous list item. --- app/logical/d_text.rb | 19 +++++++++++-------- test/unit/dtext_test.rb | 6 +++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index fd776ba5b..8f024028f 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -86,15 +86,22 @@ class DText def self.parse_list(str, options = {}) html = "" + current_item = "" layout = [] nest = 0 str.split(/\n/).each do |line| if line =~ /^\s*(\*+) (.+)/ + if nest > 0 + html += "
  • #{current_item}
  • " + elsif not current_item.strip.empty? + html += "

    #{current_item}

    " + end + nest = $1.size - content = parse_inline($2) + current_item = parse_inline($2) else - content = parse_inline(line) + current_item += parse_inline(line) end if nest > layout.size @@ -108,14 +115,10 @@ class DText html += "" end end - - if nest > 0 - html += "
  • #{content}
  • " - else - html += "

    #{content}

    " - end end + html += "
  • #{current_item}
  • " + while layout.any? elist = layout.pop html += "" diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb index f737446a6..a407f2335 100644 --- a/test/unit/dtext_test.rb +++ b/test/unit/dtext_test.rb @@ -126,7 +126,11 @@ class DTextTest < ActiveSupport::TestCase end def test_lists_not_preceded_by_newline - assert_equal('

    a

    • b
    • c
    ', p("a\n* b\n* c").gsub(/\n/, "")) + assert_equal('

    ab

    • c
    • d
    ', p("a\nb\n* c\n* d").gsub(/\n/, "")) + end + + def test_lists_with_multiline_items + assert_equal('

    a

    • bc
    • de
    ', p("a\n* b\nc\n* d\ne").gsub(/\n/, "")) end def test_inline_tags From 35aab77c5c1f562b6e8233ddcc9d18aff0218f7d Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 21:28:58 -0400 Subject: [PATCH 03/13] Fix superfluous "unvote" links (#1819) --- app/views/comments/index_for_post.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/comments/index_for_post.js.erb b/app/views/comments/index_for_post.js.erb index c7643f94a..183fd1bb9 100644 --- a/app/views/comments/index_for_post.js.erb +++ b/app/views/comments/index_for_post.js.erb @@ -11,3 +11,4 @@ $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments").ht Danbooru.Comment.initialize_reply_links(); Danbooru.Comment.initialize_edit_links(); +Danbooru.Comment.initialize_vote_links(); From 5082c9ef8c9d5952287d671fc084c1a167ce80aa Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Thu, 27 Jun 2013 15:51:13 -0400 Subject: [PATCH 04/13] Fix creation of user records after janitor trials Previously, a negative "demoted from janitor trial" record would always be created after a janitor trial ended, regardless of whether or not the user in question was actually demoted or not. This commit removes the culprit, an overly aggressive after_destroy callback, and instead directly invokes user record creation in the "demote!" method. --- app/models/janitor_trial.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index 1ec3ab20c..5b6fba2b1 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -3,7 +3,6 @@ class JanitorTrial < ActiveRecord::Base before_create :initialize_original_level after_create :send_dmail after_create :promote_user - after_destroy :create_feedback validates_presence_of :user before_validation :initialize_creator @@ -61,6 +60,7 @@ class JanitorTrial < ActiveRecord::Base def demote! user.update_column(:level, original_level) + self.create_feedback destroy end end From 2cfc5c296cd26288810167979a6db0810142d272 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Jul 2013 15:00:50 -0700 Subject: [PATCH 05/13] style intro page, ignore artist tags in Tag.trending, set root page to explore/posts/intro --- .../stylesheets/specific/explore.css.scss | 6 +++++ app/models/tag.rb | 7 ++++- config/routes.rb | 2 +- .../explore/posts_controller_test.rb | 27 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/functional/explore/posts_controller_test.rb diff --git a/app/assets/stylesheets/specific/explore.css.scss b/app/assets/stylesheets/specific/explore.css.scss index 62b76e2d6..3038cbabb 100644 --- a/app/assets/stylesheets/specific/explore.css.scss +++ b/app/assets/stylesheets/specific/explore.css.scss @@ -16,4 +16,10 @@ div#c-explore-posts { padding: 1em; margin-bottom: 2em; } + + div#a-intro { + width: 60em; + margin: 0 auto; + text-align: center; + } } diff --git a/app/models/tag.rb b/app/models/tag.rb index baa234c7c..94f9eb6de 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -141,7 +141,12 @@ class Tag < ActiveRecord::Base counts = counts.to_a.select {|x| x[1] > trending_count_limit} counts = counts.map do |tag_name, recent_count| tag = Tag.find_or_create_by_name(tag_name) - [tag_name, recent_count.to_f / tag.post_count.to_f] + if tag.category == Danbooru.config.tag_category_mapping["artist"] + # we're not interested in artists in the trending list + [tag_name, 0] + else + [tag_name, recent_count.to_f / tag.post_count.to_f] + end end counts.sort_by {|x| -x[1]}.slice(0, 25).map(&:first) diff --git a/config/routes.rb b/config/routes.rb index 24bedd4be..66b5c5deb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -352,5 +352,5 @@ Danbooru::Application.routes.draw do match "/static/benchmark" => "static#benchmark" match "/static/name_change" => "static#name_change", :as => "name_change" - root :to => "posts#index" + root :to => "explore/posts#intro" end diff --git a/test/functional/explore/posts_controller_test.rb b/test/functional/explore/posts_controller_test.rb new file mode 100644 index 000000000..23b5c3ce3 --- /dev/null +++ b/test/functional/explore/posts_controller_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +module Explore + class PostsControllerTest < ActionController::TestCase + context "in all cases" do + setup do + CurrentUser.user = FactoryGirl.create(:user) + CurrentUser.ip_addr = "127.0.0.1" + FactoryGirl.create(:post) + end + + context "#popular" do + should "render" do + get :popular + assert_response :success + end + end + + context "#intro" do + should "render" do + get :intro + assert_response :success + end + end + end + end +end From 3a31a5031bcdd05919f2c3e6d2167a64bfa65f6c Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Jul 2013 17:11:35 -0700 Subject: [PATCH 06/13] add table sorting to promotion report --- .../stylesheets/specific/reports.css.scss | 0 app/logical/reports/user_promotions.rb | 15 ++++++- app/views/reports/user_promotions.html.erb | 40 +++++++++++++------ vendor/assets/javascripts/stupidtable.js | 3 ++ 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 app/assets/stylesheets/specific/reports.css.scss create mode 100644 vendor/assets/javascripts/stupidtable.js diff --git a/app/assets/stylesheets/specific/reports.css.scss b/app/assets/stylesheets/specific/reports.css.scss new file mode 100644 index 000000000..e69de29bb diff --git a/app/logical/reports/user_promotions.rb b/app/logical/reports/user_promotions.rb index 3fe16ae27..8885797f6 100644 --- a/app/logical/reports/user_promotions.rb +++ b/app/logical/reports/user_promotions.rb @@ -2,6 +2,19 @@ require 'statistics2' module Reports class UserPromotions + class User + attr_reader :user + delegate :name, :post_upload_count, :level_string, :level, :created_at, :to => :user + + def initialize(user) + @user = user + end + + def confidence_interval_for(n) + Reports::UserPromotions.confidence_interval_for(user, n) + end + end + def self.confidence_interval_for(user, n) up_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).where("fav_count >= ?", n).count total_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).count @@ -23,7 +36,7 @@ module Reports end def users - User.where("users.level < ? and users.post_upload_count >= 100", User::Levels::CONTRIBUTOR).order("created_at desc").limit(50) + ::User.where("users.level < ? and users.post_upload_count >= 100", ::User::Levels::CONTRIBUTOR).order("created_at desc").limit(50).map {|x| Reports::UserPromotions::User.new(x)} end end end diff --git a/app/views/reports/user_promotions.html.erb b/app/views/reports/user_promotions.html.erb index db89f783f..26ba0d0e1 100644 --- a/app/views/reports/user_promotions.html.erb +++ b/app/views/reports/user_promotions.html.erb @@ -4,29 +4,45 @@

    Binomial proportion confidence interval for how likely a user's uploads will achieve a fav count of at at least n with 95% confidence within the past 30 days.

    - +
    - - - - - + + + + + + + <% cache("user-promotions-report/#{Date.today}") do %> <% @report.users.each do |user| %> - - - - - + + + + + + + <% end %> <% end %>
    UserLevelscore:1+score:5+score:10+UserLevelUploadsAgescore:1+score:5+score:10+
    <%= link_to user.name, user_path(user) %><%= user.level_string %><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 1), :precision => 0 %><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 5), :precision => 0 %><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 10), :precision => 0 %><%= link_to user.name, user_path(user.user) %><%= user.level_string %><%= user.post_upload_count %><%= time_ago_in_words user.created_at %><%= number_to_percentage user.confidence_interval_for(1), :precision => 0 %><%= number_to_percentage user.confidence_interval_for(5), :precision => 0 %><%= number_to_percentage user.confidence_interval_for(10), :precision => 0 %>
    - \ No newline at end of file + + +<%= content_for(:html_header) do %> + <%= javascript_include_tag "stupidtable" %> + +<% end %> \ No newline at end of file diff --git a/vendor/assets/javascripts/stupidtable.js b/vendor/assets/javascripts/stupidtable.js new file mode 100644 index 000000000..e376bf2a6 --- /dev/null +++ b/vendor/assets/javascripts/stupidtable.js @@ -0,0 +1,3 @@ +(function(e){e.fn.stupidtable=function(j){return this.each(function(){var d=e(this);j=j||{};j=e.extend({},{"int":function(b,a){return parseInt(b,10)-parseInt(a,10)},"float":function(b,a){return parseFloat(b)-parseFloat(a)},string:function(b,a){return ba?1:0},"string-ins":function(b,a){b=b.toLowerCase();a=a.toLowerCase();return ba?1:0}},j);d.on("click","th",function(){var b=d.children("tbody").children("tr"),a=e(this),k=0,n=e.fn.stupidtable.dir;d.find("th").slice(0,a.index()).each(function(){var a= +e(this).attr("colspan")||1;k+=parseInt(a,10)});var m=a.data("sort-dir")===n.ASC?n.DESC:n.ASC,p=m==n.DESC?a.data("sort-desc")||a.data("sort")||null:a.data("sort")||null;null!==p&&(d.trigger("beforetablesort",{column:k,direction:m}),d.css("display"),setTimeout(function(){var l=[],c=j[p];b.each(function(a,b){var c=e(b).children().eq(k),d=c.data("sort-value"),c="undefined"!==typeof d?d:c.text();l.push(c)});var f=[],g=0;if(a.data("sort-dir")&&!a.data("sort-desc"))for(c=l.length-1;0<=c;c--)f.push(c);else for(var h= +l.slice(0).sort(c),c=0;c Date: Tue, 2 Jul 2013 18:25:43 -0700 Subject: [PATCH 07/13] fixes #1796 --- vendor/assets/javascripts/jquery-ui-autocomplete-custom.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vendor/assets/javascripts/jquery-ui-autocomplete-custom.js b/vendor/assets/javascripts/jquery-ui-autocomplete-custom.js index b5413849c..88a276ebd 100644 --- a/vendor/assets/javascripts/jquery-ui-autocomplete-custom.js +++ b/vendor/assets/javascripts/jquery-ui-autocomplete-custom.js @@ -132,7 +132,9 @@ $.widget( "ui.autocomplete", { if ( this.menu.active ) { this.menu.select( event ); } - event.preventDefault(); + if ( !this.menu.element.is( ":visible" ) ) { + event.preventDefault(); + } break; case keyCode.ESCAPE: if ( this.menu.element.is( ":visible" ) ) { From 3d1a055d68f1128cffb1bfef9ae433b79b295110 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Jul 2013 18:30:37 -0700 Subject: [PATCH 08/13] fixes #1818 --- app/assets/javascripts/posts.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 5034fd9b9..9f40ddfea 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -339,11 +339,13 @@ var $link = $(e.target); var $image = $("#image"); $image.attr("src", $link.attr("href")); - $image.width($image.data("original-width")); - $image.height($image.data("original-height")); - Danbooru.Note.Box.scale_all(); - $("#image-resize-notice").hide(); - $image.data("scale_factor", 1); + $image.on("load", function() { + $image.width($image.data("original-width")); + $image.height($image.data("original-height")); + Danbooru.Note.Box.scale_all(); + $("#image-resize-notice").hide(); + $image.data("scale_factor", 1); + }); e.preventDefault(); }); } From 742dc1e1898f274373c75368544f3b4b0db55e63 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Jul 2013 18:40:46 -0700 Subject: [PATCH 09/13] update version --- config/danbooru_default_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index f195d796f..01f619052 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -4,7 +4,7 @@ module Danbooru class Configuration # The version of this Danbooru. def version - "2.22.2" + "2.23.0" end # The name of this Danbooru. From b21a0329ecc73d9282efb6cd0e0505ad83725b15 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 3 Jul 2013 13:10:23 -0700 Subject: [PATCH 10/13] style intro page --- app/assets/stylesheets/specific/explore.css.scss | 4 +++- app/logical/post_sets/intro.rb | 2 +- app/views/explore/posts/intro.html.erb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/specific/explore.css.scss b/app/assets/stylesheets/specific/explore.css.scss index 3038cbabb..0e59e150d 100644 --- a/app/assets/stylesheets/specific/explore.css.scss +++ b/app/assets/stylesheets/specific/explore.css.scss @@ -1,3 +1,5 @@ +@import "../common/000_vars.css.scss"; + div#c-explore-posts { header { text-align: center; @@ -18,7 +20,7 @@ div#c-explore-posts { } div#a-intro { - width: 60em; + width: 870px; margin: 0 auto; text-align: center; } diff --git a/app/logical/post_sets/intro.rb b/app/logical/post_sets/intro.rb index c6517e9e7..4449cb957 100644 --- a/app/logical/post_sets/intro.rb +++ b/app/logical/post_sets/intro.rb @@ -6,7 +6,7 @@ module PostSets def posts @posts ||= begin - temp = ::Post.tag_match("#{tag_string} favcount:>10").paginate(page, :search_count => nil, :limit => 6) + temp = ::Post.tag_match("#{tag_string} favcount:>3").paginate(page, :search_count => nil, :limit => 5) temp.all temp end diff --git a/app/views/explore/posts/intro.html.erb b/app/views/explore/posts/intro.html.erb index a77f0a25e..52b33da98 100644 --- a/app/views/explore/posts/intro.html.erb +++ b/app/views/explore/posts/intro.html.erb @@ -14,7 +14,7 @@ <% @presenter.each do |tag, post_set| %>
    -

    <%= link_to tag, posts_path(:tags => tag), :class => "tag-type-3" %>

    +

    <%= link_to tag, posts_path(:tags => tag) %>

    <%= post_set.presenter.post_previews_html(self) %>
    From 279c5e7b6a58be2d466fedac22cac3d3ada918eb Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 4 Jul 2013 20:48:06 -0700 Subject: [PATCH 11/13] fixes #1825 --- app/controllers/posts_controller.rb | 10 +++++++++- config/routes.rb | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3a1f320fe..89291dd1a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,5 +1,5 @@ class PostsController < ApplicationController - before_filter :member_only, :except => [:show, :show_seq, :index] + before_filter :member_only, :except => [:show, :show_seq, :index, :home] before_filter :builder_only, :only => [:copy_notes] after_filter :save_recent_tags, :only => [:update] respond_to :html, :xml, :json @@ -93,6 +93,14 @@ class PostsController < ApplicationController @error = x end + def home + if CurrentUser.user.is_anonymous? + redirect_to intro_explore_posts_path + else + redirect_to posts_path(:tags => params[:tags]) + end + end + private def tag_query params[:tags] || (params[:post] && params[:post][:tags]) diff --git a/config/routes.rb b/config/routes.rb index 66b5c5deb..1bc2ab7b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -154,6 +154,9 @@ Danbooru::Application.routes.draw do resources :pool_versions, :only => [:index] resources :posts do resources :votes, :controller => "post_votes", :only => [:create, :destroy] + collection do + get :home + end member do put :revert put :copy_notes @@ -352,5 +355,5 @@ Danbooru::Application.routes.draw do match "/static/benchmark" => "static#benchmark" match "/static/name_change" => "static#name_change", :as => "name_change" - root :to => "explore/posts#intro" + root :to => "posts#home" end From 12ca931528da5479024cfddc23467aa2cb979f7d Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 4 Jul 2013 20:51:14 -0700 Subject: [PATCH 12/13] potential fix for #1818 --- app/assets/javascripts/posts.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 9f40ddfea..2b0295ba6 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -338,14 +338,14 @@ $("#image-resize-link").click(function(e) { var $link = $(e.target); var $image = $("#image"); + $image.removeAttr("src"); + $image.attr("src", "https://www.google.com") $image.attr("src", $link.attr("href")); - $image.on("load", function() { - $image.width($image.data("original-width")); - $image.height($image.data("original-height")); - Danbooru.Note.Box.scale_all(); - $("#image-resize-notice").hide(); - $image.data("scale_factor", 1); - }); + $image.width($image.data("original-width")); + $image.height($image.data("original-height")); + Danbooru.Note.Box.scale_all(); + $("#image-resize-notice").hide(); + $image.data("scale_factor", 1); e.preventDefault(); }); } From 423c1991dbb74fc93f8c8bae9297d45326b39e2d Mon Sep 17 00:00:00 2001 From: ghostrigger Date: Fri, 5 Jul 2013 14:36:13 +0800 Subject: [PATCH 13/13] legacy support for /note/history from http://danbooru.donmai.us/note/history?user_id=32729 to http://danbooru.donmai.us/note_versions?search[updater_id]=32729 --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 1bc2ab7b8..b831401b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -289,7 +289,7 @@ Danbooru::Application.routes.draw do match "/note" => redirect {|params, req| "/notes?page=#{req.params[:page]}"} match "/note/index" => redirect {|params, req| "/notes?page=#{req.params[:page]}"} - match "/note/history" => redirect("/note_versions") + match "/note/history" => redirect {|params, req| "/note_versions?search[updater_id]=#{req.params[:user_id]}"} match "/pool" => redirect {|params, req| "/pools?page=#{req.params[:page]}"} match "/pool/index" => redirect {|params, req| "/pools?page=#{req.params[:page]}"}