| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MojoMojo::Formatter::WikipediaLink; |
|
2
|
26
|
|
|
26
|
|
71133
|
use strict; |
|
|
26
|
|
|
|
|
72
|
|
|
|
26
|
|
|
|
|
723
|
|
|
3
|
26
|
|
|
26
|
|
128
|
use warnings; |
|
|
26
|
|
|
|
|
60
|
|
|
|
26
|
|
|
|
|
664
|
|
|
4
|
26
|
|
|
26
|
|
452
|
use parent qw/MojoMojo::Formatter/; |
|
|
26
|
|
|
|
|
287
|
|
|
|
26
|
|
|
|
|
144
|
|
|
5
|
26
|
|
|
26
|
|
1744
|
use utf8; |
|
|
26
|
|
|
|
|
72
|
|
|
|
26
|
|
|
|
|
215
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=encoding utf8 |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
MojoMojo::Formatter::WikipediaLink - Linked Wikipedia by writing {{wikipedia:<lang> <word>}} |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Normally, to hyperlink to the Wikipedia, you'd write: |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
[wikipedia Hello](http://en.wikipedia.org/wiki/Hello) |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This plugin lets you write just |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{{wikipedia Hello}} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
not just Link to Wikipedia in English page, you can use many languages |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{{wikipedia:ja ããã«ã¡ã¯}} |
|
26
|
|
|
|
|
|
|
{{wikipedia:fr Salut}} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Actually, if you wrote this without a language ex.{{wikipedia Foo}}, |
|
29
|
|
|
|
|
|
|
select location of Wikipedia Link |
|
30
|
|
|
|
|
|
|
is getting default-language setting of MojoMojo. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 format_content_order |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The WikipediaLink formatter has no special requirements |
|
37
|
|
|
|
|
|
|
in terms of the order it gets run in, so it has a priority of 17. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
992
|
|
|
992
|
1
|
3215
|
sub format_content_order { 17 } |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 format_content |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Calls the formatter. Takes a ref to the content as well as the context object. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub format_content { |
|
50
|
128
|
|
|
128
|
1
|
3513
|
my ( $class, $content, $c ) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
128
|
|
|
|
|
666
|
my @lines = split /\n/, $$content; |
|
53
|
128
|
|
|
|
|
343
|
$$content = ''; |
|
54
|
|
|
|
|
|
|
|
|
55
|
128
|
|
|
|
|
740
|
my $re = $class->gen_re( qr/[wW]ikipedia(?::([^\s]+))?\s+(.+)/ ); |
|
56
|
|
|
|
|
|
|
my $lang = $c->sessionid |
|
57
|
128
|
100
|
50
|
|
|
664
|
? $c->session->{lang} : $c->pref('default_lang') || 'en'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
128
|
|
|
|
|
25558
|
for my $line (@lines) { |
|
60
|
734
|
100
|
|
|
|
2564
|
if ( $line =~ m/$re/ ) { |
|
61
|
4
|
|
|
|
|
16
|
$line = $class->process($c, $line, $re, $lang); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
734
|
|
|
|
|
1886
|
$$content .= $line . "\n"; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 process |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Here the actual formatting is done. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
|
73
|
|
|
|
|
|
|
sub process { |
|
74
|
4
|
|
|
4
|
1
|
7
|
my $class = shift; |
|
75
|
4
|
|
|
|
|
10
|
my ($c, $line, $re, $lang) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
17
|
$line =~ m/$re/; |
|
78
|
4
|
|
50
|
|
|
25
|
my $wikipedia_lang = $1 || $c->pref('default_lang') || 'en'; |
|
79
|
4
|
|
|
|
|
355
|
my $keyword = $2; |
|
80
|
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
22
|
my $uri = URI->new("http://$wikipedia_lang.wikipedia.org/"); |
|
82
|
4
|
|
|
|
|
312
|
$uri->path("/wiki/$keyword"); |
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
284
|
$line =~ s!$re!<a href="$uri">$keyword</a>!; |
|
85
|
4
|
|
|
|
|
36
|
$c->stash->{precompile_off} = 1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
259
|
return $line; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L<MojoMojo> and L<Module::Pluggable::Ordered>. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHORS |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Dai Okabayashi, L<bayashi at cpan . org> |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LICENSE |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
|
102
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |