line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blikistan::MagicEngine::TT2; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'Blikistan::MagicEngine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
5
|
1
|
|
|
1
|
|
2681
|
use Template; |
|
1
|
|
|
|
|
53513
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
1293
|
use FindBin; |
|
1
|
|
|
|
|
1391
|
|
|
1
|
|
|
|
|
48
|
|
7
|
1
|
|
|
1
|
|
8
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
8
|
1
|
|
|
1
|
|
660
|
use JSON; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub render_template { |
11
|
|
|
|
|
|
|
my $self = shift; |
12
|
|
|
|
|
|
|
my $params = $self->{params} = shift || {}; |
13
|
|
|
|
|
|
|
my $r = $self->{rester}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->load_rester_utils; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$params->{magic_engine} = ref($self); |
18
|
|
|
|
|
|
|
my $output = ''; |
19
|
|
|
|
|
|
|
my $tmpl = $self->{template_name}; |
20
|
|
|
|
|
|
|
if ($self->{template_page}) { |
21
|
|
|
|
|
|
|
$r->accept('text/x.socialtext-wiki'); |
22
|
|
|
|
|
|
|
my $content = $r->get_page($self->{template_page}); |
23
|
|
|
|
|
|
|
if ($r->response->code eq '404') { |
24
|
|
|
|
|
|
|
$content = $self->default_content; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
$content =~ s/^\.pre\n(.+?)\.pre\n?.*/$1/s; |
27
|
|
|
|
|
|
|
$tmpl = \$content; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Hide password, so it's not visible to the templates |
31
|
|
|
|
|
|
|
$r->{password} = undef; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $path = join ': ', |
34
|
|
|
|
|
|
|
grep { defined } |
35
|
|
|
|
|
|
|
($self->{template_path}, $FindBin::Bin); |
36
|
|
|
|
|
|
|
my $template = Template->new( { INCLUDE_PATH => $path } ); |
37
|
|
|
|
|
|
|
$template->process( $tmpl, $params, \$output) or |
38
|
|
|
|
|
|
|
die $template->error; |
39
|
|
|
|
|
|
|
return $output; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub default_content { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
return <
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Blikistan Problem |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Could not find template at $self->{template_page} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
[% IF yaml_error %] |
51
|
|
|
|
|
|
|
[% yaml_error %] |
52
|
|
|
|
|
|
|
[% END %] |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
EOT |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub load_rester_utils { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
my $r = $self->{rester}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $show_latest = delete $self->{params}{show_latest_posts} |
63
|
|
|
|
|
|
|
|| $self->{show_latest_posts}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->{params}{tagged_pages} ||= sub { |
66
|
|
|
|
|
|
|
my $tag = shift; |
67
|
|
|
|
|
|
|
$r->accept('text/plain'); |
68
|
|
|
|
|
|
|
my @posts = $r->get_taggedpages($tag); |
69
|
|
|
|
|
|
|
@posts = splice @posts, 0, $show_latest; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$r->accept('text/html'); |
72
|
|
|
|
|
|
|
return [ map { $self->_load_page($_) } @posts ]; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$self->{params}{show_page} ||= sub { |
76
|
|
|
|
|
|
|
my $p = $self->_load_page(shift); |
77
|
|
|
|
|
|
|
return $p->{html}; |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->{params}{workspace_tags} ||= sub { |
81
|
|
|
|
|
|
|
my $skip = shift || ''; |
82
|
|
|
|
|
|
|
$r->accept('application/json'); |
83
|
|
|
|
|
|
|
my $tags = jsonToObj($r->get_workspace_tags); |
84
|
|
|
|
|
|
|
$tags = [ |
85
|
|
|
|
|
|
|
sort { $b->{page_count} <=> $a->{page_count} } |
86
|
|
|
|
|
|
|
grep { $_->{name} ne $skip } |
87
|
|
|
|
|
|
|
@$tags |
88
|
|
|
|
|
|
|
]; |
89
|
|
|
|
|
|
|
return $tags; |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->{params}{abbrev_page} ||= sub { |
93
|
|
|
|
|
|
|
my $page = shift; |
94
|
|
|
|
|
|
|
my $length = shift || 30; |
95
|
|
|
|
|
|
|
my $p = $self->_load_page($page); |
96
|
|
|
|
|
|
|
my $small = substr($p->{wikitext}, 0, $length); |
97
|
|
|
|
|
|
|
$small .= " ..." if $small ne $p->{wikitext}; |
98
|
|
|
|
|
|
|
return $small; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub linkify { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $p = $self->_load_page(shift); |
106
|
|
|
|
|
|
|
return $p->{page_uri}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _load_page { |
110
|
|
|
|
|
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
my $page = uri_escape(shift); |
112
|
|
|
|
|
|
|
return $self->{_page}{$page} if $self->{_page}{$page}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $r = $self->{rester}; |
115
|
|
|
|
|
|
|
$r->accept('application/json'); |
116
|
|
|
|
|
|
|
$r->json_verbose(1); |
117
|
|
|
|
|
|
|
my $p = $self->{_page}{$page} = jsonToObj( $r->get_page($page) ); |
118
|
|
|
|
|
|
|
while ($p->{html} =~ s/
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$p->{html} =~ s#^ (.+) \s*$#$1#s; |
121
|
|
|
|
|
|
|
return $p; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |