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

WalWiki/カスタマイズ/差分履歴ページ

編集

[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()内の変更

編集
    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()追加

編集
# 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()追加

編集
# 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()内の変更

編集
    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=差分履歴

を追加します。


04475