# Holds global config settings, also used by some modules.
our %config=( #{{{
wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
- wiki_link_regexp => qr/\[\[([^\s]+)\]\]/,
+ wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
verbose => 0,
wikiname => "wiki",
url => '',
cgiurl => '',
historyurl => '',
+ diffurl => '',
anonok => 0,
rebuild => 0,
wrapper => undef,
"url=s" => \$config{url},
"cgiurl=s" => \$config{cgiurl},
"historyurl=s" => \$config{historyurl},
+ "diffurl=s" => \$config{diffurl},
"exclude=s@" => sub {
$config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
},
return "<a href=\"$config{url}\">$config{wikiname}</a>";
} #}}}
-sub finalize ($$) { #{{{
+sub finalize ($$$) { #{{{
my $content=shift;
my $page=shift;
+ my $mtime=shift;
my $title=basename($page);
$title=~s/_/ /g;
if (length $config{historyurl}) {
my $u=$config{historyurl};
- $u=~s/\[\[\]\]/$pagesources{$page}/g;
+ $u=~s/\[\[file\]\]/$pagesources{$page}/g;
$template->param(historyurl => $u);
}
content => $content,
backlinks => [backlinks($page)],
discussionlink => htmllink($page, "Discussion", 1, 1),
+ mtime => scalar(gmtime($mtime)),
);
return $template->output;
$content=linkify($content, $page);
$content=htmlize($type, $content);
- $content=finalize($content, $page);
+ $content=finalize($content, $page,
+ mtime("$config{srcdir}/$file"));
check_overwrite("$config{destdir}/".htmlpage($page), $page);
writefile("$config{destdir}/".htmlpage($page), $content);
if (-d "$config{srcdir}/.svn") {
# Check to see if the page has been changed by someone
# else since rcs_prepedit was called.
- my $oldrev=int($rcstoken);
+ my ($oldrev)=$rcstoken=~/^([0-9]+)$/; # untaint
my $rev=svn_info("Revision", "$config{srcdir}/$file");
- if ($rev != $oldrev) {
+ if (defined $rev && defined $oldrev && $rev != $oldrev) {
# Merge their changes into the file that we've
# changed.
+ chdir($config{srcdir}); # svn merge wants to be here
if (system("svn", "merge", "--quiet", "-r$oldrev:$rev",
"$config{srcdir}/$file") != 0) {
warn("svn merge -r$oldrev:$rev failed\n");
if (system("svn", "commit", "--quiet", "-m",
possibly_foolish_untaint($message),
- "$config{srcdir}/$file") != 0) {
- warn("svn commit failed\n");
+ "$config{srcdir}") != 0) {
my $conflict=readfile("$config{srcdir}/$file");
if (system("svn", "revert", "--quiet", "$config{srcdir}/$file") != 0) {
warn("svn revert failed\n");
} #}}}
sub svn_info ($$) { #{{{
- my $file=shift;
my $field=shift;
+ my $file=shift;
my $info=`LANG=C svn info $file`;
my ($ret)=$info=~/^$field: (.*)$/m;
$user=$2;
$when=concise(ago(time - str2time($3)));
}
- elsif ($state eq 'header' && /^\s+[A-Z]\s+\Q$svn_base\E\/(.+)$/) {
- push @pages, { link => htmllink("", pagename($1), 1) }
- if length $1;
+ elsif ($state eq 'header' && /^\s+[A-Z]\s+\Q$svn_base\E\/([^ ]+)(?:$|\s)/) {
+ my $file=$1;
+ my $diffurl=$config{diffurl};
+ $diffurl=~s/\[\[file\]\]/$file/g;
+ $diffurl=~s/\[\[r1\]\]/$rev - 1/eg;
+ $diffurl=~s/\[\[r2\]\]/$rev/g;
+ push @pages, {
+ link => htmllink("", pagename($file), 1),
+ diffurl => $diffurl,
+ } if length $file;
}
elsif ($state eq 'header' && /^$/) {
$state='body';
user => htmllink("", $user, 1),
committype => $committype,
when => $when, message => [@message],
- pages => [@pages] } if @pages;
+ pages => [@pages],
+ } if @pages;
return @ret if @ret >= $num;
$state='header';
push @params, "--url=$config{url}" if length $config{url};
push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
+ push @params, "--diffurl=$config{diffurl}" if length $config{diffurl};
push @params, "--anonok" if $config{anonok};
my $params=join(" ", @params);
my $call='';
$form->field(name => "do", type => 'hidden');
$form->field(name => "from", type => 'hidden');
+ $form->field(name => "rcsinfo", type => 'hidden');
$form->field(name => "page", value => "$page", force => 1);
$form->field(name => "comments", type => "text", size => 80);
$form->field(name => "content", type => "textarea", rows => 20,
cols => 80);
+ $form->tmpl_param("can_commit", $config{svn});
+ $form->tmpl_param("indexlink", indexlink());
+ $form->tmpl_param("helponformattinglink",
+ htmllink("", "HelpOnFormatting", 1));
if (! $form->submitted) {
- $form->field(name => "rcsinfo", type => 'hidden',
- value => rcs_prepedit($file), force => 1);
+ $form->field(name => "rcsinfo", value => rcs_prepedit($file),
+ force => 1);
}
if ($form->submitted eq "Cancel") {
else {
my $dir=$from."/";
$dir=~s![^/]+/$!!;
+
+ if ($page eq 'discussion') {
+ $best_loc="$from/$page";
+ }
+ else {
+ $best_loc=$dir.$page;
+ }
+
push @page_locs, $dir.$page;
push @page_locs, "$from/$page";
- $best_loc="$from/$page";
while (length $dir) {
$dir=~s![^/]+/$!!;
push @page_locs, $dir.$page;
$form->title("creating $page");
}
elsif ($form->field("do") eq "edit") {
- if (! length $form->field('content')) {
+ if (! defined $form->field('content') ||
+ ! length $form->field('content')) {
my $content="";
if (exists $pagesources{lc($page)}) {
$content=readfile("$config{srcdir}/$pagesources{lc($page)}");
$form->title("editing $page");
}
- $form->tmpl_param("can_commit", $config{svn});
- $form->tmpl_param("indexlink", indexlink());
print $form->render(submit => \@buttons);
}
else {
$form->field("rcsinfo"));
if (defined $conflict) {
+ $form->field(name => "rcsinfo", value => rcs_prepedit($file),
+ force => 1);
$form->tmpl_param("page_conflict", 1);
- $form->field("content", $conflict);
+ $form->field("content", value => $conflict, force => 1);
$form->field("do", "edit)");
+ $form->tmpl_param("page_select", 0);
+ $form->field(name => "page", type => 'hidden');
+ $form->title("editing $page");
print $form->render(submit => \@buttons);
return;
}
} #}}}
# main {{{
-lockwiki();
setup() if $config{setup};
+lockwiki();
if ($config{wrapper}) {
gen_wrapper(%config);
exit;