CGI-Kwiki

 view release on metacpan or  search on metacpan

lib/CGI/Kwiki.pm  view on Meta::CPAN

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
sub classes {
    qw(
        new
        config
        config_yaml
        driver
        cgi
        cookie
        database
        metadata
        backup
        display
        edit
        formatter
        template
        plugin
        search
        changes
        prefs
        pages
        slides

lib/CGI/Kwiki.pm  view on Meta::CPAN

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# The most basic attributes inherited by almost all classes
attribute 'driver';
attribute 'config';
attribute 'cgi';
attribute 'plugin';
attribute 'template';
attribute 'formatter';
attribute 'database';
attribute 'metadata';
attribute 'backup';
attribute 'prefs';
attribute 'i18n';
 
# Constructor inherited by most classes
sub new {
    my ($class, $driver) = @_;
    my $self = bless {}, $class;
    $self->driver($driver);
    $self->config($driver->config);
    $self->cgi($driver->cgi);
    $self->plugin($driver->plugin);
    $self->template($driver->template);
    $self->formatter($driver->formatter);
    $self->database($driver->database);
    $self->metadata($driver->metadata);
    $self->backup($driver->backup);
    $self->prefs($driver->prefs);
    return $self;
}
 
sub load_driver {
    require CGI::Kwiki::Config;
    my $config = CGI::Kwiki::Config->new;
    my $driver_class = $config->driver_class;
    eval qq{ require $driver_class }; die $@ if $@;
    my $driver = $driver_class->new($config);

lib/CGI/Kwiki/Database.pm  view on Meta::CPAN

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    umask 0000;
    open WIKIPAGE, "> $file_path"
      or die "Can't open $file_path for output:\n$!";
    binmode(WIKIPAGE, ':utf8') if $self->use_utf8;
    print WIKIPAGE $wiki_text;
    close WIKIPAGE;
 
    $self->driver->load_class('metadata');
    $self->metadata->set($page_id);
 
    $self->driver->load_class('backup');
    $self->backup->commit($page_id);
}
 
sub delete {
    my ($self, $page_id) = @_;
    $page_id = $self->escape($page_id);
    for (qw(database metabase/metadata
            metabase/public metabase/protected metabase/private
           )
        ) {
        unlink "$_/$page_id";

lib/CGI/Kwiki/Driver.pm  view on Meta::CPAN

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    my $self = bless {}, $class;
    $self->config($config);
    $self->load_class('cgi');
    $self->load_class('prefs');
    $self->load_class('template');
    $self->load_class('plugin');
    $self->load_class('cookie');
    $self->load_class('metadata');
    $self->load_class('database');
    $self->load_class('formatter');
    $self->load_class('backup');
    $self->database->backup($self->backup);
    return $self;
}
 
sub drive {
    my ($self) = @_;
    my $action = $self->cgi->action;
    $self->load_class($action);
    return $self->$action()->process;
}

lib/CGI/Kwiki/Edit.pm  view on Meta::CPAN

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use CGI::Kwiki ':char_classes';
 
use constant NEW_DEFAULT => 'New Page Name';
 
sub process {
    my ($self) = @_;
    return $self->protected
      unless $self->is_editable;
    my $error_msg = $self->check_new_name;
    my $page_id = $self->cgi->page_id;
    $self->driver->load_class('backup');
    return $self->save
      if $self->cgi->button =~ /^save$/i and not $error_msg;
    return $self->preview
      if $self->cgi->button =~ /^preview$/i;
    my $wiki_text = ($self->cgi->revision &&
                     $self->cgi->revision ne $self->cgi->head_revision
                    )
        ? $self->backup->fetch($page_id, $self->cgi->revision)
        : ($self->database->load($page_id) ||
           ($self->loc("Describe the new page here.") . "\n")
          );
    $self->template->process(
        [qw(display_header edit_body basic_footer)],
        wiki_text => $wiki_text,
        error_msg => $error_msg,
        history => $self->history,
        version_mark => $self->backup->version_mark,
        $self->privacy_checked,
    );
}
 
sub history {
    my ($self) = @_;
    return '' unless $self->backup->has_history;
    my $changes = $self->backup->history;
    return '' unless @$changes;
    my $selected_revision = $self->cgi->revision || $changes->[0]->{revision};
    my $head_revision = $changes->[0]->{revision};
    my $history = <<END;
<br>
<input type="hidden" name="head_revision" value="$head_revision">
<select name="revision" onchange="this.form.submit()">
END
    for my $change (@$changes) {
        my $selected = $change->{revision} eq $selected_revision

lib/CGI/Kwiki/Edit.pm  view on Meta::CPAN

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        [qw(display_header preview_body edit_body basic_footer)],
        preview => $preview,
        $self->privacy_checked,
    );
}
 
sub save {
    my ($self) = @_;
    my $page_id = $self->cgi->page_id;
    $self->database->lock($page_id);
    my $conflict = $self->backup->conflict;
    my $return;
    my $wiki_text = $self->cgi->wiki_text;
    if ($conflict) {
        $return = $self->template->process(
            [qw(display_header edit_body basic_footer)],
            wiki_text => $wiki_text,
            version_mark => $self->cgi->version_mark,
            $self->privacy_checked,
            %$conflict,
        );

lib/CGI/Kwiki/I18N/zh_cn.po  view on Meta::CPAN

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#: lib/CGI/Kwiki/Changes.pm:47
#. ($range->[0])
msgid "Changes in the last %1:"
msgstr "最近%1内的变更"
 
#: lib/CGI/Kwiki/Edit.pm:25
msgid "Describe the new page here."
msgstr "请在此输入新页面的内容。"
 
#: lib/CGI/Kwiki/Plugin/Diff.pm:100
#. ($self->backup->file_rev($page_id, $r1)
msgid "Differences from revision %1 to %2:"
msgstr "%1 版与 %2 版之间的差异:"
 
#: lib/CGI/Kwiki/Template.pm:302 lib/CGI/Kwiki/Template.pm:433
msgid "EDIT"
msgstr "编辑"
 
#: lib/CGI/Kwiki/Formatter.pm:495
msgid "Go"
msgstr "播放"

lib/CGI/Kwiki/I18N/zh_tw.po  view on Meta::CPAN

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#: lib/CGI/Kwiki/Changes.pm:47
#. ($range->[0])
msgid "Changes in the last %1:"
msgstr "最近%1內的變更"
 
#: lib/CGI/Kwiki/Edit.pm:25
msgid "Describe the new page here."
msgstr "請在此輸入新頁面的內容。"
 
#: lib/CGI/Kwiki/Plugin/Diff.pm:100
#. ($self->backup->file_rev($page_id, $r1)
msgid "Differences from revision %1 to %2:"
msgstr "%1 版與 %2 版之間的差異:"
 
#: lib/CGI/Kwiki/Template.pm:302 lib/CGI/Kwiki/Template.pm:433
msgid "EDIT"
msgstr "編輯"
 
#: lib/CGI/Kwiki/Formatter.pm:495
msgid "Go"
msgstr "播放"

lib/CGI/Kwiki/Import.pm  view on Meta::CPAN

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    my $page_file_path = $self->database->file_path($page_id);
    my $old_timestamp = (-M $local);
    LWP::Simple::mirror($url, $local);
    if (-M $local != $old_timestamp) {
        # say, we may want to muddle it a bit.
        $self->_extract_text($local);
        my $now = time;
        $self->driver->load_class('metadata');
        $self->metadata->set($page_id);
 
        $self->driver->load_class('backup');
        $self->backup->commit($page_id);
        utime $now, $now, $local;
    }
    my $script = $self->script;
    my $result .= qq{<a href="$script?$page_id">$page_id</a><br>\n};
    return $result;
}
 
sub _extract_text {
    my ($self, $file) = @_;

lib/CGI/Kwiki/Pages.pm  view on Meta::CPAN

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  - Support mailto links and inline code.
  - https links added. Thanks to GregSchueler.
  - ':' added to charset for page names. Suggested by
    JamesFitzGibbon.
  - Javascript fix reported by MikeArms.
  - Security hole in CGI params fixed. Reported by
    TimSweetman.
  - Emacs artifact bug fix by HeikkiLehvaslaiho.
  - Cleaned up unneeded <p> tags. Reported by HolgerSchurig
__KwikiBackup__
Kwiki supports backing up of each page change, so that you can easily revert a page to an older version. Currently the only backup module is CGI::Kwiki::Backup::Rcs and it uses RCS to do the backups. RCS is generally found on almost all modern Unix s...
 
KwikiBackup support is not enabled by default. To enable it, add the following line to your config.yaml file:
 
    backup_class: CGI::Kwiki::Backup::Rcs
__KwikiBlog__
KwikiBlog allows you to turn any wiki page into a blog page. You need to have KwikiPrivacy enabled, and you must be logged in as the administrator of the site.
 
Click [here http:blog.cgi] to see if this site has KwikiBlog working.
__KwikiCustomization__
There are basically three levels of customization you can do with a kwiki site. They are discussed from easiest to hardest:
 
^=== Config File Changes
 
^=== Template/CSS Changes

lib/CGI/Kwiki/Pages/zh_cn.pm  view on Meta::CPAN

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  - ':' 可以用于页面名称了。这是由 JamesFitzGibbon 所建议的。
  - 修正了由 MikeArms 所回报的 Javascript 瑕疵。
  - 修正了 CGI 参数中的安全性漏洞。这是由 TimSweetman 所回报的。
  - HeikkiLehvaslaiho 修正了由于 Emacs 所产生的人为瑕疵
  - 清掉了多馀的 <p> 卷标。这是由 HolgerSchurig 所回报的
__备份快纪__
快纪 (Kwiki) 能够备份每一次的页面变更,所以你可以很轻易地就把每一个页面回复成早先的版本。目前唯一的备份模块是 CGI::Kwiki::Backup::Rcs ,这个模块使用 RCS 来备份。大致上任何当前的 Uni...
 
[备份快纪]预设并不会启用。如果你要启用这个功能的话,请编辑你的 config.yaml 档案,然后加入这一列:
 
    backup_class: CGI::Kwiki::Backup::Rcs
__快纪部落格__
[快纪部落格]让你能把任何的 Wiki 页面都转为部落格页面。在这之前你得先启用[快纪隐私权]功能,而且也必须先以站台管理者身份登入才行。
 
请点选[这里 http:blog.cgi]来看看[快纪部落格]功能是否已经运作无误了。
__自订快纪__
基本上整个快纪站台有三个不同的自订层级。以下让我们从最简单的开始讨论:
 
^=== 修改组态档案
 
^=== 修改模版/CSS

lib/CGI/Kwiki/Pages/zh_tw.pm  view on Meta::CPAN

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  - ':' 可以用於頁面名稱了。這是由 JamesFitzGibbon 所建議的。
  - 修正了由 MikeArms 所回報的 Javascript 瑕疵。
  - 修正了 CGI 參數中的安全性漏洞。這是由 TimSweetman 所回報的。
  - HeikkiLehvaslaiho 修正了由於 Emacs 所產生的人為瑕疵
  - 清掉了多餘的 <p> 標籤。這是由 HolgerSchurig 所回報的
__備份快紀__
快紀 (Kwiki) 能夠備份每一次的頁面變更,所以妳可以很輕易地就把每一個頁面回復成早先的版本。目前唯一的備份模組是 CGI::Kwiki::Backup::Rcs ,這個模組使用 RCS 來備份。大致上任何當前的 Uni...
 
[備份快紀]預設並不會啟用。如果妳要啟用這個功能的話,請編輯妳的 config.yaml 檔案,然後加入這一列:
 
    backup_class: CGI::Kwiki::Backup::Rcs
__快紀部落格__
[快紀部落格]讓妳能把任何的 Wiki 頁面都轉為部落格頁面。在這之前妳得先啟用[快紀隱私權]功能,而且也必須先以站台管理者身份登入纔行。
 
請點選[這裡 http:blog.cgi]來看看[快紀部落格]功能是否已經運作無誤了。
__自訂快紀__
基本上整個快紀站台有三個不同的自訂層級。以下讓我們從最簡單的開始討論:
 
^=== 修改組態檔案
 
^=== 修改模版/CSS

lib/CGI/Kwiki/Plugin/Diff.pm  view on Meta::CPAN

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
sub methods {
    qw(entry_form display_diff);
}
 
sub entry_form {
    my ($self, $page_id) = @_;
    $page_id ||= $self->cgi->page_id;
 
    return ''
      unless $self->prefs->{select_diff} &&
             $self->backup->has_history;
    my $history = $self->backup->history;
    return '' unless @$history > 1;
    my $head_revision = $history->[0]{revision};
    my $current_revision = $self->cgi->current_revision ||
                           $head_revision;
    my (@values, %labels, $selected);
    for (@$history) {
        my $key = $_->{revision};
        push @values, $key;
        $selected = $key if $key eq $current_revision;
        $labels{$key} = "$_->{file_rev} ($_->{date}) $_->{edit_by}";

lib/CGI/Kwiki/Plugin/Diff.pm  view on Meta::CPAN

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<input type="hidden" name="head_revision" value="$head_revision" />
<input type="hidden" name="current_revision" value="$current_revision" />
</form>
FORM
}
 
sub display_diff {
    my ($self) = shift;
    return ''
      unless $self->prefs->{show_diff} &&
             $self->backup->has_history;
    my $page_id = $self->cgi->page_id;
    my $history = $self->backup->history;
    return '' unless @$history > 1;
    $self->diff($page_id,
                $history->[1]{revision},
                $history->[0]{revision},
                2,
               );
}
 
sub diff {
    my ($self, $page_id, $r1, $r2, $context) = @_;
    $r1 ||= $self->cgi->diff_revision;
    $r2 ||= $self->cgi->current_revision;
    (my $num1 = $r1) =~ s/.*\.//;
    (my $num2 = $r2) =~ s/.*\.//;
    if ($num1 > $num2) {
        ($r1, $r2) = ($r2, $r1);
    }
    return $self->loc('No history') unless $self->backup->has_history;
    my $diff = $self->backup->diff($page_id, $r1, $r2, $context);
    $diff = CGI->escapeHTML($diff);
    $diff =~ s/\r//g;
    $diff =~ s/^\-(.*)$/<del>$1<\/del>/mg;
    $diff =~ s/^\+(.*)$/<ins>$1<\/ins>/mg;
    $diff =~ s/\n/<br>\n/g;
    $self->decode($diff);
    $self->cgi->current_revision($r1);
 
    my $prompt = $self->loc("Differences from revision %1 to %2:", $self->backup->file_rev($page_id, $r1), $self->backup->file_rev($page_id, $r2));
    return <<END;
<h3>$prompt</h3>
<div class="diff">
$diff
</div>
END
}
 
1;



( run in 0.394 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )