diff options
Diffstat (limited to 'IkiWiki/Plugin')
26 files changed, 2839 insertions, 19 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index e000bc864..673668c0e 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -16,6 +16,7 @@ my %guids; sub import { #{{{ hook(type => "getopt", id => "aggregate", call => \&getopt); + hook(type => "getsetup", id => "aggregate", call => \&getsetup); hook(type => "checkconfig", id => "aggregate", call => \&checkconfig); hook(type => "needsbuild", id => "aggregate", call => \&needsbuild); hook(type => "preprocess", id => "aggregate", call => \&preprocess); @@ -37,6 +38,24 @@ sub getopt () { #{{{ ); } #}}} +sub getsetup () { #{{{ + return + aggregateinternal => { + type => "boolean", + example => 0, + description => "enable aggregation to internal pages?", + safe => 0, # enabling needs manual transition + rebuild => 0, + }, + aggregate_webtrigger => { + type => "boolean", + example => 0, + description => "allow aggregation to be triggered via the web?", + safe => 1, + rebuild => 0, + }, +} #}}} + sub checkconfig () { #{{{ if ($config{aggregate} && ! ($config{post_commit} && IkiWiki::commit_hook_enabled())) { diff --git a/IkiWiki/Plugin/amazon_s3.pm b/IkiWiki/Plugin/amazon_s3.pm index 187700f30..e181a84da 100644 --- a/IkiWiki/Plugin/amazon_s3.pm +++ b/IkiWiki/Plugin/amazon_s3.pm @@ -18,6 +18,7 @@ BEGIN { sub import { #{{{ hook(type => "getopt", id => "amazon_s3", call => \&getopt); + hook(type => "getsetup", id => "amazon_s3", call => \&getsetup); hook(type => "checkconfig", id => "amazon_s3", call => \&checkconfig); } # }}} @@ -39,6 +40,52 @@ sub getopt () { #{{{ }); } #}}} +sub getsetup () { #{{{ + return + amazon_s3_key_id => { + type => "string", + example => "XXXXXXXXXXXXXXXXXXXX", + description => "public access key id", + safe => 1, + rebuild => 0, + }, + amazon_s3_key_id => { + type => "string", + example => "$ENV{HOME}/.s3_key", + description => "file holding secret key (must not be readable by others!)", + safe => 0, # ikiwiki reads this file + rebuild => 0, + }, + amazon_s3_bucket => { + type => "string", + example => "mywiki", + description => "globally unique name of bucket to store wiki in", + safe => 1, + rebuild => 1, + }, + amazon_s3_prefix => { + type => "string", + example => "wiki/", + description => "a prefix to prepend to each page name", + safe => 1, + rebuild => 1, + }, + amazon_s3_location => { + type => "string", + example => "EU", + description => "which S3 datacenter to use (leave blank for default)", + safe => 1, + rebuild => 1, + }, + amazon_s3_dupindex => { + type => "boolean", + example => 0, + description => "store each index file twice? (allows urls ending in \"/index.html\" and \"/\")", + safe => 1, + rebuild => 1, + }, +} #}}} + sub checkconfig { #{{{ foreach my $field (qw{amazon_s3_key_id amazon_s3_key_file amazon_s3_bucket}) { diff --git a/IkiWiki/Plugin/anonok.pm b/IkiWiki/Plugin/anonok.pm index 1880516d5..7b966f845 100644 --- a/IkiWiki/Plugin/anonok.pm +++ b/IkiWiki/Plugin/anonok.pm @@ -6,9 +6,21 @@ use strict; use IkiWiki 2.00; sub import { #{{{ - hook(type => "canedit", id => "anonok", call => \&canedit,); + hook(type => "getsetup", id => "anonok", call => \&getsetup); + hook(type => "canedit", id => "anonok", call => \&canedit); } # }}} +sub getsetup () { #{{{ + return + anonok_pagespec => { + type => "string", + example => "*/discussion", + description => "PageSpec to limit which pages anonymous users can edit", + safe => 1, + rebuild => 0, + }, +} #}}} + sub canedit ($$$) { #{{{ my $page=shift; my $cgi=shift; diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 720078be1..47e165251 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -6,11 +6,23 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "attachment", call => \&getsetup); hook(type => "checkconfig", id => "attachment", call => \&checkconfig); hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup); hook(type => "formbuilder", id => "attachment", call => \&formbuilder); } # }}} +sub getsetup () { #{{{ + return + virus_checker => { + type => "string", + example => "clamdscan -", + description => "virus checker program (reads STDIN, returns nonzero if virus found)", + safe => 0, # executed + rebuild => 0, + }, +} #}}} + sub check_canattach ($$;$) { #{{{ my $session=shift; my $dest=shift; # where it's going to be put, under the srcdir diff --git a/IkiWiki/Plugin/bzr.pm b/IkiWiki/Plugin/bzr.pm new file mode 100644 index 000000000..e7b22f3c5 --- /dev/null +++ b/IkiWiki/Plugin/bzr.pm @@ -0,0 +1,278 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::bzr; + +use warnings; +use strict; +use IkiWiki; +use Encode; +use open qw{:utf8 :std}; + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "bzr", call => \&checkconfig); + hook(type => "getsetup", id => "bzr", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (defined $config{bzr_wrapper} && length $config{bzr_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{bzr_wrapper}, + wrappermode => (defined $config{bzr_wrappermode} ? $config{bzr_wrappermode} : "06755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + bzr_wrapper => { + type => "string", + #example => "", # FIXME add example + description => "bzr post-commit executable to generate", + safe => 0, # file + rebuild => 0, + }, + bzr_wrappermode => { + type => "string", + example => '06755', + description => "mode for bzr_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + historyurl => { + type => "string", + #example => "", # FIXME add example + description => "url to show file history, using loggerhead ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + example => "http://example.com/revision?start_revid=[[r2]]#[[file]]-s", + description => "url to view a diff, using loggerhead ([[file]] and [[r2]] substituted)", + safe => 1, + rebuild => 1, + }, +} #}}} + +sub bzr_log ($) { #{{{ + my $out = shift; + my @infos = (); + my $key = undef; + + while (<$out>) { + my $line = $_; + my ($value); + if ($line =~ /^message:/) { + $key = "message"; + $infos[$#infos]{$key} = ""; + } + elsif ($line =~ /^(modified|added|renamed|renamed and modified|removed):/) { + $key = "files"; + unless (defined($infos[$#infos]{$key})) { $infos[$#infos]{$key} = ""; } + } + elsif (defined($key) and $line =~ /^ (.*)/) { + $infos[$#infos]{$key} .= "$1\n"; + } + elsif ($line eq "------------------------------------------------------------\n") { + $key = undef; + push (@infos, {}); + } + else { + chomp $line; + ($key, $value) = split /: +/, $line, 2; + $infos[$#infos]{$key} = $value; + } + } + close $out; + + return @infos; +} #}}} + +sub rcs_update () { #{{{ + my @cmdline = ("bzr", "update", "--quiet", $config{srcdir}); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + return ""; +} #}}} + +sub bzr_author ($$) { #{{{ + my ($user, $ipaddr) = @_; + + if (defined $user) { + return IkiWiki::possibly_foolish_untaint($user); + } + elsif (defined $ipaddr) { + return "Anonymous from ".IkiWiki::possibly_foolish_untaint($ipaddr); + } + else { + return "Anonymous"; + } +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + my ($file, $message, $rcstoken, $user, $ipaddr) = @_; + + $user = bzr_author($user, $ipaddr); + + $message = IkiWiki::possibly_foolish_untaint($message); + if (! length $message) { + $message = "no message given"; + } + + my @cmdline = ("bzr", "commit", "--quiet", "-m", $message, "--author", $user, + $config{srcdir}."/".$file); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } + + return undef; # success +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + $user = bzr_author($user, $ipaddr); + + $message = IkiWiki::possibly_foolish_untaint($message); + if (! length $message) { + $message = "no message given"; + } + + my @cmdline = ("bzr", "commit", "--quiet", "-m", $message, "--author", $user, + $config{srcdir}); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } + + return undef; # success +} #}}} + +sub rcs_add ($) { # {{{ + my ($file) = @_; + + my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_remove ($) { # {{{ + my ($file) = @_; + + my @cmdline = ("bzr", "rm", "--force", "--quiet", "$config{srcdir}/$file"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_rename ($$) { # {{{ + my ($src, $dest) = @_; + + my $parent = IkiWiki::dirname($dest); + if (system("bzr", "add", "--quiet", "$config{srcdir}/$parent") != 0) { + warn("bzr add $parent failed\n"); + } + + my @cmdline = ("bzr", "mv", "--quiet", "$config{srcdir}/$src", "$config{srcdir}/$dest"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_recentchanges ($) { #{{{ + my ($num) = @_; + + my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num, + $config{srcdir}); + open (my $out, "@cmdline |"); + + eval q{use Date::Parse}; + error($@) if $@; + + my @ret; + foreach my $info (bzr_log($out)) { + my @pages = (); + my @message = (); + + foreach my $msgline (split(/\n/, $info->{message})) { + push @message, { line => $msgline }; + } + + foreach my $file (split(/\n/, $info->{files})) { + my ($filename, $fileid) = ($file =~ /^(.*?) +([^ ]+)$/); + + # Skip directories + next if ($filename =~ /\/$/); + + # Skip source name in renames + $filename =~ s/^.* => //; + + my $diffurl = defined $config{'diffurl'} ? $config{'diffurl'} : ""; + $diffurl =~ s/\[\[file\]\]/$filename/go; + $diffurl =~ s/\[\[file-id\]\]/$fileid/go; + $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go; + + push @pages, { + page => pagename($filename), + diffurl => $diffurl, + }; + } + + my $user = $info->{"committer"}; + if (defined($info->{"author"})) { $user = $info->{"author"}; } + $user =~ s/\s*<.*>\s*$//; + $user =~ s/^\s*//; + + push @ret, { + rev => $info->{"revno"}, + user => $user, + committype => "bzr", + when => time - str2time($info->{"timestamp"}), + message => [@message], + pages => [@pages], + }; + } + + return @ret; +} #}}} + +sub rcs_getctime ($) { #{{{ + my ($file) = @_; + + # XXX filename passes through the shell here, should try to avoid + # that just in case + my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file"); + open (my $out, "@cmdline |"); + + my @log = bzr_log($out); + + if (length @log < 1) { + return 0; + } + + eval q{use Date::Parse}; + error($@) if $@; + + my $ctime = str2time($log[0]->{"timestamp"}); + return $ctime; +} #}}} + +1 diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index aed087eed..6f1f9bd07 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -30,10 +30,22 @@ my $time=time; my @now=localtime($time); sub import { #{{{ - hook(type => "needsbuild", id => "version", call => \&needsbuild); + hook(type => "getsetup", id => "calendar", call => \&getsetup); + hook(type => "needsbuild", id => "calendar", call => \&needsbuild); hook(type => "preprocess", id => "calendar", call => \&preprocess); } #}}} +sub getsetup () { #{{{ + return + archivebase => { + type => "string", + example => "archives", + description => "base of the archives hierarchy", + safe => 1, + rebuild => 1, + }, +} #}}} + sub is_leap_year (@) { #{{{ my %params=@_; return ($params{year} % 4 == 0 && (($params{year} % 100 != 0) || $params{year} % 400 == 0)); diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm new file mode 100644 index 000000000..b683e4ec3 --- /dev/null +++ b/IkiWiki/Plugin/git.pm @@ -0,0 +1,564 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::git; + +use warnings; +use strict; +use IkiWiki; +use Encode; +use open qw{:utf8 :std}; + +my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums +my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "git", call => \&checkconfig); + hook(type => "getsetup", id => "git", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (! defined $config{gitorigin_branch}) { + $config{gitorigin_branch}="origin"; + } + if (! defined $config{gitmaster_branch}) { + $config{gitmaster_branch}="master"; + } + if (defined $config{git_wrapper} && length $config{git_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{git_wrapper}, + wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + git_wrapper => { + type => "string", + example => "/git/wiki.git/hooks/post-update", + description => "git post-update executable to generate", + safe => 0, # file + rebuild => 0, + }, + git_wrappermode => { + type => "string", + example => '06755', + description => "mode for git_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + historyurl => { + type => "string", + example => "http://git.example.com/gitweb.cgi?p=wiki.git;a=history;f=[[file]]", + description => "gitweb url to show file history ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + example => "http://git.example.com/gitweb.cgi?p=wiki.git;a=blobdiff;h=[[sha1_to]];hp=[[sha1_from]];hb=[[sha1_parent]];f=[[file]]", + description => "gitweb url to show a diff ([[sha1_to]], [[sha1_from]], [[sha1_parent]], and [[file]] substituted)", + safe => 1, + rebuild => 1, + }, + gitorigin_branch => { + type => "string", + example => "origin", + description => "where to pull and push changes (set to empty string to disable)", + safe => 0, # paranoia + rebuild => 0, + }, + gitmaster_branch => { + type => "string", + example => "master", + description => "branch that the wiki is stored in", + safe => 0, # paranoia + rebuild => 0, + }, +} #}}} + +sub safe_git (&@) { #{{{ + # Start a child process safely without resorting /bin/sh. + # Return command output or success state (in scalar context). + + my ($error_handler, @cmdline) = @_; + + my $pid = open my $OUT, "-|"; + + error("Cannot fork: $!") if !defined $pid; + + if (!$pid) { + # In child. + # Git commands want to be in wc. + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + exec @cmdline or error("Cannot exec '@cmdline': $!"); + } + # In parent. + + my @lines; + while (<$OUT>) { + chomp; + push @lines, $_; + } + + close $OUT; + + $error_handler->("'@cmdline' failed: $!") if $? && $error_handler; + + return wantarray ? @lines : ($? == 0); +} +# Convenient wrappers. +sub run_or_die ($@) { safe_git(\&error, @_) } +sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) } +sub run_or_non ($@) { safe_git(undef, @_) } +#}}} + +sub merge_past ($$$) { #{{{ + # Unlike with Subversion, Git cannot make a 'svn merge -rN:M file'. + # Git merge commands work with the committed changes, except in the + # implicit case of '-m' of git checkout(1). So we should invent a + # kludge here. In principle, we need to create a throw-away branch + # in preparing for the merge itself. Since branches are cheap (and + # branching is fast), this shouldn't cost high. + # + # The main problem is the presence of _uncommitted_ local changes. One + # possible approach to get rid of this situation could be that we first + # make a temporary commit in the master branch and later restore the + # initial state (this is possible since Git has the ability to undo a + # commit, i.e. 'git reset --soft HEAD^'). The method can be summarized + # as follows: + # + # - create a diff of HEAD:current-sha1 + # - dummy commit + # - create a dummy branch and switch to it + # - rewind to past (reset --hard to the current-sha1) + # - apply the diff and commit + # - switch to master and do the merge with the dummy branch + # - make a soft reset (undo the last commit of master) + # + # The above method has some drawbacks: (1) it needs a redundant commit + # just to get rid of local changes, (2) somewhat slow because of the + # required system forks. Until someone points a more straight method + # (which I would be grateful) I have implemented an alternative method. + # In this approach, we hide all the modified files from Git by renaming + # them (using the 'rename' builtin) and later restore those files in + # the throw-away branch (that is, we put the files themselves instead + # of applying a patch). + + my ($sha1, $file, $message) = @_; + + my @undo; # undo stack for cleanup in case of an error + my $conflict; # file content with conflict markers + + eval { + # Hide local changes from Git by renaming the modified file. + # Relative paths must be converted to absolute for renaming. + my ($target, $hidden) = ( + "$config{srcdir}/${file}", "$config{srcdir}/${file}.${sha1}" + ); + rename($target, $hidden) + or error("rename '$target' to '$hidden' failed: $!"); + # Ensure to restore the renamed file on error. + push @undo, sub { + return if ! -e "$hidden"; # already renamed + rename($hidden, $target) + or warn "rename '$hidden' to '$target' failed: $!"; + }; + + my $branch = "throw_away_${sha1}"; # supposed to be unique + + # Create a throw-away branch and rewind backward. + push @undo, sub { run_or_cry('git', 'branch', '-D', $branch) }; + run_or_die('git', 'branch', $branch, $sha1); + + # Switch to throw-away branch for the merge operation. + push @undo, sub { + if (!run_or_cry('git', 'checkout', $config{gitmaster_branch})) { + run_or_cry('git', 'checkout','-f',$config{gitmaster_branch}); + } + }; + run_or_die('git', 'checkout', $branch); + + # Put the modified file in _this_ branch. + rename($hidden, $target) + or error("rename '$hidden' to '$target' failed: $!"); + + # _Silently_ commit all modifications in the current branch. + run_or_non('git', 'commit', '-m', $message, '-a'); + # ... and re-switch to master. + run_or_die('git', 'checkout', $config{gitmaster_branch}); + + # Attempt to merge without complaining. + if (!run_or_non('git', 'pull', '--no-commit', '.', $branch)) { + $conflict = readfile($target); + run_or_die('git', 'reset', '--hard'); + } + }; + my $failure = $@; + + # Process undo stack (in reverse order). By policy cleanup + # actions should normally print a warning on failure. + while (my $handle = pop @undo) { + $handle->(); + } + + error("Git merge failed!\n$failure\n") if $failure; + + return $conflict; +} #}}} + +sub parse_diff_tree ($@) { #{{{ + # Parse the raw diff tree chunk and return the info hash. + # See git-diff-tree(1) for the syntax. + + my ($prefix, $dt_ref) = @_; + + # End of stream? + return if !defined @{ $dt_ref } || + !defined @{ $dt_ref }[0] || !length @{ $dt_ref }[0]; + + my %ci; + # Header line. + while (my $line = shift @{ $dt_ref }) { + return if $line !~ m/^(.+) ($sha1_pattern)/; + + my $sha1 = $2; + $ci{'sha1'} = $sha1; + last; + } + + # Identification lines for the commit. + while (my $line = shift @{ $dt_ref }) { + # Regexps are semi-stolen from gitweb.cgi. + if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { + $ci{'tree'} = $1; + } + elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) { + # XXX: collecting in reverse order + push @{ $ci{'parents'} }, $1; + } + elsif ($line =~ m/^(author|committer) (.*) ([0-9]+) (.*)$/) { + my ($who, $name, $epoch, $tz) = + ($1, $2, $3, $4 ); + + $ci{ $who } = $name; + $ci{ "${who}_epoch" } = $epoch; + $ci{ "${who}_tz" } = $tz; + + if ($name =~ m/^[^<]+\s+<([^@>]+)/) { + $ci{"${who}_username"} = $1; + } + elsif ($name =~ m/^([^<]+)\s+<>$/) { + $ci{"${who}_username"} = $1; + } + else { + $ci{"${who}_username"} = $name; + } + } + elsif ($line =~ m/^$/) { + # Trailing empty line signals next section. + last; + } + } + + debug("No 'tree' seen in diff-tree output") if !defined $ci{'tree'}; + + if (defined $ci{'parents'}) { + $ci{'parent'} = @{ $ci{'parents'} }[0]; + } + else { + $ci{'parent'} = 0 x 40; + } + + # Commit message (optional). + while ($dt_ref->[0] =~ /^ /) { + my $line = shift @{ $dt_ref }; + $line =~ s/^ //; + push @{ $ci{'comment'} }, $line; + } + shift @{ $dt_ref } if $dt_ref->[0] =~ /^$/; + + # Modified files. + while (my $line = shift @{ $dt_ref }) { + if ($line =~ m{^ + (:+) # number of parents + ([^\t]+)\t # modes, sha1, status + (.*) # file names + $}xo) { + my $num_parents = length $1; + my @tmp = split(" ", $2); + my ($file, $file_to) = split("\t", $3); + my @mode_from = splice(@tmp, 0, $num_parents); + my $mode_to = shift(@tmp); + my @sha1_from = splice(@tmp, 0, $num_parents); + my $sha1_to = shift(@tmp); + my $status = shift(@tmp); + + if ($file =~ m/^"(.*)"$/) { + ($file=$1) =~ s/\\([0-7]{1,3})/chr(oct($1))/eg; + } + $file =~ s/^\Q$prefix\E//; + if (length $file) { + push @{ $ci{'details'} }, { + 'file' => decode_utf8($file), + 'sha1_from' => $sha1_from[0], + 'sha1_to' => $sha1_to, + }; + } + next; + }; + last; + } + + return \%ci; +} #}}} + +sub git_commit_info ($;$) { #{{{ + # Return an array of commit info hashes of num commits (default: 1) + # starting from the given sha1sum. + + my ($sha1, $num) = @_; + + $num ||= 1; + + my @raw_lines = run_or_die('git', 'log', "--max-count=$num", + '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c', + '-r', $sha1, '--', '.'); + my ($prefix) = run_or_die('git', 'rev-parse', '--show-prefix'); + + my @ci; + while (my $parsed = parse_diff_tree(($prefix or ""), \@raw_lines)) { + push @ci, $parsed; + } + + warn "Cannot parse commit info for '$sha1' commit" if !@ci; + + return wantarray ? @ci : $ci[0]; +} #}}} + +sub git_sha1 (;$) { #{{{ + # Return head sha1sum (of given file). + + my $file = shift || q{--}; + + # Ignore error since a non-existing file might be given. + my ($sha1) = run_or_non('git', 'rev-list', '--max-count=1', 'HEAD', + '--', $file); + if ($sha1) { + ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now + } else { debug("Empty sha1sum for '$file'.") } + return defined $sha1 ? $sha1 : q{}; +} #}}} + +sub rcs_update () { #{{{ + # Update working directory. + + if (length $config{gitorigin_branch}) { + run_or_cry('git', 'pull', $config{gitorigin_branch}); + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + # Return the commit sha1sum of the file when editing begins. + # This will be later used in rcs_commit if a merge is required. + + my ($file) = @_; + + return git_sha1($file); +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + # Try to commit the page; returns undef on _success_ and + # a version of the page with the rcs's conflict markers on + # failure. + + my ($file, $message, $rcstoken, $user, $ipaddr) = @_; + + # Check to see if the page has been changed by someone else since + # rcs_prepedit was called. + my $cur = git_sha1($file); + my ($prev) = $rcstoken =~ /^($sha1_pattern)$/; # untaint + + if (defined $cur && defined $prev && $cur ne $prev) { + my $conflict = merge_past($prev, $file, $dummy_commit_msg); + return $conflict if defined $conflict; + } + + rcs_add($file); + return rcs_commit_staged($message, $user, $ipaddr); +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + # Set the commit author and email to the web committer. + my %env=%ENV; + if (defined $user || defined $ipaddr) { + my $u=defined $user ? $user : $ipaddr; + $ENV{GIT_AUTHOR_NAME}=$u; + $ENV{GIT_AUTHOR_EMAIL}="$u\@web"; + } + + $message = IkiWiki::possibly_foolish_untaint($message); + my @opts; + if ($message !~ /\S/) { + # Force git to allow empty commit messages. + # (If this version of git supports it.) + my ($version)=`git --version` =~ /git version (.*)/; + if ($version ge "1.5.4") { + push @opts, '--cleanup=verbatim'; + } + else { + $message.="."; + } + } + push @opts, '-q'; + # git commit returns non-zero if file has not been really changed. + # so we should ignore its exit status (hence run_or_non). + if (run_or_non('git', 'commit', @opts, '-m', $message)) { + if (length $config{gitorigin_branch}) { + run_or_cry('git', 'push', $config{gitorigin_branch}); + } + } + + %ENV=%env; + return undef; # success +} + +sub rcs_add ($) { # {{{ + # Add file to archive. + + my ($file) = @_; + + run_or_cry('git', 'add', $file); +} #}}} + +sub rcs_remove ($) { # {{{ + # Remove file from archive. + + my ($file) = @_; + + run_or_cry('git', 'rm', '-f', $file); +} #}}} + +sub rcs_rename ($$) { # {{{ + my ($src, $dest) = @_; + + run_or_cry('git', 'mv', '-f', $src, $dest); +} #}}} + +sub rcs_recentchanges ($) { #{{{ + # List of recent changes. + + my ($num) = @_; + + eval q{use Date::Parse}; + error($@) if $@; + + my @rets; + foreach my $ci (git_commit_info('HEAD', $num)) { + # Skip redundant commits. + next if ($ci->{'comment'} && @{$ci->{'comment'}}[0] eq $dummy_commit_msg); + + my ($sha1, $when) = ( + $ci->{'sha1'}, + $ci->{'author_epoch'} + ); + + my @pages; + foreach my $detail (@{ $ci->{'details'} }) { + my $file = $detail->{'file'}; + + my $diffurl = defined $config{'diffurl'} ? $config{'diffurl'} : ""; + $diffurl =~ s/\[\[file\]\]/$file/go; + $diffurl =~ s/\[\[sha1_parent\]\]/$ci->{'parent'}/go; + $diffurl =~ s/\[\[sha1_from\]\]/$detail->{'sha1_from'}/go; + $diffurl =~ s/\[\[sha1_to\]\]/$detail->{'sha1_to'}/go; + + push @pages, { + page => pagename($file), + diffurl => $diffurl, + }; + } + + my @messages; + my $pastblank=0; + foreach my $line (@{$ci->{'comment'}}) { + $pastblank=1 if $line eq ''; + next if $pastblank && $line=~m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i; + push @messages, { line => $line }; + } + + my $user=$ci->{'author_username'}; + my $web_commit = ($ci->{'author'} =~ /\@web>/); + + # compatability code for old web commit messages + if (! $web_commit && + defined $messages[0] && + $messages[0]->{line} =~ m/$config{web_commit_regexp}/) { + $user = defined $2 ? "$2" : "$3"; + $messages[0]->{line} = $4; + $web_commit=1; + } + + push @rets, { + rev => $sha1, + user => $user, + committype => $web_commit ? "web" : "git", + when => $when, + message => [@messages], + pages => [@pages], + } if @pages; + + last if @rets >= $num; + } + + return @rets; +} #}}} + +sub rcs_diff ($) { #{{{ + my $rev=shift; + my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint + my @lines; + foreach my $line (run_or_non("git", "show", $sha1)) { + if (@lines || $line=~/^diff --git/) { + push @lines, $line."\n"; + } + } + if (wantarray) { + return @lines; + } + else { + return join("", @lines); + } +} #}}} + +sub rcs_getctime ($) { #{{{ + my $file=shift; + # Remove srcdir prefix + $file =~ s/^\Q$config{srcdir}\E\/?//; + + my $sha1 = git_sha1($file); + my $ci = git_commit_info($sha1); + my $ctime = $ci->{'author_epoch'}; + debug("ctime for '$file': ". localtime($ctime)); + + return $ctime; +} #}}} + +1 diff --git a/IkiWiki/Plugin/graphviz.pm b/IkiWiki/Plugin/graphviz.pm index b13d15fa6..021aa6b23 100644 --- a/IkiWiki/Plugin/graphviz.pm +++ b/IkiWiki/Plugin/graphviz.pm @@ -9,7 +9,7 @@ use IkiWiki 2.00; use IPC::Open2; sub import { #{{{ - hook(type => "preprocess", id => "graph", call => \&graph); + hook(type => "preprocess", id => "graphviz", call => \&graph); } # }}} my %graphviz_programs = ( diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 2f0901943..ed7a58408 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -15,6 +15,7 @@ my $nested=0; sub import { #{{{ hook(type => "getopt", id => "inline", call => \&getopt); + hook(type => "getsetup", id => "inline", call => \&getsetup); hook(type => "checkconfig", id => "inline", call => \&checkconfig); hook(type => "sessioncgi", id => "inline", call => \&sessioncgi); hook(type => "preprocess", id => "inline", @@ -27,7 +28,6 @@ sub import { #{{{ # pings interrupting page builds. hook(type => "change", id => "inline", call => \&IkiWiki::pingurl); - } # }}} sub getopt () { #{{{ @@ -39,8 +39,50 @@ sub getopt () { #{{{ "atom!" => \$config{atom}, "allowrss!" => \$config{allowrss}, "allowatom!" => \$config{allowatom}, + "pingurl=s" => sub { + push @{$config{pingurl}}, $_[1]; + }, ); -} +} #}}} + +sub getsetup () { #{{{ + return + rss => { + type => "boolean", + example => 0, + description => "enable rss feeds by default?", + safe => 1, + rebuild => 1, + }, + atom => { + type => "boolean", + example => 0, + description => "enable atom feeds by default?", + safe => 1, + rebuild => 1, + }, + allowrss => { + type => "boolean", + example => 0, + description => "allow rss feeds to be used?", + safe => 1, + rebuild => 1, + }, + allowatom => { + type => "boolean", + example => 0, + description => "allow atom feeds to be used?", + safe => 1, + rebuild => 1, + }, + pingurl => { + type => "string", + example => "http://rpc.technorati.com/rpc/ping", + description => "urls to ping (using XML-RPC) on feed update", + safe => 1, + rebuild => 0, + }, +} #}}} sub checkconfig () { #{{{ if (($config{rss} || $config{atom}) && ! length $config{url}) { @@ -52,6 +94,9 @@ sub checkconfig () { #{{{ if ($config{atom}) { push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/; } + if (! exists $config{pingurl}) { + $config{pingurl}=[]; + } } #}}} sub format (@) { #{{{ @@ -202,7 +247,7 @@ sub preprocess_inline (@) { #{{{ my $atomurl=basename(atompage($params{destpage}).$feednum) if $feeds && $atom; my $ret=""; - if ($config{cgiurl} && ! $params{preview} && (exists $params{rootpage} || + if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} || (exists $params{postform} && yesno($params{postform})))) { # Add a blog post form, with feed buttons. my $formtemplate=template("blogpost.tmpl", blind_cache => 1); diff --git a/IkiWiki/Plugin/mdwn.pm b/IkiWiki/Plugin/mdwn.pm index 11f3f0137..332325adc 100644 --- a/IkiWiki/Plugin/mdwn.pm +++ b/IkiWiki/Plugin/mdwn.pm @@ -7,9 +7,21 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "mdwn", call => \&getsetup); hook(type => "htmlize", id => "mdwn", call => \&htmlize); } # }}} +sub getsetup () { #{{{ + return + multimarkdown => { + type => "boolean", + example => 0, + description => "enable multimarkdown features?", + safe => 1, + rebuild => 1, + }, +} #}}} + my $markdown_sub; sub htmlize (@) { #{{{ my %params=@_; @@ -25,13 +37,13 @@ sub htmlize (@) { #{{{ if (exists $config{multimarkdown} && $config{multimarkdown}) { eval q{use Text::MultiMarkdown}; if ($@) { - error(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed")); + debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed")); } $markdown_sub=sub { Text::MultiMarkdown::markdown(shift, {use_metadata => 0}); } } - else { + if (! defined $markdown_sub) { eval q{use Text::Markdown}; if (! $@) { if (Text::Markdown->can('markdown')) { diff --git a/IkiWiki/Plugin/mercurial.pm b/IkiWiki/Plugin/mercurial.pm new file mode 100644 index 000000000..b05c954dc --- /dev/null +++ b/IkiWiki/Plugin/mercurial.pm @@ -0,0 +1,255 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::mercurial; + +use warnings; +use strict; +use IkiWiki; +use Encode; +use open qw{:utf8 :std}; + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "mercurial", call => \&checkconfig); + hook(type => "getsetup", id => "mercurial", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (exists $config{mercurial_wrapper} && length $config{mercurial_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{mercurial_wrapper}, + wrappermode => (defined $config{mercurial_wrappermode} ? $config{mercurial_wrappermode} : "06755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + mercurial_wrapper => { + type => "string", + #example => # FIXME add example + description => "mercurial post-commit executable to generate", + safe => 0, # file + rebuild => 0, + }, + mercurial_wrappermode => { + type => "string", + example => '06755', + description => "mode for mercurial_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + historyurl => { + type => "string", + example => "http://example.com:8000/log/tip/[[file]]", + description => "url to hg serve'd repository, to show file history ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + example => "http://localhost:8000/?fd=[[r2]];file=[[file]]", + description => "url to hg serve'd repository, to show diff ([[file]] and [[r2]] substituted)", + safe => 1, + rebuild => 1, + }, +} #}}} + +sub mercurial_log ($) { #{{{ + my $out = shift; + my @infos; + + while (<$out>) { + my $line = $_; + my ($key, $value); + + if (/^description:/) { + $key = "description"; + $value = ""; + + # slurp everything as the description text + # until the next changeset + while (<$out>) { + if (/^changeset: /) { + $line = $_; + last; + } + + $value .= $_; + } + + local $/ = ""; + chomp $value; + $infos[$#infos]{$key} = $value; + } + + chomp $line; + ($key, $value) = split /: +/, $line, 2; + + if ($key eq "changeset") { + push @infos, {}; + + # remove the revision index, which is strictly + # local to the repository + $value =~ s/^\d+://; + } + + $infos[$#infos]{$key} = $value; + } + close $out; + + return @infos; +} #}}} + +sub rcs_update () { #{{{ + my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + return ""; +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + my ($file, $message, $rcstoken, $user, $ipaddr) = @_; + + if (defined $user) { + $user = IkiWiki::possibly_foolish_untaint($user); + } + elsif (defined $ipaddr) { + $user = "Anonymous from ".IkiWiki::possibly_foolish_untaint($ipaddr); + } + else { + $user = "Anonymous"; + } + + $message = IkiWiki::possibly_foolish_untaint($message); + if (! length $message) { + $message = "no message given"; + } + + my @cmdline = ("hg", "-q", "-R", $config{srcdir}, "commit", + "-m", $message, "-u", $user); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } + + return undef; # success +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + error("rcs_commit_staged not implemented for mercurial"); # TODO +} + +sub rcs_add ($) { # {{{ + my ($file) = @_; + + my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_remove ($) { # {{{ + my ($file) = @_; + + error("rcs_remove not implemented for mercurial"); # TODO +} #}}} + +sub rcs_rename ($$) { # {{{ + my ($src, $dest) = @_; + + error("rcs_rename not implemented for mercurial"); # TODO +} #}}} + +sub rcs_recentchanges ($) { #{{{ + my ($num) = @_; + + my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num, + "--style", "default"); + open (my $out, "@cmdline |"); + + eval q{use Date::Parse}; + error($@) if $@; + + my @ret; + foreach my $info (mercurial_log($out)) { + my @pages = (); + my @message = (); + + foreach my $msgline (split(/\n/, $info->{description})) { + push @message, { line => $msgline }; + } + + foreach my $file (split / /,$info->{files}) { + my $diffurl = defined $config{diffurl} ? $config{'diffurl'} : ""; + $diffurl =~ s/\[\[file\]\]/$file/go; + $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go; + + push @pages, { + page => pagename($file), + diffurl => $diffurl, + }; + } + + my $user = $info->{"user"}; + $user =~ s/\s*<.*>\s*$//; + $user =~ s/^\s*//; + + push @ret, { + rev => $info->{"changeset"}, + user => $user, + committype => "mercurial", + when => str2time($info->{"date"}), + message => [@message], + pages => [@pages], + }; + } + + return @ret; +} #}}} + +sub rcs_diff ($) { #{{{ + # TODO +} #}}} + +sub rcs_getctime ($) { #{{{ + my ($file) = @_; + + # XXX filename passes through the shell here, should try to avoid + # that just in case + my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", '1', + "--style", "default", "$config{srcdir}/$file"); + open (my $out, "@cmdline |"); + + my @log = mercurial_log($out); + + if (length @log < 1) { + return 0; + } + + eval q{use Date::Parse}; + error($@) if $@; + + my $ctime = str2time($log[0]->{"date"}); + return $ctime; +} #}}} + +1 diff --git a/IkiWiki/Plugin/mirrorlist.pm b/IkiWiki/Plugin/mirrorlist.pm index 3997e6fef..f7c78fdee 100644 --- a/IkiWiki/Plugin/mirrorlist.pm +++ b/IkiWiki/Plugin/mirrorlist.pm @@ -6,9 +6,21 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "mirrorlist", call => \&getsetup); hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate); } # }}} +sub getsetup () { #{{{ + return + mirrorlist => { + type => "string", + example => {}, + description => "list of mirrors", + safe => 1, + rebuild => 1, + }, +} #}}} + sub pagetemplate (@) { #{{{ my %params=@_; my $template=$params{template}; diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm new file mode 100644 index 000000000..a591ecec5 --- /dev/null +++ b/IkiWiki/Plugin/monotone.pm @@ -0,0 +1,695 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::monotone; + +use warnings; +use strict; +use IkiWiki; +use Monotone; +use Date::Parse qw(str2time); +use Date::Format qw(time2str); + +my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate sha1sums + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "monotone", call => \&checkconfig); + hook(type => "getsetup", id => "monotone", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (!defined($config{mtnrootdir})) { + $config{mtnrootdir} = $config{srcdir}; + } + if (! -d "$config{mtnrootdir}/_MTN") { + error("Ikiwiki srcdir does not seem to be a Monotone workspace (or set the mtnrootdir)!"); + } + + my $child = open(MTN, "-|"); + if (! $child) { + open STDERR, ">/dev/null"; + exec("mtn", "version") || error("mtn version failed to run"); + } + + my $version=undef; + while (<MTN>) { + if (/^monotone (\d+\.\d+) /) { + $version=$1; + } + } + + close MTN || debug("mtn version exited $?"); + + if (!defined($version)) { + error("Cannot determine monotone version"); + } + if ($version < 0.38) { + error("Monotone version too old, is $version but required 0.38"); + } + + if (length $config{mtn_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{mtn_wrapper}, + wrappermode => (defined $config{mtn_wrappermode} ? $config{mtn_wrappermode} : "06755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + mtn_wrapper => { + type => "string", + example => "/srv/mtn/wiki/_MTN/ikiwiki-netsync-hook", + description => "monotone netsync hook executable to generate", + safe => 0, # file + rebuild => 0, + }, + mtn_wrappermode => { + type => "string", + example => '06755', + description => "mode for mtn_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + mtnkey => { + type => "string", + example => 'web@example.com', + description => "your monotone key", + safe => 1, + rebuild => 0, + }, + historyurl => { + type => "string", + example => "http://viewmtn.example.com/branch/head/filechanges/com.example.branch/[[file]]", + description => "viewmtn url to show file history ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + example => "http://viewmtn.example.com/revision/diff/[[r1]]/with/[[r2]]/[[file]]", + description => "viewmtn url to show a diff ([[r1]], [[r2]], and [[file]] substituted)", + safe => 1, + rebuild => 1, + }, + mtnsync => { + type => "boolean", + example => 0, + description => "sync on update and commit?", + safe => 0, # paranoia + rebuild => 0, + }, + mtnrootdir => { + type => "string", + description => "path to your workspace (defaults to the srcdir; specify if the srcdir is a subdirectory of the workspace)", + safe => 0, # path + rebuild => 0, + }, +} #}}} + +sub get_rev () { #{{{ + my $sha1 = `mtn --root=$config{mtnrootdir} automate get_base_revision_id`; + + ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now + if (! $sha1) { + debug("Unable to get base revision for '$config{srcdir}'.") + } + + return $sha1; +} #}}} + +sub get_rev_auto ($) { #{{{ + my $automator=shift; + + my @results = $automator->call("get_base_revision_id"); + + my $sha1 = $results[0]; + ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now + if (! $sha1) { + debug("Unable to get base revision for '$config{srcdir}'.") + } + + return $sha1; +} #}}} + +sub mtn_merge ($$$$) { #{{{ + my $leftRev=shift; + my $rightRev=shift; + my $branch=shift; + my $author=shift; + + my $mergeRev; + + my $child = open(MTNMERGE, "-|"); + if (! $child) { + open STDERR, ">&STDOUT"; + exec("mtn", "--root=$config{mtnrootdir}", + "explicit_merge", $leftRev, $rightRev, + $branch, "--author", $author, "--key", + $config{mtnkey}) || error("mtn merge failed to run"); + } + + while (<MTNMERGE>) { + if (/^mtn.\s.merged.\s($sha1_pattern)$/) { + $mergeRev=$1; + } + } + + close MTNMERGE || return undef; + + debug("merged $leftRev, $rightRev to make $mergeRev"); + + return $mergeRev; +} #}}} + +sub commit_file_to_new_rev ($$$$$$$$) { #{{{ + my $automator=shift; + my $wsfilename=shift; + my $oldFileID=shift; + my $newFileContents=shift; + my $oldrev=shift; + my $branch=shift; + my $author=shift; + my $message=shift; + + #store the file + my ($out, $err) = $automator->call("put_file", $oldFileID, $newFileContents); + my ($newFileID) = ($out =~ m/^($sha1_pattern)$/); + error("Failed to store file data for $wsfilename in repository") + if (! defined $newFileID || length $newFileID != 40); + + # get the mtn filename rather than the workspace filename + ($out, $err) = $automator->call("get_corresponding_path", $oldrev, $wsfilename, $oldrev); + my ($filename) = ($out =~ m/^file "(.*)"$/); + error("Couldn't find monotone repository path for file $wsfilename") if (! $filename); + debug("Converted ws filename of $wsfilename to repos filename of $filename"); + + # then stick in a new revision for this file + my $manifest = "format_version \"1\"\n\n". + "new_manifest [0000000000000000000000000000000000000000]\n\n". + "old_revision [$oldrev]\n\n". + "patch \"$filename\"\n". + " from [$oldFileID]\n". + " to [$newFileID]\n"; + ($out, $err) = $automator->call("put_revision", $manifest); + my ($newRevID) = ($out =~ m/^($sha1_pattern)$/); + error("Unable to make new monotone repository revision") + if (! defined $newRevID || length $newRevID != 40); + debug("put revision: $newRevID"); + + # now we need to add certs for this revision... + # author, branch, changelog, date + $automator->call("cert", $newRevID, "author", $author); + $automator->call("cert", $newRevID, "branch", $branch); + $automator->call("cert", $newRevID, "changelog", $message); + $automator->call("cert", $newRevID, "date", + time2str("%Y-%m-%dT%T", time, "UTC")); + + debug("Added certs for rev: $newRevID"); + return $newRevID; +} #}}} + +sub read_certs ($$) { #{{{ + my $automator=shift; + my $rev=shift; + my @results = $automator->call("certs", $rev); + my @ret; + + my $line = $results[0]; + while ($line =~ m/\s+key\s"(.*?)"\nsignature\s"(ok|bad|unknown)"\n\s+name\s"(.*?)"\n\s+value\s"(.*?)"\n\s+trust\s"(trusted|untrusted)"\n/sg) { + push @ret, { + key => $1, + signature => $2, + name => $3, + value => $4, + trust => $5, + }; + } + + return @ret; +} #}}} + +sub get_changed_files ($$) { #{{{ + my $automator=shift; + my $rev=shift; + + my @results = $automator->call("get_revision", $rev); + my $changes=$results[0]; + + my @ret; + my %seen = (); + + while ($changes =~ m/\s*(add_file|patch|delete|rename)\s"(.*?)(?<!\\)"\n/sg) { + my $file = $2; + # don't add the same file multiple times + if (! $seen{$file}) { + push @ret, $file; + $seen{$file} = 1; + } + } + + return @ret; +} #}}} + +sub rcs_update () { #{{{ + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + if (defined($config{mtnsync}) && $config{mtnsync}) { + if (system("mtn", "--root=$config{mtnrootdir}", "sync", + "--quiet", "--ticker=none", + "--key", $config{mtnkey}) != 0) { + debug("monotone sync failed before update"); + } + } + + if (system("mtn", "--root=$config{mtnrootdir}", "update", "--quiet") != 0) { + debug("monotone update failed"); + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + my $file=shift; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + # For monotone, return the revision of the file when + # editing begins. + return get_rev(); +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + # Tries to commit the page; returns undef on _success_ and + # a version of the page with the rcs's conflict markers on failure. + # The file is relative to the srcdir. + my $file=shift; + my $message=shift; + my $rcstoken=shift; + my $user=shift; + my $ipaddr=shift; + my $author; + + if (defined $user) { + $author="Web user: " . $user; + } + elsif (defined $ipaddr) { + $author="Web IP: " . $ipaddr; + } + else { + $author="Web: Anonymous"; + } + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + my ($oldrev)= $rcstoken=~ m/^($sha1_pattern)$/; # untaint + my $rev = get_rev(); + if (defined $rev && defined $oldrev && $rev ne $oldrev) { + my $automator = Monotone->new(); + $automator->open_args("--root", $config{mtnrootdir}, "--key", $config{mtnkey}); + + # Something has been committed, has this file changed? + my ($out, $err); + $automator->setOpts("r", $oldrev, "r", $rev); + ($out, $err) = $automator->call("content_diff", $file); + debug("Problem committing $file") if ($err ne ""); + my $diff = $out; + + if ($diff) { + # Commit a revision with just this file changed off + # the old revision. + # + # first get the contents + debug("File changed: forming branch"); + my $newfile=readfile("$config{srcdir}/$file"); + + # then get the old content ID from the diff + if ($diff !~ m/^---\s$file\s+($sha1_pattern)$/m) { + error("Unable to find previous file ID for $file"); + } + my $oldFileID = $1; + + # get the branch we're working in + ($out, $err) = $automator->call("get_option", "branch"); + chomp $out; + error("Illegal branch name in monotone workspace") if ($out !~ m/^([-\@\w\.]+)$/); + my $branch = $1; + + # then put the new content into the DB (and record the new content ID) + my $newRevID = commit_file_to_new_rev($automator, $file, $oldFileID, $newfile, $oldrev, $branch, $author, $message); + + $automator->close(); + + # if we made it to here then the file has been committed... revert the local copy + if (system("mtn", "--root=$config{mtnrootdir}", "revert", $file) != 0) { + debug("Unable to revert $file after merge on conflicted commit!"); + } + debug("Divergence created! Attempting auto-merge."); + + # see if it will merge cleanly + $ENV{MTN_MERGE}="fail"; + my $mergeResult = mtn_merge($newRevID, $rev, $branch, $author); + $ENV{MTN_MERGE}=""; + + # push any changes so far + if (defined($config{mtnsync}) && $config{mtnsync}) { + if (system("mtn", "--root=$config{mtnrootdir}", "push", "--quiet", "--ticker=none", "--key", $config{mtnkey}) != 0) { + debug("monotone push failed"); + } + } + + if (defined($mergeResult)) { + # everything is merged - bring outselves up to date + if (system("mtn", "--root=$config{mtnrootdir}", + "update", "-r", $mergeResult) != 0) { + debug("Unable to update to rev $mergeResult after merge on conflicted commit!"); + } + } + else { + debug("Auto-merge failed. Using diff-merge to add conflict markers."); + + $ENV{MTN_MERGE}="diffutils"; + $ENV{MTN_MERGE_DIFFUTILS}="partial=true"; + $mergeResult = mtn_merge($newRevID, $rev, $branch, $author); + $ENV{MTN_MERGE}=""; + $ENV{MTN_MERGE_DIFFUTILS}=""; + + if (!defined($mergeResult)) { + debug("Unable to insert conflict markers!"); + error("Your commit succeeded. Unfortunately, someone else committed something to the same ". + "part of the wiki at the same time. Both versions are stored in the monotone repository, ". + "but at present the different versions cannot be reconciled through the web interface. ". + "Please use the non-web interface to resolve the conflicts."); + } + + if (system("mtn", "--root=$config{mtnrootdir}", + "update", "-r", $mergeResult) != 0) { + debug("Unable to update to rev $mergeResult after conflict-enhanced merge on conflicted commit!"); + } + + # return "conflict enhanced" file to the user + # for cleanup note, this relies on the fact + # that ikiwiki seems to call rcs_prepedit() + # again after we return + return readfile("$config{srcdir}/$file"); + } + return undef; + } + $automator->close(); + } + + # If we reached here then the file we're looking at hasn't changed + # since $oldrev. Commit it. + + if (system("mtn", "--root=$config{mtnrootdir}", "commit", "--quiet", + "--author", $author, "--key", $config{mtnkey}, "-m", + IkiWiki::possibly_foolish_untaint($message), $file) != 0) { + debug("Traditional commit failed! Returning data as conflict."); + my $conflict=readfile("$config{srcdir}/$file"); + if (system("mtn", "--root=$config{mtnrootdir}", "revert", + "--quiet", $file) != 0) { + debug("monotone revert failed"); + } + return $conflict; + } + if (defined($config{mtnsync}) && $config{mtnsync}) { + if (system("mtn", "--root=$config{mtnrootdir}", "push", + "--quiet", "--ticker=none", "--key", + $config{mtnkey}) != 0) { + debug("monotone push failed"); + } + } + + return undef # success +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + # Note - this will also commit any spurious changes that happen to be + # lying around in the working copy. There shouldn't be any, but... + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + my $author; + + if (defined $user) { + $author="Web user: " . $user; + } + elsif (defined $ipaddr) { + $author="Web IP: " . $ipaddr; + } + else { + $author="Web: Anonymous"; + } + + if (system("mtn", "--root=$config{mtnrootdir}", "commit", "--quiet", + "--author", $author, "--key", $config{mtnkey}, "-m", + IkiWiki::possibly_foolish_untaint($message)) != 0) { + error("Monotone commit failed"); + } +} + +sub rcs_add ($) { #{{{ + my $file=shift; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + if (system("mtn", "--root=$config{mtnrootdir}", "add", "--quiet", + $file) != 0) { + error("Monotone add failed"); + } +} #}}} + +sub rcs_remove ($) { # {{{ + my $file = shift; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + # Note: it is difficult to undo a remove in Monotone at the moment. + # Until this is fixed, it might be better to make 'rm' move things + # into an attic, rather than actually remove them. + # To resurrect a file, you currently add a new file with the contents + # you want it to have. This loses all connectivity and automated + # merging with the 'pre-delete' versions of the file. + + if (system("mtn", "--root=$config{mtnrootdir}", "rm", "--quiet", + $file) != 0) { + error("Monotone remove failed"); + } +} #}}} + +sub rcs_rename ($$) { # {{{ + my ($src, $dest) = @_; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + if (system("mtn", "--root=$config{mtnrootdir}", "rename", "--quiet", + $src, $dest) != 0) { + error("Monotone rename failed"); + } +} #}}} + +sub rcs_recentchanges ($) { #{{{ + my $num=shift; + my @ret; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + # use log --brief to get a list of revs, as this + # gives the results in a nice order + # (otherwise we'd have to do our own date sorting) + + my @revs; + + my $child = open(MTNLOG, "-|"); + if (! $child) { + exec("mtn", "log", "--root=$config{mtnrootdir}", "--no-graph", + "--brief") || error("mtn log failed to run"); + } + + while (($num >= 0) and (my $line = <MTNLOG>)) { + if ($line =~ m/^($sha1_pattern)/) { + push @revs, $1; + $num -= 1; + } + } + close MTNLOG || debug("mtn log exited $?"); + + my $automator = Monotone->new(); + $automator->open(undef, $config{mtnrootdir}); + + while (@revs != 0) { + my $rev = shift @revs; + # first go through and figure out the messages, etc + + my $certs = [read_certs($automator, $rev)]; + + my $user; + my $when; + my $committype; + my (@pages, @message); + + foreach my $cert (@$certs) { + if ($cert->{signature} eq "ok" && + $cert->{trust} eq "trusted") { + if ($cert->{name} eq "author") { + $user = $cert->{value}; + # detect the source of the commit + # from the changelog + if ($cert->{key} eq $config{mtnkey}) { + $committype = "web"; + } else { + $committype = "monotone"; + } + } elsif ($cert->{name} eq "date") { + $when = str2time($cert->{value}, 'UTC'); + } elsif ($cert->{name} eq "changelog") { + my $messageText = $cert->{value}; + # split the changelog into multiple + # lines + foreach my $msgline (split(/\n/, $messageText)) { + push @message, { line => $msgline }; + } + } + } + } + + my @changed_files = get_changed_files($automator, $rev); + my $file; + + my ($out, $err) = $automator->call("parents", $rev); + my @parents = ($out =~ m/^($sha1_pattern)$/); + my $parent = $parents[0]; + + foreach $file (@changed_files) { + next unless length $file; + + if (defined $config{diffurl} and (@parents == 1)) { + my $diffurl=$config{diffurl}; + $diffurl=~s/\[\[r1\]\]/$parent/g; + $diffurl=~s/\[\[r2\]\]/$rev/g; + $diffurl=~s/\[\[file\]\]/$file/g; + push @pages, { + page => pagename($file), + diffurl => $diffurl, + }; + } + else { + push @pages, { + page => pagename($file), + } + } + } + + push @ret, { + rev => $rev, + user => $user, + committype => $committype, + when => $when, + message => [@message], + pages => [@pages], + } if @pages; + } + + $automator->close(); + + return @ret; +} #}}} + +sub rcs_diff ($) { #{{{ + my $rev=shift; + my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + my $child = open(MTNDIFF, "-|"); + if (! $child) { + exec("mtn", "diff", "--root=$config{mtnrootdir}", "-r", "p:".$sha1, "-r", $sha1) || error("mtn diff $sha1 failed to run"); + } + + my (@lines) = <MTNDIFF>; + + close MTNDIFF || debug("mtn diff $sha1 exited $?"); + + if (wantarray) { + return @lines; + } + else { + return join("", @lines); + } +} #}}} + +sub rcs_getctime ($) { #{{{ + my $file=shift; + + chdir $config{srcdir} + or error("Cannot chdir to $config{srcdir}: $!"); + + my $child = open(MTNLOG, "-|"); + if (! $child) { + exec("mtn", "log", "--root=$config{mtnrootdir}", "--no-graph", + "--brief", $file) || error("mtn log $file failed to run"); + } + + my $firstRev; + while (<MTNLOG>) { + if (/^($sha1_pattern)/) { + $firstRev=$1; + } + } + close MTNLOG || debug("mtn log $file exited $?"); + + if (! defined $firstRev) { + debug "failed to parse mtn log for $file"; + return 0; + } + + my $automator = Monotone->new(); + $automator->open(undef, $config{mtnrootdir}); + + my $certs = [read_certs($automator, $firstRev)]; + + $automator->close(); + + my $date; + + foreach my $cert (@$certs) { + if ($cert->{signature} eq "ok" && $cert->{trust} eq "trusted") { + if ($cert->{name} eq "date") { + $date = $cert->{value}; + } + } + } + + if (! defined $date) { + debug "failed to find date cert for revision $firstRev when looking for creation time of $file"; + return 0; + } + + $date=str2time($date, 'UTC'); + debug("found ctime ".localtime($date)." for $file"); + return $date; +} #}}} + +1 diff --git a/IkiWiki/Plugin/norcs.pm b/IkiWiki/Plugin/norcs.pm new file mode 100644 index 000000000..72c66569c --- /dev/null +++ b/IkiWiki/Plugin/norcs.pm @@ -0,0 +1,58 @@ +#!/usr/bin/perl +# Stubs for no revision control. +package IkiWiki::Plugin::norcs; + +use warnings; +use strict; +use IkiWiki; + +sub import { #{{{ + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub rcs_update () { #{{{ +} #}}} + +sub rcs_prepedit ($) { #{{{ + return "" +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + my ($file, $message, $rcstoken, $user, $ipaddr) = @_; + return undef # success +} #}}} + +sub rcs_commit_staged ($$$) { #{{{ + my ($message, $user, $ipaddr)=@_; + return undef # success +} #}}} + +sub rcs_add ($) { #{{{ +} #}}} + +sub rcs_remove ($) { #{{{ +} #}}} + +sub rcs_rename ($$) { #{{{ +} #}}} + +sub rcs_recentchanges ($) { #{{{ +} #}}} + +sub rcs_diff ($) { #{{{ +} #}}} + +sub rcs_getctime ($) { #{{{ + error gettext("getctime not implemented"); +} #}}} + +1 diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index 10a8fa22f..de7f7280e 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -8,6 +8,7 @@ use IkiWiki 2.00; sub import { #{{{ hook(type => "getopt", id => "openid", call => \&getopt); + hook(type => "getsetup", id => "openid", call => \&getsetup); hook(type => "auth", id => "openid", call => \&auth); hook(type => "formbuilder_setup", id => "openid", call => \&formbuilder_setup, last => 1); @@ -20,6 +21,17 @@ sub getopt () { #{{{ GetOptions("openidsignup=s" => \$config{openidsignup}); } #}}} +sub getsetup () { #{{{ + return + openidsignup => { + type => "string", + example => "http://myopenid.com/", + description => "an url where users can signup for an OpenID", + safe => 1, + rebuild => 0, + }, +} #}}} + sub formbuilder_setup (@) { #{{{ my %params=@_; diff --git a/IkiWiki/Plugin/passwordauth.pm b/IkiWiki/Plugin/passwordauth.pm index f3f1aa4bf..82afeef98 100644 --- a/IkiWiki/Plugin/passwordauth.pm +++ b/IkiWiki/Plugin/passwordauth.pm @@ -7,13 +7,30 @@ use strict; use IkiWiki 2.00; sub import { #{{{ - hook(type => "formbuilder_setup", id => "passwordauth", - call => \&formbuilder_setup); - hook(type => "formbuilder", id => "passwordauth", - call => \&formbuilder); + hook(type => "getsetup", id => "passwordauth", "call" => \&getsetup); + hook(type => "formbuilder_setup", id => "passwordauth", call => \&formbuilder_setup); + hook(type => "formbuilder", id => "passwordauth", call => \&formbuilder); hook(type => "sessioncgi", id => "passwordauth", call => \&sessioncgi); } # }}} +sub getsetup () { #{{{ + return + account_creation_password => { + type => "string", + example => "s3cr1t", + description => "a password that must be entered when signing up for an account", + safe => 1, + rebuild => 0, + }, + password_cost => { + type => "integer", + example => 8, + description => "cost of generating a password using Authen::Passphrase::BlowfishCrypt", + safe => 1, + rebuild => 0, + }, +} #}}} + # Checks if a string matches a user's password, and returns true or false. sub checkpassword ($$;$) { #{{{ my $user=shift; @@ -88,7 +105,9 @@ sub formbuilder_setup (@) { #{{{ if ($form->submitted eq "Register" || $form->submitted eq "Create Account") { $form->field(name => "confirm_password", type => "password"); - $form->field(name => "account_creation_password", type => "password") if (length $config{account_creation_password}); + $form->field(name => "account_creation_password", type => "password") + if (defined $config{account_creation_password} && + length $config{account_creation_password}); $form->field(name => "email", size => 50); $form->title("register"); $form->text(""); @@ -125,7 +144,8 @@ sub formbuilder_setup (@) { #{{{ shift eq $config{account_creation_password}; }, required => 1, - ) if (length $config{account_creation_password}); + ) if (defined $config{account_creation_password} && + length $config{account_creation_password}); $form->field( name => "email", validate => "EMAIL", @@ -259,7 +279,9 @@ sub formbuilder (@) { #{{{ error($@) if $@; sendmail( To => IkiWiki::userinfo_get($user_name, "email"), - From => "$config{wikiname} admin <$config{adminemail}>", + From => "$config{wikiname} admin <". + (defined $config{adminemail} ? $config{adminemail} : "") + .">", Subject => "$config{wikiname} information", Message => $template->output, ) or error(gettext("Failed to send mail")); diff --git a/IkiWiki/Plugin/pinger.pm b/IkiWiki/Plugin/pinger.pm index 614d42885..e72833b8f 100644 --- a/IkiWiki/Plugin/pinger.pm +++ b/IkiWiki/Plugin/pinger.pm @@ -9,12 +9,24 @@ my %pages; my $pinged=0; sub import { #{{{ + hook(type => "getsetup", id => "pinger", call => \&getsetup); hook(type => "needsbuild", id => "pinger", call => \&needsbuild); hook(type => "preprocess", id => "ping", call => \&preprocess); hook(type => "delete", id => "pinger", call => \&ping); hook(type => "change", id => "pinger", call => \&ping); } # }}} +sub getsetup () { #{{{ + return + pinger_timeout => { + type => "integer", + example => 15, + description => "how many seconds to try pinging before timing out", + safe => 1, + rebuild => 0, + }, +} #}}} + sub needsbuild (@) { #{{{ my $needsbuild=shift; foreach my $page (keys %pagestate) { diff --git a/IkiWiki/Plugin/prettydate.pm b/IkiWiki/Plugin/prettydate.pm index 745e6a1de..db5a94f41 100644 --- a/IkiWiki/Plugin/prettydate.pm +++ b/IkiWiki/Plugin/prettydate.pm @@ -40,9 +40,27 @@ sub default_timetable { } sub import { #{{{ + hook(type => "getsetup", id => "prettydate", call => \&getsetup); hook(type => "checkconfig", id => "prettydate", call => \&checkconfig); } # }}} +sub getsetup () { #{{{ + return + prettydateformat => { + type => "string", + example => '%X, %B %o, %Y', + description => "format to use to display date", + safe => 1, + rebuild => 1, + }, + timetable => { + type => "internal", + description => "array of time descriptions", + safe => 1, + rebuild => 1, + }, +} #}}} + sub checkconfig () { #{{{ if (! defined $config{prettydateformat} || $config{prettydateformat} eq '%c') { diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 8383fb72a..d534d0cd9 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -6,6 +6,7 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "recentchanges", call => \&getsetup); hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig); hook(type => "refresh", id => "recentchanges", call => \&refresh); hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate); @@ -13,6 +14,24 @@ sub import { #{{{ hook(type => "cgi", id => "recentchanges", call => \&cgi); } #}}} +sub getsetup () { #{{{ + return + recentchangespage => { + type => "string", + example => "recentchanges", + description => "name of the recentchanges page", + safe => 1, + rebuild => 1, + }, + recentchangesnum => { + type => "integer", + example => 100, + description => "number of changes to track", + safe => 1, + rebuild => 0, + }, +} #}}} + sub checkconfig () { #{{{ $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage}; $config{recentchangesnum}=100 unless defined $config{recentchangesnum}; diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index eedfa6924..cb12d9500 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -7,6 +7,7 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "search", call => \&getsetup); hook(type => "checkconfig", id => "search", call => \&checkconfig); hook(type => "pagetemplate", id => "search", call => \&pagetemplate); hook(type => "postscan", id => "search", call => \&index); @@ -14,6 +15,17 @@ sub import { #{{{ hook(type => "cgi", id => "search", call => \&cgi); } # }}} +sub getsetup () { #{{{ + return + omega_cgi => { + type => "string", + example => "/usr/lib/cgi-bin/omega/omega", + description => "path to the omega cgi program", + safe => 0, # external program + rebuild => 0, + }, +} #}}} + sub checkconfig () { #{{{ foreach my $required (qw(url cgiurl)) { if (! length $config{$required}) { @@ -21,7 +33,7 @@ sub checkconfig () { #{{{ } } - if (! exists $config{omega_cgi}) { + if (! defined $config{omega_cgi}) { $config{omega_cgi}="/usr/lib/cgi-bin/omega/omega"; } } #}}} diff --git a/IkiWiki/Plugin/shortcut.pm b/IkiWiki/Plugin/shortcut.pm index 8df60cfe2..dfc3cd7c7 100644 --- a/IkiWiki/Plugin/shortcut.pm +++ b/IkiWiki/Plugin/shortcut.pm @@ -6,11 +6,11 @@ use strict; use IkiWiki 2.00; sub import { #{{{ - hook(type => "checkconfig", id => "shortcut", call => \&checkconfig); + hook(type => "refresh", id => "shortcut", call => \&refresh); hook(type => "preprocess", id => "shortcut", call => \&preprocess_shortcut); } #}}} -sub checkconfig () { #{{{ +sub refresh () { #{{{ # Preprocess the shortcuts page to get all the available shortcuts # defined before other pages are rendered. my $srcfile=srcfile("shortcuts.mdwn", 1); diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index 10c7002e4..bbf11e603 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -10,6 +10,7 @@ use IkiWiki 2.00; sub import { #{{{ hook(type => "getopt", id => "skeleton", call => \&getopt); + hook(type => "getsetup", id => "skeleton", call => \&getsetup); hook(type => "checkconfig", id => "skeleton", call => \&checkconfig); hook(type => "refresh", id => "skeleton", call => \&refresh); hook(type => "needsbuild", id => "skeleton", call => \&needsbuild); @@ -39,6 +40,17 @@ sub getopt () { #{{{ debug("skeleton plugin getopt"); } #}}} +sub getsetup () { #{{{ + return + skeleton => { + type => "boolean", + example => 0, + description => "example option", + safe => 0, + rebuild => 0, + }, +} #}}} + sub checkconfig () { #{{{ debug("skeleton plugin checkconfig"); } #}}} diff --git a/IkiWiki/Plugin/svn.pm b/IkiWiki/Plugin/svn.pm new file mode 100644 index 000000000..262fca99a --- /dev/null +++ b/IkiWiki/Plugin/svn.pm @@ -0,0 +1,380 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::svn; + +use warnings; +use strict; +use IkiWiki; +use POSIX qw(setlocale LC_CTYPE); + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "svn", call => \&checkconfig); + hook(type => "getsetup", id => "svn", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (! defined $config{svnpath}) { + $config{svnpath}="trunk"; + } + if (exists $config{svnpath}) { + # code depends on the path not having extraneous slashes + $config{svnpath}=~tr#/#/#s; + $config{svnpath}=~s/\/$//; + $config{svnpath}=~s/^\///; + } + if (defined $config{svn_wrapper} && length $config{svn_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{svn_wrapper}, + wrappermode => (defined $config{svn_wrappermode} ? $config{svn_wrappermode} : "04755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + svnrepo => { + type => "string", + example => "/svn/wiki", + description => "subversion repository location", + safe => 0, # path + rebuild => 0, + }, + svnpath => { + type => "string", + example => "trunk", + description => "path inside repository where the wiki is located", + safe => 0, # paranoia + rebuild => 0, + }, + svn_wrapper => { + type => "string", + example => "/svn/wikirepo/hooks/post-commit", + description => "svn post-commit executable to generate", + safe => 0, # file + rebuild => 0, + }, + svn_wrappermode => { + type => "string", + example => '04755', + description => "mode for svn_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + historyurl => { + type => "string", + example => "http://svn.example.org/trunk/[[file]]", + description => "viewvc url to show file history ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + example => "http://svn.example.org/trunk/[[file]]?root=wiki&r1=[[r1]]&r2=[[r2]]", + description => "viewvc url to show a diff ([[file]], [[r1]], and [[r2]] substituted)", + safe => 1, + rebuild => 1, + }, +} #}}} + +# svn needs LC_CTYPE set to a UTF-8 locale, so try to find one. Any will do. +sub find_lc_ctype() { + my $current = setlocale(LC_CTYPE()); + return $current if $current =~ m/UTF-?8$/i; + + # Make some obvious attempts to avoid calling `locale -a` + foreach my $locale ("$current.UTF-8", "en_US.UTF-8", "en_GB.UTF-8") { + return $locale if setlocale(LC_CTYPE(), $locale); + } + + # Try to get all available locales and pick the first UTF-8 one found. + if (my @locale = grep(/UTF-?8$/i, `locale -a`)) { + chomp @locale; + return $locale[0] if setlocale(LC_CTYPE(), $locale[0]); + } + + # fallback to the current locale + return $current; +} # }}} +$ENV{LC_CTYPE} = $ENV{LC_CTYPE} || find_lc_ctype(); + +sub svn_info ($$) { #{{{ + my $field=shift; + my $file=shift; + + my $info=`LANG=C svn info $file`; + my ($ret)=$info=~/^$field: (.*)$/m; + return $ret; +} #}}} + +sub rcs_update () { #{{{ + if (-d "$config{srcdir}/.svn") { + if (system("svn", "update", "--quiet", $config{srcdir}) != 0) { + warn("svn update failed\n"); + } + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + # Prepares to edit a file under revision control. Returns a token + # that must be passed into rcs_commit when the file is ready + # for committing. + # The file is relative to the srcdir. + my $file=shift; + + if (-d "$config{srcdir}/.svn") { + # For subversion, return the revision of the file when + # editing begins. + my $rev=svn_info("Revision", "$config{srcdir}/$file"); + return defined $rev ? $rev : ""; + } +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + # Tries to commit the page; returns undef on _success_ and + # a version of the page with the rcs's conflict markers on failure. + # The file is relative to the srcdir. + my $file=shift; + my $message=shift; + my $rcstoken=shift; + my $user=shift; + my $ipaddr=shift; + + if (defined $user) { + $message="web commit by $user".(length $message ? ": $message" : ""); + } + elsif (defined $ipaddr) { + $message="web commit from $ipaddr".(length $message ? ": $message" : ""); + } + + if (-d "$config{srcdir}/.svn") { + # Check to see if the page has been changed by someone + # else since rcs_prepedit was called. + my ($oldrev)=$rcstoken=~/^([0-9]+)$/; # untaint + my $rev=svn_info("Revision", "$config{srcdir}/$file"); + if (defined $rev && defined $oldrev && $rev != $oldrev) { + # Merge their changes into the file that we've + # changed. + if (system("svn", "merge", "--quiet", "-r$oldrev:$rev", + "$config{srcdir}/$file", "$config{srcdir}/$file") != 0) { + warn("svn merge -r$oldrev:$rev failed\n"); + } + } + + if (system("svn", "commit", "--quiet", + "--encoding", "UTF-8", "-m", + IkiWiki::possibly_foolish_untaint($message), + $config{srcdir}) != 0) { + my $conflict=readfile("$config{srcdir}/$file"); + if (system("svn", "revert", "--quiet", "$config{srcdir}/$file") != 0) { + warn("svn revert failed\n"); + } + return $conflict; + } + } + return undef # success +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + if (defined $user) { + $message="web commit by $user".(length $message ? ": $message" : ""); + } + elsif (defined $ipaddr) { + $message="web commit from $ipaddr".(length $message ? ": $message" : ""); + } + + if (system("svn", "commit", "--quiet", + "--encoding", "UTF-8", "-m", + IkiWiki::possibly_foolish_untaint($message), + $config{srcdir}) != 0) { + warn("svn commit failed\n"); + return 1; # failure + } + return undef # success +} + +sub rcs_add ($) { #{{{ + # filename is relative to the root of the srcdir + my $file=shift; + + if (-d "$config{srcdir}/.svn") { + my $parent=IkiWiki::dirname($file); + while (! -d "$config{srcdir}/$parent/.svn") { + $file=$parent; + $parent=IkiWiki::dirname($file); + } + + if (system("svn", "add", "--quiet", "$config{srcdir}/$file") != 0) { + warn("svn add failed\n"); + } + } +} #}}} + +sub rcs_remove ($) { #{{{ + # filename is relative to the root of the srcdir + my $file=shift; + + if (-d "$config{srcdir}/.svn") { + if (system("svn", "rm", "--force", "--quiet", "$config{srcdir}/$file") != 0) { + warn("svn rm failed\n"); + } + } +} #}}} + +sub rcs_rename ($$) { #{{{ + # filenames relative to the root of the srcdir + my ($src, $dest)=@_; + + if (-d "$config{srcdir}/.svn") { + # Add parent directory for $dest + my $parent=dirname($dest); + if (! -d "$config{srcdir}/$parent/.svn") { + while (! -d "$config{srcdir}/$parent/.svn") { + $parent=dirname($dest); + } + if (system("svn", "add", "--quiet", "$config{srcdir}/$parent") != 0) { + warn("svn add $parent failed\n"); + } + } + + if (system("svn", "mv", "--force", "--quiet", + "$config{srcdir}/$src", "$config{srcdir}/$dest") != 0) { + warn("svn rename failed\n"); + } + } +} #}}} + +sub rcs_recentchanges ($) { #{{{ + my $num=shift; + my @ret; + + return unless -d "$config{srcdir}/.svn"; + + eval q{ + use Date::Parse; + use XML::SAX; + use XML::Simple; + }; + error($@) if $@; + + # avoid using XML::SAX::PurePerl, it's buggy with UTF-8 data + my @parsers = map { ${$_}{Name} } @{XML::SAX->parsers()}; + do { + $XML::Simple::PREFERRED_PARSER = pop @parsers; + } until $XML::Simple::PREFERRED_PARSER ne 'XML::SAX::PurePerl'; + + # --limit is only supported on Subversion 1.2.0+ + my $svn_version=`svn --version -q`; + my $svn_limit=''; + $svn_limit="--limit $num" + if $svn_version =~ /\d\.(\d)\.\d/ && $1 >= 2; + + my $svn_url=svn_info("URL", $config{srcdir}); + my $xml = XMLin(scalar `svn $svn_limit --xml -v log '$svn_url'`, + ForceArray => [ 'logentry', 'path' ], + GroupTags => { paths => 'path' }, + KeyAttr => { path => 'content' }, + ); + foreach my $logentry (@{$xml->{logentry}}) { + my (@pages, @message); + + my $rev = $logentry->{revision}; + my $user = $logentry->{author}; + + my $when=str2time($logentry->{date}, 'UTC'); + + foreach my $msgline (split(/\n/, $logentry->{msg})) { + push @message, { line => $msgline }; + } + + my $committype="web"; + if (defined $message[0] && + $message[0]->{line}=~/$config{web_commit_regexp}/) { + $user=defined $2 ? "$2" : "$3"; + $message[0]->{line}=$4; + } + else { + $committype="svn"; + } + + foreach my $file (keys %{$logentry->{paths}}) { + if (length $config{svnpath}) { + next unless $file=~/^\/\Q$config{svnpath}\E\/([^ ]+)(?:$|\s)/; + $file=$1; + } + + my $diffurl=defined $config{diffurl} ? $config{diffurl} : ""; + $diffurl=~s/\[\[file\]\]/$file/g; + $diffurl=~s/\[\[r1\]\]/$rev - 1/eg; + $diffurl=~s/\[\[r2\]\]/$rev/g; + + push @pages, { + page => pagename($file), + diffurl => $diffurl, + } if length $file; + } + push @ret, { + rev => $rev, + user => $user, + committype => $committype, + when => $when, + message => [@message], + pages => [@pages], + } if @pages; + return @ret if @ret >= $num; + } + + return @ret; +} #}}} + +sub rcs_diff ($) { #{{{ + my $rev=IkiWiki::possibly_foolish_untaint(int(shift)); + return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`; +} #}}} + +sub rcs_getctime ($) { #{{{ + my $file=shift; + + my $svn_log_infoline=qr/^r\d+\s+\|\s+[^\s]+\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/; + + my $child = open(SVNLOG, "-|"); + if (! $child) { + exec("svn", "log", $file) || error("svn log $file failed to run"); + } + + my $date; + while (<SVNLOG>) { + if (/$svn_log_infoline/) { + $date=$1; + } + } + close SVNLOG || warn "svn log $file exited $?"; + + if (! defined $date) { + warn "failed to parse svn log for $file\n"; + return 0; + } + + eval q{use Date::Parse}; + error($@) if $@; + $date=str2time($date); + debug("found ctime ".localtime($date)." for $file"); + return $date; +} #}}} + +1 diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index b0a0e53be..36b434f67 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -10,6 +10,7 @@ my %tags; sub import { #{{{ hook(type => "getopt", id => "tag", call => \&getopt); + hook(type => "getsetup", id => "tag", call => \&getsetup); hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1); hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1); hook(type => "pagetemplate", id => "tag", call => \&pagetemplate); @@ -22,6 +23,17 @@ sub getopt () { #{{{ GetOptions("tagbase=s" => \$config{tagbase}); } #}}} +sub getsetup () { #{{{ + return + tagbase => { + type => "string", + example => "tag", + description => "parent page tags are located under", + safe => 1, + rebuild => 1, + }, +} #}}} + sub tagpage ($) { #{{{ my $tag=shift; diff --git a/IkiWiki/Plugin/tla.pm b/IkiWiki/Plugin/tla.pm new file mode 100644 index 000000000..fe5965259 --- /dev/null +++ b/IkiWiki/Plugin/tla.pm @@ -0,0 +1,285 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::tla; + +use warnings; +use strict; +use IkiWiki; + +sub import { #{{{ + if (exists $IkiWiki::hooks{rcs}) { + error(gettext("cannot use multiple rcs plugins")); + } + hook(type => "checkconfig", id => "tla", call => \&checkconfig); + hook(type => "getsetup", id => "tla", call => \&getsetup); + hook(type => "rcs", id => "rcs_update", call => \&rcs_update); + hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); + hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); + hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged); + hook(type => "rcs", id => "rcs_add", call => \&rcs_add); + hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove); + hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename); + hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges); + hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff); + hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); +} #}}} + +sub checkconfig () { #{{{ + if (defined $config{tla_wrapper} && length $config{tla_wrapper}) { + push @{$config{wrappers}}, { + wrapper => $config{tla_wrapper}, + wrappermode => (defined $config{tla_wrappermode} ? $config{tla_wrappermode} : "06755"), + }; + } +} #}}} + +sub getsetup () { #{{{ + return + tla_wrapper => { + type => "string", + #example => "", # TODO example + description => "tla post-commit executable to generate", + safe => 0, # file + rebuild => 0, + }, + tla_wrappermode => { + type => "string", + example => '06755', + description => "mode for tla_wrapper (can safely be made suid)", + safe => 0, + rebuild => 0, + }, + historyurl => { + type => "string", + #example => "", # TODO example + description => "url to show file history ([[file]] substituted)", + safe => 1, + rebuild => 1, + }, + diffurl => { + type => "string", + #example => "", # TODO example + description => "url to show a diff ([[file]] and [[rev]] substituted)", + safe => 1, + rebuild => 1, + }, +} #}}} + +sub quiet_system (@) { #{{{ + # See Debian bug #385939. + open (SAVEOUT, ">&STDOUT"); + close STDOUT; + open (STDOUT, ">/dev/null"); + my $ret=system(@_); + close STDOUT; + open (STDOUT, ">&SAVEOUT"); + close SAVEOUT; + return $ret; +} #}}} + +sub rcs_update () { #{{{ + if (-d "$config{srcdir}/{arch}") { + if (quiet_system("tla", "replay", "-d", $config{srcdir}) != 0) { + warn("tla replay failed\n"); + } + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + my $file=shift; + + if (-d "$config{srcdir}/{arch}") { + # For Arch, return the tree-id of archive when + # editing begins. + my $rev=`tla tree-id $config{srcdir}`; + return defined $rev ? $rev : ""; + } +} #}}} + +sub rcs_commit ($$$;$$) { #{{{ + my $file=shift; + my $message=shift; + my $rcstoken=shift; + my $user=shift; + my $ipaddr=shift; + + if (defined $user) { + $message="web commit by $user".(length $message ? ": $message" : ""); + } + elsif (defined $ipaddr) { + $message="web commit from $ipaddr".(length $message ? ": $message" : ""); + } + + if (-d "$config{srcdir}/{arch}") { + # Check to see if the page has been changed by someone + # else since rcs_prepedit was called. + my ($oldrev)=$rcstoken=~/^([A-Za-z0-9@\/._-]+)$/; # untaint + my $rev=`tla tree-id $config{srcdir}`; + if (defined $rev && defined $oldrev && $rev ne $oldrev) { + # Merge their changes into the file that we've + # changed. + if (quiet_system("tla", "update", "-d", + "$config{srcdir}") != 0) { + warn("tla update failed\n"); + } + } + + if (quiet_system("tla", "commit", + "-L".IkiWiki::possibly_foolish_untaint($message), + '-d', $config{srcdir}) != 0) { + my $conflict=readfile("$config{srcdir}/$file"); + if (system("tla", "undo", "-n", "--quiet", "-d", "$config{srcdir}") != 0) { + warn("tla undo failed\n"); + } + return $conflict; + } + } + return undef # success +} #}}} + +sub rcs_commit_staged ($$$) { + # Commits all staged changes. Changes can be staged using rcs_add, + # rcs_remove, and rcs_rename. + my ($message, $user, $ipaddr)=@_; + + error("rcs_commit_staged not implemented for tla"); # TODO +} + +sub rcs_add ($) { #{{{ + my $file=shift; + + if (-d "$config{srcdir}/{arch}") { + if (quiet_system("tla", "add", "$config{srcdir}/$file") != 0) { + warn("tla add failed\n"); + } + } +} #}}} + +sub rcs_remove ($) { # {{{ + my $file = shift; + + error("rcs_remove not implemented for tla"); # TODO +} #}}} + +sub rcs_rename ($$) { # {{{a + my ($src, $dest) = @_; + + error("rcs_rename not implemented for tla"); # TODO +} #}}} + +sub rcs_recentchanges ($) { + my $num=shift; + my @ret; + + return unless -d "$config{srcdir}/{arch}"; + + eval q{use Date::Parse}; + error($@) if $@; + eval q{use Mail::Header}; + error($@) if $@; + + my $logs = `tla logs -d $config{srcdir}`; + my @changesets = reverse split(/\n/, $logs); + + for (my $i=0; $i<$num && $i<$#changesets; $i++) { + my ($change)=$changesets[$i]=~/^([A-Za-z0-9@\/._-]+)$/; # untaint + + open(LOG, "tla cat-log -d $config{srcdir} $change|"); + my $head = Mail::Header->new(\*LOG); + close(LOG); + + my $rev = $head->get("Revision"); + my $summ = $head->get("Summary"); + my $newfiles = $head->get("New-files"); + my $modfiles = $head->get("Modified-files"); + my $remfiles = $head->get("Removed-files"); + my $user = $head->get("Creator"); + + my @paths = grep { !/^(.*\/)?\.arch-ids\/.*\.id$/ } + split(/ /, "$newfiles $modfiles .arch-ids/fake.id"); + + my $sdate = $head->get("Standard-date"); + my $when = str2time($sdate, 'UTC'); + + my $committype = "web"; + if (defined $summ && $summ =~ /$config{web_commit_regexp}/) { + $user = defined $2 ? "$2" : "$3"; + $summ = $4; + } + else { + $committype="tla"; + } + + my @message; + push @message, { line => $summ }; + + my @pages; + + foreach my $file (@paths) { + my $diffurl=defined $config{diffurl} ? $config{diffurl} : ""; + $diffurl=~s/\[\[file\]\]/$file/g; + $diffurl=~s/\[\[rev\]\]/$change/g; + push @pages, { + page => pagename($file), + diffurl => $diffurl, + } if length $file; + } + push @ret, { + rev => $change, + user => $user, + committype => $committype, + when => $when, + message => [@message], + pages => [@pages], + } if @pages; + + last if $i == $num; + } + + return @ret; +} + +sub rcs_diff ($) { #{{{ + my $rev=shift; + my $logs = `tla logs -d $config{srcdir}`; + my @changesets = reverse split(/\n/, $logs); + my $i; + + for($i=0;$i<$#changesets;$i++) { + last if $changesets[$i] eq $rev; + } + + my $revminusone = $changesets[$i+1]; + return `tla diff -d $config{srcdir} $revminusone`; +} #}}} + +sub rcs_getctime ($) { #{{{ + my $file=shift; + eval q{use Date::Parse}; + error($@) if $@; + eval q{use Mail::Header}; + error($@) if $@; + + my $logs = `tla logs -d $config{srcdir}`; + my @changesets = reverse split(/\n/, $logs); + my $sdate; + + for (my $i=0; $i<$#changesets; $i++) { + my $change = $changesets[$i]; + + open(LOG, "tla cat-log -d $config{srcdir} $change|"); + my $head = Mail::Header->new(\*LOG); + close(LOG); + + $sdate = $head->get("Standard-date"); + my $newfiles = $head->get("New-files"); + + my ($lastcreation) = grep {/^$file$/} split(/ /, "$newfiles"); + last if defined($lastcreation); + } + + my $date=str2time($sdate, 'UTC'); + debug("found ctime ".localtime($date)." for $file"); + return $date; +} #}}} + +1 diff --git a/IkiWiki/Plugin/typography.pm b/IkiWiki/Plugin/typography.pm index fe6996898..6229e6c33 100644 --- a/IkiWiki/Plugin/typography.pm +++ b/IkiWiki/Plugin/typography.pm @@ -8,6 +8,7 @@ use IkiWiki 2.00; sub import { #{{{ hook(type => "getopt", id => "typography", call => \&getopt); + hook(type => "getsetup", id => "typography", call => \&getsetup); IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize); } # }}} @@ -18,11 +19,25 @@ sub getopt () { #{{{ GetOptions("typographyattributes=s" => \$config{typographyattributes}); } #}}} +sub getsetup () { #{{{ + eval q{use Text::Typography}; + error($@) if $@; + + return + typographyattributes => { + type => "string", + example => "3", + description => "Text::Typography attributes value", + safe => 1, + rebuild => 1, + }, +} #}}} + sub sanitize (@) { #{{{ my %params=@_; eval q{use Text::Typography}; - error($@) if $@; + return $params{content} if $@; my $attributes=defined $config{typographyattributes} ? $config{typographyattributes} : '3'; return Text::Typography::typography($params{content}, $attributes); |