Merge branch 'master' of github.com:r888888888/danbooru

This commit is contained in:
r888888888
2013-06-24 11:51:44 -07:00
28 changed files with 138 additions and 54 deletions

View File

@@ -6,13 +6,15 @@
Danbooru.Artist.initialize_check_name_link(); Danbooru.Artist.initialize_check_name_link();
if (Danbooru.meta("enable-auto-complete") === "true") { if (Danbooru.meta("enable-auto-complete") === "true") {
Danbooru.Artist.initialize_auto_complete(); Danbooru.Artist.initialize_autocomplete();
} }
} }
} }
Danbooru.Artist.initialize_auto_complete = function() { Danbooru.Artist.initialize_autocomplete = function() {
$("#quick_search_name").autocomplete({ var $fields = $("#search_name,#quick_search_name");
$fields.autocomplete({
minLength: 1, minLength: 1,
source: function(req, resp) { source: function(req, resp) {
$.ajax({ $.ajax({
@@ -32,10 +34,16 @@
} }
}); });
} }
}).data("uiAutocomplete")._renderItem = function(list, artist) { });
var render_artist = function(list, artist) {
var $link = $("<a/>").addClass("tag-type-1").text(artist.label); var $link = $("<a/>").addClass("tag-type-1").text(artist.label);
return $("<li/>").data("item.autocomplete", artist).append($link).appendTo(list); return $("<li/>").data("item.autocomplete", artist).append($link).appendTo(list);
} }
$fields.each(function(i, field) {
$(field).data("uiAutocomplete")._renderItem = render_artist;
});
} }
Danbooru.Artist.initialize_check_name_link = function() { Danbooru.Artist.initialize_check_name_link = function() {

View File

@@ -36,22 +36,41 @@
} }
Danbooru.Post.initialize_tag_autocomplete = function() { Danbooru.Post.initialize_tag_autocomplete = function() {
var $fields = $("#tags,#post_tag_string,#upload_tag_string"); var $fields = $(
"#tags,#post_tag_string,#upload_tag_string,#tag-script-field," +
"#search_post_tags_match,#c-tags #search_name_matches,#c-tag-aliases #query,#c-tag-implications #query," +
"#wiki_page_title,#artist_name," +
"#tag_alias_request_antecedent_name,#tag_alias_request_consequent_name," +
"#tag_implication_request_antecedent_name,#tag_implication_request_consequent_name," +
"#tag_alias_antecedent_name,#tag_alias_consequent_name," +
"#tag_implication_antecedent_name,#tag_implication_consequent_name"
);
$fields.autocomplete({ $fields.autocomplete({
focus: function() { focus: function() {
return false; return false;
}, },
select: function(event, ui) { select: function(event, ui) {
this.value = this.value.replace(/\S+\s*$/g, ui.item.value + " "); var before_caret_text = this.value.substring(0, this.selectionStart);
var after_caret_text = this.value.substring(this.selectionStart);
this.value = before_caret_text.replace(/\S+\s*$/g, ui.item.value + " ");
// Preserve original caret position to prevent it from jumping to the end
var original_start = this.selectionStart;
this.value += after_caret_text;
this.selectionStart = this.selectionEnd = original_start;
return false; return false;
}, },
source: function(req, resp) { source: function(req, resp) {
if (req.term.match(/ $/)) { var before_caret_text = req.term.substring(0, this.element.get(0).selectionStart);
if (before_caret_text.match(/ $/)) {
return; return;
} }
var term = req.term.match(/\S+/g).pop(); var term = before_caret_text.match(/\S+/g).pop();
$.ajax({ $.ajax({
url: "/tags.json", url: "/tags.json",
data: { data: {

View File

@@ -105,8 +105,14 @@
var $dest = $("#related-tags"); var $dest = $("#related-tags");
$dest.empty(); $dest.empty();
$dest.append(this.build_html("recent", this.other_tags(Danbooru.Cookie.get("recent_tags_with_categories")))); var recent_tags = Danbooru.Cookie.get("recent_tags_with_categories");
$dest.append(this.build_html("frequent", this.other_tags(Danbooru.Cookie.get("favorite_tags_with_categories")))); var favorite_tags = Danbooru.Cookie.get("favorite_tags_with_categories");
if (recent_tags.length) {
$dest.append(this.build_html("recent", this.other_tags(recent_tags)));
}
if (favorite_tags.length) {
$dest.append(this.build_html("frequent", this.other_tags(favorite_tags)));
}
$dest.append(this.build_html(query, related_tags)); $dest.append(this.build_html(query, related_tags));
if (wiki_page_tags.length) { if (wiki_page_tags.length) {
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags)); $dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags));

View File

@@ -9,7 +9,9 @@
Danbooru.WikiPage.initialize_typeahead = function() { Danbooru.WikiPage.initialize_typeahead = function() {
if (Danbooru.meta("enable-auto-complete") === "true") { if (Danbooru.meta("enable-auto-complete") === "true") {
$("#quick_search_title,#wiki_page_title").autocomplete({ var $fields = $("#search_title,#quick_search_title");
$fields.autocomplete({
minLength: 1, minLength: 1,
source: function(req, resp) { source: function(req, resp) {
$.ajax({ $.ajax({
@@ -20,16 +22,26 @@
}, },
method: "get", method: "get",
success: function(data) { success: function(data) {
resp($.map(data, function(tag) { resp($.map(data, function(wiki_page) {
return { return {
label: tag.title.replace(/_/g, " "), label: wiki_page.title.replace(/_/g, " "),
value: tag.title value: wiki_page.title,
category: wiki_page.category_name
}; };
})); }));
} }
}); });
} }
}); });
var render_wiki_page = function(list, wiki_page) {
var $link = $("<a/>").addClass("tag-type-" + wiki_page.category).text(wiki_page.label);
return $("<li/>").data("item.autocomplete", wiki_page).append($link).appendTo(list);
}
$fields.each(function(i, field) {
$(field).data("uiAutocomplete")._renderItem = render_wiki_page;
});
} }
} }
})(); })();

View File

@@ -50,7 +50,7 @@ class ForumPostsController < ApplicationController
@forum_post = ForumPost.find(params[:id]) @forum_post = ForumPost.find(params[:id])
check_privilege(@forum_post) check_privilege(@forum_post)
@forum_post.update_attributes(params[:forum_post]) @forum_post.update_attributes(params[:forum_post])
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page)) respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page, :anchor => "forum_post_#{@forum_post.id}"))
end end
def destroy def destroy

View File

@@ -16,7 +16,11 @@ class PostVersionsController < ApplicationController
def undo def undo
@post_version = PostVersion.find(params[:id]) @post_version = PostVersion.find(params[:id])
@post_version.undo!
if Danbooru.config.can_user_see_post?(CurrentUser.user, @post_version.post)
@post_version.undo!
end
respond_with(@post_version) do |format| respond_with(@post_version) do |format|
format.js format.js
end end

View File

@@ -69,7 +69,11 @@ class PostsController < ApplicationController
def revert def revert
@post = Post.find(params[:id]) @post = Post.find(params[:id])
@version = PostVersion.find(params[:version_id]) @version = PostVersion.find(params[:version_id])
@post.revert_to!(@version)
if Danbooru.config.can_user_see_post?(CurrentUser.user, @post)
@post.revert_to!(@version)
end
respond_with(@post) do |format| respond_with(@post) do |format|
format.js format.js
end end

View File

@@ -14,7 +14,7 @@ class TagCorrectionsController < ApplicationController
if params[:commit] == "Fix" if params[:commit] == "Fix"
@correction.fix! @correction.fix!
redirect_to tags_path(:search => {:name_matches => @correction.tag.name}), :notice => "Tag will be fixed in a few seconds" redirect_to tags_path(:search => {:name_matches => @correction.tag.name, :hide_empty => "no"}), :notice => "Tag will be fixed in a few seconds"
else else
redirect_to tags_path(:search => {:name_matches => @correction.tag.name}) redirect_to tags_path(:search => {:name_matches => @correction.tag.name})
end end

View File

@@ -81,7 +81,7 @@ class Artist < ActiveRecord::Base
def rename!(new_name) def rename!(new_name)
new_wiki_page = WikiPage.titled(new_name).first new_wiki_page = WikiPage.titled(new_name).first
if new_wiki_page if new_wiki_page && wiki_page
# Merge the old wiki page into the new one # Merge the old wiki page into the new one
new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes) new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes)
elsif wiki_page elsif wiki_page
@@ -306,6 +306,24 @@ class Artist < ActiveRecord::Base
end end
end end
module ApiMethods
def hidden_attributes
super + [:other_names_index]
end
def legacy_api_hash
return {
:id => id,
:name => name,
:other_names => other_names,
:group_name => group_name,
:urls => artist_urls.map {|x| x.url},
:is_active => is_active?,
:updater_id => 0
}
end
end
include UrlMethods include UrlMethods
include NameMethods include NameMethods
include GroupMethods include GroupMethods
@@ -315,6 +333,7 @@ class Artist < ActiveRecord::Base
include TagMethods include TagMethods
include BanMethods include BanMethods
extend SearchMethods extend SearchMethods
include ApiMethods
def status def status
if is_banned? && is_active? if is_banned? && is_active?
@@ -328,18 +347,6 @@ class Artist < ActiveRecord::Base
end end
end end
def legacy_api_hash
return {
:id => id,
:name => name,
:other_names => other_names,
:group_name => group_name,
:urls => artist_urls.map {|x| x.url},
:is_active => is_active?,
:updater_id => 0
}
end
def initialize_creator def initialize_creator
self.creator_id = CurrentUser.user.id self.creator_id = CurrentUser.user.id
end end

View File

@@ -140,6 +140,10 @@ class Comment < ActiveRecord::Base
def editable_by?(user) def editable_by?(user)
creator_id == user.id || user.is_janitor? creator_id == user.id || user.is_janitor?
end end
def hidden_attributes
super + [:body_index]
end
end end
Comment.connection.extend(PostgresExtensions) Comment.connection.extend(PostgresExtensions)

View File

@@ -188,4 +188,8 @@ class Dmail < ActiveRecord::Base
def visible_to?(user) def visible_to?(user)
user.is_moderator? || owner_id == user.id user.is_moderator? || owner_id == user.id
end end
def hidden_attributes
super + [:message_index]
end
end end

View File

@@ -161,4 +161,8 @@ class ForumPost < ActiveRecord::Base
x.body = x.quoted_response x.body = x.quoted_response
end end
end end
def hidden_attributes
super + [:text_index]
end
end end

View File

@@ -96,4 +96,8 @@ class ForumTopic < ActiveRecord::Base
def presenter(forum_posts) def presenter(forum_posts)
@presenter ||= ForumTopicPresenter.new(self, forum_posts) @presenter ||= ForumTopicPresenter.new(self, forum_posts)
end end
def hidden_attributes
super + [:text_index]
end
end end

View File

@@ -61,6 +61,10 @@ class Note < ActiveRecord::Base
end end
module ApiMethods module ApiMethods
def hidden_attributes
super + [:body_index]
end
def serializable_hash(options = {}) def serializable_hash(options = {})
options ||= {} options ||= {}
options[:except] ||= [] options[:except] ||= []
@@ -75,8 +79,8 @@ class Note < ActiveRecord::Base
def to_xml(options = {}, &block) def to_xml(options = {}, &block)
options ||= {} options ||= {}
options[:procs] ||= [] options[:methods] ||= []
options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} options[:methods] += [:creator_name]
super(options, &block) super(options, &block)
end end
end end

View File

@@ -168,7 +168,7 @@ class Pool < ActiveRecord::Base
end end
def page_number(post_id) def page_number(post_id)
post_id_array.find_index(post_id) + 1 post_id_array.find_index(post_id).to_i + 1
end end
def deletable_by?(user) def deletable_by?(user)

View File

@@ -145,8 +145,7 @@ class TagAlias < ActiveRecord::Base
if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank? if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank?
CurrentUser.scoped(creator, creator_ip_addr) do CurrentUser.scoped(creator, creator_ip_addr) do
antecedent_wiki.update_attributes( antecedent_wiki.update_attributes(
:title => consequent_name, :title => consequent_name
:body => "[i]This page was automatically renamed from [[#{antecedent_name}]] by a tag alias.[/i]\n\n#{antecedent_wiki.body}"
) )
end end
end end

View File

@@ -396,8 +396,8 @@ class Upload < ActiveRecord::Base
def to_xml(options = {}, &block) def to_xml(options = {}, &block)
options ||= {} options ||= {}
options[:procs] ||= [] options[:methods] ||= []
options[:procs] << lambda {|options, record| options[:builder].tag!("uploader-name", record.uploader_name)} options[:methods] += [:uploader_name]
super(options, &block) super(options, &block)
end end
end end

View File

@@ -58,13 +58,17 @@ class WikiPage < ActiveRecord::Base
end end
module ApiMethods module ApiMethods
def hidden_attributes
super + [:body_index]
end
def serializable_hash(options = {}) def serializable_hash(options = {})
options ||= {} options ||= {}
options[:except] ||= [] options[:except] ||= []
options[:except] += hidden_attributes options[:except] += hidden_attributes
unless options[:builder] unless options[:builder]
options[:methods] ||= [] options[:methods] ||= []
options[:methods] += [:creator_name] options[:methods] += [:creator_name, :category_name]
end end
hash = super(options) hash = super(options)
hash hash
@@ -72,8 +76,8 @@ class WikiPage < ActiveRecord::Base
def to_xml(options = {}, &block) def to_xml(options = {}, &block)
options ||= {} options ||= {}
options[:procs] ||= [] options[:methods] ||= []
options[:procs] << lambda {|options, record| options[:builder].tag!("creator-name", record.creator_name)} options[:methods] += [:creator_name, :category_name]
super(options, &block) super(options, &block)
end end
end end

View File

@@ -1,6 +1,6 @@
class PostPresenter < Presenter class PostPresenter < Presenter
def self.preview(post, options = {}) def self.preview(post, options = {})
if post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ if post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ && !options[:raw]
return "" return ""
end end

View File

@@ -12,7 +12,7 @@ module PostSetPresenters
end end
posts.each do |post| posts.each do |post|
html << PostPresenter.preview(post, :tags => @post_set.tag_string) html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw)
html << "\n" html << "\n"
end end

View File

@@ -29,7 +29,7 @@ create implication aaa -> bbb
<div class="input"> <div class="input">
<label for="batch_rename_aliased_pages"> <label for="batch_rename_aliased_pages">
<%= check_box "batch", "rename_aliased_pages" %> <%= check_box "batch", "rename_aliased_pages" %>
Automatically rename all wiki pages and artists for aliases in this batch Rename aliased wiki pages and artists
</label> </label>
</div> </div>

View File

@@ -9,7 +9,7 @@
<div class="body prose"> <div class="body prose">
<%= format_text(comment.body) %> <%= format_text(comment.body) %>
<% if comment.updater_id.present? && (comment.updater_id != comment.creator_id || comment.created_at != comment.updated_at) %> <% if comment.updated_at - comment.created_at > 5.minutes %>
<p class="info">Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %></p> <p class="info">Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %></p>
<% end %> <% end %>
</div> </div>

View File

@@ -5,8 +5,8 @@
<%= form_tag(notes_path, :method => :get, :class => "simple_form") do %> <%= form_tag(notes_path, :method => :get, :class => "simple_form") do %>
<%= hidden_field_tag "group_by", "note" %> <%= hidden_field_tag "group_by", "note" %>
<%= search_field "body_matches", :label => "Body" %> <%= search_field "body_matches", :label => "Body" %>
<%= search_field "post_tags_match", :label => "Tags" %>
<%= search_field "creator_name", :label => "Author" %> <%= search_field "creator_name", :label => "Author" %>
<%= search_field "post_tags_match", :label => "Tags" %>
<%= submit_tag "Search" %> <%= submit_tag "Search" %>
<% end %> <% end %>
</div> </div>

View File

@@ -36,10 +36,12 @@
<td><%= post_version_diff(post_version) %></td> <td><%= post_version_diff(post_version) %></td>
<% if CurrentUser.is_member? %> <% if CurrentUser.is_member? %>
<td> <td>
<% if post_version.id != post_version.post.versions.first.id %> <% if Danbooru.config.can_user_see_post?(CurrentUser.user, post_version.post) %>
<%= link_to "Undo", undo_post_version_path(post_version), :method => :put, :remote => true %> | <% if post_version.id != post_version.post.versions.first.id %>
<%= link_to "Undo", undo_post_version_path(post_version), :method => :put, :remote => true %> |
<% end %>
<%= link_to "Revert to", revert_post_path(post_version.post_id, :version_id => post_version.id), :method => :put, :remote => true %>
<% end %> <% end %>
<%= link_to "Revert to", revert_post_path(post_version.post_id, :version_id => post_version.id), :method => :put, :remote => true %>
</td> </td>
<% end %> <% end %>
</tr> </tr>

View File

@@ -24,9 +24,7 @@
<section> <section>
<h1>History</h1> <h1>History</h1>
<ul> <ul>
<% if Danbooru.config.can_user_see_post?(CurrentUser.user, @post) %> <li><%= fast_link_to "Tags", post_versions_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Tags", post_versions_path(:search => {:post_id => @post.id}) %></li>
<% end %>
<li><%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %></li> <li><%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %></li> <li><%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %></li> <li><%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %></li>

View File

@@ -64,6 +64,7 @@ namespace :data do
run "mkdir -p #{release_path}/public/cache" run "mkdir -p #{release_path}/public/cache"
run "mkdir -p #{deploy_to}/shared/system/cache" run "mkdir -p #{deploy_to}/shared/system/cache"
run "touch #{deploy_to}/shared/system/cache/tags.json" run "touch #{deploy_to}/shared/system/cache/tags.json"
run "ln -s #{deploy_to}/shared/system/cache/tags.json #{release_path}/public/cache/tags.json"
run "touch #{deploy_to}/shared/system/cache/tags.json.gz" run "touch #{deploy_to}/shared/system/cache/tags.json.gz"
run "ln -s #{deploy_to}/shared/system/cache/tags.json.gz #{release_path}/public/cache/tags.json.gz" run "ln -s #{deploy_to}/shared/system/cache/tags.json.gz #{release_path}/public/cache/tags.json.gz"
end end

View File

@@ -312,7 +312,7 @@ Danbooru::Application.routes.draw do
page = req.params[:before_id].present? ? "b#{req.params[:before_id]}" : req.params[:page] page = req.params[:before_id].present? ? "b#{req.params[:before_id]}" : req.params[:page]
"/post_versions?page=#{page}&search[updater_id]=#{req.params[:user_id]}" "/post_versions?page=#{page}&search[updater_id]=#{req.params[:user_id]}"
end) end)
match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}"} match "/post_tag_history/index" => redirect {|params, req| "/post_versions?page=#{req.params[:page]}&search[post_id]=#{req.params[:post_id]}"}
match "/tag/index.xml", :controller => "legacy", :action => "tags", :format => "xml" match "/tag/index.xml", :controller => "legacy", :action => "tags", :format => "xml"
match "/tag/index.json", :controller => "legacy", :action => "tags", :format => "json" match "/tag/index.json", :controller => "legacy", :action => "tags", :format => "json"

View File

@@ -60,7 +60,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
@importer.process! @importer.process!
artist.reload artist.reload
assert_equal("bbb", artist.name) assert_equal("bbb", artist.name)
assert_match(/automatically renamed/, artist.notes) assert_equal("testing", artist.notes)
end end
end end
end end