diff --git a/app/helpers/HistoryHelper.php b/app/helpers/HistoryHelper.php
index 004c0c3..b439e25 100755
--- a/app/helpers/HistoryHelper.php
+++ b/app/helpers/HistoryHelper.php
@@ -2,7 +2,7 @@
class HistoryHelper extends Rails\ActionView\Helper
{
protected $att_options;
-
+
# :all: By default, some changes are not displayed. When displaying details
# for a single change, set :all=>true to display all changes.
#
@@ -11,12 +11,12 @@ public function get_default_field_options()
{
return [ 'suppress_fields' => [] ];
}
-
+
public function get_attribute_options()
{
if ($this->att_options)
return $this->att_options;
-
+
$att_options = [
# :suppress_fields => If this attribute was changed, don't display changes to specified
# fields to the same object in the same change.
@@ -52,16 +52,16 @@ public function get_attribute_options()
],
'never_obsolete' => ['cached_tags' => true] # tags handle obsolete themselves per-tag
],
-
+
'Pool' => [
'primary_order' => 0,
-
+
'fields' => [
'description' => [ 'primary_order' => 5 ] # we don't handle commas correctly if this isn't last
],
'never_obsolete' => [ 'description' => true ] # changes to description aren't obsolete just because the text has changed again
],
-
+
'PoolPost' => [
'fields' => [
'sequence' => [ 'max_to_display' => 5],
@@ -73,14 +73,14 @@ public function get_attribute_options()
],
'cached_tags' => [ ],
],
-
+
'Tag' => [
],
-
+
'Note' => [
],
];
-
+
foreach (array_keys($att_options) as $classname) {
$att_options[$classname] = array_merge([
'fields' => [],
@@ -88,20 +88,20 @@ public function get_attribute_options()
'never_obsolete' => [],
'force_show_initial' => []
], $att_options[$classname]);
-
+
$c = $att_options[$classname]['fields'];
foreach (array_keys($c) as $field) {
$c[$field] = array_merge($this->get_default_field_options(), $c[$field]);
}
}
}
-
+
public function format_changes($history, array $options = [])
{
$html = '';
-
+
$changes = $history->history_changes;
-
+
# Group the changes by class and field.
$change_groups = [];
foreach ($changes as $c) {
@@ -111,9 +111,9 @@ public function format_changes($history, array $options = [])
$change_groups[$c->table_name][$c->column_name] = [];
$change_groups[$c->table_name][$c->column_name][] = $c;
}
-
+
$att_options = $this->get_attribute_options();
-
+
# Number of changes hidden (not including suppressions):
$hidden = 0;
$parts = [];
@@ -126,14 +126,14 @@ public function format_changes($history, array $options = [])
$field_options = isset($table_options['fields']['field']) ? $table_options['fields']['field'] : $this->get_default_field_options();
$to_suppress = array_merge($to_suppress, $field_options['suppress_fields']);
}
-
+
foreach ($to_suppress as $suppress)
unset($fields[$suppress]);
-
+
foreach ($fields as $field => $group) {
$class_name = $group[0]->master_class();
$field_options = isset($table_options['fields']['field']) ? $table_options['fields']['field'] : $this->get_default_field_options();
-
+
# Check for entry limits.
if (empty($options['specific_history'])) {
$max = isset($field_options['max_to_display']) ? $field_options['max_to_display'] : null;
@@ -142,29 +142,29 @@ public function format_changes($history, array $options = [])
$group = array_slice($group, $max);
}
}
-
+
# Format the rest.
foreach ($group as $c) {
if (!$c->previous && $c->changes_to_default() && empty($table_options['force_show_initial']['field']))
continue;
-
+
$part = $this->format_change($history, $c, $options, $table_options);
if (!$part)
continue;
-
+
if (!empty($field_options['primary_order']))
$primary_order = $field_options['primary_order'];
elseif (!empty($table_options['primary_order']))
$primary_order = $table_options['primary_order'];
else
$primary_order = null;
-
+
$part = array_merge($part, ['primary_order' => $primary_order]);
$parts[] = $part;
}
}
}
-
+
usort($parts, function($a, $b) {
$comp = 0;
foreach (['primary_order', 'field', 'sort_key'] as $field) {
@@ -174,55 +174,55 @@ public function format_changes($history, array $options = [])
$comp = 0;
else
$comp = 1;
-
+
if ($comp != 0)
break;
}
return $comp;
});
-
+
foreach (array_keys($parts) as $idx) {
if (!$idx || $parts[$idx]['field'] == $parts[$idx - 1]['field'])
continue;
$parts[$idx-1]['html'] .= ', ';
}
-
+
$html = '';
-
+
if (empty($options['show_name']) && $history->group_by_table == 'tags') {
$tag = $history->history_changes[0]->obj();
$html .= $this->tag_link($tag->name);
$html .= ': ';
}
-
+
if (!empty($history->aux()->note_body)) {
$body = $history->aux()->note_body;
if (strlen($body) > 20)
$body = substr($body, 0, 20) . '...';
$html .= 'note ' . $this->h($body) . ' ';
}
-
+
$html .= implode(' ', array_map(function($part) { return $part['html']; }, $parts));
-
+
if ($hidden > 0) {
$html .= ' (' . $this->linkTo($hidden . ' more...', ['search' => 'change:' . $history->id]) . ')';
}
-
+
return $html;
}
-
+
public function format_change($history, $change, $options, $table_options)
{
$html = '';
-
+
$classes = [];
if (empty($table_options['never_obsolete'][$change->column_name]) && $change->is_obsolete()) {
$classes[] = 'obsolete';
}
-
+
$added = '+';
$removed = '-';
-
+
$sort_key = $change->remote_id;
$primary_order = 1;
switch ($change->table_name) {
@@ -237,7 +237,7 @@ public function format_change($history, $change, $options, $table_options)
}
$html .= '';
break;
-
+
case 'parent_id':
$html .= 'parent:';
if ($change->value) {
@@ -250,7 +250,7 @@ public function format_change($history, $change, $options, $table_options)
} else {
$html .= 'none';
}
-
+
if ($change->previous) {
$html .= '←';
if ($change->previous->value) {
@@ -265,7 +265,7 @@ public function format_change($history, $change, $options, $table_options)
}
}
break;
-
+
case 'source':
if ($change->previous) {
$html .= sprintf("source changed from %s to %s", $this->source_link($change->previous->value, false), $this->source_link($change->value, false));
@@ -273,32 +273,38 @@ public function format_change($history, $change, $options, $table_options)
$html .= sprintf("source: %s", $this->source_link($change->value, false));
}
break;
-
+
case 'frames_pending':
$html .= 'frames changed: ' . $this->h($change->value ?: '(none)');
break;
-
+
case 'is_rating_locked':
# Trueish: if a value equals true or 't'
$html .= $change->value || $change->value == 't' ? $added : $removed;
+ $html .= 'rating-locked';
+ break;
+
+ case 'is_note_locked':
+ # Trueish
+ $html .= $change->value || $change->value == 't' ? $added : $removed;
$html .= 'note-locked';
break;
-
+
case 'is_shown_in_index':
# Trueish
$html .= $change->value || $change->value == 't' ? $added : $removed;
$html .= 'shown';
break;
-
+
case 'cached_tags':
$previous = $change->previous;
-
+
$changes = Post::tag_changes($change, $previous, $change->latest());
-
+
$list = [];
$list[] = $this->tag_list($changes['added_tags'], ['obsolete' => $changes['obsolete_added_tags'], 'prefix' => '+', 'class' => 'added']);
$list[] = $this->tag_list($changes['removed_tags'], ['obsolete' => $changes['obsolete_removed_tags'], 'prefix' => '-', 'class' => 'removed']);
-
+
if (!empty($options['show_all_tags']))
$list[] = $this->tag_list($changes['unchanged_tags'], ['prefix' => '', 'class' => 'unchanged']);
$html .= trim(implode(' ', $list));
@@ -308,7 +314,7 @@ public function format_change($history, $change, $options, $table_options)
case 'pools':
$primary_order = 0;
-
+
switch ($change->column_name) {
case 'name':
if ($change->previous) {
@@ -317,7 +323,7 @@ public function format_change($history, $change, $options, $table_options)
$html .= sprintf("name: %s", $this->h($change->value));
}
break;
-
+
case 'description':
if ($change->value === '') {
$html .= 'description removed';
@@ -328,7 +334,7 @@ public function format_change($history, $change, $options, $table_options)
$html .= 'description added: ';
else
$html .= 'description changed: ';
-
+
# Show a diff if there's a previous description and it's not blank. Otherwise,
# just show the new text.
$show_diff = $change->previous && $change->previous->value !== '';
@@ -336,11 +342,11 @@ public function format_change($history, $change, $options, $table_options)
$text = Moebooru\Diff::generate($change->previous->value, $change->value);
else
$text = $this->h($change->value);
-
+
# If there's only one line in the output, just show it inline. Otherwise, show it
# as a separate block.
$multiple_lines = is_int(strpos($text, '
')) || is_int(strpos($text, '
'));
-
+
$show_in_detail = !empty($options['specific_history']) || !empty($options['specific_object']);
if (!$multiple_lines)
$display = $text;
@@ -348,20 +354,20 @@ public function format_change($history, $change, $options, $table_options)
$display = "