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 |
|
|
$Date: 2004/01/16 07:54:22 $ |
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 |
|
|
@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 |
|
|
for (sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @list) { |
72 |
|
|
local $o->{iwc__param}->{uri_reference} = URI->new ($_->[0]); |
73 |
|
|
my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match |
74 |
|
|
(o => $o, |
75 |
|
|
page => $o->{wiki}->{config}->{page}->{InterWikiName}); |
76 |
|
|
$WIKILINKING->to_resource_by_uri_in_html ({ |
77 |
|
|
label => $WIKIRESOURCE->get |
78 |
|
|
(name => 'Referer:RefererList:Label', |
79 |
|
|
o => $o, wiki => $o->{wiki}), |
80 |
|
|
ref__label => (($site ? |
81 |
|
|
$site->get_attribute_value ('URIReference2Label'):'') |
82 |
|
|
|| $WIKIRESOURCE->get |
83 |
|
|
(name => 'Referer:URIReference2Label', |
84 |
|
|
o => $o, wiki => $o->{wiki})), |
85 |
|
|
} => { |
86 |
|
|
uri => $o->{iwc__param}->{uri_reference} = URI->new ($_->[0]), |
87 |
|
|
}, { |
88 |
|
|
o => $o, |
89 |
|
|
parent => $list->append_new_node |
90 |
|
|
(type => '#element', |
91 |
|
|
namespace_uri => $NS_XHTML1, |
92 |
|
|
local_name => 'li'), |
93 |
|
|
ref__weight => $_->[1], |
94 |
|
|
}); |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
Function: |
99 |
|
|
@Name: add_referer |
100 |
|
|
@Main: |
101 |
|
|
my (undef, %opt) = @_; |
102 |
|
|
return unless $opt{wiki}->{db}; |
103 |
|
|
$opt{page} ||= $opt{wiki}->{var}->{page}; |
104 |
|
|
my $o = $opt{o} || {wiki => $opt{wiki}}; |
105 |
|
|
|
106 |
|
|
## To be canonical URI reference object |
107 |
|
|
unless (ref $opt{uri}) { |
108 |
|
|
$opt{uri} = URI->new ($opt{uri})->canonical; |
109 |
|
|
} else { |
110 |
|
|
$opt{uri} = $opt{uri}->canonical; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
local $o->{iwc__param} = { |
114 |
|
|
uri_reference => $opt{uri}, |
115 |
|
|
}; |
116 |
|
|
|
117 |
|
|
## Check with site definition |
118 |
|
|
my $site = $INTERWIKICORE->get_site_entry_by_uri_reference_match |
119 |
|
|
(o => $o, |
120 |
|
|
page => $opt{wiki}->{config}->{page}->{InterWikiName}); |
121 |
|
|
if ($site) { |
122 |
|
|
my $v = 1; |
123 |
|
|
my $check = $site->get_attribute_value |
124 |
|
|
('RefererLog', default => '1'); |
125 |
|
|
try { |
126 |
|
|
$v = $o->{wiki}->{plugin} |
127 |
|
|
->boolean_formatter ('iwc__urireference_operation') |
128 |
|
|
->replace ($check, param => $o); |
129 |
|
|
} catch Message::Util::Formatter::error with { |
130 |
|
|
my $err = shift; |
131 |
|
|
if ($err->{-object}->{-category_name} eq 'iwc__urireference_operation') { |
132 |
|
|
my $wiki = $err->{-option}->{param}->{wiki}; |
133 |
|
|
SuikaWiki::Plugin->module_package ('Error') |
134 |
|
|
->reporting_formatting_template_error |
135 |
|
|
($err, $err->{option}->{param}->{wiki}, |
136 |
|
|
template => $check); |
137 |
|
|
} else { |
138 |
|
|
$err->throw; |
139 |
|
|
} |
140 |
|
|
}; |
141 |
|
|
return unless $v; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
## Update referer list |
145 |
|
|
my %referer; |
146 |
|
|
for (split /\x0A/, $opt{wiki}->{db}->get ('referer', $opt{page})) { |
147 |
|
|
my ($n, $t) = split /\x09/, $_, 2; |
148 |
|
|
$referer{$n} = $t + 0; |
149 |
|
|
} |
150 |
|
|
$referer{$o->{iwc__param}->{uri_reference}}++; |
151 |
|
|
$opt{wiki}->{db}->set ('referer', $opt{page} |
152 |
|
|
=> join "\x0A", map {$_ . "\x09" . $referer{$_}} keys %referer); |
153 |
|
|
|
154 |
|
|
FormattingRule: |
155 |
|
|
@Category[list]: link-to-resource |
156 |
|
|
@Name: ref--referer-item-weight |
157 |
|
|
@Formatting: |
158 |
|
|
$p->{-parent}->append_text ($o->{link}->{option}->{ref__weight}); |
159 |
|
|
|
160 |
|
|
FormattingRule: |
161 |
|
|
@Category[list]: link-to-resource |
162 |
|
|
@Name: ref--referer-item-label |
163 |
|
|
@Formatting: |
164 |
|
|
$f->replace ($o->{link}->{src}->{ref__label}, |
165 |
|
|
param => $o, |
166 |
|
|
-parent => $p->{-parent}); |
167 |
|
|
|
168 |
|
|
Resource: |
169 |
|
|
@Referer:RefererList:Label: |
170 |
|
|
{%ref--referer-item-weight;} %ref--referer-item-label; |
171 |
|
|
@Referer:URIReference2Label: |
172 |
|
|
<%link-to-it (label => {%uri-reference;}p);> |