/[pub]/suikawiki/script/misc/plugins/referer.wp2
Suika

Contents of /suikawiki/script/misc/plugins/referer.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Sun Aug 17 05:14:53 2008 UTC (16 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, HEAD
Changes since 1.8: +2 -2 lines
*** empty log message ***

1 #?SuikaWikiConfig/2.0
2
3 Plugin:
4 @Name: Referer
5 @Description:
6 @@@: Backward hyperlinking
7 @@lang:en
8 @License: %%Perl%%
9 @Author:
10 @@Name:
11 @@@@: Wakaba
12 @@@lang:ja
13 @@@script:Latn
14 @@Mail[list]: w@suika.fam.cx
15 @Date.RCS:
16 $Date: 2004/04/17 04:17:53 $
17 @RequiredPlugin[list]:
18 InterWikiCore
19 WikiStructure
20 WikiLinking
21 @RequiredModule[list]:
22 URI
23 @Use:
24 use Message::Util::Error;
25 require URI;
26 my $INTERWIKICORE;
27 my $WIKIRESOURCE;
28 my $WIKILINKING;
29
30 PluginConst:
31 @NS_XHTML1:
32 http://www.w3.org/1999/xhtml
33 @INTERWIKICORE:
34 {($INTERWIKICORE ||= SuikaWiki::Plugin->module_package ('InterWikiCore'))}
35 @WIKIRESOURCE:
36 {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))}
37 @WIKILINKING:
38 {($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))}
39
40 FormattingRule:
41 @Category[list]:
42 view
43 view-resource
44 form-input
45 @Name: referer-list
46 @Parameter:
47 @@Name: page
48 @@Type: WikiName
49 @@Default: (auto)
50 @@Description:
51 @@@: WikiPage name
52 @@lang: en
53 @Formatting:
54 __ATTRTEXT:%page__;
55 my @list;
56 try {
57 my $ref = $o->{wiki}->{db}->get ('referer',
58 $o->{wiki}->name ($p->{page} ||
59 $o->{wiki}->{var}->{page}));
60 @list = map {[$_ => $ref->{$_}]} keys %$ref;
61 } catch SuikaWiki::DB::Util::Error with {
62 #
63 };
64
65 if (@list) {
66 my $list = $p->{-parent}->append_new_node
67 (type => '#element',
68 namespace_uri => $NS_XHTML1,
69 local_name => 'ol');
70
71 @list = sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @list;
72
73 my $start = length $p->{start} ? $p->{start} :
74 $o->{wiki}->{input}->parameter ('ref--range-start') || 0;
75 $p->{number} = $o->{wiki}->{input}->parameter ('ref--range-number')
76 unless length $p->{number};
77 my $end = $p->{number} ? $start + $p->{number} - 1 : $start + 29;
78 $start = 0 if $start > $#list or $start < 0;
79 $end = $#list if $end < $start or $end > $#list;
80 $end = $start + 255 if $end > $start + 255;
81 local $o->{var}->{search__result} = {
82 min => 0,
83 max => $#list,
84 start => $start,
85 end => $end,
86 number => $p->{number} || 30,
87 param_prefix => 'ref',
88 };
89
90 my $default_label = $WIKIRESOURCE->get
91 (name => 'Referer:URIReference2Label',
92 o => $o, wiki => $o->{wiki});
93 my $li_label = $WIKIRESOURCE->get
94 (name => 'Referer:RefererList:Label',
95 o => $o, wiki => $o->{wiki});
96
97 for my $item (@list[$start..$end]) {
98 local $o->{iwc__param}->{uri_reference} = URI->new ($item->[0]);
99 my $label;
100 try {
101 $label = $o->{wiki}->{db}->get (ref__item_template => [$item->[0]])
102 or do {
103 my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match
104 (o => $o,
105 page => $o->{wiki}->{config}->{page}->{InterWikiName});
106 $label = $site ? $site->get_attribute_value
107 ('URIReference2Label') || $default_label
108 : $default_label;
109 $o->{wiki}->{db}->set (ref__item_template => [$item->[0]]
110 => $label);
111 };
112 } catch SuikaWiki::DB::Util::Error with {};
113 $WIKILINKING->to_resource_by_uri_in_html ({
114 label => $li_label,
115 ref__label => $label,
116 } => {
117 uri => $o->{iwc__param}->{uri_reference},
118 }, {
119 o => $o,
120 parent => $list->append_new_node
121 (type => '#element',
122 namespace_uri => $NS_XHTML1,
123 local_name => 'li'),
124 ref__weight => $item->[1],
125 });
126 }
127
128 $list->set_attribute (start => $start + 1);
129 __ATTRNODE:%post_list->{$p->{-parent}}__;
130 }
131
132 Function:
133 @Name: add_referer
134 @Main:
135 my (undef, %opt) = @_;
136 return unless $opt{wiki}->{db};
137 return unless $opt{uri};
138 $opt{page} ||= $opt{wiki}->{var}->{page};
139 my $o = $opt{o} || {wiki => $opt{wiki}};
140
141 ## To be canonical URI reference object
142 unless (ref $opt{uri}) {
143 $opt{uri} = URI->new ($opt{uri})->canonical;
144 } else {
145 $opt{uri} = $opt{uri}->canonical;
146 }
147
148 local $o->{iwc__param} = {
149 uri_reference => $opt{uri},
150 };
151
152 ## Check with site definition
153 my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match
154 (o => $o,
155 page => $opt{wiki}->{config}->{page}->{InterWikiName});
156 if ($site) {
157 my $v = 1;
158 my $check = $site->get_attribute_value
159 ('RefererLog', default => '1');
160 try {
161 $v = $o->{wiki}->{plugin}
162 ->boolean_formatter ('iwc__urireference_operation')
163 ->replace ($check, param => $o);
164 } catch Message::Util::Formatter::error with {
165 my $err = shift;
166 if ($err->{-object}->{-category_name} eq 'iwc__urireference_operation') {
167 my $wiki = $err->{-option}->{param}->{wiki};
168 SuikaWiki::Plugin->module_package ('Error')
169 ->reporting_formatting_template_error
170 ($err, $err->{option}->{param}->{wiki},
171 template => $check);
172 } else {
173 $err->throw;
174 }
175 };
176 return unless $v;
177 }
178
179 ## Update referer list
180 my $ref = $opt{wiki}->{db}->get ('referer', $opt{page});
181 $ref->{$o->{iwc__param}->{uri_reference}}++;
182 $opt{wiki}->{db}->set ('referer', $opt{page} => $ref);
183
184 FormattingRule:
185 @Category[list]: link-to-resource
186 @Name: ref--referer-item-weight
187 @Formatting:
188 $p->{-parent}->append_text ($o->{link}->{option}->{ref__weight});
189
190 FormattingRule:
191 @Category[list]: link-to-resource
192 @Name: ref--referer-item-label
193 @Description:
194 @@@:
195 Label for referer list item, that is taken from InterWikiName database.
196 @@lang: en
197 @Formatting:
198 try {
199 $f->replace ($o->{link}->{src}->{ref__label},
200 param => $o,
201 -parent => $p->{-parent});
202 } catch Message::Util::Formatter::error with {
203 my $err = shift;
204 if ($err->{-object}->{-category_name} eq $f->{-category_name}) {
205 my $wiki = $err->{option}->{param}->{wiki};
206 SuikaWiki::Plugin->module_package ('Error')
207 ->reporting_formatting_template_error
208 ($err, $wiki,
209 template => $o->{link}->{src}->{ref__label});
210 undef;
211 } else {
212 $err->throw;
213 }
214 };
215
216 XViewFragment:
217 @Name: ws--post-content
218 @Description:
219 @@@: After content body -- referer lista
220 @@lang:en
221 @Order: 150
222 @Formatting:
223 %section (
224 id => referer,
225 title => {%res(name=>Referer);}p, heading,
226 content => {%referer-list (
227 number => 10,
228 post-list => {%search--result-navigation (
229 fragment => referer,
230 );}p,
231 );}p,
232 );
233
234 Resource:
235 @Referer:RefererList:Label:
236 {%ref--referer-item-weight;} %ref--referer-item-label;
237 @Referer:URIReference2Label:
238 <%link-to-it (label => {%uri-reference;}p);>

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24