[recent diffs]
通常の差分だとすぐに無くなってしまうのと、変更箇所を探すのが面倒なので
全ページの差分を履歴に残すRecentDiffsページを作成するようにしてみました。
グローバル変数定義
my $RecentDiffs = 'RecentDiffs'; # yakty add [recent diffs]
%fixedpageへの追加
my %fixedpage = ( $IndexPage => 1, $CreatePage => 1, $ErrorPage => 1, $RssPage => 1, $RecentChanges => 1, $SearchPage => 1, $AdminChangePassword => 1, $CompletedSuccessfully => 1, $FrontPage => 1, $RecentDiffs => 1, # yakty add [recent diffs] );
%page_commandへの追加
my %page_command = ( $IndexPage => 'index', $SearchPage => 'searchform', $CreatePage => 'create', $RssPage => 'rss', $AdminChangePassword => 'adminchangepasswordform', $FrontPage => 'FrontPage', $RecentDiffs => 'recentdiff', # yakty add [recent diffs] );
%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] recentdiff => \&do_recent_diffs, # yakty add [recent diffs] );
do_write()内の変更
- 2003-07-10 (Thu) 09:09:36 保存時に変更がなければ更新しないの修正に伴う修正
- 2003-07-14 (Mon) 10:40:45 &close_diff()を書き忘れていたので追加。変数定義が抜けていたので追加。
- 2003-07-16 (Wed) 09:04:46 なぜか条件が逆になっていたので修正
my $isChanged; # yakty add [recent diffs] # Making diff { # &open_diff; # yakty del [noupdate if nochange] my @msg1 = split(/\x0D\x0A|\x0D|\x0A/, $database{$form{mypage}}); # Walrus add [unify new-line] my @msg2 = split(/\n/, $form{mymsg}); # $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2); # yakty del [noupdate if nochange] # &close_diff; # yakty del [noupdate if nochange] # yakty add [noupdate if nochange] start my $diffmsg = &difftext(\@msg1, \@msg2); $isChanged = $diffmsg =~ /^[^=]/m; if($isChanged){ &open_diff; $diffbase{$form{mypage}} = $diffmsg; &close_diff; &update_recent_diffs($diffmsg); # yakty add [recent diffs] } # yakty add [noupdate if nochange] end }
update_recent_diffs()追加
- 2003-07-10 (Thu) 09:51:25 危険な間違いをしていたので修正($maxrecent行しか残してなかった…(--;)
- 2003-07-22 (Tue) 22:07:10 インクリメンタル差分追加に伴う実装変更
# yakty add [recent diffs] start sub update_recent_diffs { my ($diffmsg, $skippage) = @_; my $contents; return if($form{mypage} eq $RecentDiffs); my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]}"; my @difftxt = split(/\n/, $diffmsg); if((@difftxt = grep /^[-+]/, @difftxt)){ $diffmsg = join("\n", @difftxt); $diffmsg =~ s/^/ /gm; $contents = $update . "\n" . $diffmsg . "\n"; } my @txt = split(/\n/, $database{$RecentDiffs}); my $n = 0; my $skip = 0; my @diffs; foreach (@txt){ if(/^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/){ last if(++$n > $maxrecent); my $name = &unarmor_name($1); $skip = 0; if($name eq $skippage){ $skip = 1; $skippage = ''; } } next if($skip); push @diffs, $_; } $contents .= join("\n", @diffs); if ($lock_enable) { my $lock_handle = &create_lock($file_lock, $lock_retry); &print_error($resource{writedatafailed}) unless ($lock_handle); $database{$RecentDiffs} = $contents; &remove_lock($file_lock, $lock_handle); } else { $database{$RecentDiffs} = $contents; } } # yakty add [recent diffs] end
do_recent_diffs()追加
- 2003-09-12 (Fri) 10:32:27 <b>タグ、<s>タグを<span>タグに変更。
# yakty add [recent diffs] start sub do_recent_diffs { &print_header($RecentDiffs); print qq($resource{diffnotice}); my $content = $database{$RecentDiffs}; my %check; $content =~ s/^- (\d\d\d\d-\d\d-\d\d)/($check{$1}++ ? $& : qq(**$1\n$&))/gme; undef %check; $content =~ s/^\*\*(\d\d\d\d-\d\d)/($check{$1}++ ? $& : qq(*$1\n$&))/gme; $content = &text_to_html($content, toc=>1); $content =~ s|<pre>|<pre class="diff">|g; $content =~ s|^\+(.*)$|<span class="added">$1</span>|gm; $content =~ s|^-(.*)$|<span class="deleted">$1</span>|gm; print $content; &print_footer($RecentDiffs); } # yakty add [recent diffs] end
do_search()内の変更
- 2003-07-20 (Sun) 00:20:36 RecentDiffsが検索にヒットしないように修正
if (@search_words) { my $opt = {'margin' => 30, 'case_sense' => $case_sense, 'combination' => $combination}; my @pages = ($sort_case_sense) ? (sort keys(%database)) : sort {lc($a) cmp lc($b)} keys(%database); # Walrus add [sort case sense] foreach my $page (@pages) { next if ($page eq $RecentChanges); next if ($page eq $RecentDiffs); # yakty add [recent diffs] my $cooked_page = &encode($page); my $list = '';
print_header()内の変更
<a href="$url_cgi?$RssPage">$resource{rssbutton}</a> | <a href="$url_cgi?$FrontPage">$FrontPage</a> | <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> | <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a> | <a href="$url_cgi?$RecentDiffs">$resource{recentdiffsbutton}</a>
最後の1行を追加します。
また、resource.txt に
recentdiffsbutton=差分履歴
を追加します。