]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge commit 'ecdfd1b8644bc926db008054ab6192e18351afed' into sipb
authorAnders Kaseorg <andersk@mit.edu>
Fri, 31 Jan 2014 05:50:01 +0000 (00:50 -0500)
committerAnders Kaseorg <andersk@mit.edu>
Fri, 31 Jan 2014 05:50:01 +0000 (00:50 -0500)
Conflicts:
IkiWiki/Plugin/git.pm

1  2 
IkiWiki/CGI.pm
IkiWiki/Plugin/git.pm
templates/editpage.tmpl

diff --combined IkiWiki/CGI.pm
index 11b2f2ce39d4f1ab2cf158ea3baf81d1578c35af,f2a32a9581077553d5b542fde40f428c15a5e41a..ad253c803901c1aea194224043488fa4a8d89322
@@@ -121,9 -121,7 +121,9 @@@ sub cgi_signin ($$;$) 
                template => {type => 'div'},
                stylesheet => 1,
        );
 -      my $buttons=["Login"];
 +      # MITLOGIN: These should be restored when logins are allowed again.
 +      #my $buttons=["Login"];
 +      my $buttons=[];
        
        $form->field(name => "do", type => "hidden", value => "signin",
                force => 1);
@@@ -222,16 -220,13 +222,16 @@@ sub cgi_prefs ($$) 
                force => 1);
        $form->field(name => "sid", type => "hidden", value => $session->id,
                force => 1);
 -      $form->field(name => "email", size => 50, fieldset => "preferences");
 +            #$form->field(name => "email", size => 50, fieldset => "preferences");
 +      $form->field(name => "realname", size => 50, fieldset => "preferences");
        
        my $user_name=$session->param("name");
  
        if (! $form->submitted) {
 -              $form->field(name => "email", force => 1,
 -                      value => userinfo_get($user_name, "email"));
 +            #$form->field(name => "email", force => 1,
 +            #value => userinfo_get($user_name, "email"));
 +              $form->field(name => "realname", force => 1,
 +                      value => userinfo_get($user_name, "realname"));
        }
        
        if ($form->submitted eq 'Logout') {
                        userinfo_set($user_name, 'email', $form->field('email')) ||
                                error("failed to set email");
                }
 -
 +              if (defined $form->field('realname')) {
 +                      userinfo_set($user_name, 'realname', $form->field('realname')) ||
 +                              error("failed to set realname");
 +                }
                $form->text(gettext("Preferences saved."));
        }
        
@@@ -291,7 -283,7 +291,7 @@@ sub check_banned ($$) 
  
        foreach my $b (@{$config{banned_users}}) {
                if (pagespec_match("", $b,
-                       ip => $ENV{REMOTE_ADDR},
+                       ip => $session->remote_addr(),
                        name => defined $name ? $name : "",
                )) {
                        $banned=1;
diff --combined IkiWiki/Plugin/git.pm
index 79162d14105f58c19a2490f88feba84a12fc56f0,b02fc118ddc0e758bee82b22b7c49b713a1e3153..c9e2d391c54995b731bc6e1d5716f017323b3c26
@@@ -4,7 -4,6 +4,7 @@@ package IkiWiki::Plugin::git
  use warnings;
  use strict;
  use IkiWiki;
 +use IkiWiki::UserInfo;
  use Encode;
  use open qw{:utf8 :std};
  
@@@ -281,11 -280,35 +281,35 @@@ sub merge_past ($$$) 
        return $conflict;
  }
  
- sub parse_diff_tree ($@) {
+ {
+ my $prefix;
+ sub decode_git_file ($) {
+       my $file=shift;
+       # git does not output utf-8 filenames, but instead
+       # double-quotes them with the utf-8 characters
+       # escaped as \nnn\nnn.
+       if ($file =~ m/^"(.*)"$/) {
+               ($file=$1) =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
+       }
+       # strip prefix if in a subdir
+       if (! defined $prefix) {
+               ($prefix) = run_or_die('git', 'rev-parse', '--show-prefix');
+               if (! defined $prefix) {
+                       $prefix="";
+               }
+       }
+       $file =~ s/^\Q$prefix\E//;
+       return decode("utf8", $file);
+ }
+ }
+ 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) = @_;
+       my $dt_ref = shift;
  
        # End of stream?
        return if !defined @{ $dt_ref } ||
                        $ci{ "${who}_epoch" } = $epoch;
                        $ci{ "${who}_tz"    } = $tz;
  
-                       if ($name =~ m/^[^<]+\s+<([^@>]+)/) {
-                               $ci{"${who}_username"} = $1;
+                       if ($name =~ m/^([^<]+)\s+<([^@>]+)/) {
+                               $ci{"${who}_name"} = $1;
+                               $ci{"${who}_username"} = $2;
                        }
                        elsif ($name =~ m/^([^<]+)\s+<>$/) {
                                $ci{"${who}_username"} = $1;
                        my $sha1_to = shift(@tmp);
                        my $status = shift(@tmp);
  
-                       # git does not output utf-8 filenames, but instead
-                       # double-quotes them with the utf-8 characters
-                       # escaped as \nnn\nnn.
-                       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),
+                                       'file'      => decode_git_file($file),
                                        'sha1_from' => $sha1_from[0],
                                        'sha1_to'   => $sha1_to,
                                        'mode_from' => $mode_from[0],
@@@ -404,10 -421,9 +422,9 @@@ sub git_commit_info ($;$) 
        my @raw_lines = run_or_die('git', 'log', @opts,
                '--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)) {
+       while (my $parsed = parse_diff_tree(\@raw_lines)) {
                push @ci, $parsed;
        }
  
@@@ -448,44 -464,55 +465,56 @@@ sub rcs_prepedit ($) 
        return git_sha1($file);
  }
  
- sub rcs_commit ($$$;$$) {
+ 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) = @_;
+       my %params=@_;
  
        # 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
+       my $cur    = git_sha1($params{file});
+       my ($prev) = $params{token} =~ /^($sha1_pattern)$/; # untaint
  
        if (defined $cur && defined $prev && $cur ne $prev) {
-               my $conflict = merge_past($prev, $file, $dummy_commit_msg);
+               my $conflict = merge_past($prev, $params{file}, $dummy_commit_msg);
                return $conflict if defined $conflict;
        }
  
-       rcs_add($file); 
-       return rcs_commit_staged($message, $user, $ipaddr);
+       rcs_add($params{file});
+       return rcs_commit_staged(
+               message => $params{message},
+               session => $params{session},
+       );
  }
  
- sub rcs_commit_staged ($$$) {
+ 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 %params=@_;
+       
        my %env=%ENV;
-       if (defined $user || defined $ipaddr) {
-               my $u=encode_utf8(defined $user ? $user : $ipaddr);
-               # MITLOGIN This algorithm could be improved
-               $ENV{GIT_AUTHOR_NAME}=IkiWiki::userinfo_get($u, "realname");
-               $ENV{GIT_AUTHOR_EMAIL}="$u\@mit.edu";
+       if (defined $params{session}) {
+               # Set the commit author and email based on web session info.
+               my $u;
+               if (defined $params{session}->param("name")) {
+                       $u=$params{session}->param("name");
+               }
+               elsif (defined $params{session}->remote_addr()) {
+                       $u=$params{session}->remote_addr();
+               }
+               if (defined $u) {
+                       $u=encode_utf8($u);
 -                      $ENV{GIT_AUTHOR_NAME}=$u;
 -                      $ENV{GIT_AUTHOR_EMAIL}="$u\@web";
++                      # MITLOGIN This algorithm could be improved
++                      $ENV{GIT_AUTHOR_NAME}=IkiWiki::userinfo_get($u, "realname");
++                      $ENV{GIT_AUTHOR_EMAIL}="$u\@mit.edu";
+               }
        }
  
-       $message = IkiWiki::possibly_foolish_untaint($message);
+       $params{message} = IkiWiki::possibly_foolish_untaint($params{message});
        my @opts;
-       if ($message !~ /\S/) {
+       if ($params{message} !~ /\S/) {
                # Force git to allow empty commit messages.
                # (If this version of git supports it.)
                my ($version)=`git --version` =~ /git version (.*)/;
                        push @opts, '--cleanup=verbatim';
                }
                else {
-                       $message.=".";
+                       $params{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 (run_or_non('git', 'commit', @opts, '-m', $params{message})) {
                if (length $config{gitorigin_branch}) {
                        run_or_cry('git', 'push', $config{gitorigin_branch});
                }
@@@ -574,9 -601,14 +603,14 @@@ sub rcs_recentchanges ($) 
                        push @messages, { line => $line };
                }
  
-               my $user=$ci->{'author_username'};
+               my $user=$ci->{'author_name'};
+               my $usershort=$ci->{'author_username'};
                my $web_commit = ($ci->{'author'} =~ /\@web>/);
-               
+               if ($usershort =~ /:\/\//) {
+                       $usershort=undef; # url; not really short
+               }
                # compatability code for old web commit messages
                if (! $web_commit &&
                      defined $messages[0] &&
                push @rets, {
                        rev        => $sha1,
                        user       => $user,
+                       usershort  => $usershort,
                        committype => $web_commit ? "web" : "git",
                        when       => $when,
                        message    => [@messages],
@@@ -640,10 -673,12 +675,12 @@@ sub findtimes ($$) 
                                $date=undef;
                        }
                        else {
-                               if (! $time_cache{$line}) {
-                                       $time_cache{$line}[0]=$date; # mtime
+                               my $f=decode_git_file($line);
+                               if (! $time_cache{$f}) {
+                                       $time_cache{$f}[0]=$date; # mtime
                                }
-                               $time_cache{$line}[1]=$date; # ctime
+                               $time_cache{$f}[1]=$date; # ctime
                        }
                }
        }
diff --combined templates/editpage.tmpl
index 127212342241313ca6796f0e31aea2b3a09068d9,d6ad8061420f2c8056b6c1d12f3da6223ba0582f..70bbfb28f06237c2ddfb9235386b7882453c0768
@@@ -1,33 -1,26 +1,26 @@@
  <TMPL_VAR JAVASCRIPT>
  <TMPL_VAR MESSAGE>
+ <br />
  <TMPL_VAR FORM-START>
  <TMPL_VAR FIELD-DO>
  <TMPL_VAR FIELD-SID>
  <TMPL_VAR FIELD-FROM>
  <TMPL_VAR FIELD-RCSINFO>
  <TMPL_VAR FIELD-NEWFILE>
- <ol class="form">
  <TMPL_IF NAME="PAGE_SELECT">
- <li>
  <label for="page" class="inline">Page location:</label><TMPL_VAR FIELD-PAGE>
  <label for="type" class="inline">Page type:</label><TMPL_VAR FIELD-TYPE>
- </li>
  <TMPL_ELSE>
  <TMPL_VAR FIELD-PAGE>
  <TMPL_VAR FIELD-TYPE>
  </TMPL_IF>
- <li>
  <div class="editcontentdiv">
  <TMPL_VAR FIELD-EDITCONTENT><br />
  </div>
- </li>
  <TMPL_IF NAME="CAN_COMMIT">
- <li>
- <label for="comments" class="block">Optional comment about this change:</label>
- <TMPL_VAR FIELD-COMMENTS><br />
- </li>
+ <label for="editmessage" class="block">Optional comment about this change:</label>
+ <TMPL_VAR FIELD-EDITMESSAGE><br />
  </TMPL_IF>
- </ol>
  <TMPL_VAR FORM-SUBMIT>
  <TMPL_VAR HELPONFORMATTINGLINK>
  <TMPL_IF NAME="FIELD-ATTACHMENT">
  </table>
  </div>
  </TMPL_IF>
 +<div class="license">
 +    <p>By submitting content to this wiki, you agree to release your work under
 +    the dual license of</p>
 +    <ul>
 +      <li>the Creative Commons Attribution-Share Alike license, and</li>
 +      <li>the GNU Free Documentation License, with no Invariant Sections, no
 +         Front-Cover Texts, and no Back-Cover-Texts.</li>
 +    </ul>
 +</div>
  <TMPL_VAR FORM-END>
  <TMPL_VAR WMD_PREVIEW>