1 |
use strict; |
2 |
package SuikaWiki::Plugin::Registry; |
3 |
|
4 |
|
5 |
our %Info; |
6 |
$Info{q#Referer#}->{Name} = q#Referer#; |
7 |
$Info{q#Referer#}->{q#Version#} = q#2006.1203.0355#; |
8 |
$Info{q#Referer#}->{q#InterfaceVersion#} = q#2.9.1#; |
9 |
$Info{q#Referer#}->{q#mkpluginVersion#} = q#2.1.21#; |
10 |
$Info{q#Referer#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::Referer1061103035513VAp6#; |
11 |
$Info{q#Referer#}->{q#Date.RCS#} = q#$Date: 2004/04/17 04:17:53 $#; |
12 |
$Info{q#Referer#}->{RequiredPlugin} = [q#InterWikiCore#, q#WikiStructure#, q#WikiLinking#]; |
13 |
$Info{q#Referer#}->{RequiredModule} = [q#URI#]; |
14 |
$Info{q#Referer#}->{Description} = [[q#Backward hyperlinking#, q#en#, q##]]; |
15 |
$Info{q#Referer#}->{License} = [[q#%%Perl%%#, q##, q##]]; |
16 |
$Info{q#Referer#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#w@suika.fam.cx#]], [q##]]]; |
17 |
package SuikaWiki::Plugin::plugin::Referer1061103035513VAp6; |
18 |
|
19 |
|
20 |
#line 1 "(WikiPlugin module source referer.wp2, block Plugin/Use)" |
21 |
use Message::Util::Error; |
22 |
require URI; |
23 |
my $INTERWIKICORE; |
24 |
my $WIKIRESOURCE; |
25 |
my $WIKILINKING; |
26 |
#line 1 "(WikiPlugin module Referer, chunk 1)" |
27 |
|
28 |
{my $def = {q#Parameter#, {q#page#, {q#Type#, q#WikiName#, q#Default#, q#(auto)#, q#Description#, [[q##, q##, q##]]}}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
29 |
|
30 |
#line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/referer_list']/Formatting)" |
31 |
$p->{q#page#} = do { my $r = $f->parse_attr ($p=>q#page#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r}; |
32 |
my @list; |
33 |
try { |
34 |
my $ref = $o->{wiki}->{db}->get ('referer', |
35 |
$o->{wiki}->name ($p->{page} || |
36 |
$o->{wiki}->{var}->{page})); |
37 |
@list = map {[$_ => $ref->{$_}]} keys %$ref; |
38 |
} catch SuikaWiki::DB::Util::Error with { |
39 |
}; |
40 |
if (@list) { |
41 |
my $list = $p->{-parent}->append_new_node |
42 |
(type => '#element', |
43 |
namespace_uri => q#http://www.w3.org/1999/xhtml#, |
44 |
local_name => 'ol'); |
45 |
@list = sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @list; |
46 |
my $start = length $p->{start} ? $p->{start} : |
47 |
$o->{wiki}->{input}->parameter ('ref--range-start') || 0; |
48 |
$p->{number} = $o->{wiki}->{input}->parameter ('ref--range-number') |
49 |
unless length $p->{number}; |
50 |
my $end = $p->{number} ? $start + $p->{number} - 1 : $start + 29; |
51 |
$start = 0 if $start > $#list or $start < 0; |
52 |
$end = $#list if $end < $start or $end > $#list; |
53 |
$end = $start + 255 if $end > $start + 255; |
54 |
local $o->{var}->{search__result} = { |
55 |
min => 0, |
56 |
max => $#list, |
57 |
start => $start, |
58 |
end => $end, |
59 |
number => $p->{number} || 30, |
60 |
param_prefix => 'ref', |
61 |
}; |
62 |
my $default_label = ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get |
63 |
(name => 'Referer:URIReference2Label', |
64 |
o => $o, wiki => $o->{wiki}); |
65 |
my $li_label = ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get |
66 |
(name => 'Referer:RefererList:Label', |
67 |
o => $o, wiki => $o->{wiki}); |
68 |
for my $item (@list[$start..$end]) { |
69 |
local $o->{iwc__param}->{uri_reference} = URI->new ($item->[0]); |
70 |
my $label; |
71 |
try { |
72 |
$label = $o->{wiki}->{db}->get (ref__item_template => [$item->[0]]) |
73 |
or do { |
74 |
my $site = ($INTERWIKICORE ||= SuikaWiki::Plugin->module_package ('InterWikiCore'))->get_site_entry_by_uri_reference_match |
75 |
(o => $o, |
76 |
page => $o->{wiki}->{config}->{page}->{InterWikiName}); |
77 |
$label = $site ? $site->get_attribute_value |
78 |
('URIReference2Label') || $default_label |
79 |
: $default_label; |
80 |
$o->{wiki}->{db}->set (ref__item_template => [$item->[0]] |
81 |
=> $label); |
82 |
}; |
83 |
} catch SuikaWiki::DB::Util::Error with {}; |
84 |
($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))->to_resource_by_uri_in_html ({ |
85 |
label => $li_label, |
86 |
ref__label => $label, |
87 |
} => { |
88 |
uri => $o->{iwc__param}->{uri_reference}, |
89 |
}, { |
90 |
o => $o, |
91 |
parent => $list->append_new_node |
92 |
(type => '#element', |
93 |
namespace_uri => q#http://www.w3.org/1999/xhtml#, |
94 |
local_name => 'li'), |
95 |
ref__weight => $item->[1], |
96 |
}); |
97 |
} |
98 |
$list->set_attribute (start => $start + 1); |
99 |
$f->parse_attr ($p=>q#post_list#, $o, -parent => $p->{-parent}, -non_parsed_to_node => 1, %opt); |
100 |
}}} |
101 |
#line 1 "(WikiPlugin module Referer, chunk 2)" |
102 |
; |
103 |
$SuikaWiki::Plugin::Rule{view}->{referer_list} = $def; |
104 |
$SuikaWiki::Plugin::Rule{view_resource}->{referer_list} = $def; |
105 |
$SuikaWiki::Plugin::Rule{form_input}->{referer_list} = $def; |
106 |
}; |
107 |
|
108 |
|
109 |
sub add_referer { |
110 |
|
111 |
#line 1 "(WikiPlugin module source referer.wp2, block Function[Name='add_referer']/Main)" |
112 |
my (undef, %opt) = @_; |
113 |
return unless $opt{wiki}->{db}; |
114 |
return unless $opt{uri}; |
115 |
$opt{page} ||= $opt{wiki}->{var}->{page}; |
116 |
my $o = $opt{o} || {wiki => $opt{wiki}}; |
117 |
unless (ref $opt{uri}) { |
118 |
$opt{uri} = URI->new ($opt{uri})->canonical; |
119 |
} else { |
120 |
$opt{uri} = $opt{uri}->canonical; |
121 |
} |
122 |
local $o->{iwc__param} = { |
123 |
uri_reference => $opt{uri}, |
124 |
}; |
125 |
my $site = ($INTERWIKICORE ||= SuikaWiki::Plugin->module_package ('InterWikiCore'))->get_site_entry_by_uri_reference_match |
126 |
(o => $o, |
127 |
page => $opt{wiki}->{config}->{page}->{InterWikiName}); |
128 |
if ($site) { |
129 |
my $v = 1; |
130 |
my $check = $site->get_attribute_value |
131 |
('RefererLog', default => '1'); |
132 |
try { |
133 |
$v = $o->{wiki}->{plugin} |
134 |
->boolean_formatter ('iwc__urireference_operation') |
135 |
->replace ($check, param => $o); |
136 |
} catch Message::Util::Formatter::error with { |
137 |
my $err = shift; |
138 |
if ($err->{-object}->{-category_name} eq 'iwc__urireference_operation') { |
139 |
my $wiki = $err->{-option}->{param}->{wiki}; |
140 |
SuikaWiki::Plugin->module_package ('Error') |
141 |
->reporting_formatting_template_error |
142 |
($err, $err->{option}->{param}->{wiki}, |
143 |
template => $check); |
144 |
} else { |
145 |
$err->throw; |
146 |
} |
147 |
}; |
148 |
return unless $v; |
149 |
} |
150 |
my $ref = $opt{wiki}->{db}->get ('referer', $opt{page}); |
151 |
$ref->{$o->{iwc__param}->{uri_reference}}++; |
152 |
$opt{wiki}->{db}->set ('referer', $opt{page} => $ref); |
153 |
} |
154 |
|
155 |
#line 1 "(WikiPlugin module Referer, chunk 4)" |
156 |
|
157 |
|
158 |
$SuikaWiki::Plugin::Rule{link_to_resource}->{ref__referer_item_weight} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
159 |
|
160 |
#line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#link-to-resource#]/ref__referer_item_weight']/Formatting)" |
161 |
$p->{-parent}->append_text ($o->{link}->{option}->{ref__weight});}} |
162 |
#line 1 "(WikiPlugin module Referer, chunk 5)" |
163 |
; |
164 |
|
165 |
$SuikaWiki::Plugin::Rule{link_to_resource}->{ref__referer_item_label} = {q#Parameter#, {}, q#Description#, [[q#Label for referer list item, that is taken from InterWikiName database.#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
166 |
|
167 |
#line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#link-to-resource#]/ref__referer_item_label']/Formatting)" |
168 |
try { |
169 |
$f->replace ($o->{link}->{src}->{ref__label}, |
170 |
param => $o, |
171 |
-parent => $p->{-parent}); |
172 |
} catch Message::Util::Formatter::error with { |
173 |
my $err = shift; |
174 |
if ($err->{-object}->{-category_name} eq $f->{-category_name}) { |
175 |
my $wiki = $err->{option}->{param}->{wiki}; |
176 |
SuikaWiki::Plugin->module_package ('Error') |
177 |
->reporting_formatting_template_error |
178 |
($err, $wiki, |
179 |
template => $o->{link}->{src}->{ref__label}); |
180 |
undef; |
181 |
} else { |
182 |
$err->throw; |
183 |
} |
184 |
};}} |
185 |
#line 1 "(WikiPlugin module Referer, chunk 7)" |
186 |
; |
187 |
|
188 |
package SuikaWiki::Plugin::Resource; |
189 |
|
190 |
our $BaseResource; |
191 |
$BaseResource->{q#und#}->{q##}->{q#Referer:RefererList:Label#} = q#{%ref--referer-item-weight;} %ref--referer-item-label;#; |
192 |
$BaseResource->{q#und#}->{q##}->{q#Referer:URIReference2Label#} = q#<%link-to-it (label => {%uri-reference;}p);>#; |
193 |
package SuikaWiki::Plugin::Registry; |
194 |
|
195 |
$Info{q#Referer#}->{provide} = {q#rule#, {q#link_to_resource#, [q#ref__referer_item_weight#, q#ref__referer_item_label#], q#form_input#, [q#referer_list#], q#view#, [q#referer_list#], q#view_resource#, [q#referer_list#]}}; |
196 |
|
197 |
1; |