Commit Graph

11687 Commits

Author SHA1 Message Date
evazion
0267e4e3d7 wikis: fix exception when wiki doesn't have a tag.
Fix a nil reference exception in the sidebar when a wiki page doesn't
belong to a tag.

Also hide the options sidebar on the new wiki page since none of the
options are relevant when creating a new wiki.
2022-09-12 21:24:03 -05:00
evazion
e1fb219738 aliases: retire artist aliases after 2 years.
Automatically retire artist aliases after they're more than 2 years old.
Before the rule was that artist aliases were only retired if they didn't
have any new posts in the last 2 years.
2022-09-12 02:31:12 -05:00
evazion
2c37fdf9e8 tags: don't create mod action when tag is deprecated.
Not needed anymore since deprecations are now tracked in the tag history.
2022-09-12 02:06:16 -05:00
evazion
600e75e324 /tags: update tag actions menu.
Replace the "Edit | History | Related | Similar" links on the /tags
index with a popup menu containing more actions, including links to the
tag's version history, links to the tag's aliases and implications,
links to comments and forum discussions mentioning the tag, and links to
find untagged and mistagged posts using AI tags.
2022-09-12 00:28:26 -05:00
evazion
bb728ecebf tags: add /tag_versions page. 2022-09-11 18:41:16 -05:00
evazion
54a45a3021 tags: track tag histories.
Track the history of the tag `category` and `is_deprecated` fields in
the `tag_versions` table.

Adds generic Versionable and VersionFor concerns that encapsulate most
of the history tracking logic. These concerns are designed to make it
easy to add history to any model.

There are a couple notable differences between tag versions and other versions:

* There is no 1 hour edit merge window. All changes to the `category`
  and `is_deprecated` fields produce a new version in the tag history.

* New versions aren't created when a tag is created. Versions are only
  created when a tag is edited for the first time. The tag's initial
  version isn't created until *after* the tag is edited for the first time.

For example, if you change the category of a tag that was last updated
10 years ago, that will create an initial version of the tag backdated
to 10 years ago, plus a new version for your edit.

This is for a few reasons:

* So that we don't have to create new tag versions every time a new tag
  is created. This would be wasteful because most tags never have their
  category or deprecation status change.
* So that if you make a typo tag, your name isn't recorded in the tag's
  history forever.
