Files
danbooru/app/models/wiki_page_version.rb
evazion a586916cb3 /wiki_page_versions: various usability improvements.
Changes to the /wiki_page_versions global listing:

* Add "diff" links that show you what changed in the given edit.
* Add "?" links that take you to the current version of the wiki.
* Add "»" links next to wiki page titles that take you to the wiki's full edit history.
* Add "»" links next to usernames that take you to the user's full edit history.
* Add a "Status" column that shows whether the wiki page was created,
  deleted, undeleted, or renamed.
* Link to /wiki_page_versions in sidebar, not /wiki_pages?order=time.
2019-08-18 17:08:35 -05:00

47 lines
1.1 KiB
Ruby

class WikiPageVersion < ApplicationRecord
array_attribute :other_names
belongs_to :wiki_page
belongs_to_updater
belongs_to :artist, optional: true
delegate :visible?, :to => :wiki_page
module SearchMethods
def for_user(user_id)
where("updater_id = ?", user_id)
end
def search(params)
q = super
if params[:updater_id].present?
q = q.for_user(params[:updater_id].to_i)
end
if params[:wiki_page_id].present?
q = q.where("wiki_page_id = ?", params[:wiki_page_id].to_i)
end
q = q.attribute_matches(:title, params[:title])
q = q.attribute_matches(:body, params[:body])
q = q.attribute_matches(:is_locked, params[:is_locked])
q = q.attribute_matches(:is_deleted, params[:is_deleted])
q.apply_default_order(params)
end
end
extend SearchMethods
def pretty_title
title.tr("_", " ")
end
def previous
WikiPageVersion.where("wiki_page_id = ? and id < ?", wiki_page_id, id).order("id desc").first
end
def category_name
Tag.category_for(title)
end
end