line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Wikiwyg; |
2
|
1
|
|
|
1
|
|
35838
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
182
|
|
3
|
1
|
|
|
1
|
|
2280
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
5
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
6
|
|
|
|
|
|
|
use Spoon::Formatter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
const class_id => 'wikiwyg'; |
9
|
|
|
|
|
|
|
const css_file => 'wikiwyg.css'; |
10
|
|
|
|
|
|
|
const config_file => 'wikiwyg.yaml'; |
11
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::Wikiwyg::CGI'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
14
|
|
|
|
|
|
|
my $registry = shift; |
15
|
|
|
|
|
|
|
$registry->add(action => 'wikiwyg_save_wikitext'); |
16
|
|
|
|
|
|
|
$registry->add(action => 'wikiwyg_wikitext_to_html'); |
17
|
|
|
|
|
|
|
$registry->add(preference => $self->wikiwyg_use); |
18
|
|
|
|
|
|
|
$registry->add(preference => $self->wikiwyg_double); |
19
|
|
|
|
|
|
|
$registry->add(hook => 'display:display', pre => 'add_library'); |
20
|
|
|
|
|
|
|
$registry->add(hook => 'display:display', post => 'modify_html'); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub wikiwyg_use { |
24
|
|
|
|
|
|
|
my $p = $self->new_preference('wikiwyg_use'); |
25
|
|
|
|
|
|
|
$p->query('Use the Wikiwyg Editor? (IE/Firefox only)'); |
26
|
|
|
|
|
|
|
$p->type('boolean'); |
27
|
|
|
|
|
|
|
$p->default(1); |
28
|
|
|
|
|
|
|
return $p; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub wikiwyg_double { |
32
|
|
|
|
|
|
|
my $p = $self->new_preference('wikiwyg_double'); |
33
|
|
|
|
|
|
|
$p->query('Double Click to Wikiwyg Edit?'); |
34
|
|
|
|
|
|
|
$p->type('boolean'); |
35
|
|
|
|
|
|
|
$p->default(1); |
36
|
|
|
|
|
|
|
return $p; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add_library { |
40
|
|
|
|
|
|
|
return unless $self->preferences->wikiwyg_use->value; |
41
|
|
|
|
|
|
|
$self->hub->css->add_file('wikiwyg.css'); |
42
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg.js'); |
43
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/Toolbar.js'); |
44
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/Wysiwyg.js'); |
45
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/Wikitext.js'); |
46
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/Preview.js'); |
47
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/HTML.js'); |
48
|
|
|
|
|
|
|
$self->hub->javascript->add_file('Wikiwyg/Kwiki.js'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub modify_html { |
52
|
|
|
|
|
|
|
my $hook = pop; |
53
|
|
|
|
|
|
|
my $html = $hook->returned; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $double = $self->preferences->wikiwyg_double->value ? 'true' : 'false'; |
56
|
|
|
|
|
|
|
$html =~ |
57
|
|
|
|
|
|
|
s{(\n$1}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$html =~ |
61
|
|
|
|
|
|
|
s{()} |
62
|
|
|
|
|
|
|
{\n$1}; |
63
|
|
|
|
|
|
|
$html =~ |
64
|
|
|
|
|
|
|
s{(href="css/wikiwyg.css" />)} |
65
|
|
|
|
|
|
|
{$1\n}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $html; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub wikiwyg_wikitext_to_html { |
71
|
|
|
|
|
|
|
my $wikitext = $self->cgi->content; |
72
|
|
|
|
|
|
|
return $self->hub->formatter->text_to_html($wikitext); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub wikiwyg_save_wikitext { |
76
|
|
|
|
|
|
|
my $wikitext = $self->cgi->content; |
77
|
|
|
|
|
|
|
return $self->save($wikitext); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub save { |
81
|
|
|
|
|
|
|
my $content = shift; |
82
|
|
|
|
|
|
|
return $self->redirect($self->pages->current->uri) |
83
|
|
|
|
|
|
|
unless defined $content; |
84
|
|
|
|
|
|
|
my $page = $self->pages->current; |
85
|
|
|
|
|
|
|
$page->content($content); |
86
|
|
|
|
|
|
|
$page->update->store; |
87
|
|
|
|
|
|
|
return $self->redirect($page->uri); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
package Spoon::Formatter::WaflPhrase; |
91
|
|
|
|
|
|
|
sub wikiwyg_to_html { |
92
|
|
|
|
|
|
|
return sprintf '%s', |
93
|
|
|
|
|
|
|
$self->method, |
94
|
|
|
|
|
|
|
$self->arguments, |
95
|
|
|
|
|
|
|
$self->to_html; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
package Spoon::Formatter::WaflBlock; |
99
|
|
|
|
|
|
|
sub wikiwyg_to_html { |
100
|
|
|
|
|
|
|
my $opaque = $self->block_text; |
101
|
|
|
|
|
|
|
$opaque =~ s/\A\n*//; |
102
|
|
|
|
|
|
|
$opaque =~ s/\n*\z/\n/; |
103
|
|
|
|
|
|
|
$opaque =~ s//-=->/g; |
105
|
|
|
|
|
|
|
return sprintf qq{ %s }, |
106
|
|
|
|
|
|
|
$self->to_html, |
107
|
|
|
|
|
|
|
$self->method, |
108
|
|
|
|
|
|
|
$opaque, |
109
|
|
|
|
|
|
|
$self->method; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
package Spoon::Formatter::Unit; |
113
|
|
|
|
|
|
|
sub wikiwyg_to_html { |
114
|
|
|
|
|
|
|
$self->to_html; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
no warnings; |
118
|
|
|
|
|
|
|
sub html { |
119
|
|
|
|
|
|
|
my $inner = $self->text_filter(join '', |
120
|
|
|
|
|
|
|
map { |
121
|
|
|
|
|
|
|
ref($_) ? $_->wikiwyg_to_html : $_; |
122
|
|
|
|
|
|
|
} @{$self->units} |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
$self->html_start . $inner . $self->html_end; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
use warnings; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
package Kwiki::Wikiwyg::CGI; |
130
|
|
|
|
|
|
|
use base 'Kwiki::CGI'; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
cgi 'content' => qw(-utf8 -newlines); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
package Kwiki::Wikiwyg; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__DATA__ |