[ 新規 ] [ 検索 | 一覧 | FrontPage ] [ 履歴 (RSS) | 差分履歴 (RSS) ] [ ログイン ]
【PR】Amazon | SL-C3000 | SL-C1000(3/18発売!) | SL-C860 | SL-6000W | SL-6000L | SL-6000N

WalWiki/カスタマイズ/UNDO機能

差分表示


編集前の状態に戻します。
差分ページから最後の更新をUNDOする事が出来るようになります。

また、ページ削除をUNDOする事も出来るようになります。
* [undo edit]

** ライブラリ追加

[[Algorithm::Diff::Apply http://search.cpan.org/author/ANDREWC/Algorithm-Diff-Apply-0.2.1/lib/Algorithm/Diff/Apply.pod]]を ''lib/Algorithm/Diff/Apply.pm'' に設置します。

 use Algorithm::Diff::Apply qw(apply_diff);      # yakty add [incremental diff] [undo edit]
** resource.txtへの追加

,undobutton,undo
,undonotice,編集前の状態に戻します。

** %command_doへの追加

 my %command_do = (
     read => \&do_read,
     edit => \&do_edit,
     adminedit => \&do_adminedit,
     adminchangepasswordform => \&do_adminchangepasswordform,
     adminchangepassword => \&do_adminchangepassword,
     write => \&do_write,
     index => \&do_index,
     searchform => \&do_searchform,
     search => \&do_search,
     create => \&do_create,
     createresult => \&do_createresult,
     FrontPage => \&do_FrontPage,
     comment => \&do_comment,
     rss => \&do_rss,
     diff => \&do_diff,
     interwikibox => \&do_interwiki_box, # Walrus add [InterWikiBox]
     undo => \&do_undo,                                      # yakty add [undo edit]
 );

** do_undo()追加

 # yakty add [undo edit] start
 sub do_undo {
     &open_diff;
     my @diffs = split(/\n/, $diffbase{$form{mypage}});
     &close_diff;
     my @msg1 = split(/\x0D\x0A|\x0D|\x0A/, $database{$form{mypage}});
 
     @msg1 = &reverse_diff(\@msg1, \@diffs);
     $form{mymsg} = join("\n", @msg1);
     $form{myfrozen} = &get_info($form{mypage}, $info_IsFrozen);
     &do_write;
 }
 # yakty add [undo edit] end

** reverse_diff()追加

- インクリメンタル差分のupdate_diff()から切り出し。

 # yakty add [incremental diff] [undo edit] start
 sub reverse_diff {
     my ($msgref, $diffref) = @_;
     my $lineno = 0;
     my @patch;
     my $hunk = [];
     my $delta1 = 0;
     my $delta2 = 0;
     # make diff
     foreach (@$diffref){
         /^(.)(.*)/;
         if($1 eq '-'){
             push(@$hunk, ['+', $lineno+$delta1, $2]);
             $delta1++;
         } elsif($1 eq '+'){
             push(@$hunk, ['-', $lineno+$delta2, $2]);
             $delta2++;
         } else {
             push(@patch, $hunk) if scalar(@$hunk);
             $hunk = [];
             $lineno++;
         }
     }
     push(@patch, $hunk) if scalar(@$hunk);
     return &apply_diff($msgref, \@patch);
 }
 # yakty add [incremental diff] [undo edit] end
** do_diff()内の変更

     &open_diff;
     my $title = $form{mypage};
     &print_header($title);
     $_ = &escape($diffbase{$form{mypage}});
     &close_diff;
     print qq(<h3>$resource{difftitle}</h3>);
     print qq($resource{diffnotice});
     &print_undoform;                                       # yakty add [undo edit]
     print qq(<pre class="diff">);

** print_undoform()追加

 # yakty add [undo edit] start
 sub print_undoform {
     my $escapedmypage = &escape($form{mypage});
     my $lastmodified = &get_info($form{mypage}, $info_LastModified);
     print <<"EOD";
 <form action="$url_xcg" method="post" class="undo"><!-- yakty mod [for XREA] -->
     $resource{undonotice}
     <input type="hidden" name="mycmd" value="undo">
     <input type="hidden" name="mypage" value="$escapedmypage">
     <input type="hidden" name="myLastModified" value="$lastmodified">
     <input type="submit" value="$resource{undobutton}">
 </form>
 EOD
 }
 # yakty add [undo edit] end

** do_write()内の変更

- 2003-10-09 (Thu) 19:37:38 ページを削除した後のページにUNDOボタンを表示。

         &print_header($form{mypage});
         &print_message($resource{deleted});
         &print_undoform;                        # yakty add [undo edit]
         &print_footer($form{mypage});
     }
 }


02988