/[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.4 - (hide annotations) (download)
Fri Mar 12 04:57:10 2004 UTC (20 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +19 -11 lines
*** empty log message ***

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24