First attempt at a global latest changes overview.
- uses a wiki_options entry named :latest_changes_count instead of a constant - lists modified pages with links
This commit is contained in:
@@ -351,6 +351,13 @@ module Precious
|
||||
end
|
||||
end
|
||||
|
||||
get '/latest_changes' do
|
||||
@wiki = wiki_new
|
||||
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
|
||||
@versions = @wiki.latest_changes({:max_count => max_count})
|
||||
mustache :latest_changes
|
||||
end
|
||||
|
||||
post '/compare/*' do
|
||||
@file = params[:splat].first
|
||||
@versions = params[:versions] || []
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<div id="wiki-wrapper" class="history">
|
||||
<div id="head">
|
||||
<h1><strong>{{title}}</strong></h1>
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">Home</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="wiki-history">
|
||||
|
||||
<fieldset>
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
{{#versions}}
|
||||
<tr>
|
||||
<td class="author">
|
||||
{{>author_template}}
|
||||
</td>
|
||||
<td class="commit-name">
|
||||
<span class="time-elapsed" title="{{date_full}}">{{date}}:</span>
|
||||
{{message}}
|
||||
[{{id7}}]
|
||||
{{#files}}
|
||||
<br>
|
||||
<a href="{{link}}">{{file}}</a>
|
||||
{{/files}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/versions}}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="footer">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -34,6 +34,9 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
<li class="minibutton jaws">
|
||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
||||
class="action-page-history">History</a></li>
|
||||
<li class="minibutton jaws">
|
||||
<li class="minibutton"><a href="{{base_url}}/latest_changes"
|
||||
class="action-page-history">Latest Changes</a></li>
|
||||
{{/page_exists}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
module Precious
|
||||
module Views
|
||||
class LatestChanges < Layout
|
||||
|
||||
attr_reader :wiki
|
||||
|
||||
def title
|
||||
"Latest Changes (Globally)"
|
||||
end
|
||||
|
||||
def versions
|
||||
i = @versions.size + 1
|
||||
@versions.map do |v|
|
||||
i -= 1
|
||||
{ :id => v.id,
|
||||
:id7 => v.id[0..6],
|
||||
:num => i,
|
||||
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
||||
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
||||
:date => v.authored_date.strftime("%B %d, %Y"),
|
||||
:gravatar => Digest::MD5.hexdigest(v.author.email.strip.downcase),
|
||||
:identicon => self._identicon_code(v.author.email),
|
||||
:date_full => v.authored_date,
|
||||
:files => v.stats.files.map { |f,*rest|
|
||||
page_path = extract_renamed_path_destination(f)
|
||||
page_path = remove_page_extentions(page_path)
|
||||
{ :file => f,
|
||||
:link => "#{page_path}/#{v.id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def remove_page_extentions(page_path)
|
||||
Gollum::Markup.formats.values.each do |format|
|
||||
page_path = page_path.gsub(/\.#{format[:regexp]}$/, '')
|
||||
end
|
||||
return page_path
|
||||
end
|
||||
|
||||
def extract_renamed_path_destination(file)
|
||||
return file.gsub(/{.* => (.*)}/, '\1').gsub(/.* => (.*)/, '\1')
|
||||
end
|
||||
|
||||
# http://stackoverflow.com/questions/9445760/bit-shifting-in-ruby
|
||||
def left_shift(int, shift)
|
||||
r = ((int & 0xFF) << (shift & 0x1F)) & 0xFFFFFFFF
|
||||
# 1>>31, 2**32
|
||||
(r & 2147483648) == 0 ? r : r - 4294967296
|
||||
end
|
||||
|
||||
def string_to_code(string)
|
||||
# sha bytes
|
||||
b = [Digest::SHA1.hexdigest(string)[0, 20]].pack('H*').bytes.to_a
|
||||
# Thanks donpark's IdenticonUtil.java for this.
|
||||
# Match the following Java code
|
||||
# ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) |
|
||||
# ((b[2] & 0xFF) << 8) | (b[3] & 0xFF)
|
||||
|
||||
return left_shift(b[0], 24) |
|
||||
left_shift(b[1], 16) |
|
||||
left_shift(b[2], 8) |
|
||||
b[3] & 0xFF
|
||||
end
|
||||
|
||||
def _identicon_code(blob)
|
||||
string_to_code blob + @request.host
|
||||
end
|
||||
|
||||
def use_identicon
|
||||
@wiki.user_icons == 'identicon'
|
||||
end
|
||||
|
||||
def partial(name)
|
||||
if name == :author_template
|
||||
self.class.partial("history_authors/#{@wiki.user_icons}")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def previous_link
|
||||
end
|
||||
|
||||
def next_link
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user