/[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.7 - (hide annotations) (download)
Tue Mar 30 04:04:44 2004 UTC (22 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +32 -11 lines
Referer list navigation implemented

1 wakaba 1.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]: [email protected]
15     @Date.RCS:
16 wakaba 1.7 $Date: 2004/03/13 12:29:21 $
17 wakaba 1.1 @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     @list = map {[split /\x09/, $_, 2]}
58     split /\x0A/,
59     $o->{wiki}->{db}->get ('referer',
60     $o->{wiki}->name ($p->{page} ||
61     $o->{wiki}->{var}->{page}));
62     } catch SuikaWiki::DB::Util::Error with {
63     #
64     };
65 wakaba 1.6
66 wakaba 1.1 if (@list) {
67     my $list = $p->{-parent}->append_new_node
68     (type => '#element',
69     namespace_uri => $NS_XHTML1,
70     local_name => 'ol');
71 wakaba 1.7
72     @list = sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @list;
73    
74     my $start = length $p->{start} ? $p->{start} :
75     $o->{wiki}->{input}->parameter ('ref--range-start') || 0;
76     $p->{number} = $o->{wiki}->{input}->parameter ('ref--range-number')
77     unless length $p->{number};
78     my $end = $p->{number} ? $start + $p->{number} - 1 : $start + 29;
79     $start = 0 if $start > $#list or $start < 0;
80     $end = $#list if $end < $start or $end > $#list;
81     $end = $start + 255 if $end > $start + 255;
82     local $o->{var}->{search__result} = {
83     min => 0,
84     max => $#list,
85     start => $start,
86     end => $end,
87     number => $p->{number} || 30,
88     param_prefix => 'ref',
89     };
90    
91 wakaba 1.2 my $default_label = $WIKIRESOURCE->get
92     (name => 'Referer:URIReference2Label',
93     o => $o, wiki => $o->{wiki});
94     my $li_label = $WIKIRESOURCE->get
95     (name => 'Referer:RefererList:Label',
96     o => $o, wiki => $o->{wiki});
97 wakaba 1.7
98     for my $item (@list[$start..$end]) {
99 wakaba 1.2 local $o->{iwc__param}->{uri_reference} = URI->new ($item->[0]);
100     my $label;
101     try {
102 wakaba 1.4 $label = $o->{wiki}->{db}->get (ref__item_template => [$item->[0]])
103     or do {
104     my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match
105 wakaba 1.2 (o => $o,
106     page => $o->{wiki}->{config}->{page}->{InterWikiName});
107 wakaba 1.4 $label = $site ? $site->get_attribute_value
108     ('URIReference2Label') || $default_label
109     : $default_label;
110     $o->{wiki}->{db}->set (ref__item_template => [$item->[0]]
111     => $label);
112     };
113 wakaba 1.2 } catch SuikaWiki::DB::Util::Error with {};
114 wakaba 1.1 $WIKILINKING->to_resource_by_uri_in_html ({
115 wakaba 1.2 label => $li_label,
116 wakaba 1.4 ref__label => $label,
117 wakaba 1.1 } => {
118 wakaba 1.2 uri => $o->{iwc__param}->{uri_reference},
119 wakaba 1.1 }, {
120     o => $o,
121     parent => $list->append_new_node
122     (type => '#element',
123     namespace_uri => $NS_XHTML1,
124     local_name => 'li'),
125 wakaba 1.2 ref__weight => $item->[1],
126 wakaba 1.1 });
127     }
128 wakaba 1.7
129     $list->set_attribute (start => $start + 1);
130     __ATTRNODE:%post_list->{$p->{-parent}}__;
131 wakaba 1.1 }
132    
133     Function:
134     @Name: add_referer
135     @Main:
136     my (undef, %opt) = @_;
137     return unless $opt{wiki}->{db};
138 wakaba 1.2 return unless $opt{uri};
139 wakaba 1.1 $opt{page} ||= $opt{wiki}->{var}->{page};
140     my $o = $opt{o} || {wiki => $opt{wiki}};
141    
142     ## To be canonical URI reference object
143     unless (ref $opt{uri}) {
144     $opt{uri} = URI->new ($opt{uri})->canonical;
145     } else {
146     $opt{uri} = $opt{uri}->canonical;
147     }
148    
149     local $o->{iwc__param} = {
150     uri_reference => $opt{uri},
151     };
152    
153     ## Check with site definition
154     my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match
155     (o => $o,
156     page => $opt{wiki}->{config}->{page}->{InterWikiName});
157     if ($site) {
158     my $v = 1;
159     my $check = $site->get_attribute_value
160     ('RefererLog', default => '1');
161     try {
162     $v = $o->{wiki}->{plugin}
163     ->boolean_formatter ('iwc__urireference_operation')
164     ->replace ($check, param => $o);
165     } catch Message::Util::Formatter::error with {
166     my $err = shift;
167     if ($err->{-object}->{-category_name} eq 'iwc__urireference_operation') {
168     my $wiki = $err->{-option}->{param}->{wiki};
169     SuikaWiki::Plugin->module_package ('Error')
170     ->reporting_formatting_template_error
171     ($err, $err->{option}->{param}->{wiki},
172     template => $check);
173     } else {
174     $err->throw;
175     }
176     };
177     return unless $v;
178     }
179    
180     ## Update referer list
181     my %referer;
182     for (split /\x0A/, $opt{wiki}->{db}->get ('referer', $opt{page})) {
183     my ($n, $t) = split /\x09/, $_, 2;
184     $referer{$n} = $t + 0;
185     }
186     $referer{$o->{iwc__param}->{uri_reference}}++;
187     $opt{wiki}->{db}->set ('referer', $opt{page}
188     => join "\x0A", map {$_ . "\x09" . $referer{$_}} keys %referer);
189    
190     FormattingRule:
191     @Category[list]: link-to-resource
192     @Name: ref--referer-item-weight
193     @Formatting:
194     $p->{-parent}->append_text ($o->{link}->{option}->{ref__weight});
195    
196     FormattingRule:
197     @Category[list]: link-to-resource
198     @Name: ref--referer-item-label
199 wakaba 1.2 @Description:
200     @@@:
201     Label for referer list item, that is taken from InterWikiName database.
202     @@lang: en
203 wakaba 1.1 @Formatting:
204 wakaba 1.2 try {
205     $f->replace ($o->{link}->{src}->{ref__label},
206     param => $o,
207     -parent => $p->{-parent});
208     } catch Message::Util::Formatter::error with {
209     my $err = shift;
210     if ($err->{-object}->{-category_name} eq $f->{-category_name}) {
211     my $wiki = $err->{option}->{param}->{wiki};
212     SuikaWiki::Plugin->module_package ('Error')
213     ->reporting_formatting_template_error
214     ($err, $wiki,
215     template => $o->{link}->{src}->{ref__label});
216     undef;
217     } else {
218     $err->throw;
219     }
220     };
221 wakaba 1.3
222     ViewFragment:
223     @Name: ws--post-content
224     @Description:
225     @@@: After content body -- referer lista
226     @@lang:en
227     @Order: 150
228     @Formatting:
229     %section (
230     id => referer,
231     title => {%res(name=>Referer);}p, heading,
232 wakaba 1.7 content => {%referer-list (
233     number => 10,
234     post-list => {%search--result-navigation (
235     fragment => referer,
236     );}p,
237     );}p,
238 wakaba 1.3 );
239 wakaba 1.1
240     Resource:
241     @Referer:RefererList:Label:
242     {%ref--referer-item-weight;} %ref--referer-item-label;
243     @Referer:URIReference2Label:
244     <%link-to-it (label => {%uri-reference;}p);>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24