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();
if (Danbooru.meta("enable-auto-complete") === "true") {
Danbooru.Artist.initialize_auto_complete();
Danbooru.Artist.initialize_autocomplete();
}
}
}
Danbooru.Artist.initialize_auto_complete = function() {
$("#quick_search_name").autocomplete({
Danbooru.Artist.initialize_autocomplete = function() {
var $fields = $("#search_name,#quick_search_name");
$fields.autocomplete({
minLength: 1,
source: function(req, resp) {
$.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);
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() {

View File

@@ -36,22 +36,41 @@
}
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({
focus: function() {
return false;
},
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;
},
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;
}
var term = req.term.match(/\S+/g).pop();
var term = before_caret_text.match(/\S+/g).pop();
$.ajax({
url: "/tags.json",
data: {

View File

@@ -105,8 +105,14 @@
var $dest = $("#related-tags");
$dest.empty();
$dest.append(this.build_html("recent", this.other_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 recent_tags = Danbooru.Cookie.get("recent_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));
if (wiki_page_tags.length) {
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags));

View File

@@ -9,7 +9,9 @@
Danbooru.WikiPage.initialize_typeahead = function() {
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,
source: function(req, resp) {
$.ajax({
@@ -20,16 +22,26 @@
},
method: "get",
success: function(data) {
resp($.map(data, function(tag) {
resp($.map(data, function(wiki_page) {
return {
label: tag.title.replace(/_/g, " "),
value: tag.title
label: wiki_page.title.replace(/_/g, " "),
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])
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))
respond_with(@forum_post, :location => forum_topic_path(@forum_post.topic, :page => @forum_post.forum_topic_page, :anchor => "forum_post_#{@forum_post.id}"))
end
def destroy

View File

@@ -16,7 +16,11 @@ class PostVersionsController < ApplicationController
def undo
@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|
format.js
end

View File

@@ -69,7 +69,11 @@ class PostsController < ApplicationController
def revert
@post = Post.find(params[: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|
format.js
end

View File

@@ -14,7 +14,7 @@ class TagCorrectionsController < ApplicationController
if params[:commit] == "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
redirect_to tags_path(:search => {:name_matches => @correction.tag.name})
end

View File

@@ -81,7 +81,7 @@ class Artist < ActiveRecord::Base
def rename!(new_name)
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
new_wiki_page.update_attributes(:body => new_wiki_page.body + "\n\n" + notes)
elsif wiki_page
@@ -306,6 +306,24 @@ class Artist < ActiveRecord::Base
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 NameMethods
include GroupMethods
@@ -315,6 +333,7 @@ class Artist < ActiveRecord::Base
include TagMethods
include BanMethods
extend SearchMethods
include ApiMethods
def status
if is_banned? && is_active?
@@ -328,18 +347,6 @@ class Artist < ActiveRecord::Base
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
self.creator_id = CurrentUser.user.id
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
class PostPresenter < Presenter
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 ""
end

View File

@@ -12,7 +12,7 @@ module PostSetPresenters
end
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"
end

View File

@@ -29,7 +29,7 @@ create implication aaa -> bbb
<div class="input">
<label for="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>
</div>

View File

@@ -9,7 +9,7 @@
<div class="body prose">
<%= 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>
<% end %>
</div>

View File

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

View File

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

View File

@@ -24,9 +24,7 @@
<section>
<h1>History</h1>
<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>
<% end %>
<li><%= fast_link_to "Tags", post_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 "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 #{deploy_to}/shared/system/cache"
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 "ln -s #{deploy_to}/shared/system/cache/tags.json.gz #{release_path}/public/cache/tags.json.gz"
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]
"/post_versions?page=#{page}&search[updater_id]=#{req.params[:user_id]}"
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.json", :controller => "legacy", :action => "tags", :format => "json"

View File

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