commit
ea176264d9
|
@ -48,12 +48,10 @@ class WikiController < ApplicationController
|
|||
@name = CGI.unescape(params[:id])
|
||||
@page = @wiki.page(@name)
|
||||
name = params[:rename] || @name
|
||||
committer = Gollum::Committer.new(@wiki, commit)
|
||||
commit_arg = {:committer => committer}
|
||||
|
||||
update_wiki_page(@wiki, @page, params[:content], commit_arg, name, params[:format])
|
||||
update_wiki_page(@wiki, @page.footer, params[:footer], commit_arg) if params[:footer]
|
||||
update_wiki_page(@wiki, @page.sidebar, params[:sidebar], commit_arg) if params[:sidebar]
|
||||
update_wiki_page(@wiki, @page, params[:content], {:committer => committer}, name, params[:format])
|
||||
update_wiki_page(@wiki, @page.footer, params[:footer], {:committer => committer}) if params[:footer]
|
||||
update_wiki_page(@wiki, @page.sidebar, params[:sidebar], {:committer => committer}) if params[:sidebar]
|
||||
|
||||
committer.commit
|
||||
|
||||
|
@ -68,9 +66,8 @@ class WikiController < ApplicationController
|
|||
def create
|
||||
@name = CGI.unescape(params['page'])
|
||||
format = params['format'].intern
|
||||
|
||||
begin
|
||||
@wiki.write_page(@name, format, params['content'] || '', commit)
|
||||
@wiki.write_page(@name, format, params['content'] || '', {:committer => committer}).commit
|
||||
redirect_to project_wiki_path(@project, CGI.escape(@name))
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
flash[:error] = t("flash.wiki.duplicate_page", :name => @name)
|
||||
|
@ -82,7 +79,7 @@ class WikiController < ApplicationController
|
|||
@name = CGI.unescape(params[:id])
|
||||
page = @wiki.page(@name)
|
||||
if page
|
||||
@wiki.delete_page(page, commit.merge(:message => 'Page removed'))
|
||||
@wiki.delete_page(page, {:committer => committer}).commit
|
||||
flash[:notice] = t("flash.wiki.page_successfully_removed")
|
||||
else
|
||||
flash[:notice] = t("flash.wiki.page_not_found", :name => params[:id])
|
||||
|
@ -145,7 +142,7 @@ class WikiController < ApplicationController
|
|||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
|
||||
if @wiki.revert_page(@page, sha1, sha2, commit)
|
||||
if @wiki.revert_page(@page, sha1, sha2, {:committer => committer}).commit
|
||||
flash[:notice] = t("flash.wiki.revert_success")
|
||||
redirect_to project_wiki_path(@project, CGI.escape(@name))
|
||||
else
|
||||
|
@ -165,7 +162,7 @@ class WikiController < ApplicationController
|
|||
def revert_wiki
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
if @wiki.revert_commit(sha1, sha2, commit)
|
||||
if @wiki.revert_commit(sha1, sha2, {:committer => committer}).commit
|
||||
flash[:notice] = t("flash.wiki.revert_success")
|
||||
redirect_to project_wiki_index_path(@project)
|
||||
else
|
||||
|
@ -233,10 +230,10 @@ class WikiController < ApplicationController
|
|||
if params['message'] and !params['message'].empty?
|
||||
msg = params['message']
|
||||
else
|
||||
# msg = "#{!!@wiki.page(@name) ? 'Updated page' : 'Created page'} #{@name}"
|
||||
msg = case action_name.to_s
|
||||
when 'create' then "Created page #{@name.to_s}"
|
||||
when 'update' then "Updated page #{@name.to_s}"
|
||||
when 'destroy' then "Removed page #{@name.to_s}"
|
||||
when 'revert' then "Reverted page #{@name.to_s}"
|
||||
when 'revert_wiki' then "Reverted wiki"
|
||||
end
|
||||
|
@ -246,8 +243,13 @@ class WikiController < ApplicationController
|
|||
{ :message => msg }
|
||||
end
|
||||
|
||||
def commit
|
||||
commit_message.merge({:name => current_user.uname, :email => current_user.email})
|
||||
def committer
|
||||
p = commit_message.merge({:name => current_user.uname, :email => current_user.email})
|
||||
@committer ||= Gollum::Committer.new(@wiki, p)
|
||||
# @committer.after_commit do |committer, sha1|
|
||||
# here goes callback for notification
|
||||
# end
|
||||
@committer
|
||||
end
|
||||
|
||||
def show_or_create_page
|
||||
|
@ -258,20 +260,19 @@ class WikiController < ApplicationController
|
|||
elsif file = @wiki.file(@name)
|
||||
render :text => file.raw_data, :content_type => file.mime_type
|
||||
elsif can? :write, @project
|
||||
# @name = CGI.escape(@name)
|
||||
@new = true
|
||||
render :new
|
||||
else
|
||||
redirect_to forbidden_path
|
||||
redirect_to :action => :index #forbidden_path
|
||||
end
|
||||
end
|
||||
|
||||
def authorize_read_actions
|
||||
redirect_to forbidden_path and return if cannot? :read, @project
|
||||
authorize! :read, @project
|
||||
end
|
||||
|
||||
def authorize_write_actions
|
||||
redirect_to forbidden_path and return if cannot? :write, @project
|
||||
authorize! :write, @project
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module DiffHelper
|
|||
res += "</tbody>"
|
||||
res += "</table>"
|
||||
|
||||
res.html_safe.force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
res.html_safe.encode_to_default
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -86,7 +86,7 @@ module WikiHelper
|
|||
end
|
||||
|
||||
def author
|
||||
@page.version.author.name.force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
@page.version.author.name.encode_to_default
|
||||
end
|
||||
|
||||
def author_email
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
- user = User.where(:email => v.author.email).first
|
||||
= link_to user_path_by_user(user) do
|
||||
%img{:src => gravatar_url(v.author.email),
|
||||
:alt => "avatar: #{v.author.name.force_encoding(Encoding.default_internal || Encoding::UTF_8)}",
|
||||
:alt => "avatar: #{v.author.name.encode_to_default}",
|
||||
:class => "mini-gravatar"}
|
||||
%span.username= user.present? ? user.uname : v.author.name
|
||||
%span.username= user.present? ? user.uname : v.author.name.encode_to_default
|
||||
%td.commit-name
|
||||
%span.time-elapsed= "#{l v.committed_date.to_date, :format => :long}:"
|
||||
|
||||
= v.message.force_encoding(Encoding.default_internal)
|
||||
= v.message.encode_to_default
|
||||
- if @name
|
||||
= raw "[#{link_to v.id[0..6], versioned_project_wiki_path(@project, escaped_name, v.id), :title => t("layout.wiki.view_commit")}]"
|
||||
- else
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Gollum
|
||||
class Page
|
||||
alias_method :native_gollum_name, :name
|
||||
|
||||
def name
|
||||
native_gollum_name.force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
def name_with_encoding
|
||||
name_without_encoding.encode_to_default
|
||||
end
|
||||
|
||||
alias_method_chain :name, :encoding
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,26 +2,90 @@
|
|||
module Gollum
|
||||
class Wiki
|
||||
|
||||
alias_method :native_gollum_page, :page
|
||||
alias_method :native_gollum_file, :file
|
||||
alias_method :native_gollum_write_page, :write_page
|
||||
alias_method :native_gollum_update_page, :update_page
|
||||
def page_with_forced_encoding(name, version = @ref)
|
||||
page_without_forced_encoding(force_grit_encoding(name), version)
|
||||
end
|
||||
alias_method_chain :page, :forced_encoding
|
||||
|
||||
def page(name, version = @ref)
|
||||
native_gollum_page(force_grit_encoding(name), version)
|
||||
def file_with_forced_encoding(name, version = @ref)
|
||||
file_without_forced_encoding(force_grit_encoding(name), version)
|
||||
end
|
||||
alias_method_chain :file, :forced_encoding
|
||||
|
||||
def write_page_with_forced_encoding(name, format, data, commit = {})
|
||||
write_page_without_forced_encoding(force_grit_encoding(name), format, data, commit)
|
||||
end
|
||||
alias_method_chain :write_page, :forced_encoding
|
||||
|
||||
def update_page_with_forced_encoding(page, name, format, data, commit = {})
|
||||
update_page_without_forced_encoding(page, force_grit_encoding(name), format, data, commit)
|
||||
end
|
||||
alias_method_chain :update_page, :forced_encoding
|
||||
|
||||
# Public: Applies a reverse diff for a given page. If only 1 SHA is given,
|
||||
# the reverse diff will be taken from its parent (^SHA...SHA). If two SHAs
|
||||
# are given, the reverse diff is taken from SHA1...SHA2.
|
||||
#
|
||||
# page - The Gollum::Page to delete.
|
||||
# sha1 - String SHA1 of the earlier parent if two SHAs are given,
|
||||
# or the child.
|
||||
# sha2 - Optional String SHA1 of the child.
|
||||
# commit - The commit Hash details:
|
||||
# :message - The String commit message.
|
||||
# :name - The String author full name.
|
||||
# :email - The String email address.
|
||||
# :parent - Optional Grit::Commit parent to this update.
|
||||
#
|
||||
# Returns a String SHA1 of the new commit, or nil if the reverse diff does
|
||||
# not apply.
|
||||
def revert_page_with_committer(page, sha1, sha2 = nil, commit = {})
|
||||
if sha2.is_a?(Hash)
|
||||
commit = sha2
|
||||
sha2 = nil
|
||||
end
|
||||
|
||||
def file(name, version = @ref)
|
||||
native_gollum_file(force_grit_encoding(name), version)
|
||||
multi_commit = false
|
||||
|
||||
patch = full_reverse_diff_for(page, sha1, sha2)
|
||||
committer = if obj = commit[:committer]
|
||||
multi_commit = true
|
||||
obj
|
||||
else
|
||||
Committer.new(self, commit)
|
||||
end
|
||||
parent = committer.parents[0]
|
||||
committer.options[:tree] = @repo.git.apply_patch(parent.sha, patch)
|
||||
return false unless committer.options[:tree]
|
||||
committer.after_commit do |index, sha|
|
||||
@access.refresh
|
||||
|
||||
files = []
|
||||
if page
|
||||
files << [page.path, page.name, page.format]
|
||||
else
|
||||
# Grit::Diff can't parse reverse diffs.... yet
|
||||
patch.each_line do |line|
|
||||
if line =~ %r{^diff --git b/.+? a/(.+)$}
|
||||
path = $1
|
||||
ext = ::File.extname(path)
|
||||
name = ::File.basename(path, ext)
|
||||
if format = ::Gollum::Page.format_for(ext)
|
||||
files << [path, name, format]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def write_page(name, format, data, commit = {})
|
||||
native_gollum_write_page(force_grit_encoding(name), format, data, commit)
|
||||
files.each do |(path, name, format)|
|
||||
dir = ::File.dirname(path)
|
||||
dir = '' if dir == '.'
|
||||
index.update_working_dir(dir, name, format)
|
||||
end
|
||||
end
|
||||
|
||||
def update_page(page, name, format, data, commit = {})
|
||||
native_gollum_update_page(page, force_grit_encoding(name), format, data, commit)
|
||||
multi_commit ? committer : committer.commit
|
||||
end
|
||||
alias_method_chain :revert_page, :committer
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -2,12 +2,8 @@
|
|||
module Grit
|
||||
class Repo
|
||||
|
||||
alias_method :native_grit_diff, :diff
|
||||
|
||||
def diff(a, b, *paths)
|
||||
diff = self.git.native('diff', {}, a, b, '--', *paths).force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||
Grit.log 'in grit'
|
||||
Grit.log diff
|
||||
def diff_with_encoding(a, b, *paths)
|
||||
diff = self.git.native('diff', {}, a, b, '--', *paths).encode_to_default
|
||||
if diff =~ /diff --git "{0,1}a/
|
||||
diff = diff.sub(/.*?(diff --git "{0,1}a)/m, '\1')
|
||||
else
|
||||
|
@ -15,6 +11,7 @@ module Grit
|
|||
end
|
||||
Diff.list_from_string(self, diff)
|
||||
end
|
||||
alias_method_chain :diff, :encoding
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue