forked from e621ng/e621ng
Kill trailing whitespace in ruby files
This commit is contained in:
parent
c107f96cec
commit
cba839ba76
@ -1,10 +1,10 @@
|
||||
module Admin
|
||||
class AliasAndImplicationImportsController < ApplicationController
|
||||
before_filter :admin_only
|
||||
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@importer = AliasAndImplicationImporter.new(params[:batch][:text], params[:batch][:forum_id])
|
||||
@importer.process!
|
||||
|
@ -1,11 +1,11 @@
|
||||
module Admin
|
||||
class UsersController < ApplicationController
|
||||
before_filter :moderator_only
|
||||
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
@user.level = params[:user][:level]
|
||||
|
@ -8,5 +8,5 @@ class AdvertisementHitsController < ApplicationController
|
||||
protected
|
||||
def set_title
|
||||
@page_title = Danbooru.config.app_name + "/advertisements"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,27 +1,27 @@
|
||||
class AdvertisementsController < ApplicationController
|
||||
before_filter :advertiser_only
|
||||
|
||||
|
||||
def new
|
||||
@advertisement = Advertisement.new(
|
||||
:ad_type => "vertical",
|
||||
:status => "active"
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@advertisement = Advertisement.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@advertisements = Advertisement.order("id desc").all
|
||||
@start_date = 1.month.ago.to_date
|
||||
@end_date = Date.today
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@advertisement = Advertisement.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@advertisement = Advertisement.new(params[:advertisement])
|
||||
if @advertisement.save
|
||||
@ -31,7 +31,7 @@ class AdvertisementsController < ApplicationController
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@advertisement = Advertisement.find(params[:id])
|
||||
if @advertisement.update_attributes(params[:advertisement])
|
||||
@ -41,13 +41,13 @@ class AdvertisementsController < ApplicationController
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@advertisement = Advertisement.find(params[:id])
|
||||
@advertisement.destroy
|
||||
redirect_to advertisements_path, :notice => "Advertisement destroyed"
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def advertiser_only
|
||||
if !Danbooru.config.is_user_advertiser?(CurrentUser.user)
|
||||
|
@ -6,14 +6,14 @@ class ApplicationController < ActionController::Base
|
||||
before_filter :set_title
|
||||
before_filter :set_started_at_session
|
||||
layout "default"
|
||||
|
||||
|
||||
rescue_from User::PrivilegeError, :with => :access_denied
|
||||
rescue_from Danbooru::Paginator::PaginationError, :with => :render_pagination_limit
|
||||
|
||||
protected
|
||||
def rescue_exception(exception)
|
||||
@exception = exception
|
||||
|
||||
|
||||
if exception.is_a?(::ActiveRecord::StatementInvalid) && exception.to_s =~ /statement timeout/
|
||||
@exception = nil
|
||||
@error_message = "The database timed out running your query."
|
||||
@ -26,17 +26,17 @@ protected
|
||||
render :template => "static/error", :status => 500
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def render_pagination_limit
|
||||
@error_message = "You can only view up to #{Danbooru.config.max_numbered_pages} pages. Please narrow your search terms."
|
||||
render :template => "static/error", :status => 410
|
||||
end
|
||||
|
||||
|
||||
def access_denied
|
||||
previous_url = params[:url] || request.fullpath
|
||||
|
||||
respond_to do |fmt|
|
||||
fmt.html do
|
||||
fmt.html do
|
||||
if request.get?
|
||||
redirect_to new_session_path(:url => previous_url), :notice => "Access denied"
|
||||
else
|
||||
@ -56,18 +56,18 @@ protected
|
||||
session_loader = SessionLoader.new(session, cookies, request)
|
||||
session_loader.load
|
||||
end
|
||||
|
||||
|
||||
def reset_current_user
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
|
||||
def set_started_at_session
|
||||
if session[:started_at].blank?
|
||||
session[:started_at] = Time.now
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
%w(member banned privileged platinum contributor janitor moderator admin).each do |level|
|
||||
define_method("#{level}_only") do
|
||||
if CurrentUser.user.__send__("is_#{level}?")
|
||||
@ -78,7 +78,7 @@ protected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def set_title
|
||||
@page_title = Danbooru.config.app_name + "/#{params[:controller]}"
|
||||
end
|
||||
|
@ -2,28 +2,28 @@ class ArtistsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show, :banned]
|
||||
before_filter :admin_only, :only => [:ban]
|
||||
|
||||
|
||||
def new
|
||||
@artist = Artist.new_with_defaults(params)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@artist = Artist.find(params[:id])
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def banned
|
||||
@artists = Artist.where("is_banned = ?", true).order("name")
|
||||
respond_with(@artists)
|
||||
end
|
||||
|
||||
|
||||
def ban
|
||||
@artist = Artist.find(params[:id])
|
||||
@artist.ban!
|
||||
redirect_to(artist_path(@artist), :notice => "Artist was banned")
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@artists = Artist.search(params[:search] || params).order("id desc").paginate(params[:page])
|
||||
respond_with(@artists) do |format|
|
||||
@ -35,34 +35,34 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@artist = Artist.find(params[:id])
|
||||
@post_set = PostSets::Artist.new(@artist)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@artist = Artist.create(params[:artist], :as => CurrentUser.role)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@artist = Artist.find(params[:id])
|
||||
@artist.update_attributes(params[:artist], :as => CurrentUser.role)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def revert
|
||||
@artist = Artist.find(params[:id])
|
||||
@version = ArtistVersion.find(params[:version_id])
|
||||
@artist.revert_to!(@version)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
def show_or_new
|
||||
@artist = Artist.find_by_name(params[:name])
|
||||
if @artist
|
||||
|
@ -1,33 +1,33 @@
|
||||
class BansController < ApplicationController
|
||||
before_filter :moderator_only, :except => [:show, :index]
|
||||
|
||||
|
||||
def new
|
||||
@ban = Ban.new
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@ban = Ban.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = Ban.search(params[:search]).order("id desc")
|
||||
@bans = @search.paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@ban = Ban.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@ban = Ban.create(params[:ban])
|
||||
|
||||
|
||||
if @ban.errors.any?
|
||||
render :action => "new"
|
||||
else
|
||||
redirect_to ban_path(@ban), :notice => "Ban created"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@ban = Ban.find(params[:id])
|
||||
if @ban.update_attributes(params[:ban])
|
||||
@ -35,8 +35,8 @@ class BansController < ApplicationController
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
@ban = Ban.find(params[:id])
|
||||
@ban.destroy
|
||||
|
@ -1,7 +1,7 @@
|
||||
class CommentVotesController < ApplicationController
|
||||
respond_to :js
|
||||
before_filter :member_only
|
||||
|
||||
|
||||
def create
|
||||
@comment = Comment.find(params[:comment_id])
|
||||
@comment_vote = @comment.vote!(params[:score])
|
||||
|
@ -3,7 +3,7 @@ class CommentsController < ApplicationController
|
||||
before_filter :member_only, :only => [:update, :create, :edit, :destroy]
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
rescue_from ActiveRecord::StatementInvalid, :with => :search_error
|
||||
|
||||
|
||||
def index
|
||||
if params[:group_by] == "comment"
|
||||
index_by_comment
|
||||
@ -13,21 +13,21 @@ class CommentsController < ApplicationController
|
||||
index_by_post
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def new
|
||||
redirect_to comments_path
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@comment = Comment.find(params[:id])
|
||||
check_privilege(@comment)
|
||||
@comment.update_attributes(params[:comment])
|
||||
respond_with(@comment, :location => post_path(@comment.post_id))
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@comment = Comment.create(params[:comment])
|
||||
respond_with(@comment) do |format|
|
||||
@ -40,20 +40,20 @@ class CommentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@comment = Comment.find(params[:id])
|
||||
check_privilege(@comment)
|
||||
respond_with(@comment)
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@comment = Comment.find(params[:id])
|
||||
respond_with(@comment) do |format|
|
||||
format.json {render :json => @comment.to_json(:methods => [:creator_name])}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@comment = Comment.find(params[:id])
|
||||
check_privilege(@comment)
|
||||
@ -62,7 +62,7 @@ class CommentsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def index_for_post
|
||||
@post = Post.find(params[:post_id])
|
||||
@ -78,14 +78,14 @@ private
|
||||
format.html {render :action => "index_by_post"}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def index_by_comment
|
||||
@comments = Comment.search(params[:search]).order("comments.id DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@comments) do |format|
|
||||
format.html {render :action => "index_by_comment"}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def check_privilege(comment)
|
||||
if !comment.editable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
@ -93,7 +93,7 @@ private
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def search_error(e)
|
||||
if e.message =~ /syntax error in tsquery/
|
||||
@error_message = "Meta-tags are not supported in comment searches by tag"
|
||||
|
@ -9,19 +9,19 @@ class DmailsController < ApplicationController
|
||||
else
|
||||
@dmail = Dmail.new(params[:dmail])
|
||||
end
|
||||
|
||||
|
||||
respond_with(@dmail)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = Dmail.visible.search(params[:search])
|
||||
@dmails = @search.order("dmails.created_at desc").paginate(params[:page])
|
||||
respond_with(@dmails)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@dmail = Dmail.find(params[:id])
|
||||
check_privilege(@dmail)
|
||||
@ -33,20 +33,20 @@ class DmailsController < ApplicationController
|
||||
@dmail = Dmail.create_split(params[:dmail])
|
||||
respond_with(@dmail)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@dmail = Dmail.find(params[:id])
|
||||
check_privilege(@dmail)
|
||||
@dmail.destroy
|
||||
redirect_to dmails_path, :notice => "Message destroyed"
|
||||
end
|
||||
|
||||
|
||||
def mark_all_as_read
|
||||
Dmail.visible.unread.each do |x|
|
||||
x.update_column(:is_read, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def check_privilege(dmail)
|
||||
if !dmail.visible_to?(CurrentUser.user)
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Explore
|
||||
class PostsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
|
||||
def popular
|
||||
@post_set = PostSets::Popular.new(params[:date], params[:scale])
|
||||
@posts = @post_set.posts
|
||||
|
@ -1,6 +1,6 @@
|
||||
class FavoritesController < ApplicationController
|
||||
before_filter :member_only
|
||||
|
||||
|
||||
def index
|
||||
if params[:tags]
|
||||
redirect_to(posts_path(:tags => params[:tags]))
|
||||
@ -8,7 +8,7 @@ class FavoritesController < ApplicationController
|
||||
@favorite_set = PostSets::Favorite.new(CurrentUser.user, params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
if CurrentUser.favorite_limit.nil? || CurrentUser.favorite_count < CurrentUser.favorite_limit
|
||||
@post = Post.find(params[:post_id])
|
||||
@ -17,7 +17,7 @@ class FavoritesController < ApplicationController
|
||||
@error_msg = "You can only keep up to #{CurrentUser.favorite_limit} favorites. Upgrade your account to save more."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@post = Post.find(params[:id])
|
||||
@post.remove_favorite!(CurrentUser.user)
|
||||
|
@ -8,19 +8,19 @@ class ForumPostsController < ApplicationController
|
||||
@forum_post = ForumPost.new_reply(params)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
check_privilege(@forum_post)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = ForumPost.active.search(params[:search])
|
||||
@forum_posts = @search.order("forum_posts.id DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@forum_posts)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
@ -32,33 +32,33 @@ class ForumPostsController < ApplicationController
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@forum_post = ForumPost.create(params[:forum_post])
|
||||
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.topic.last_page))
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@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))
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
raise User::PrivilegeError unless @forum_post.editable_by?(CurrentUser.user)
|
||||
@forum_post.update_attribute(:is_deleted, true)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
|
||||
def undelete
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
check_privilege(@forum_post)
|
||||
@forum_post.update_attribute(:is_deleted, false)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def check_privilege(forum_post)
|
||||
if !forum_post.editable_by?(CurrentUser.user)
|
||||
|
@ -10,45 +10,45 @@ class ForumTopicsController < ApplicationController
|
||||
@forum_topic.original_post = ForumPost.new
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
check_privilege(@forum_topic)
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = ForumTopic.active.search(params[:search])
|
||||
@forum_topics = @search.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@forum_topics)
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
|
||||
@forum_posts.all
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@forum_topic = ForumTopic.create(params[:forum_topic], :as => CurrentUser.role)
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
check_privilege(@forum_topic)
|
||||
@forum_topic.update_attributes(params[:forum_topic], :as => CurrentUser.role)
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
check_privilege(@forum_topic)
|
||||
@forum_topic.update_attribute(:is_deleted, true)
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
|
||||
def undelete
|
||||
@forum_topic = ForumTopic.find(params[:id])
|
||||
check_privilege(@forum_topic)
|
||||
@ -64,18 +64,18 @@ class ForumTopicsController < ApplicationController
|
||||
private
|
||||
def update_last_forum_read_at
|
||||
return if CurrentUser.is_anonymous?
|
||||
|
||||
|
||||
if CurrentUser.last_forum_read_at.nil? || CurrentUser.last_forum_read_at < @forum_topic.updated_at
|
||||
CurrentUser.update_column(:last_forum_read_at, @forum_topic.updated_at)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def normalize_search
|
||||
if params[:title_matches]
|
||||
params[:search] ||= {}
|
||||
params[:search][:title_matches] = params.delete(:title_matches)
|
||||
end
|
||||
|
||||
|
||||
if params[:title]
|
||||
params[:search] ||= {}
|
||||
params[:search][:title] = params.delete(:title)
|
||||
|
@ -14,12 +14,12 @@ class IpBansController < ApplicationController
|
||||
redirect_to ip_bans_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = IpBan.search(params[:search])
|
||||
@ip_bans = @search.order("id desc").paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@ip_ban = IpBan.find(params[:id])
|
||||
@ip_ban.destroy
|
||||
|
@ -1,28 +1,28 @@
|
||||
class JanitorTrialsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :moderator_only, :only => [:create, :promote, :demote]
|
||||
|
||||
|
||||
def new
|
||||
@janitor_trial = JanitorTrial.new
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
respond_with(@janitor_trial)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = JanitorTrial.search(params[:search])
|
||||
@janitor_trials = @search.order("id desc").paginate(params[:page])
|
||||
respond_with(@janitor_trials)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@janitor_trial = JanitorTrial.create(params[:janitor_trial])
|
||||
respond_with(@janitor_trial, :location => janitor_trials_path)
|
||||
end
|
||||
|
||||
|
||||
def promote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.promote!
|
||||
@ -30,7 +30,7 @@ class JanitorTrialsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def demote
|
||||
@janitor_trial = JanitorTrial.find(params[:id])
|
||||
@janitor_trial.demote!
|
||||
@ -38,7 +38,7 @@ class JanitorTrialsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test
|
||||
@tester = JanitorTrialTester.new(params[:janitor_trial][:user_name])
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ class LegacyController < ApplicationController
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit])
|
||||
@posts = @post_set.posts
|
||||
end
|
||||
|
||||
|
||||
def create_post
|
||||
@upload = Upload.new
|
||||
@upload.server = Socket.gethostname
|
||||
@ -19,19 +19,19 @@ class LegacyController < ApplicationController
|
||||
@upload.save
|
||||
@upload.process!
|
||||
end
|
||||
|
||||
|
||||
def users
|
||||
@users = User.limit(100).search(params).paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def tags
|
||||
@tags = Tag.limit(100).search(params).paginate(params[:page], :limit => params[:limit])
|
||||
end
|
||||
|
||||
|
||||
def artists
|
||||
@artists = Artist.limit(100).search(params[:search]).paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def unavailable
|
||||
render :text => "this resource is no longer available", :status => 410
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ module Maintenance
|
||||
class LoginRemindersController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@user = ::User.with_email(params[:user][:email]).first
|
||||
if @user
|
||||
@ -12,7 +12,7 @@ module Maintenance
|
||||
else
|
||||
flash[:notice] = "Email address not found"
|
||||
end
|
||||
|
||||
|
||||
redirect_to new_maintenance_user_login_reminder_path
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ module Maintenance
|
||||
def new
|
||||
@nonce = UserPasswordResetNonce.new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@nonce = UserPasswordResetNonce.create(params[:nonce])
|
||||
if @nonce.errors.any?
|
||||
@ -13,14 +13,14 @@ module Maintenance
|
||||
redirect_to new_maintenance_user_password_reset_path, :notice => "Email request sent"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@nonce = UserPasswordResetNonce.where(:email => params[:email], :key => params[:key]).first
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@nonce = UserPasswordResetNonce.where(:email => params[:email], :key => params[:key]).first
|
||||
|
||||
|
||||
if @nonce
|
||||
@nonce.reset_user!
|
||||
@nonce.destroy
|
||||
|
@ -2,7 +2,7 @@ module Moderator
|
||||
class DashboardsController < ApplicationController
|
||||
before_filter :janitor_only
|
||||
helper :post_flags, :post_appeals
|
||||
|
||||
|
||||
def show
|
||||
@dashboard = Moderator::Dashboard::Report.new(params[:min_date] || 2.days.ago.to_date, params[:max_level] || 20)
|
||||
end
|
||||
|
@ -1,15 +1,15 @@
|
||||
module Moderator
|
||||
class InvitationsController < ApplicationController
|
||||
before_filter :moderator_only
|
||||
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
User.find(params[:invitation][:user_id]).invite!(params[:invitation][:level])
|
||||
redirect_to moderator_invitations_path
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@users = User.where("inviter_id = ?", CurrentUser.id).paginate(params[:page])
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
module Moderator
|
||||
class IpAddrsController < ApplicationController
|
||||
before_filter :janitor_only
|
||||
|
||||
|
||||
def index
|
||||
@search = IpAddrSearch.new(params[:search])
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ module Moderator
|
||||
module Post
|
||||
class ApprovalsController < ApplicationController
|
||||
before_filter :janitor_only
|
||||
|
||||
|
||||
def create
|
||||
@post = ::Post.find(params[:post_id])
|
||||
if @post.is_deleted? || @post.is_flagged? || @post.is_pending?
|
||||
|
@ -2,7 +2,7 @@ module Moderator
|
||||
module Post
|
||||
class DisapprovalsController < ApplicationController
|
||||
before_filter :janitor_only
|
||||
|
||||
|
||||
def create
|
||||
@post = ::Post.find(params[:post_id])
|
||||
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
|
||||
|
@ -8,7 +8,7 @@ module Moderator
|
||||
def confirm_delete
|
||||
@post = ::Post.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def delete
|
||||
@post = ::Post.find(params[:id])
|
||||
if params[:commit] == "Delete"
|
||||
@ -17,12 +17,12 @@ module Moderator
|
||||
end
|
||||
redirect_to(post_path(@post))
|
||||
end
|
||||
|
||||
|
||||
def undelete
|
||||
@post = ::Post.find(params[:id])
|
||||
@post.undelete!
|
||||
end
|
||||
|
||||
|
||||
def annihilate
|
||||
@post = ::Post.find(params[:id])
|
||||
@post.annihilate!
|
||||
|
@ -3,7 +3,7 @@ module Moderator
|
||||
class QueuesController < ApplicationController
|
||||
respond_to :html, :json
|
||||
before_filter :janitor_only
|
||||
|
||||
|
||||
def show
|
||||
::Post.without_timeout do
|
||||
@posts = ::Post.order("posts.id asc").pending_or_flagged.available_for_moderation(params[:hidden]).search(:tag_match => "#{params[:query]} status:any").paginate(params[:page], :limit => 100)
|
||||
|
@ -2,15 +2,15 @@ module Moderator
|
||||
class TagsController < ApplicationController
|
||||
before_filter :moderator_only
|
||||
rescue_from TagBatchChange::Error, :with => :error
|
||||
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
Delayed::Job.enqueue(TagBatchChange.new(params[:tag][:antecedent], params[:tag][:consequent], CurrentUser.user, CurrentUser.ip_addr))
|
||||
redirect_to edit_moderator_tag_path, :notice => "Post changes queued"
|
||||
end
|
||||
|
||||
|
||||
def error
|
||||
redirect_to edit_moderator_tag_path, :notice => "Error"
|
||||
end
|
||||
|
@ -1,33 +1,33 @@
|
||||
class NewsUpdatesController < ApplicationController
|
||||
before_filter :admin_only
|
||||
respond_to :html
|
||||
|
||||
|
||||
def index
|
||||
@news_updates = NewsUpdate.order("id desc").paginate(params[:page])
|
||||
respond_with(@news_updates)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
respond_with(@news_update)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
@news_update.update_attributes(params[:news_update])
|
||||
respond_with(@news_update, :location => news_updates_path)
|
||||
end
|
||||
|
||||
|
||||
def new
|
||||
@news_update = NewsUpdate.new
|
||||
respond_with(@news_update)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@news_update = NewsUpdate.create(params[:news_update])
|
||||
respond_with(@news_update, :location => news_updates_path)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
@news_update.destroy
|
||||
|
@ -1,7 +1,7 @@
|
||||
class NoteVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
|
||||
|
||||
def index
|
||||
@search = NoteVersion.search(params[:search])
|
||||
@note_versions = @search.order("note_versions.id desc").paginate(params[:page])
|
||||
|
@ -2,10 +2,10 @@ class NotesController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
before_filter :pass_html_id, :only => [:create]
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
if params[:group_by] == "note"
|
||||
index_by_note
|
||||
@ -13,12 +13,12 @@ class NotesController < ApplicationController
|
||||
index_by_post
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@note = Note.find(params[:id])
|
||||
respond_with(@note)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@note = Note.create(params[:note])
|
||||
respond_with(@note) do |fmt|
|
||||
@ -27,19 +27,19 @@ class NotesController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@note = Note.find(params[:id])
|
||||
@note.update_attributes(params[:note])
|
||||
respond_with(@note)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@note = Note.find(params[:id])
|
||||
@note.update_attribute(:is_active, false)
|
||||
respond_with(@note)
|
||||
end
|
||||
|
||||
|
||||
def revert
|
||||
@note = Note.find(params[:id])
|
||||
@version = NoteVersion.find(params[:version_id])
|
||||
|
@ -1,30 +1,30 @@
|
||||
class PoolElementsController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only
|
||||
|
||||
|
||||
def create
|
||||
@pool = Pool.find_by_name(params[:pool_name]) || Pool.find_by_id(params[:pool_id])
|
||||
|
||||
|
||||
if @pool.present?
|
||||
@post = Post.find(params[:post_id])
|
||||
@pool.add!(@post)
|
||||
append_pool_to_session(@pool)
|
||||
end
|
||||
|
||||
|
||||
respond_with(@pool, :location => post_path(@post))
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@pool = Pool.find(params[:pool_id])
|
||||
@post = Post.find(params[:post_id])
|
||||
@pool.remove!(@post)
|
||||
respond_with(@pool, :location => post_path(@post))
|
||||
end
|
||||
|
||||
|
||||
def all_select
|
||||
@pools = Pool.active.order("name").select("id, name").all
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def append_pool_to_session(pool)
|
||||
recent_pool_ids = session[:recent_pool_ids].to_s.scan(/\d+/)
|
||||
|
@ -3,7 +3,7 @@ class PoolVersionsController < ApplicationController
|
||||
if params[:search] && params[:search][:pool_id]
|
||||
@pool = Pool.find(params[:search][:pool_id])
|
||||
end
|
||||
|
||||
|
||||
@pool_versions = PoolVersion.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
end
|
||||
end
|
||||
|
@ -8,31 +8,31 @@ class PoolsController < ApplicationController
|
||||
@pool = Pool.new
|
||||
respond_with(@pool)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@pool = Pool.find(params[:id])
|
||||
respond_with(@pool)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@pools = Pool.active.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@pools)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@pool = Pool.find(params[:id])
|
||||
@post_set = PostSets::Pool.new(@pool, params[:page])
|
||||
respond_with(@pool)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@pool = Pool.create(params[:pool])
|
||||
respond_with(@pool, :notice => "Pool created")
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
# need to do this in order for synchronize! to work correctly
|
||||
@pool = Pool.find(params[:id])
|
||||
@ -41,7 +41,7 @@ class PoolsController < ApplicationController
|
||||
@pool.save
|
||||
respond_with(@pool, :notice => "Pool updated")
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@pool = Pool.find(params[:id])
|
||||
if !@pool.deletable_by?(CurrentUser.user)
|
||||
@ -50,7 +50,7 @@ class PoolsController < ApplicationController
|
||||
@pool.update_attribute(:is_deleted, true)
|
||||
respond_with(@pool, :notice => "Pool deleted")
|
||||
end
|
||||
|
||||
|
||||
def undelete
|
||||
@pool = Pool.find(params[:id])
|
||||
if !@pool.deletable_by?(CurrentUser.user)
|
||||
@ -59,7 +59,7 @@ class PoolsController < ApplicationController
|
||||
@pool.update_attribute(:is_deleted, false)
|
||||
respond_with(@pool, :notice => "Pool undeleted")
|
||||
end
|
||||
|
||||
|
||||
def revert
|
||||
@pool = Pool.find(params[:id])
|
||||
@version = PoolVersion.find(params[:version_id])
|
||||
|
@ -7,12 +7,12 @@ class PostAppealsController < ApplicationController
|
||||
@post_appeal = PostAppeal.new
|
||||
respond_with(@post_appeal)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = PostAppeal.order("id desc").search(params[:search])
|
||||
@post_appeals = @search.paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@post_appeal = PostAppeal.create(params[:post_appeal])
|
||||
respond_with(@post_appeal)
|
||||
|
@ -7,12 +7,12 @@ class PostFlagsController < ApplicationController
|
||||
@post_flag = PostFlag.new
|
||||
respond_with(@post_flag)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = PostFlag.order("id desc").search(params[:search])
|
||||
@post_flags = @search.paginate(params[:page])
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@post_flag = PostFlag.create(params[:post_flag].merge(:is_resolved => false))
|
||||
respond_with(@post_flag)
|
||||
|
@ -6,7 +6,7 @@ class PostVersionsController < ApplicationController
|
||||
@post_versions = PostVersion.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@post_versions)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class PostVotesController < ApplicationController
|
||||
before_filter :privileged_only
|
||||
|
||||
|
||||
def create
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.vote!(params[:score])
|
||||
|
@ -6,7 +6,7 @@ class PostsController < ApplicationController
|
||||
rescue_from Post::SearchError, :with => :rescue_exception
|
||||
rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception
|
||||
rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception
|
||||
|
||||
|
||||
def index
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit])
|
||||
@posts = @post_set.posts
|
||||
@ -14,14 +14,14 @@ class PostsController < ApplicationController
|
||||
format.atom
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@post = Post.find(params[:id])
|
||||
@post_flag = PostFlag.new(:post_id => @post.id)
|
||||
@post_appeal = PostAppeal.new(:post_id => @post.id)
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
|
||||
def show_seq
|
||||
context = PostSearchContext.new(params)
|
||||
if context.post_id
|
||||
@ -30,14 +30,14 @@ class PostsController < ApplicationController
|
||||
redirect_to(post_path(params[:id], :tags => params[:tags]))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@post = Post.find(params[:id])
|
||||
|
||||
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?
|
||||
@ -49,13 +49,13 @@ class PostsController < ApplicationController
|
||||
redirect_to post_path(@post)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
format.json do
|
||||
render :json => @post.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def revert
|
||||
@post = Post.find(params[:id])
|
||||
@version = PostVersion.find(params[:version_id])
|
||||
|
@ -1,6 +1,6 @@
|
||||
class RelatedTagsController < ApplicationController
|
||||
respond_to :json
|
||||
|
||||
|
||||
def show
|
||||
@query = RelatedTagQuery.new(params[:query].to_s.downcase, params[:category])
|
||||
respond_with(@query) do |format|
|
||||
|
@ -2,24 +2,24 @@ class SessionsController < ApplicationController
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
session_creator = SessionCreator.new(session, cookies, params[:name], params[:password], params[:remember])
|
||||
|
||||
|
||||
if session_creator.authenticate
|
||||
redirect_to(params[:url] || session[:previous_uri] || posts_path, :notice => "You are now logged in.")
|
||||
else
|
||||
redirect_to(new_session_path, :notice => "Password was incorrect.")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
session.delete(:user_id)
|
||||
cookies.delete(:cookie_password_hash)
|
||||
cookies.delete(:user_name)
|
||||
redirect_to(posts_path, :notice => "You are now logged out.")
|
||||
end
|
||||
|
||||
|
||||
def sign_out
|
||||
destroy()
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
class SourcesController < ApplicationController
|
||||
# before_filter :member_only
|
||||
respond_to :json
|
||||
|
||||
|
||||
def show
|
||||
@source = Sources::Site.new(params[:url])
|
||||
@source.get
|
||||
|
||||
|
||||
respond_with(@source) do |format|
|
||||
format.json do
|
||||
render :json => @source.to_json
|
||||
|
@ -2,7 +2,7 @@ class StaticController < ApplicationController
|
||||
def terms_of_service
|
||||
render :layout => "blank"
|
||||
end
|
||||
|
||||
|
||||
def error
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class TagAliasCorrectionsController < ApplicationController
|
||||
before_filter :moderator_only
|
||||
|
||||
|
||||
def create
|
||||
@correction = TagAliasCorrection.new(params[:tag_alias_id])
|
||||
|
||||
@ -8,10 +8,10 @@ class TagAliasCorrectionsController < ApplicationController
|
||||
@correction.fix!
|
||||
flash[:notice] = "The fix has been queued and will be processed"
|
||||
end
|
||||
|
||||
|
||||
redirect_to tag_alias_correction_path(:tag_alias_id => params[:tag_alias_id])
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@correction = TagAliasCorrection.new(params[:tag_alias_id])
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
class TagAliasRequestsController < ApplicationController
|
||||
before_filter :member_only
|
||||
rescue_from TagAliasRequest::ValidationError, :with => :rescue_exception
|
||||
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@tag_alias_request = TagAliasRequest.new(
|
||||
params[:tag_alias_request][:antecedent_name],
|
||||
|
@ -1,12 +1,12 @@
|
||||
class TagAliasesController < ApplicationController
|
||||
before_filter :admin_only, :only => [:approve, :destroy, :new, :create]
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
|
||||
def new
|
||||
@tag_alias = TagAlias.new(params[:tag_alias])
|
||||
respond_with(@tag_alias)
|
||||
end
|
||||
|
||||
|
||||
def general_search
|
||||
if params[:commit] == "Search Aliases"
|
||||
redirect_to tag_aliases_path(:search => {:name_matches => params[:query]})
|
||||
@ -14,18 +14,18 @@ class TagAliasesController < ApplicationController
|
||||
redirect_to tag_implications_path(:search => {:name_matches => params[:query]})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = TagAlias.search(params[:search])
|
||||
@tag_aliases = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page])
|
||||
respond_with(@tag_aliases)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@tag_alias = TagAlias.create(params[:tag_alias])
|
||||
respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id => @tag_alias.id}))
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@tag_alias = TagAlias.find(params[:id])
|
||||
@tag_alias.update_column(:status, "deleted")
|
||||
@ -33,7 +33,7 @@ class TagAliasesController < ApplicationController
|
||||
@tag_alias.destroy
|
||||
respond_with(@tag_alias, :location => tag_aliases_path)
|
||||
end
|
||||
|
||||
|
||||
def approve
|
||||
@tag_alias = TagAlias.find(params[:id])
|
||||
@tag_alias.update_column(:status, "queued")
|
||||
|
@ -1,16 +1,16 @@
|
||||
class TagCorrectionsController < ApplicationController
|
||||
before_filter :member_only
|
||||
|
||||
|
||||
def new
|
||||
@correction = TagCorrection.new(params[:tag_id])
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
if params[:commit] == "Fix"
|
||||
@correction = TagCorrection.new(params[:tag_id])
|
||||
@correction.fix!
|
||||
end
|
||||
|
||||
|
||||
redirect_to tags_path(:search => {:name_matches => @correction.tag.name}), :notice => "Tag will be fixed in a few seconds"
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
class TagImplicationRequestsController < ApplicationController
|
||||
before_filter :member_only
|
||||
rescue_from TagImplicationRequest::ValidationError, :with => :rescue_exception
|
||||
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@tag_implication_request = TagImplicationRequest.new(
|
||||
params[:tag_implication_request][:antecedent_name],
|
||||
|
@ -1,29 +1,29 @@
|
||||
class TagImplicationsController < ApplicationController
|
||||
before_filter :admin_only, :only => [:new, :create, :approve, :destroy]
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
|
||||
def new
|
||||
@tag_implication = TagImplication.new
|
||||
respond_with(@tag_implication)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = TagImplication.search(params[:search])
|
||||
@tag_implications = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page])
|
||||
respond_with(@tag_implications)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@tag_implication = TagImplication.create(params[:tag_implication])
|
||||
respond_with(@tag_implication, :location => tag_implications_path(:search => {:id => @tag_implication.id}))
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@tag_implication = TagImplication.find(params[:id])
|
||||
@tag_implication.destroy
|
||||
respond_with(@tag_implication)
|
||||
end
|
||||
|
||||
|
||||
def approve
|
||||
@tag_implication = TagImplication.find(params[:id])
|
||||
@tag_implication.update_column(:status, "queued")
|
||||
|
@ -7,20 +7,20 @@ class TagSubscriptionsController < ApplicationController
|
||||
@tag_subscription = TagSubscription.new
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@user = CurrentUser.user
|
||||
@search = TagSubscription.owned_by(@user).order("name").search(params[:search])
|
||||
@tag_subscriptions = @search.paginate(params[:page])
|
||||
respond_with(@tag_subscriptions)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@tag_subscription = TagSubscription.create(params[:tag_subscription])
|
||||
respond_with(@tag_subscription) do |format|
|
||||
@ -33,7 +33,7 @@ class TagSubscriptionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
@ -48,20 +48,20 @@ class TagSubscriptionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
@tag_subscription.destroy
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
@user = User.find(params[:id])
|
||||
@post_set = PostSets::Post.new("sub:#{@user.name} #{params[:tags]}", params[:page])
|
||||
@posts = @post_set.posts
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def check_privilege(tag_subscription)
|
||||
raise User::PrivilegeError unless tag_subscription.editable_by?(CurrentUser.user)
|
||||
|
@ -1,20 +1,20 @@
|
||||
class TagsController < ApplicationController
|
||||
before_filter :member_only, :only => [:edit, :update]
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
|
||||
def edit
|
||||
@tag = Tag.find(params[:id])
|
||||
respond_with(@tag)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@tags = Tag.search(params[:search]).paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@tags)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@tag = Tag.find(params[:id])
|
||||
respond_with(@tag)
|
||||
@ -25,5 +25,5 @@ class TagsController < ApplicationController
|
||||
@tag.update_attributes(params[:tag])
|
||||
@tag.update_category_cache_for_all
|
||||
respond_with(@tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ class UploadsController < ApplicationController
|
||||
after_filter :save_recent_tags, :only => [:create]
|
||||
respond_to :html, :xml, :json, :js
|
||||
rescue_from Upload::Error, :with => :rescue_exception
|
||||
|
||||
|
||||
def new
|
||||
@upload = Upload.new(:rating => "q")
|
||||
if params[:url]
|
||||
@ -15,13 +15,13 @@ class UploadsController < ApplicationController
|
||||
end
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = Upload.search(params[:search])
|
||||
@uploads = @search.order("id desc").paginate(params[:page])
|
||||
respond_with(@uploads)
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@upload = Upload.find(params[:id])
|
||||
respond_with(@upload) do |format|
|
||||
@ -38,7 +38,7 @@ class UploadsController < ApplicationController
|
||||
@upload.process! if @upload.errors.empty?
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@upload = Upload.find(params[:id])
|
||||
@upload.process!
|
||||
|
@ -7,29 +7,29 @@ class UserFeedbacksController < ApplicationController
|
||||
@user_feedback = UserFeedback.new(params[:user_feedback])
|
||||
respond_with(@user_feedback)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@user_feedback = UserFeedback.find(params[:id])
|
||||
check_privilege(@user_feedback)
|
||||
respond_with(@user_feedback)
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@user_feedback = UserFeedback.find(params[:id])
|
||||
respond_with(@user_feedback)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@search = UserFeedback.search(params[:search])
|
||||
@user_feedbacks = @search.paginate(params[:page]).order("created_at desc")
|
||||
respond_with(@user_feedbacks)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@user_feedback = UserFeedback.create(params[:user_feedback])
|
||||
respond_with(@user_feedback)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@user_feedback = UserFeedback.find(params[:id])
|
||||
check_privilege(@user_feedback)
|
||||
|
@ -7,27 +7,27 @@ class UsersController < ApplicationController
|
||||
@user = User.new
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
check_privilege(@user)
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@users = User.search(params[:search]).order("users.id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@users)
|
||||
end
|
||||
|
||||
|
||||
def search
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
@presenter = UserPresenter.new(@user)
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@user = User.create(params[:user], :as => CurrentUser.role)
|
||||
if @user.errors.empty?
|
||||
@ -36,32 +36,32 @@ class UsersController < ApplicationController
|
||||
set_current_user
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
check_privilege(@user)
|
||||
@user.update_attributes(params[:user], :as => CurrentUser.role)
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
|
||||
def upgrade
|
||||
@user = User.find(params[:id])
|
||||
|
||||
|
||||
if params[:email] =~ /paypal/
|
||||
UserMailer.upgrade_fail(params[:email]).deliver
|
||||
else
|
||||
UserMailer.upgrade(@user, params[:email]).deliver
|
||||
end
|
||||
|
||||
|
||||
redirect_to user_path(@user), :notice => "Email was sent"
|
||||
end
|
||||
|
||||
|
||||
def cache
|
||||
@user = User.find(params[:id])
|
||||
@user.update_cache
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
def restore_uploaded_tags
|
||||
@user = User.find(params[:id])
|
||||
importer = UploadedTagsImporter.new(@user)
|
||||
|
@ -1,16 +1,16 @@
|
||||
class WikiPageVersionsController < ApplicationController
|
||||
respond_to :json, :html, :xml
|
||||
|
||||
|
||||
def index
|
||||
@wiki_page_versions = WikiPageVersion.search(params[:search]).order("id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@wiki_page_versions)
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@wiki_page_version = WikiPageVersion.find(params[:id])
|
||||
respond_with(@wiki_page_version)
|
||||
end
|
||||
|
||||
|
||||
def diff
|
||||
@thispage = WikiPageVersion.find(params[:thispage])
|
||||
@otherpage = WikiPageVersion.find(params[:otherpage])
|
||||
|
@ -9,12 +9,12 @@ class WikiPagesController < ApplicationController
|
||||
@wiki_page = WikiPage.new(params[:wiki_page])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def index
|
||||
@wiki_pages = WikiPage.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@wiki_pages) do |format|
|
||||
@ -25,7 +25,7 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
if params[:id] =~ /[a-zA-Z]/
|
||||
@wiki_page = WikiPage.find_by_title(params[:id])
|
||||
@ -34,31 +34,31 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@wiki_page = WikiPage.create(params[:wiki_page])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@wiki_page.update_attributes(params[:wiki_page])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@wiki_page.destroy
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def revert
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@version = WikiPageVersion.find(params[:version_id])
|
||||
@wiki_page.revert_to!(@version)
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
||||
def show_or_new
|
||||
@wiki_page = WikiPage.find_by_title(params[:title])
|
||||
if @wiki_page
|
||||
|
@ -4,14 +4,14 @@ module AdvertisementsHelper
|
||||
@advertisement = Advertisement.find(:first, :conditions => ["ad_type = ? AND status = 'active'", ad_type], :order => "random()")
|
||||
if @advertisement
|
||||
content_tag(
|
||||
"div",
|
||||
"div",
|
||||
link_to(
|
||||
image_tag(
|
||||
@advertisement.image_url,
|
||||
:alt => "Advertisement",
|
||||
:width => @advertisement.width,
|
||||
@advertisement.image_url,
|
||||
:alt => "Advertisement",
|
||||
:width => @advertisement.width,
|
||||
:height => @advertisement.height
|
||||
),
|
||||
),
|
||||
advertisement_hits_path(:advertisement_id => @advertisement.id),
|
||||
:method => :post
|
||||
),
|
||||
@ -22,7 +22,7 @@ module AdvertisementsHelper
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def render_rss_advertisement(short_or_long, safe)
|
||||
if Danbooru.config.can_see_ads?(CurrentUser.user)
|
||||
if safe
|
||||
|
@ -8,27 +8,27 @@ module ApplicationHelper
|
||||
|
||||
content_tag("li", link_to(text, url, options), :class => klass)
|
||||
end
|
||||
|
||||
|
||||
def fast_link_to(text, link_params, options = {})
|
||||
if options
|
||||
attributes = options.map do |k, v|
|
||||
attributes = options.map do |k, v|
|
||||
%{#{k}="#{h(v)}"}
|
||||
end.join(" ")
|
||||
else
|
||||
attributes = ""
|
||||
end
|
||||
|
||||
|
||||
if link_params.is_a?(Hash)
|
||||
action = link_params.delete(:action)
|
||||
controller = link_params.delete(:controller) || controller_name
|
||||
id = link_params.delete(:id)
|
||||
|
||||
|
||||
link_params = link_params.map {|k, v| "#{k}=#{u(v)}"}.join("&")
|
||||
|
||||
|
||||
if link_params.present?
|
||||
link_params = "?#{link_params}"
|
||||
end
|
||||
|
||||
|
||||
if id
|
||||
url = "/#{controller}/#{action}/#{id}#{link_params}"
|
||||
else
|
||||
@ -37,43 +37,43 @@ module ApplicationHelper
|
||||
else
|
||||
url = link_params
|
||||
end
|
||||
|
||||
|
||||
raw %{<a href="#{h(url)}" #{attributes}>#{text}</a>}
|
||||
end
|
||||
|
||||
|
||||
def format_text(text, options = {})
|
||||
DText.parse(text)
|
||||
end
|
||||
|
||||
def error_messages_for(instance_name)
|
||||
instance = instance_variable_get("@#{instance_name}")
|
||||
|
||||
|
||||
if instance && instance.errors.any?
|
||||
%{<div class="error-messages ui-state-error ui-corner-all"><strong>Error</strong>: #{instance.__send__(:errors).full_messages.join(", ")}</div>}.html_safe
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def time_tag(content, time)
|
||||
zone = time.strftime("%z")
|
||||
datetime = time.strftime("%Y-%m-%dT%H:%M" + zone[0, 3] + ":" + zone[3, 2])
|
||||
|
||||
|
||||
content_tag(:time, content || datetime, :datetime => datetime, :title => time.to_formatted_s)
|
||||
end
|
||||
|
||||
|
||||
def time_ago_in_words_tagged(time)
|
||||
raw time_tag(time_ago_in_words(time) + " ago", time)
|
||||
end
|
||||
|
||||
|
||||
def compact_time(time)
|
||||
time_tag(time.strftime("%Y-%m-%d %H:%M"), time)
|
||||
end
|
||||
|
||||
|
||||
def mod_link_to_user(user, positive_or_negative)
|
||||
html = ""
|
||||
html << link_to(user.name, user_path(user))
|
||||
|
||||
|
||||
if positive_or_negative == :positive
|
||||
html << " [" + link_to("+", new_user_feedback_path(:user_feedback => {:category => "positive", :user_id => user.id})) + "]"
|
||||
|
||||
@ -83,26 +83,26 @@ module ApplicationHelper
|
||||
else
|
||||
html << " [" + link_to("–".html_safe, new_user_feedback_path(:user_feedback => {:category => "negative", :user_id => user.id})) + "]"
|
||||
end
|
||||
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
|
||||
def dtext_field(object, name, options = {})
|
||||
options[:name] ||= "Body"
|
||||
options[:input_id] ||= "#{object}_#{name}"
|
||||
options[:input_name] ||= "#{object}[#{name}]"
|
||||
options[:value] ||= instance_variable_get("@#{object}").try(name)
|
||||
options[:preview_id] ||= "dtext-preview"
|
||||
|
||||
|
||||
render "dtext/form", options
|
||||
end
|
||||
|
||||
|
||||
def dtext_preview_button(object, name, options = {})
|
||||
options[:input_id] ||= "#{object}_#{name}"
|
||||
options[:preview_id] ||= "dtext-preview"
|
||||
submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id])
|
||||
end
|
||||
|
||||
|
||||
def search_field(method, options = {})
|
||||
name = options[:label] || method.titleize
|
||||
string = '<div class="input"><label for="search_' + method + '">' + name + '</label><input type="text" name="search[' + method + ']" id="search_' + method + '">'
|
||||
@ -112,49 +112,49 @@ module ApplicationHelper
|
||||
string += '</div>'
|
||||
string.html_safe
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def nav_link_match(controller, url)
|
||||
url =~ case controller
|
||||
when "sessions", "users", "maintenance/user/login_reminders", "maintenance/user/password_resets", "admin/users", "tag_subscriptions"
|
||||
/^\/(session|users)/
|
||||
|
||||
|
||||
when "forum_posts"
|
||||
/^\/forum_topics/
|
||||
|
||||
|
||||
when "comments"
|
||||
/^\/comments/
|
||||
|
||||
|
||||
when "notes", "note_versions"
|
||||
/^\/notes/
|
||||
|
||||
|
||||
when "posts", "uploads", "post_versions", "explore/posts", "moderator/post/dashboards", "favorites"
|
||||
/^\/post/
|
||||
|
||||
|
||||
when "artists", "artist_versions"
|
||||
/^\/artist/
|
||||
|
||||
|
||||
when "tags"
|
||||
/^\/tags/
|
||||
|
||||
|
||||
when "pools"
|
||||
/^\/pools/
|
||||
|
||||
|
||||
when "moderator/dashboards"
|
||||
/^\/moderator/
|
||||
|
||||
|
||||
when "tag_aliases", "tag_alias_corrections", "tag_alias_requests"
|
||||
/^\/tag_aliases/
|
||||
|
||||
|
||||
when "tag_implications", "tag_implication_requests"
|
||||
/^\/tag_implications/
|
||||
|
||||
|
||||
when "wiki_pages", "wiki_page_versions"
|
||||
/^\/wiki_pages/
|
||||
|
||||
|
||||
when "forum_topics", "forum_posts"
|
||||
/^\/forum_topics/
|
||||
|
||||
|
||||
else
|
||||
/^\/static/
|
||||
end
|
||||
|
@ -1,16 +1,16 @@
|
||||
module ArtistsHelper
|
||||
def link_to_artist(name)
|
||||
artist = Artist.find_by_name(name)
|
||||
|
||||
|
||||
if artist
|
||||
link_to(artist.name, artist_path(artist))
|
||||
else
|
||||
link_to(name, new_artist_path(:name => name)) + " " + content_tag("span", "*", :class => "new-artist")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def link_to_artists(names)
|
||||
names.map do |name|
|
||||
names.map do |name|
|
||||
link_to_artist(name)
|
||||
end.join(", ").html_safe
|
||||
end
|
||||
|
@ -3,28 +3,28 @@ module DelayedJobsHelper
|
||||
case job.name
|
||||
when "Class#expire_cache"
|
||||
"<strong>expire post count cache</strong>: " + job.payload_object.args.flatten.join(" ")
|
||||
|
||||
|
||||
when "Upload#process!"
|
||||
'<strong>upload post</strong>: <a href="/uploads/' + job.payload_object.object.id.to_s + '">record</a>'
|
||||
|
||||
|
||||
when "Tag#update_related"
|
||||
"<strong>update related tags</strong>: " + job.payload_object.name
|
||||
|
||||
|
||||
when "TagAlias#process!"
|
||||
'<strong>alias</strong>: ' + job.payload_object.antecedent_name + " -> " + job.payload_object.consequent_name
|
||||
|
||||
|
||||
when "TagImplication#process!"
|
||||
'<strong>implication</strong>: ' + job.payload_object.antecedent_name + " -> " + job.payload_object.consequent_name
|
||||
|
||||
|
||||
when "Class#clear_cache_for"
|
||||
"<strong>expire tag alias cache</strong>: " + job.payload_object.flatten.join(" ")
|
||||
|
||||
|
||||
when "Tag#update_category_cache"
|
||||
"<strong>update tag category cache</strong>: " + job.payload_object.name
|
||||
|
||||
when "Tag#update_category_post_counts"
|
||||
"<strong>update category post counts</strong>: " + job.payload_object.name
|
||||
|
||||
|
||||
else
|
||||
job.handler
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ module Moderator
|
||||
["Moderator", 40],
|
||||
["Admin", 50]
|
||||
]
|
||||
|
||||
|
||||
select_tag(name, options_for_select(choices, params[name].to_i), options)
|
||||
end
|
||||
end
|
||||
|
@ -1,31 +1,31 @@
|
||||
module PaginationHelper
|
||||
def sequential_paginator(records)
|
||||
html = '<div class="paginator"><menu>'
|
||||
|
||||
if records.any?
|
||||
|
||||
if records.any?
|
||||
if params[:page] =~ /[ab]/
|
||||
html << '<li>' + link_to("< Previous", params.merge(:page => "a#{records[0].id}"), :rel => "prev") + '</li>'
|
||||
end
|
||||
|
||||
|
||||
html << '<li>' + link_to("Next >", params.merge(:page => "b#{records[-1].id}"), :rel => "next") + '</li>'
|
||||
end
|
||||
|
||||
|
||||
html << "</menu></div>"
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
|
||||
def use_sequential_paginator?(records)
|
||||
params[:page] =~ /[ab]/ || records.current_page >= Danbooru.config.max_numbered_pages
|
||||
end
|
||||
|
||||
|
||||
def numbered_paginator(records, switch_to_sequential = true)
|
||||
if use_sequential_paginator?(records) && switch_to_sequential
|
||||
return sequential_paginator(records)
|
||||
end
|
||||
|
||||
|
||||
html = '<div class="paginator"><menu>'
|
||||
window = 3
|
||||
|
||||
|
||||
if records.current_page >= 2
|
||||
html << "<li>" + link_to("<<", params.merge(:page => records.current_page - 1), :rel => "prev") + "</li>"
|
||||
end
|
||||
@ -34,7 +34,7 @@ module PaginationHelper
|
||||
1.upto(records.total_pages) do |page|
|
||||
html << numbered_paginator_item(page, records.current_page)
|
||||
end
|
||||
|
||||
|
||||
elsif records.current_page <= window + 2
|
||||
1.upto(records.current_page + window) do |page|
|
||||
html << numbered_paginator_item(page, records.current_page)
|
||||
@ -63,15 +63,15 @@ module PaginationHelper
|
||||
html << numbered_paginator_final_item(records.total_pages, records.current_page)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if records.current_page < records.total_pages && records.size > 0
|
||||
html << "<li>" + link_to(">>", params.merge(:page => records.current_page + 1), :rel => "next") + "</li>"
|
||||
end
|
||||
|
||||
|
||||
html << "</menu></div>"
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
|
||||
def numbered_paginator_final_item(total_pages, current_page)
|
||||
if total_pages <= Danbooru.config.max_numbered_pages
|
||||
numbered_paginator_item(total_pages, current_page)
|
||||
@ -79,10 +79,10 @@ module PaginationHelper
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def numbered_paginator_item(page, current_page)
|
||||
return "" if page.to_i > Danbooru.config.max_numbered_pages
|
||||
|
||||
|
||||
html = "<li>"
|
||||
if page == "..."
|
||||
html << "..."
|
||||
|
@ -2,11 +2,11 @@ module PostAppealsHelper
|
||||
def post_appeal_reasons(post)
|
||||
html = []
|
||||
html << '<ul>'
|
||||
|
||||
|
||||
post.appeals.each do |appeal|
|
||||
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>'
|
||||
html.join("\n").html_safe
|
||||
end
|
||||
|
@ -2,24 +2,24 @@ module PostFlagsHelper
|
||||
def post_flag_reasons(post)
|
||||
html = []
|
||||
html << '<ul>'
|
||||
|
||||
|
||||
post.flags.each do |flag|
|
||||
html << '<li>'
|
||||
html << DText.parse_inline(flag.reason).html_safe
|
||||
|
||||
|
||||
if CurrentUser.is_janitor?
|
||||
html << ' - ' + link_to(flag.creator.name, user_path(flag.creator))
|
||||
end
|
||||
|
||||
html << ' - ' + time_ago_in_words_tagged(flag.created_at)
|
||||
|
||||
|
||||
if flag.is_resolved?
|
||||
html << ' <span class="resolved">RESOLVED</span>'
|
||||
end
|
||||
|
||||
|
||||
html << '</li>'
|
||||
end
|
||||
|
||||
|
||||
html << '</ul>'
|
||||
html.join("\n").html_safe
|
||||
end
|
||||
|
@ -5,18 +5,18 @@ module PostsHelper
|
||||
if post.has_large?
|
||||
links << link_to("L", post.large_file_url, :id => "large-file-link")
|
||||
end
|
||||
|
||||
|
||||
if post.has_large?
|
||||
links << link_to("O", post.file_url, :id => "original-file-link")
|
||||
end
|
||||
|
||||
|
||||
if links.any?
|
||||
content_tag("span", raw("Resize: " + links.join(" ")))
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def post_source_tag(post)
|
||||
if post.source =~ /^http/
|
||||
text = truncate(post.normalized_source.sub(/^https?:\/\//, ""))
|
||||
|
@ -1,18 +1,18 @@
|
||||
class AliasAndImplicationImporter
|
||||
attr_accessor :text, :commands, :forum_id
|
||||
|
||||
|
||||
def initialize(text, forum_id)
|
||||
@forum_id = forum_id
|
||||
@text = text
|
||||
end
|
||||
|
||||
|
||||
def process!
|
||||
tokens = tokenize(text)
|
||||
parse(tokens)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def tokenize(text)
|
||||
text.gsub!(/^\s+/, "")
|
||||
text.gsub!(/\s+$/, "")
|
||||
@ -33,7 +33,7 @@ private
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def parse(tokens)
|
||||
ActiveRecord::Base.transaction do
|
||||
tokens.map do |token|
|
||||
@ -41,21 +41,21 @@ private
|
||||
when :create_alias
|
||||
tag_alias = TagAlias.create(:forum_topic_id => forum_id, :status => "pending", :antecedent_name => token[1], :consequent_name => token[2])
|
||||
tag_alias.delay(:queue => "default").process!
|
||||
|
||||
|
||||
when :create_implication
|
||||
tag_implication = TagImplication.create(:forum_topic_id => forum_id, :status => "pending", :antecedent_name => token[1], :consequent_name => token[2])
|
||||
tag_implication.delay(:queue => "default").process!
|
||||
|
||||
|
||||
when :remove_alias
|
||||
tag_alias = TagAlias.where("antecedent_name = ?", token[1]).first
|
||||
raise "Alias for #{token[1]} not found" if tag_alias.nil?
|
||||
tag_alias.destroy
|
||||
|
||||
|
||||
when :remove_implication
|
||||
tag_implication = TagImplication.where("antecedent_name = ? and consequent_name = ?", token[1], token[2]).first
|
||||
raise "Implication for #{token[1]} not found" if tag_implication.nil?
|
||||
tag_implication.destroy
|
||||
|
||||
|
||||
else
|
||||
raise "Unknown token: #{token[0]}"
|
||||
end
|
||||
|
@ -11,15 +11,15 @@ class AnonymousUser
|
||||
def comment_threshold
|
||||
0
|
||||
end
|
||||
|
||||
|
||||
def created_at
|
||||
Time.now
|
||||
end
|
||||
|
||||
|
||||
def updated_at
|
||||
Time.now
|
||||
end
|
||||
|
||||
|
||||
def name
|
||||
"Anonymous"
|
||||
end
|
||||
@ -31,11 +31,11 @@ class AnonymousUser
|
||||
def is_anonymous?
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
def has_mail?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def has_forum_been_updated?
|
||||
false
|
||||
end
|
||||
@ -47,11 +47,11 @@ class AnonymousUser
|
||||
def ban
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def always_resize_images?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def show_samples?
|
||||
true
|
||||
end
|
||||
@ -59,15 +59,15 @@ class AnonymousUser
|
||||
def tag_subscriptions
|
||||
[]
|
||||
end
|
||||
|
||||
|
||||
def favorite_tags
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
def upload_limit
|
||||
0
|
||||
end
|
||||
|
||||
|
||||
def base_upload_limit
|
||||
0
|
||||
end
|
||||
@ -75,15 +75,15 @@ class AnonymousUser
|
||||
def uploaded_tags
|
||||
""
|
||||
end
|
||||
|
||||
|
||||
def uploaded_tags_with_types
|
||||
[]
|
||||
end
|
||||
|
||||
|
||||
def recent_tags
|
||||
""
|
||||
end
|
||||
|
||||
|
||||
def recent_tags_with_types
|
||||
[]
|
||||
end
|
||||
@ -91,15 +91,15 @@ class AnonymousUser
|
||||
def can_upload?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def can_comment?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def can_remove_from_pools?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def blacklisted_tags
|
||||
""
|
||||
end
|
||||
@ -107,64 +107,64 @@ class AnonymousUser
|
||||
def time_zone
|
||||
"Eastern Time (US & Canada)"
|
||||
end
|
||||
|
||||
|
||||
def default_image_size
|
||||
"large"
|
||||
end
|
||||
|
||||
|
||||
def blacklisted_tags
|
||||
[]
|
||||
end
|
||||
|
||||
|
||||
def email
|
||||
""
|
||||
end
|
||||
|
||||
|
||||
def last_forum_read_at
|
||||
Time.now
|
||||
end
|
||||
|
||||
|
||||
def update_column(*params)
|
||||
end
|
||||
|
||||
|
||||
def increment!(field)
|
||||
end
|
||||
|
||||
|
||||
def decrement!(field)
|
||||
end
|
||||
|
||||
|
||||
def role
|
||||
:anonymous
|
||||
end
|
||||
|
||||
|
||||
def tag_query_limit
|
||||
2
|
||||
end
|
||||
|
||||
|
||||
def favorite_limit
|
||||
0
|
||||
end
|
||||
|
||||
|
||||
def favorite_count
|
||||
0
|
||||
end
|
||||
|
||||
|
||||
def enable_post_navigation
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
def new_post_navigation_layout
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
def enable_privacy_mode
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def enable_sequential_post_navigation
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
%w(member banned privileged builder platinum contributor janitor moderator admin).each do |name|
|
||||
define_method("is_#{name}?") do
|
||||
false
|
||||
|
@ -4,7 +4,7 @@ class Cache
|
||||
Cache.put(key, val.to_i + 1)
|
||||
ActiveRecord::Base.logger.debug('MemCache Incr %s' % [key])
|
||||
end
|
||||
|
||||
|
||||
def self.decr(key, expiry = 0)
|
||||
val = Cache.get(key, expiry)
|
||||
if val.to_i > 0
|
||||
@ -12,7 +12,7 @@ class Cache
|
||||
end
|
||||
ActiveRecord::Base.logger.debug('MemCache Decr %s' % [key])
|
||||
end
|
||||
|
||||
|
||||
def self.get_multi(keys, prefix, expiry = 0)
|
||||
key_to_sanitized_key_hash = keys.inject({}) do |hash, x|
|
||||
hash[x] = "#{prefix}:#{Cache.sanitize(x)}"
|
||||
@ -30,11 +30,11 @@ class Cache
|
||||
Cache.put(sanitized_key, result_hash[key], expiry)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
ActiveRecord::Base.logger.debug('MemCache Multi-Get (%0.6f) %s' % [elapsed, keys.join(",")])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.get(key, expiry = 0)
|
||||
begin
|
||||
start_time = Time.now
|
||||
@ -55,11 +55,11 @@ class Cache
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.put(key, value, expiry = 0)
|
||||
key.gsub!(/\s/, "_")
|
||||
key = key[0, 200]
|
||||
|
||||
|
||||
begin
|
||||
start_time = Time.now
|
||||
MEMCACHE.set key, value, expiry
|
||||
@ -71,7 +71,7 @@ class Cache
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.delete(key, delay = nil)
|
||||
begin
|
||||
start_time = Time.now
|
||||
@ -84,7 +84,7 @@ class Cache
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.sanitize(key)
|
||||
key.gsub(/\W/) {|x| "%#{x.ord}"}.slice(0, 240)
|
||||
end
|
||||
|
@ -2,10 +2,10 @@ class CurrentUser
|
||||
def self.scoped(user, ip_addr)
|
||||
old_user = self.user
|
||||
old_ip_addr = self.ip_addr
|
||||
|
||||
|
||||
self.user = user
|
||||
self.ip_addr = ip_addr
|
||||
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
@ -17,19 +17,19 @@ class CurrentUser
|
||||
def self.user=(user)
|
||||
Thread.current[:current_user] = user
|
||||
end
|
||||
|
||||
|
||||
def self.ip_addr=(ip_addr)
|
||||
Thread.current[:current_ip_addr] = ip_addr
|
||||
end
|
||||
|
||||
|
||||
def self.user
|
||||
Thread.current[:current_user]
|
||||
end
|
||||
|
||||
|
||||
def self.ip_addr
|
||||
Thread.current[:current_ip_addr]
|
||||
end
|
||||
|
||||
|
||||
def self.id
|
||||
if user.nil?
|
||||
nil
|
||||
@ -37,11 +37,11 @@ class CurrentUser
|
||||
user.id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.name
|
||||
user.name
|
||||
end
|
||||
|
||||
|
||||
def self.method_missing(method, *params, &block)
|
||||
if user.respond_to?(method)
|
||||
user.__send__(method, *params, &block)
|
||||
|
@ -5,11 +5,11 @@ class DText
|
||||
def self.u(string)
|
||||
CGI.escape(string)
|
||||
end
|
||||
|
||||
|
||||
def self.h(string)
|
||||
CGI.escapeHTML(string)
|
||||
end
|
||||
|
||||
|
||||
def self.parse_inline(str, options = {})
|
||||
str.gsub!(/&/, "&")
|
||||
str.gsub!(/</, "<")
|
||||
@ -25,7 +25,7 @@ class DText
|
||||
str = parse_id_links(str)
|
||||
str
|
||||
end
|
||||
|
||||
|
||||
def self.parse_links(str)
|
||||
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+)+/) do |url|
|
||||
if url =~ /^"([^"]+)":(.+)$/
|
||||
@ -34,7 +34,7 @@ class DText
|
||||
else
|
||||
text = url
|
||||
end
|
||||
|
||||
|
||||
if url =~ /([;,.!?\)\]<>])$/
|
||||
url.chop!
|
||||
ch = $1
|
||||
@ -45,7 +45,7 @@ class DText
|
||||
'<a href="' + url + '">' + text + '</a>' + ch
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_aliased_wiki_links(str)
|
||||
str.gsub(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m) do
|
||||
text = CGI.unescapeHTML($2)
|
||||
@ -53,7 +53,7 @@ class DText
|
||||
%{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_wiki_links(str)
|
||||
str.gsub(/\[\[([^\]]+)\]\]/) do
|
||||
text = CGI.unescapeHTML($1)
|
||||
@ -61,14 +61,14 @@ class DText
|
||||
%{<a href="/wiki_pages/show_or_new?title=#{u(title)}">#{h(text)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_post_links(str)
|
||||
str.gsub(/\{\{([^\}]+)\}\}/) do
|
||||
tags = CGI.unescapeHTML($1)
|
||||
%{<a href="/posts?tags=#{u(tags)}">#{h(tags)}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.parse_id_links(str)
|
||||
str = str.gsub(/\bpost #(\d+)/i, %{<a href="/posts/\\1">post #\\1</a>})
|
||||
str = str.gsub(/\bforum #(\d+)/i, %{<a href="/forum_posts/\\1">forum #\\1</a>})
|
||||
@ -76,7 +76,7 @@ class DText
|
||||
str = str.gsub(/\bpool #(\d+)/i, %{<a href="/pools/\\1">pool #\\1</a>})
|
||||
str = str.gsub(/\buser #(\d+)/i, %{<a href="/users/\\1">user #\\1</a>})
|
||||
end
|
||||
|
||||
|
||||
def self.parse_list(str, options = {})
|
||||
html = ""
|
||||
layout = []
|
||||
@ -115,27 +115,27 @@ class DText
|
||||
|
||||
def self.parse(str, options = {})
|
||||
return "" if str.blank?
|
||||
|
||||
|
||||
# Make sure quote tags are surrounded by newlines
|
||||
|
||||
|
||||
unless options[:inline]
|
||||
str.gsub!(/\s*\[quote\]\s*/m, "\n\n[quote]\n\n")
|
||||
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
|
||||
str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n")
|
||||
str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n")
|
||||
end
|
||||
|
||||
|
||||
str.gsub!(/(?:\r?\n){3,}/, "\n\n")
|
||||
str.strip!
|
||||
blocks = str.split(/(?:\r?\n){2}/)
|
||||
stack = []
|
||||
|
||||
|
||||
html = blocks.map do |block|
|
||||
case block
|
||||
when /^(h[1-6])\.\s*(.+)$/
|
||||
tag = $1
|
||||
content = $2
|
||||
|
||||
content = $2
|
||||
|
||||
if options[:inline]
|
||||
"<h6>" + parse_inline(content, options) + "</h6>"
|
||||
else
|
||||
@ -144,7 +144,7 @@ class DText
|
||||
|
||||
when /^\s*\*+ /
|
||||
parse_list(block, options)
|
||||
|
||||
|
||||
when "[quote]"
|
||||
if options[:inline]
|
||||
""
|
||||
@ -152,7 +152,7 @@ class DText
|
||||
stack << "blockquote"
|
||||
"<blockquote>"
|
||||
end
|
||||
|
||||
|
||||
when "[/quote]"
|
||||
if options[:inline]
|
||||
""
|
||||
@ -166,7 +166,7 @@ class DText
|
||||
when /\[spoilers?\](?!\])/
|
||||
stack << "div"
|
||||
'<div class="spoiler">'
|
||||
|
||||
|
||||
when /\[\/spoilers?\]/
|
||||
if stack.last == "div"
|
||||
stack.pop
|
||||
@ -177,7 +177,7 @@ class DText
|
||||
'<p>' + parse_inline(block) + "</p>"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
stack.reverse.each do |tag|
|
||||
if tag == "blockquote"
|
||||
html << "</blockquote>"
|
||||
@ -188,10 +188,10 @@ class DText
|
||||
|
||||
sanitize(html.join("")).html_safe
|
||||
end
|
||||
|
||||
|
||||
def self.sanitize(text)
|
||||
text.gsub!(/<( |-|\Z)/, "<\\1")
|
||||
|
||||
|
||||
Sanitize.clean(
|
||||
text,
|
||||
:elements => %w(code center tn h1 h2 h3 h4 h5 h6 a span div blockquote br p ul li ol em strong small big b i font u s),
|
||||
|
@ -1,14 +1,14 @@
|
||||
module Downloads
|
||||
class File
|
||||
class Error < Exception ; end
|
||||
|
||||
|
||||
attr_accessor :source, :content_type, :file_path
|
||||
|
||||
|
||||
def initialize(source, file_path)
|
||||
@source = source
|
||||
@file_path = file_path
|
||||
end
|
||||
|
||||
|
||||
def download!
|
||||
http_get_streaming do |response|
|
||||
self.content_type = response["Content-Type"]
|
||||
@ -18,23 +18,23 @@ module Downloads
|
||||
end
|
||||
after_download
|
||||
end
|
||||
|
||||
|
||||
def before_download(url, headers)
|
||||
Strategies::Base.strategies.each do |strategy|
|
||||
url, headers = strategy.new.rewrite(url, headers)
|
||||
end
|
||||
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
|
||||
def after_download
|
||||
fix_image_board_sources
|
||||
end
|
||||
|
||||
|
||||
def url
|
||||
URI.parse(source)
|
||||
end
|
||||
|
||||
|
||||
def http_get_streaming(options = {})
|
||||
max_size = options[:max_size] || Danbooru.config.max_file_size
|
||||
max_size = nil if max_size == 0 # unlimited
|
||||
@ -49,7 +49,7 @@ module Downloads
|
||||
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
|
||||
}
|
||||
@source, headers = before_download(source, headers)
|
||||
|
||||
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 10
|
||||
http.request_get(url.request_uri, headers) do |res|
|
||||
@ -76,7 +76,7 @@ module Downloads
|
||||
end # http.start
|
||||
end # while
|
||||
end # def
|
||||
|
||||
|
||||
def fix_image_board_sources
|
||||
if source =~ /\/src\/\d{12,}|urnc\.yi\.org|yui\.cynthia\.bne\.jp/
|
||||
@source = "Image board"
|
||||
|
@ -4,7 +4,7 @@ module Downloads
|
||||
def self.strategies
|
||||
[Pixiv]
|
||||
end
|
||||
|
||||
|
||||
def rewrite(url, headers)
|
||||
return [url, headers]
|
||||
end
|
||||
|
@ -8,16 +8,16 @@ module Downloads
|
||||
url, headers = rewrite_small_images(url, headers)
|
||||
url, headers = rewrite_small_manga_pages(url, headers)
|
||||
end
|
||||
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def rewrite_headers(url, headers)
|
||||
headers["Referer"] = "http://www.pixiv.net"
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
|
||||
def rewrite_html_pages(url, headers)
|
||||
# example: http://www.pixiv.net/member_illust.php?mode=big&illust_id=23828655
|
||||
|
||||
@ -29,16 +29,16 @@ module Downloads
|
||||
return [url, headers]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def rewrite_small_images(url, headers)
|
||||
if url =~ %r!(/img/.+?/.+?)_m.+$!
|
||||
match = $1
|
||||
url.sub!(match + "_m", match)
|
||||
end
|
||||
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
|
||||
def rewrite_small_manga_pages(url, headers)
|
||||
if url =~ %r!(\d+_p\d+)\.!
|
||||
match = $1
|
||||
@ -48,7 +48,7 @@ module Downloads
|
||||
url = big_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
class JanitorTrialTester
|
||||
attr_reader :user
|
||||
|
||||
|
||||
def initialize(user_name)
|
||||
@user = User.find_by_name(user_name)
|
||||
end
|
||||
|
||||
|
||||
def test
|
||||
if user.nil?
|
||||
"User not found"
|
||||
|
@ -7,16 +7,16 @@ module Moderator
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
SELECT artist_versions.updater_id AS updater_id, count(*)
|
||||
FROM artist_versions
|
||||
JOIN users ON users.id = artist_versions.updater_id
|
||||
WHERE
|
||||
artist_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY artist_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
FROM artist_versions
|
||||
JOIN users ON users.id = artist_versions.updater_id
|
||||
WHERE
|
||||
artist_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY artist_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
@ -6,20 +6,20 @@ module Moderator
|
||||
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
SELECT comment_votes.comment_id, count(*)
|
||||
FROM comment_votes
|
||||
JOIN comments ON comments.id = comment_id
|
||||
JOIN users ON users.id = comments.creator_id
|
||||
WHERE
|
||||
comment_votes.created_at > ?
|
||||
AND comments.score < 0
|
||||
AND users.level <= ?
|
||||
GROUP BY comment_votes.comment_id
|
||||
SELECT comment_votes.comment_id, count(*)
|
||||
FROM comment_votes
|
||||
JOIN comments ON comments.id = comment_id
|
||||
JOIN users ON users.id = comments.creator_id
|
||||
WHERE
|
||||
comment_votes.created_at > ?
|
||||
AND comments.score < 0
|
||||
AND users.level <= ?
|
||||
GROUP BY comment_votes.comment_id
|
||||
HAVING count(*) >= 3
|
||||
ORDER BY count(*) DESC
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
@ -3,23 +3,23 @@ module Moderator
|
||||
module Queries
|
||||
class Note
|
||||
attr_reader :user, :count
|
||||
|
||||
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
SELECT note_versions.updater_id, count(*)
|
||||
FROM note_versions
|
||||
JOIN users ON users.id = note_versions.updater_id
|
||||
WHERE
|
||||
note_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY note_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
SELECT note_versions.updater_id, count(*)
|
||||
FROM note_versions
|
||||
JOIN users ON users.id = note_versions.updater_id
|
||||
WHERE
|
||||
note_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY note_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
||||
def initialize(hash)
|
||||
@user = ::User.find(hash["updater_id"])
|
||||
@count = hash["count"]
|
||||
|
@ -10,14 +10,14 @@ module Moderator
|
||||
FROM post_appeals
|
||||
JOIN posts ON posts.id = post_appeals.post_id
|
||||
WHERE
|
||||
post_appeals.created_at > ?
|
||||
post_appeals.created_at > ?
|
||||
and posts.is_deleted = true
|
||||
and posts.is_pending = false
|
||||
GROUP BY post_appeals.post_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
@ -6,22 +6,22 @@ module Moderator
|
||||
|
||||
def self.all(min_date)
|
||||
sql = <<-EOS
|
||||
SELECT post_flags.post_id, count(*)
|
||||
FROM post_flags
|
||||
JOIN posts ON posts.id = post_flags.post_id
|
||||
WHERE
|
||||
post_flags.created_at > ?
|
||||
AND post_flags.reason <> ?
|
||||
SELECT post_flags.post_id, count(*)
|
||||
FROM post_flags
|
||||
JOIN posts ON posts.id = post_flags.post_id
|
||||
WHERE
|
||||
post_flags.created_at > ?
|
||||
AND post_flags.reason <> ?
|
||||
AND posts.is_deleted = false
|
||||
and posts.is_pending = false
|
||||
GROUP BY post_flags.post_id
|
||||
ORDER BY count(*) DESC
|
||||
GROUP BY post_flags.post_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, "Unapproved in three days").map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
||||
def initialize(hash)
|
||||
@post = Post.find(hash["post_id"])
|
||||
@count = hash["count"]
|
||||
|
@ -3,25 +3,25 @@ module Moderator
|
||||
module Queries
|
||||
class Tag
|
||||
attr_reader :user, :count
|
||||
|
||||
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
SELECT post_versions.updater_id, count(*)
|
||||
FROM post_versions
|
||||
JOIN users ON users.id = post_versions.updater_id
|
||||
WHERE
|
||||
post_versions.updated_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY post_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
SELECT post_versions.updater_id, count(*)
|
||||
FROM post_versions
|
||||
JOIN users ON users.id = post_versions.updater_id
|
||||
WHERE
|
||||
post_versions.updated_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY post_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.without_timeout do
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(hash)
|
||||
@user = ::User.find(hash["updater_id"])
|
||||
@count = hash["count"]
|
||||
|
@ -3,23 +3,23 @@ module Moderator
|
||||
module Queries
|
||||
class Upload
|
||||
attr_reader :user, :count
|
||||
|
||||
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
select uploader_id, count(*)
|
||||
from posts
|
||||
join users on uploader_id = users.id
|
||||
where
|
||||
posts.created_at > ?
|
||||
and level <= ?
|
||||
group by posts.uploader_id
|
||||
order by count(*) desc
|
||||
select uploader_id, count(*)
|
||||
from posts
|
||||
join users on uploader_id = users.id
|
||||
where
|
||||
posts.created_at > ?
|
||||
and level <= ?
|
||||
group by posts.uploader_id
|
||||
order by count(*) desc
|
||||
limit 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
||||
def initialize(hash)
|
||||
@user = ::User.find(hash["uploader_id"])
|
||||
@count = hash["count"]
|
||||
|
@ -3,23 +3,23 @@ module Moderator
|
||||
module Queries
|
||||
class WikiPage
|
||||
attr_reader :user, :count
|
||||
|
||||
|
||||
def self.all(min_date, max_level)
|
||||
sql = <<-EOS
|
||||
SELECT wiki_page_versions.updater_id, count(*)
|
||||
FROM wiki_page_versions
|
||||
JOIN users ON users.id = wiki_page_versions.updater_id
|
||||
WHERE
|
||||
wiki_page_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY wiki_page_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
SELECT wiki_page_versions.updater_id, count(*)
|
||||
FROM wiki_page_versions
|
||||
JOIN users ON users.id = wiki_page_versions.updater_id
|
||||
WHERE
|
||||
wiki_page_versions.created_at > ?
|
||||
AND users.level <= ?
|
||||
GROUP BY wiki_page_versions.updater_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 10
|
||||
EOS
|
||||
|
||||
|
||||
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
|
||||
end
|
||||
|
||||
|
||||
def initialize(hash)
|
||||
@user = ::User.find(hash["updater_id"])
|
||||
@count = hash["count"]
|
||||
|
@ -2,18 +2,18 @@ module Moderator
|
||||
module Dashboard
|
||||
class Report
|
||||
attr_reader :min_date, :max_level
|
||||
|
||||
|
||||
def initialize(min_date, max_level)
|
||||
@min_date = min_date.present? ? min_date.to_date : 1.week.ago
|
||||
@max_level = max_level.present? ? User::Levels::MEMBER : max_level.to_i
|
||||
end
|
||||
|
||||
|
||||
def artists
|
||||
ActiveRecord::Base.without_timeout do
|
||||
Queries::Artist.all(min_date, max_level)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def comments
|
||||
ActiveRecord::Base.without_timeout do
|
||||
Queries::Comment.all(min_date, max_level)
|
||||
@ -55,7 +55,7 @@ module Moderator
|
||||
Queries::Upload.all(min_date, max_level)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def user_feedbacks
|
||||
ActiveRecord::Base.without_timeout do
|
||||
Queries::UserFeedback.all
|
||||
|
@ -1,12 +1,12 @@
|
||||
module Moderator
|
||||
class IpAddrSearch
|
||||
attr_reader :params, :errors
|
||||
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
@errors = []
|
||||
end
|
||||
|
||||
|
||||
def execute
|
||||
if params[:user_id].present?
|
||||
search_by_user_id(params[:user_id].split(/,/))
|
||||
@ -18,41 +18,41 @@ module Moderator
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def select_all_sql(sql, *params)
|
||||
ActiveRecord::Base.select_all_sql(sql, *params)
|
||||
end
|
||||
|
||||
|
||||
def search_by_ip_addr(ip_addrs)
|
||||
sums = Hash.new {|h, k| h[k] = 0}
|
||||
|
||||
|
||||
add_row(sums, "select creator_id as k, count(*) from comments where ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from post_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from note_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from pool_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
add_row(sums, "select updater_id as k, count(*) from wiki_page_versions where updater_ip_addr in (?) group by k", ip_addrs)
|
||||
|
||||
|
||||
sums
|
||||
end
|
||||
|
||||
|
||||
def search_by_user_name(user_names)
|
||||
users = User.where("name in (?)", user_names)
|
||||
search_by_user_id(users.map(&:id))
|
||||
end
|
||||
|
||||
|
||||
def search_by_user_id(user_ids)
|
||||
sums = Hash.new {|h, k| h[k] = 0}
|
||||
|
||||
|
||||
add_row(sums, "select ip_addr as k, count(*) from comments where creator_id in (?) group by k", user_ids)
|
||||
add_row(sums, "select updater_ip_addr as k, count(*) from post_versions where updater_id in (?) group by k", user_ids)
|
||||
add_row(sums, "select updater_ip_addr as k, count(*) from note_versions where updater_id in (?) group by k", user_ids)
|
||||
add_row(sums, "select updater_ip_addr as k, count(*) from pool_versions where updater_id in (?) group by k", user_ids)
|
||||
add_row(sums, "select updater_ip_addr as k, count(*) from wiki_page_versions where updater_id in (?) group by k", user_ids)
|
||||
|
||||
|
||||
sums
|
||||
end
|
||||
|
||||
|
||||
def add_row(sums, sql, ip_addrs)
|
||||
select_all_sql(sql, ip_addrs).each do |row|
|
||||
sums[row["k"]] += row["count"].to_i
|
||||
|
@ -1,15 +1,15 @@
|
||||
module Moderator
|
||||
class TagBatchChange < Struct.new(:antecedent, :consequent, :updater_id, :updater_ip_addr)
|
||||
class Error < Exception ; end
|
||||
|
||||
|
||||
def perform
|
||||
raise Error.new("antecedent is missing") if antecedent.blank?
|
||||
|
||||
|
||||
normalized_antecedent = TagAlias.to_aliased(::Tag.scan_tags(antecedent))
|
||||
normalized_consequent = TagAlias.to_aliased(::Tag.scan_tags(consequent))
|
||||
|
||||
|
||||
updater = User.find(updater_id)
|
||||
|
||||
|
||||
CurrentUser.scoped(updater, updater_ip_addr) do
|
||||
::Post.tag_match(antecedent).each do |post|
|
||||
tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ")
|
||||
|
@ -1,16 +1,16 @@
|
||||
class PostPruner
|
||||
attr_reader :admin
|
||||
|
||||
|
||||
def initialize
|
||||
@admin = User.where(:level => User::Levels::ADMIN).first
|
||||
end
|
||||
|
||||
|
||||
def prune!
|
||||
prune_pending!
|
||||
prune_flagged!
|
||||
prune_mod_actions!
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def prune_pending!
|
||||
@ -25,7 +25,7 @@ protected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def prune_flagged!
|
||||
CurrentUser.scoped(admin, "127.0.0.1") do
|
||||
Post.where("is_deleted = ? and is_flagged = ?", false, true).each do |post|
|
||||
@ -40,7 +40,7 @@ protected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def prune_mod_actions!
|
||||
ModAction.destroy_all(["creator_id = ? and description like ?", admin.id, "deleted post %"])
|
||||
end
|
||||
|
@ -1,24 +1,24 @@
|
||||
class PostQueryBuilder
|
||||
attr_accessor :query_string, :has_constraints
|
||||
|
||||
|
||||
def initialize(query_string)
|
||||
@query_string = query_string
|
||||
@has_constraint = false
|
||||
end
|
||||
|
||||
|
||||
def has_constraints?
|
||||
@has_constraints
|
||||
end
|
||||
|
||||
|
||||
def has_constraints!
|
||||
@has_constraints = true
|
||||
end
|
||||
|
||||
|
||||
def add_range_relation(arr, field, relation)
|
||||
return relation if arr.nil?
|
||||
|
||||
|
||||
has_constraints!
|
||||
|
||||
|
||||
case arr[0]
|
||||
when :eq
|
||||
if arr[1].is_a?(Time)
|
||||
@ -38,7 +38,7 @@ class PostQueryBuilder
|
||||
|
||||
when :lte
|
||||
relation.where(["#{field} <= ?", arr[1]])
|
||||
|
||||
|
||||
when :in
|
||||
relation.where(["#{field} in (?)", arr[1]])
|
||||
|
||||
@ -76,10 +76,10 @@ class PostQueryBuilder
|
||||
if tag_query_sql.any?
|
||||
relation = relation.where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag_query_sql.join(" & "))
|
||||
end
|
||||
|
||||
|
||||
relation
|
||||
end
|
||||
|
||||
|
||||
def add_tag_subscription_relation(subscriptions, relation)
|
||||
subscriptions.each do |subscription|
|
||||
if subscription =~ /^(.+?):(.+)$/
|
||||
@ -93,25 +93,25 @@ class PostQueryBuilder
|
||||
return relation if user.nil?
|
||||
post_ids = TagSubscription.find_post_ids(user.id)
|
||||
end
|
||||
|
||||
|
||||
post_ids = [0] if post_ids.empty?
|
||||
relation = relation.where(["posts.id IN (?)", post_ids])
|
||||
end
|
||||
|
||||
|
||||
relation
|
||||
end
|
||||
|
||||
|
||||
def build
|
||||
unless query_string.is_a?(Hash)
|
||||
q = Tag.parse_query(query_string)
|
||||
end
|
||||
|
||||
|
||||
relation = Post.scoped
|
||||
|
||||
|
||||
if q[:tag_count].to_i > Danbooru.config.tag_query_limit
|
||||
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time")
|
||||
end
|
||||
|
||||
|
||||
relation = add_range_relation(q[:post_id], "posts.id", relation)
|
||||
relation = add_range_relation(q[:mpixels], "posts.image_width * posts.image_height / 1000000.0", relation)
|
||||
relation = add_range_relation(q[:width], "posts.image_width", relation)
|
||||
@ -125,12 +125,12 @@ class PostQueryBuilder
|
||||
relation = add_range_relation(q[:character_tag_count], "posts.tag_count_character", relation)
|
||||
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
|
||||
relation = add_range_relation(q[:pixiv], "substring(posts.source, 'pixiv.net/img.*/([0-9]+)[^/]*$')::integer", relation)
|
||||
|
||||
|
||||
if q[:md5]
|
||||
relation = relation.where(["posts.md5 IN (?)", q[:md5]])
|
||||
has_constraints!
|
||||
end
|
||||
|
||||
|
||||
if q[:status] == "pending"
|
||||
relation = relation.where("posts.is_pending = TRUE")
|
||||
elsif q[:status] == "flagged"
|
||||
@ -167,26 +167,26 @@ class PostQueryBuilder
|
||||
if q[:uploader_id_neg]
|
||||
relation = relation.where("posts.uploader_id not in (?)", q[:uploader_id_neg])
|
||||
end
|
||||
|
||||
|
||||
if q[:uploader_id]
|
||||
relation = relation.where("posts.uploader_id = ?", q[:uploader_id])
|
||||
has_constraints!
|
||||
end
|
||||
|
||||
|
||||
if q[:approver_id_neg]
|
||||
relation = relation.where("posts.approver_id not in (?)", q[:approver_id_neg])
|
||||
end
|
||||
|
||||
|
||||
if q[:approver_id]
|
||||
relation = relation.where("posts.approver_id = ?", q[:approver_id])
|
||||
has_constraints!
|
||||
end
|
||||
|
||||
|
||||
if q[:parent_id]
|
||||
relation = relation.where("(posts.id = ? or posts.parent_id = ?)", q[:parent_id], q[:parent_id])
|
||||
has_constraints!
|
||||
end
|
||||
|
||||
|
||||
if q[:rating] =~ /^q/
|
||||
relation = relation.where("posts.rating = 'q'")
|
||||
elsif q[:rating] =~ /^s/
|
||||
@ -202,13 +202,13 @@ class PostQueryBuilder
|
||||
elsif q[:rating_negated] =~ /^e/
|
||||
relation = relation.where("posts.rating <> 'e'")
|
||||
end
|
||||
|
||||
|
||||
relation = add_tag_string_search_relation(q[:tags], relation)
|
||||
|
||||
|
||||
if q[:order] == "rank"
|
||||
relation = relation.where("posts.score > 0 and posts.created_at >= ?", 2.days.ago)
|
||||
end
|
||||
|
||||
|
||||
case q[:order]
|
||||
when "id", "id_asc"
|
||||
relation = relation.order("posts.id ASC")
|
||||
@ -221,10 +221,10 @@ class PostQueryBuilder
|
||||
|
||||
when "score_asc"
|
||||
relation = relation.order("posts.score ASC, posts.id DESC")
|
||||
|
||||
|
||||
when "favcount"
|
||||
relation = relation.order("posts.fav_count DESC, posts.id DESC")
|
||||
|
||||
|
||||
when "favcount_asc"
|
||||
relation = relation.order("posts.fav_count ASC, posts.id DESC")
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
class PostSearchContext
|
||||
attr_reader :params, :post_id
|
||||
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
raise unless params[:seq].present?
|
||||
raise unless params[:id].present?
|
||||
|
||||
|
||||
@post_id = find_post_id
|
||||
end
|
||||
|
||||
|
||||
def find_post_id
|
||||
if params[:seq] == "prev"
|
||||
post = Post.tag_match(params[:tags]).where("posts.id > ?", params[:id].to_i).reorder("posts.id asc").first
|
||||
|
@ -1,12 +1,12 @@
|
||||
module PostSets
|
||||
class Artist < PostSets::Post
|
||||
attr_reader :artist
|
||||
|
||||
|
||||
def initialize(artist)
|
||||
super(artist.name)
|
||||
@artist = artist
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
::Post.tag_match(@artist.name).limit(10)
|
||||
rescue ::Post::SearchError
|
||||
|
@ -3,38 +3,38 @@ module PostSets
|
||||
def has_wiki?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def wiki_page
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
def has_artist?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def artist
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
def is_single_tag?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def presenter
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
|
||||
def arbitrary_sql_order_clause(ids, table_name)
|
||||
if ids.empty?
|
||||
return "#{table_name}.id desc"
|
||||
end
|
||||
|
||||
|
||||
conditions = []
|
||||
|
||||
|
||||
ids.each_with_index do |x, n|
|
||||
conditions << "when #{x} then #{n}"
|
||||
end
|
||||
|
||||
|
||||
"case #{table_name}.id " + conditions.join(" ") + " end"
|
||||
end
|
||||
end
|
||||
|
@ -1,28 +1,28 @@
|
||||
module PostSets
|
||||
class Favorite < Base
|
||||
attr_reader :user, :page, :favorites
|
||||
|
||||
|
||||
def initialize(user_id, page = 1)
|
||||
@user = ::User.find(user_id)
|
||||
@favorites = ::Favorite.for_user(user.id).paginate(page).order("favorites.id desc")
|
||||
end
|
||||
|
||||
|
||||
def tag_array
|
||||
@tag_array ||= ["fav:#{user.name}"]
|
||||
end
|
||||
|
||||
|
||||
def tag_string
|
||||
tag_array.uniq.join(" ")
|
||||
end
|
||||
|
||||
|
||||
def humanized_tag_string
|
||||
"fav:#{user.pretty_name}"
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
favorites.includes(:post).map(&:post)
|
||||
end
|
||||
|
||||
|
||||
def presenter
|
||||
@presenter ||= ::PostSetPresenters::Favorite.new(self)
|
||||
end
|
||||
|
@ -3,26 +3,26 @@ module PostSets
|
||||
module ActiveRecordExtension
|
||||
attr_accessor :total_pages, :current_page
|
||||
end
|
||||
|
||||
|
||||
attr_reader :pool, :page
|
||||
|
||||
|
||||
def initialize(pool, page = 1)
|
||||
@pool = pool
|
||||
@page = page
|
||||
end
|
||||
|
||||
|
||||
def offset
|
||||
(current_page - 1) * limit
|
||||
end
|
||||
|
||||
|
||||
def limit
|
||||
Danbooru.config.posts_per_page
|
||||
end
|
||||
|
||||
|
||||
def tag_array
|
||||
["pool:#{pool.id}"]
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
@posts ||= begin
|
||||
x = pool.posts(:offset => offset, :limit => limit)
|
||||
@ -32,27 +32,27 @@ module PostSets
|
||||
x
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def tag_string
|
||||
tag_array.join("")
|
||||
end
|
||||
|
||||
|
||||
def humanized_tag_string
|
||||
"pool:#{pool.pretty_name}"
|
||||
end
|
||||
|
||||
|
||||
def presenter
|
||||
@presenter ||= PostSetPresenters::Pool.new(self)
|
||||
end
|
||||
|
||||
|
||||
def total_pages
|
||||
(pool.post_count.to_f / limit).ceil
|
||||
end
|
||||
|
||||
|
||||
def size
|
||||
posts.size
|
||||
end
|
||||
|
||||
|
||||
def current_page
|
||||
[page.to_i, 1].max
|
||||
end
|
||||
|
@ -1,41 +1,41 @@
|
||||
module PostSets
|
||||
class Popular < Base
|
||||
attr_reader :date, :scale
|
||||
|
||||
|
||||
def initialize(date, scale)
|
||||
@date = date.blank? ? Time.zone.now : Time.zone.parse(date)
|
||||
@scale = scale
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
::Post.where("created_at between ? and ?", min_date.beginning_of_day, max_date.end_of_day).order("score desc").limit(limit)
|
||||
end
|
||||
|
||||
|
||||
def limit
|
||||
25
|
||||
end
|
||||
|
||||
|
||||
def min_date
|
||||
case scale
|
||||
when "week"
|
||||
date.beginning_of_week
|
||||
|
||||
|
||||
when "month"
|
||||
date.beginning_of_month
|
||||
|
||||
|
||||
else
|
||||
date
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def max_date
|
||||
case scale
|
||||
when "week"
|
||||
date.end_of_week
|
||||
|
||||
|
||||
when "month"
|
||||
date.end_of_month
|
||||
|
||||
|
||||
else
|
||||
date
|
||||
end
|
||||
|
@ -1,22 +1,22 @@
|
||||
module PostSets
|
||||
class Post < Base
|
||||
attr_reader :tag_array, :page, :per_page
|
||||
|
||||
|
||||
def initialize(tags, page = 1, per_page = nil)
|
||||
@tag_array = Tag.scan_query(tags)
|
||||
@page = page
|
||||
@per_page = (per_page || Danbooru.config.posts_per_page).to_i
|
||||
@per_page = 200 if @per_page > 200
|
||||
end
|
||||
|
||||
|
||||
def tag_string
|
||||
@tag_string ||= tag_array.uniq.join(" ")
|
||||
end
|
||||
|
||||
|
||||
def humanized_tag_string
|
||||
tag_array.slice(0, 25).join(" ").tr("_", " ")
|
||||
end
|
||||
|
||||
|
||||
def has_wiki?
|
||||
tag_array.size == 1 && ::WikiPage.titled(tag_string).exists?
|
||||
end
|
||||
@ -28,15 +28,15 @@ module PostSets
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def has_deleted?
|
||||
CurrentUser.is_privileged? && tag_string !~ /status/ && ::Post.tag_match("#{tag_string} status:deleted").exists?
|
||||
end
|
||||
|
||||
|
||||
def has_explicit?
|
||||
posts.any? {|x| x.rating == "e"}
|
||||
end
|
||||
|
||||
|
||||
def posts
|
||||
if tag_array.size > 2 && !CurrentUser.is_privileged?
|
||||
raise SearchError.new("Upgrade your account to search more than two tags at once")
|
||||
@ -45,50 +45,50 @@ module PostSets
|
||||
if tag_array.any? {|x| x =~ /^source:.*\*.*pixiv/} && !CurrentUser.user.is_builder?
|
||||
raise SearchError.new("Your search took too long to execute and was canceled")
|
||||
end
|
||||
|
||||
|
||||
@posts ||= begin
|
||||
temp = ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page)
|
||||
temp.all
|
||||
temp
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def has_artist?
|
||||
tag_array.any? && ::Artist.name_equals(tag_string).exists?
|
||||
end
|
||||
|
||||
|
||||
def artist
|
||||
::Artist.name_matches(tag_string).first
|
||||
end
|
||||
|
||||
|
||||
def is_single_tag?
|
||||
tag_array.size == 1
|
||||
end
|
||||
|
||||
|
||||
def is_empty_tag?
|
||||
tag_array.size == 0
|
||||
end
|
||||
|
||||
|
||||
def is_pattern_search?
|
||||
tag_string =~ /\*/
|
||||
end
|
||||
|
||||
|
||||
def current_page
|
||||
[page.to_i, 1].max
|
||||
end
|
||||
|
||||
|
||||
def is_tag_subscription?
|
||||
tag_subscription.present?
|
||||
end
|
||||
|
||||
|
||||
def tag_subscription
|
||||
@tag_subscription ||= tag_array.select {|x| x =~ /^sub:/}.map {|x| x.sub(/^sub:/, "")}.first
|
||||
end
|
||||
|
||||
|
||||
def tag_subscription_tags
|
||||
@tag_subscription_tags ||= TagSubscription.find_tags(tag_subscription)
|
||||
end
|
||||
|
||||
|
||||
def presenter
|
||||
@presenter ||= ::PostSetPresenters::Post.new(self)
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
module PostSets
|
||||
class SearchError < Exception
|
||||
end
|
||||
|
||||
|
||||
class WikiPage < Post
|
||||
def presenter
|
||||
@presenter ||= ::PostSetPresenters::WikiPage.new(self)
|
||||
|
@ -2,25 +2,25 @@ class RelatedTagCalculator
|
||||
def self.find_tags(tag, limit)
|
||||
Post.tag_match(tag).limit(limit).select("posts.tag_string").reorder("posts.md5").map(&:tag_string)
|
||||
end
|
||||
|
||||
|
||||
def self.calculate_from_sample_to_array(tags, category_constraint = nil)
|
||||
convert_hash_to_array(calculate_from_sample(tags, Danbooru.config.post_sample_size, category_constraint))
|
||||
end
|
||||
|
||||
|
||||
def self.calculate_from_sample(tags, limit, category_constraint = nil)
|
||||
counts = Hash.new {|h, k| h[k] = 0}
|
||||
|
||||
|
||||
case category_constraint
|
||||
when Tag.categories.artist
|
||||
limit *= 4
|
||||
|
||||
|
||||
when Tag.categories.copyright
|
||||
limit *= 3
|
||||
|
||||
|
||||
when Tag.categories.character
|
||||
limit *= 2
|
||||
end
|
||||
|
||||
|
||||
find_tags(tags, limit).each do |tags|
|
||||
tag_array = Tag.scan_tags(tags)
|
||||
if category_constraint
|
||||
@ -36,14 +36,14 @@ class RelatedTagCalculator
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
counts
|
||||
end
|
||||
|
||||
|
||||
def self.convert_hash_to_array(hash)
|
||||
hash.to_a.sort_by {|x| -x[1]}.slice(0, 25)
|
||||
end
|
||||
|
||||
|
||||
def self.convert_hash_to_string(hash)
|
||||
convert_hash_to_array(hash).flatten.join(" ")
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class RelatedTagQuery
|
||||
attr_reader :query, :category
|
||||
|
||||
|
||||
def initialize(query, category)
|
||||
@query = query.strip
|
||||
@category = category
|
||||
@ -17,7 +17,7 @@ class RelatedTagQuery
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def wiki_page_tags
|
||||
results = wiki_page.try(:tags) || []
|
||||
results.reject! do |name|
|
||||
@ -25,31 +25,31 @@ class RelatedTagQuery
|
||||
end
|
||||
results
|
||||
end
|
||||
|
||||
|
||||
def to_json
|
||||
{:query => query, :category => category, :tags => map_with_category_data(tags), :wiki_page_tags => map_with_category_data(wiki_page_tags)}.to_json
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def map_with_category_data(list_of_tag_names)
|
||||
Tag.categories_for(list_of_tag_names).to_a
|
||||
end
|
||||
|
||||
|
||||
def pattern_matching_tags
|
||||
Tag.name_matches(query).where("post_count > 0").order("post_count desc").limit(50).sort_by {|x| x.name}.map(&:name)
|
||||
end
|
||||
|
||||
|
||||
def related_tags
|
||||
tag = Tag.named(query.strip).first
|
||||
|
||||
|
||||
if tag
|
||||
tag.related_tag_array.map(&:first)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def related_tags_by_category
|
||||
RelatedTagCalculator.calculate_from_sample_to_array(query, Tag.categories.value_for(category)).map(&:first)
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
class RemoteFileManager
|
||||
attr_reader :path
|
||||
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
end
|
||||
|
||||
|
||||
def distribute
|
||||
Danbooru.config.other_server_hosts.each do |hostname|
|
||||
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
|
||||
@ -12,7 +12,7 @@ class RemoteFileManager
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete
|
||||
Danbooru.config.other_server_hosts.each do |hostname|
|
||||
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
|
||||
|
@ -1,6 +1,6 @@
|
||||
class SessionCreator
|
||||
attr_reader :session, :cookies, :name, :password, :remember
|
||||
|
||||
|
||||
def initialize(session, cookies, name, password, remember)
|
||||
@session = session
|
||||
@cookies = cookies
|
||||
@ -8,17 +8,17 @@ class SessionCreator
|
||||
@password = password
|
||||
@remember = remember
|
||||
end
|
||||
|
||||
|
||||
def authenticate
|
||||
if User.authenticate(name, password)
|
||||
user = User.find_by_name(name)
|
||||
user.update_column(:last_logged_in_at, Time.now)
|
||||
|
||||
|
||||
if remember.present?
|
||||
cookies.permanent.signed[:user_name] = user.name
|
||||
cookies.permanent[:password_hash] = user.bcrypt_cookie_password_hash
|
||||
end
|
||||
|
||||
|
||||
session[:user_id] = user.id
|
||||
return true
|
||||
else
|
||||
|
@ -1,55 +1,55 @@
|
||||
class SessionLoader
|
||||
attr_reader :session, :cookies, :request
|
||||
|
||||
|
||||
def initialize(session, cookies, request)
|
||||
@session = session
|
||||
@cookies = cookies
|
||||
@request = request
|
||||
end
|
||||
|
||||
|
||||
def load
|
||||
if session[:user_id]
|
||||
load_session_user
|
||||
elsif cookie_password_hash_valid?
|
||||
load_cookie_user
|
||||
end
|
||||
|
||||
|
||||
if CurrentUser.user
|
||||
CurrentUser.user.unban! if ban_expired?
|
||||
else
|
||||
CurrentUser.user = AnonymousUser.new
|
||||
end
|
||||
|
||||
|
||||
update_last_logged_in_at
|
||||
set_time_zone
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def load_session_user
|
||||
CurrentUser.user = User.find_by_id(session[:user_id])
|
||||
CurrentUser.ip_addr = request.remote_ip
|
||||
end
|
||||
|
||||
|
||||
def load_cookie_user
|
||||
CurrentUser.user = User.find_by_name(cookies.signed[:user_name])
|
||||
CurrentUser.ip_addr = request.remote_ip
|
||||
end
|
||||
|
||||
|
||||
def ban_expired?
|
||||
CurrentUser.user.is_banned? && CurrentUser.user.ban && CurrentUser.user.ban.expired?
|
||||
end
|
||||
|
||||
|
||||
def cookie_password_hash_valid?
|
||||
cookies[:password_hash] && cookies.signed[:user_name] && User.authenticate_cookie_hash(cookies.signed[:user_name], cookies[:password_hash])
|
||||
end
|
||||
|
||||
|
||||
def update_last_logged_in_at
|
||||
return if CurrentUser.is_anonymous?
|
||||
return if CurrentUser.last_logged_in_at && CurrentUser.last_logged_in_at > 1.week.ago
|
||||
CurrentUser.user.update_attribute(:last_logged_in_at, Time.now)
|
||||
end
|
||||
|
||||
|
||||
def set_time_zone
|
||||
Time.zone = CurrentUser.user.time_zone
|
||||
end
|
||||
|
@ -2,14 +2,14 @@ module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :to => :strategy
|
||||
|
||||
|
||||
def self.strategies
|
||||
[Strategies::NicoSeiga, Strategies::Pixiv]
|
||||
end
|
||||
|
||||
|
||||
def initialize(url)
|
||||
@url = url
|
||||
|
||||
|
||||
Site.strategies.each do |strategy|
|
||||
if strategy.url_match?(url)
|
||||
@strategy = strategy.new(url)
|
||||
@ -18,7 +18,7 @@ module Sources
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def to_json
|
||||
return {
|
||||
:artist_name => artist_name,
|
||||
@ -30,7 +30,7 @@ module Sources
|
||||
:unique_id => unique_id
|
||||
}.to_json
|
||||
end
|
||||
|
||||
|
||||
def available?
|
||||
strategy.present?
|
||||
end
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user