Commit Graph

71 Commits

Author SHA1 Message Date
evazion
63f675b7d6 config: remove enable_post_search_counts option.
Enable by default if reportbooru is configured, otherwise disable.
2020-06-02 14:41:06 -05:00
evazion
67aab0236d search: apply aliases after parsing searches.
Make PostQueryBuilder apply aliases earlier, immediately after parsing
the search.

On the post index page there are multiple places where we need to apply
aliases:

* When running the search with PostQueryBuilder#build.
* When calculating the search count with PostQueryBuilder#fast_count.
* When calculating the related tags for the sidebar.
* When tracking missed searches and popular searches for Reportbooru.
* When looking up wiki excerpts.

Applying aliases after parsing ensures we only have to apply aliases
once for all of these things.

We also normalize the order of tags in searches and strip repeated tags.
This is so that we have consistent cache keys for fast_count.

* Fixes searches for aliased tags being counted as missed searches (fixes #4433).
* Fixes wiki excerpts not showing up when searching for aliased tags.
2020-05-07 13:53:35 -05:00
evazion
abda687345 posts/index: fix search count tracking.
* Eliminate "&ms=1" url param.
* Only track simple single-tag searches (not multi-tag searches,
  metatags, negated tags, etc).
2020-04-27 19:12:16 -05:00
evazion
d5a7fafca1 posts/index: fix several "This tag is under discussion" issues.
Several fixes for the "This tag is under discussion" notice on the post
index page:

* Fix the notice appearing for BURs that aren't pending.
* Fix the notice never going away because of the cache never expiring.
* List all topics when a tag is involved in multiple BURs.
* Link to the forum post instead of the forum topic (fix #4421).
* Optimization: don't check for BURs when the search isn't a simple
  single tag search.
* Add a `tags` field to the bulk update requests table for tracking all
  tags involved in the request (excluding tags in mass updates that are
  negated/optional/wildcards). Known issue: doesn't handle tag type
  prefixes in mass updates correctly (e.g. `mass update foo -> artist:bar`
  doesn't detect the tag `bar`).
* Allow searching the /bulk_update_requests page by tags.

We don't really need to cache the notice here, but we do it anyway to
reduce queries on the post index page.
2020-04-27 19:11:47 -05:00
evazion
dd0d9dff4a search: move misc search parsing helpers to PostQueryBuilder.
* Move various search parser helper methods (`has_metatag?`,
  `is_single_tag?` et al) from PostSets and the Tag model to
  PostQueryBuilder.

* Fix various minor bugs stemming from trying to check if a search query
  contains certain metatags using regexes or other adhoc techniques.
2020-04-23 01:51:30 -05:00
evazion
3dab648d0e search: refactor PostQueryBuilder class methods into instance methods.
* Make scan_query, parse_query, normalize_query into instance methods
  instead of class methods. This is to a) clean up the API and b)
  prepare for moving certain tag utility methods into PostQueryBuilder.

* Fix a few cases where a caller used scan_query when they should have
  used split_query or parse_tag_edit.
2020-04-22 19:38:17 -05:00
evazion
a93a902982 posts/index: only show tag change notices for members.
This is to reduce Redis calls per second.
2020-04-21 15:06:25 -05:00
evazion
7726563733 search: refactor scan_query callers to use split_query.
Refactor to use split_query instead of scan_query to split a query on
spaces. Preparation for refactoring scan_query into something smarter.
2020-04-19 02:54:44 -05:00
evazion
ab4d596ac2 Fix #4405: Post version table css doesn't keep ratio at smaller resolutions.
Bug: extremely long sources cause the Tags column to become extremely
wide. Caused by the source link not having the word-break property set.

Fix: use post_source_tag, which lets the `a[rel=external] { word-break: break-word; }`
rule take effect.

Example: https://danbooru.donmai.us/post_versions?search%5Bpost_id%5D=3809742
2020-04-17 01:46:14 -05:00
evazion
967d398c8e search: move query parsing code from tag model to post query builder. 2020-03-06 23:23:38 -06:00
evazion
edfef10dc9 Fix #1883: Add <link> elements for all paginated pages.
Add <link rel="prev"> and <link rel="next"> elements to most pages with
pagination. This should work on all index pages, but it won't work for
things like pool or forum topic show pages.

Also remove the <link rel="top"> element (wasn't useful, was just a link
back to the root url).
2020-01-31 02:43:08 -06:00
evazion
40711e1d4f posts/show: refactor parent/child notices.
* Convert notices from helpers to partials.
* Eliminate PostSets::PostRelationship class in favor of post_sets/posts template.
* Eliminate COUNT(*) queries when calculating the number of child posts.
* Eliminate redundant parent load and parent exists queries.
2020-01-12 18:38:38 -06:00
evazion
231e4872ed Re-enable post search counts and view counts.
Re-enable post view counts, post search counts, and missed search
counts. These were disabled in 89adf88d5 because of a bug caused by the
upgrade to rack-2.0.8 in a58dd83ad.

The bug was that rack-2.0.8 changed `session.id` to return a value of a
new wrapper type that doesn't respond to `to_s`. Previously it just
returned a string. Now we have to call `session[:session_id]` or
`session.id.public_id` to get a plain string. This was an undocumented
breaking change in rack-2.0.8 to fix CVE-2019-16782.
2019-12-25 23:53:50 -06:00
evazion
89adf88d50 temp disable search counts. 2019-12-24 17:13:17 -06:00
evazion
283bed64da temp disable view counts 2019-12-24 17:00:40 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
5422db1c3c Standardize links to wiki help pages.
* Fix inconsistencies in how wiki pages were linked.

* Link directly to the wiki instead of to a title search that is expected
  to redirect to the wiki.
2019-10-31 19:04:18 -05:00
evazion
20f28910da /posts: word wrap long sources in sidebar.
* Don't truncate long sources in the sidebar on the post show page. Word
  wrap them instead.
* Word wrap long external links in general (mainly links in dtext).
* Turn sources into links on modqueue page.
2019-10-13 18:53:46 -05:00
evazion
61619b719e Add rel="noreferrer" to external links.
Tells browsers not to send the Referer header when following external
links. Among other things, this bypasses Pixiv's anti-hotlinking
protection when opening direct image sources from Pixiv.
2019-10-06 01:32:14 -05:00
evazion
8f6fd95e2d posts: change "»" links next to sources in sidebar.
* On the posts show page, make the "»" link next to the source visible
  to all users, not just builders.
* Make "»" link to the raw unnormalized source, instead of a `source:` search.
* Remove the special case for displaying old pixiv sources as `pixiv/moniker`.
2019-09-22 02:58:09 -05:00
evazion
4fb24c812f Fix #4155: Fix profile/settings metadata discrepancy. 2019-09-05 00:14:11 -05:00
evazion
95b8420ba2 Drop unused common_searches code. 2019-09-01 15:54:00 -05:00
Albert Yi
1550538dc1 Tag change notices
This adds a small notice at the bottom of post searches if a single tag search is the target of any tag change request.
2019-01-22 17:22:07 -08:00
Albert Yi
542641e3e2 refactor pool nav html 2018-11-01 17:42:49 -07:00
evazion
8833374294 Fix calling reportbooru when it isn't fully configured (#3834). 2018-08-24 11:23:19 -05:00
r888888888
4f0f622d7b fix typo 2018-05-26 13:15:09 -07:00
r888888888
c054784302 eliminate unused vars in search counters 2018-05-26 11:59:40 -07:00
Albert Yi
a0aa2f3f4a fixes #3276 2018-05-15 14:30:28 -07:00
evazion
84a0a89f4b Fix #3539: Open redirect vulnerabilities. 2018-02-07 19:52:52 -06:00
evazion
583520b97c pagination helpers: convert to strong params. 2018-02-07 18:07:45 -06:00
r888888888
36948bbf33 move explore links to sidebar, fix popular searches action 2017-11-13 11:14:09 -08:00
r888888888
6431dafa80 use json serializer for message verifier 2017-11-10 14:37:27 -08:00
r888888888
9250dd599d fix bug with verifier 2017-11-10 14:12:15 -08:00
r888888888
710a5f1abe fix typo 2017-11-10 14:06:56 -08:00
r888888888
131734f7a6 enable post view count tracking (for mods initially) 2017-11-09 16:10:34 -08:00
r888888888
d883de258c add rel meta links for prev and next page 2017-10-11 15:31:13 -07:00
evazion
38355b4839 posts_helper.rb: remove unused resize_image_links.
Unused since 1ef7ef4.
2017-02-06 19:07:03 -06:00
Albert Yi
e7907e0e14 rename some config keys to clarify what they are 2016-11-28 17:31:01 -08:00
r888888888
fc4b2e54a4 fix common searches 2016-09-29 17:45:16 -07:00
r888888888
b13c76b9d9 only trigger common searches js on manual searches 2016-09-07 18:35:28 -07:00
r888888888
c3b78b1752 add user searches 2016-08-23 18:20:21 -07:00
r888888888
504674b288 add rel=nofollow in more places 2016-02-03 23:47:17 -08:00
r888888888
16e437b048 ignore forbidden tags on missed search counter 2016-02-03 16:56:37 -08:00
r888888888
025d66a639 optimize missing search js script 2016-02-02 17:26:28 -08:00
r888888888
fe4cb7f3ba track searches that return no results 2016-02-02 16:25:14 -08:00
r888888888
f87c71cf23 remove post view counts, add search counts 2015-07-27 17:27:40 -07:00
r888888888
9e6d08600c store post view counts in reportbooru/fetch view counts from reportbooru #2128 2015-07-21 13:09:32 -07:00
evazion
a38e12f091 Fix XSS in source link on post show page.
This vulnerability allows someone to create a source link that appears
to lead to Pixiv like normal, but that actually executes Javascript code
when clicked.

1) Set the source of a post to javascript:"http://img1.pixiv.net/img/xss/";alert("xss");
2) Wait for someone to click the source link in the Information sidebar.
3) Profit.

The cause is that the regexes for detecting Pixiv URLs aren't anchored
to the front of the string using \A. This allows non-http:// links to be
created.
2014-10-17 15:15:48 -05:00
Toks
96d5a937d5 fixes #2106 2014-03-14 11:35:26 -04:00
Toks
424d84661a fixes #2105
Also fix bug where sources were not escaped at all on post versions page
2014-03-10 22:34:22 -04:00