* So that we can create new tags in various places without having to know
  who created the tag (which may be unknown if the current user isn't set).
* Because we don't know the full history of most tags, so we have to
  deal with incomplete histories anyway.

This has a few important consequences:

* Most tags won't have any tag versions. They only gain tag versions if
  they're edited.
* You can't track /tag_versions to see newly created tags. It only
  shows changes to already existing tags.
* Tag version IDs won't be in strict chronological order. Higher IDs may
  have created_at timestamps before lower IDs. For example, if you
  change the category of a tag that is 10 years old, that will create an
  initial version with a high ID, but with a created_at timestamp dated
  to 10 years ago.

Fixes #4402: Track tag category changes
2022-09-11 17:47:44 -05:00
evazion
0c327a2228 tags: add tag_versions table.
Add a tag_versions table for tracking the history of tags.

A couple notable differences from other version tables:

* There is a previous_version_id column that points to the previous
  version. This allows finding the first, last, previous, or next
  version efficiently in SQL.

* There is a `version` column that tracks the revision number (1, 2, 3, etc).
  Post versions and note versions have this, but other version tables don't.

* The `updater_id` column is optional. This is because we don't know who
  the last updater was before we started tracking the history of tags,
  so the initial updater will be NULL in the first version of the tag.
2022-09-11 17:35:53 -05:00
evazion
10cb97dbd5 Fix #5200: non-web_source, bad_source, etc. not removed when using source: metatag 2022-09-11 03:03:57 -05:00
evazion
2eead46ad4 tags: remove dead code. 2022-09-10 14:39:17 -05:00
evazion
22bfa44183 posts: fix exception when tagging post with char:copy:foo.
Fixup for 015c6dc7d. Show a warning about failure to add a tag instead
of raising an exception when trying to tag a post with `char:copy:foo`.
This tries to create a tag named `copy:foo` then set the category to
character, which doesn't work because `copy:foo` isn't a valid tag name.
2022-09-10 14:39:17 -05:00
evazion
015c6dc7db Fix #4965: Account for metatag prefixes when searching/linking
Drop the ability to write e.g. `create alias foo -> char:bar` in a BUR
to change the tag's type as a side effect. You can only use these
tag type prefixes in tag edits now.

This feature was only intended to be used in tag edits. The fact it
worked elsewhere was unintended behavior.

This feature was problematic because it relied on `Tag.find_or_create_by_name`
automagically changing the tag's category when the tag name contained a
tag category prefix, e.g. `char:hatsune_miku`. This meant that merely
looking up a tag could have the side effect of changing its category.
It was also bad because `find_or_create_by_name` had a hidden dependency
on the current user, which may not be set or available in all contexts.
2022-09-10 04:49:24 -05:00
evazion
f36f1ff37b tags: drop is_locked column.
This column was deprecated in 208b6189. Finish removing it.
2022-09-09 15:58:48 -05:00
evazion
c96bdd1766 autocomplete: fix ranking of exact matches.
Fix a bug where searching for `sakana~` ranked `sakana~_(meme)` beneath
random artist tags containing the word `sakana`. Now, if the search contains
punctuation, we rank exact matches first, even for small tags. Before we
ranked exact matches for small tags lower than inexact matches for large
tags. If the search contains punctuation, it's a strong signal the user
is looking for an exact match.
2022-09-09 15:58:48 -05:00
evazion
0cc76625eb Update Ruby gems and Yarn packages. 2022-09-07 03:13:13 -05:00
evazion
a80ee22746 autocomplete: fix incorrect highlighting when tag contains repeated words.
Fix tags like `short_shorts` or `hunter_x_hunter` being highlighted
incorrectly. Typing `short_sh` would highlight it as SHort_SHorts
instead of as SHORT_SHorts.
2022-09-06 18:01:30 -05:00
evazion
d2147eca80 tumblr: fix exception when fetching data for video urls.
Fix an exception when trying to fetch source data for URLs like
https://va.media.tumblr.com/tumblr_pgohk0TjhS1u7mrsl.mp4.

For these URLs it's not possible to use the trick where we try to open
the URL as a HTML page and scrape the post id from the HTML. Instead we
get the raw video if we try to to this.
2022-09-05 16:15:47 -05:00
evazion
f55951ab58 tumblr: fix exception when parsing mangled image urls.
Fix a nil exception when trying to parse invalid URLs like `https://25.media.tumblr.com/91719d337b218681abc48cdc24e`.
2022-09-05 16:15:46 -05:00
evazion
3d5b201e0d tests: fix upload tests. 2022-09-03 23:54:28 -05:00
evazion
1968c9c69d autocomplete: lowercase searches clientside.
Lowercase searches clientside before sending them to the server. This is
to improve cache hit rates when users accidentally type in uppercase,
especially on mobile where the first letter often gets capitalized.
2022-09-03 23:54:28 -05:00
evazion
306f3d8f1a autocomplete: add tests. 2022-09-03 20:34:34 -05:00
evazion
4a77d67d1f autocomplete: fix completion of ai: metatag.
Fix it so we don't show the `ai:` prefix in front of results in the
autocomplete menu when completing the `ai: metatag.
2022-09-03 20:34:34 -05:00
evazion
f83af31a00 autocomplete: fix usernames not being highlighted in @mentions.
Fix usernames not being highlighted when completing @mentions.

This also changes it so the autocomplete results don't include the '@'
in front of the name.

Minor breaking change to the /autocomplete.json API. Autocomplete
results for mentions now have the type `mention` instead of `user`.
2022-09-03 20:34:26 -05:00
evazion
03c02ef78e autocomplete: fix accidental API breakage.
Fix /autocomplete.json returning results like this:

    [
      {
        "table": {
          "type": "tag-word",
          "label": "long hair",
          "value": "long_hair",
          "category": 0,
          "post_count": 2818211,
          "antecedent": null
        }
      },
    ]

instead of like this:

    [
      {
        "type": "tag-word",
        "label": "long hair",
        "value": "long_hair",
        "category": 0,
        "post_count": 2818211,
      },
    ]

Also change it so that optional attributes like `antecedent` aren't
returned if they're null. This could be a minor breaking change if users
rely on these attributes always being present.

Lastly change XML results to look like this:

    <autocomplete-service-results type="array">
      <autocomplete-service-result>
        <type>tag-word</type>
        <label>long hair</label>
        <value>long_hair</value>
        <category type="integer">0</category>
        <post-count type="integer">2801117</post-count>
      </autocomplete-service-result>
    </autocomplete-service-results>

instead of like this:

    <objects type="array">
      <object>
        <type>tag</type>
        <label>hair ornament</label>
        <value>hair_ornament</value>
        <category type="integer">0</category>
        <post-count type="integer">883340</post-count>
        <antecedent nil="true"/>
      </object>
    </objects>
2022-09-03 18:53:29 -05:00
evazion
0274dbde10 autocomplete: fix highlighting of words surrounded by punctuation.
Fix a bug where the word `lazy` wasn't highlighted in `don't_say_"lazy"`
when searching for `lazy`. The bug was that punctuation surrounding
words wasn't properly split from the word.
2022-09-03 18:21:56 -05:00
evazion
f20e1d5bc9 autocomplete: fix highlighting of short searches.
Fix a bug where tags weren't highlighted correctly when the search only contained one character.
2022-09-02 14:15:25 -05:00
evazion
6235965da0 autocomplete: fix labels for static metatags.
When completing a static metatag, such as rating: or order:,
don't include the metatag name in the autocomplete menu.

For example, when completing `rating:g`, show `general` in the
autocomplete menu, not `rating:general`.

This makes static metatags consistent with other metatags.
2022-09-02 13:56:53 -05:00
evazion
6b6c452ea2 autocomplete: remove unused html data attributes.
Remove the `data-autocomplete-antecedent`, `data-autocomplete-category`,
and `data-autocomplete-post-count` data attributes from the autocomplete
menu. These weren't used by Danbooru itself and they bloat the HTML.
2022-09-02 13:56:53 -05:00
evazion
3d831f7e1c autocomplete: limit width of autocomplete menu.
Limit the width of the autocomplete menu to 480px. This is so that
stupidly long isekai titles don't blow out the size of the menu when
searching for common words.

For example, when searching for "look", one of the results is:

   no_matter_how_you_look_at_it_it's_your_fault_that_i'm_not_popular! -> watashi_ga_motenai_no_wa_dou_kangaetemo_omaera_ga_warui!
2022-09-02 13:56:53 -05:00
evazion
350009fd15 autocomplete: increase number of results returned from 10 to 20.
The new autocomplete system tends to return more results, so increase
the number of tags shown from 10 to 20. This is useful so you can do things
like search for 'skirt' during tagging to find all skirt-related tags.
2022-09-02 13:56:52 -05:00
evazion
8491bef6e6 autocomplete: highlight matches in autocomplete menu.
Highlight the matching part of the tag in the autocomplete menu. For
example, if you search "hair", then the word "hair" will be bolded in
every matching tag. This is so users can tell why a particular tag was
matched.
2022-09-02 13:56:52 -05:00
evazion
f8e4e5724f autocomplete: switch to word-based tag matching.
Switch autocomplete to match individual words in the tag, instead of
only matching the start of the tag.

For example, "hair" matches any tag containing the word "hair", not just tags
starting with "hair". "long_hair" matches all tags containing the words "long"
and "hair", which includes "very_long_hair" and "absurdly_long_hair".

Words can be in any order and words can be left out. So "closed_eye" matches
"one_eye_closed". "asuka_langley_souryuu" matches "souryuu_asuka_langley".

This has several advantages:

* You can search characters by first name. For example, "miku" matches "hatsune_miku".
  "zelda" matches both "princess_zelda" and "the_legend_of_zelda".
* You can find the right tag even if you get the word order wrong, or forget a word.
  For example, "eyes_closed" matches "closed_eyes". "hair_over_eye" matches "hair_over_one_eye".
* You can find more related tags. For example, searching "skirt" shows all tags
  containing the word "skirt", not just tags starting with "skirt".

The downside is this may break muscle memory by changing the autocomplete order of
some tags. This is an acceptable trade-off.

You can get the old behavior by writing a "*" at the end of the tag. For
example, searching "skirt*" gives the same results as before.
2022-09-02 13:56:26 -05:00
evazion
ec382357b8 tags: populate words column.
Add code for parsing tags into words and for populating the `words` column
in the tags table.
2022-09-01 23:54:07 -05:00
evazion
e058cfba4d tags: add words column.
Add a `words` column to the tags table. This will be used for parsing
tags into words for word-based matching in autocomplete.

For example, "very_long_hair" can be parsed into ["very", "long", "hair"].

The `array_to_tsvector(words)` index is for performing wildcard
searches. It lets us do e.g

    SELECT * FROM tags WHERE array_to_tsvector(words) @@ 'hand:* & hold:*'

to find tags containing the words "hand*" and "hold*".
2022-09-01 23:54:07 -05:00
evazion
2b76a4c5ba tumblr: fix exception when parsing subdomainless Tumblr URLs.
Fix exception when a post has a Tumblr source without a subdomain, such
as `https://tumblr.com`.
2022-08-30 01:52:55 -05:00
evazion
cf13ab1540 autocomplete: render html server-side.
Render the HTML for autocomplete results server-side instead of in
Javascript. This is cleaner than building HTML in Javascript, but it may
hurt caching because the HTTP responses are larger.

Fixes #4698: user autocomplete contains links to /posts

Also fixes a bug where tag counts in the autocomplete menu were different
from tag counts displayed elsewhere because of differences in rounding.
2022-08-30 01:26:02 -05:00
evazion
55266be2ef autocomplete: drop support for shortcut abbreviations in aliases.
Previously if you typed e.g. "/tr" in autocomplete we would first check
if "/tr" was aliased to another tag before expanding out the abbreviation.
This was for compatibility with legacy shortcut aliases. These aliases
have been removed so this is dead code now.
2022-08-30 01:25:46 -05:00
evazion
e1df93c4dc Fix #5073: Navigating search containing pool tag only uses pool
Show the search navbar when searching for `pool:1234 tag`. Before the
search navbar would always be hidden if the search contained a pool:
metatag, even if it was a multi-tag search.
2022-08-28 23:17:46 -05:00
evazion
4448b3d15b posts: fix incorrect post counts for -pool:, -fav: searches
Fix `-pool:1234` and `-fav:evazion` searches incorrectly returning the
same post count as `pool:1234` and `fav:evazion` searches.
2022-08-28 23:17:01 -05:00
evazion
fa0d7990fb posts: fix selected pool not being highlighted when doing pool:<name> search.
Fix the pool name not being bolded in the pool navbar when doing a
pool:<name> search. Previously the selected pool was only bolded when
doing a pool:<id> search.
2022-08-28 23:16:45 -05:00
evazion
6afdb921de users: don't return unused boolean attributes in API.
Don't return unused flags like `is_super_voter` or `enable_auto_complete` in the /profile.json API.
2022-08-28 23:16:33 -05:00
evazion
0391f6f835 tests: fix broken autocomplete tests. 2022-08-28 19:54:26 -05:00
evazion
f7794de0b7 weibo: fix bad artist name suggestions in new artist form.
Fix the new artist form suggesting invalid Chinese tag names for Weibo
artists. Suggest `weibo_123456` instead as a placeholder.
2022-08-26 01:25:05 -05:00
evazion
4d009568fd Fix #5165: add support for weibo share urls 2022-08-26 01:12:23 -05:00
evazion
18c949ff34 Fix #5208: The posts version of create or update artist commentary endpoint does not work without the post ID parameter being passed in the body
Fix /posts/:post_id/artist_commentary/create_or_update not working
without passing `artist_commentary[post_id]` in the form body.
2022-08-25 21:50:33 -05:00
evazion
91b3a4c37a Fix #5205: Creating posts via API fails if you pass any commentary field but not all. 2022-08-25 21:35:29 -05:00
evazion
1ee2d22b97 Fix #5184: undefined method `to_model' for []:Array searching for IQDB queries with JSON. 2022-08-25 21:28:21 -05:00
evazion
115085006e Fix #5194: AND/OR no longer trigger autocomplete.
Also change the /autocomplete.json API to no longer strip '-' and '~'
from the start of the tag. This may be a breaking change if third-party
scripts relied on this behavior.
2022-08-25 20:45:22 -05:00
evazion
9eb31c8018 Fix #5212: Allow larger IPv6 bans 2022-08-24 22:04:30 -05:00
evazion
28ee901192 Fix #5211: Using tab to autocomplete tags in tag implication/alias search adds a space making it return no results.
Fix the alias and implication search forms not normalizing tags before search.
2022-08-24 22:01:03 -05:00
evazion
3f10eeb954 Fix #5227: Error on note previews due to URL length limit
Allow either GET or POST for /note_previews.
2022-08-24 16:27:05 -05:00