use strict; package SuikaWiki::Plugin::Registry; our %Info; $Info{q#Referer#}->{Name} = q#Referer#; $Info{q#Referer#}->{q#Version#} = q#2006.1203.0355#; $Info{q#Referer#}->{q#InterfaceVersion#} = q#2.9.1#; $Info{q#Referer#}->{q#mkpluginVersion#} = q#2.1.21#; $Info{q#Referer#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::Referer1061103035513VAp6#; $Info{q#Referer#}->{q#Date.RCS#} = q#$Date: 2010/05/16 23:05:49 $#; $Info{q#Referer#}->{RequiredPlugin} = [q#InterWikiCore#, q#WikiStructure#, q#WikiLinking#]; $Info{q#Referer#}->{RequiredModule} = [q#URI#]; $Info{q#Referer#}->{Description} = [[q#Backward hyperlinking#, q#en#, q##]]; $Info{q#Referer#}->{License} = [[q#%%Perl%%#, q##, q##]]; $Info{q#Referer#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#w@suika.fam.cx#]], [q##]]]; package SuikaWiki::Plugin::plugin::Referer1061103035513VAp6; #line 1 "(WikiPlugin module source referer.wp2, block Plugin/Use)" use Message::Util::Error; require URI; my $INTERWIKICORE; my $WIKIRESOURCE; my $WIKILINKING; #line 1 "(WikiPlugin module Referer, chunk 1)" {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) = @_; #line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/referer_list']/Formatting)" $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}; my @list; try { my $ref = $o->{wiki}->{db}->get ('referer', $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page})); @list = map {[$_ => $ref->{$_}]} keys %$ref; } catch SuikaWiki::DB::Util::Error with { }; if (@list) { my $list = $p->{-parent}->append_new_node (type => '#element', namespace_uri => q#http://www.w3.org/1999/xhtml#, local_name => 'ol'); @list = sort {$b->[1] <=> $a->[1] or $a->[0] cmp $b->[0]} @list; my $start = length $p->{start} ? $p->{start} : $o->{wiki}->{input}->parameter ('ref--range-start') || 0; $p->{number} = $o->{wiki}->{input}->parameter ('ref--range-number') unless length $p->{number}; my $end = $p->{number} ? $start + $p->{number} - 1 : $start + 29; $start = 0 if $start > $#list or $start < 0; $end = $#list if $end < $start or $end > $#list; $end = $start + 255 if $end > $start + 255; local $o->{var}->{search__result} = { min => 0, max => $#list, start => $start, end => $end, number => $p->{number} || 30, param_prefix => 'ref', }; my $default_label = ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get (name => 'Referer:URIReference2Label', o => $o, wiki => $o->{wiki}); my $li_label = ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get (name => 'Referer:RefererList:Label', o => $o, wiki => $o->{wiki}); for my $item (@list[$start..$end]) { local $o->{iwc__param}->{uri_reference} = URI->new ($item->[0]); my $label; try { $label = $o->{wiki}->{db}->get (ref__item_template => [$item->[0]]) or do { my $site = ($INTERWIKICORE ||= SuikaWiki::Plugin->module_package ('InterWikiCore'))->get_site_entry_by_uri_reference_match (o => $o, page => $o->{wiki}->{config}->{page}->{InterWikiName}); $label = $site ? $site->get_attribute_value ('URIReference2Label') || $default_label : $default_label; $o->{wiki}->{db}->set (ref__item_template => [$item->[0]] => $label); }; } catch SuikaWiki::DB::Util::Error with {}; ($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))->to_resource_by_uri_in_html ({ label => $li_label, ref__label => $label, } => { uri => $o->{iwc__param}->{uri_reference}, }, { o => $o, parent => $list->append_new_node (type => '#element', namespace_uri => q#http://www.w3.org/1999/xhtml#, local_name => 'li'), ref__weight => $item->[1], }); } $list->set_attribute (start => $start + 1); $f->parse_attr ($p=>q#post_list#, $o, -parent => $p->{-parent}, -non_parsed_to_node => 1, %opt); }}} #line 1 "(WikiPlugin module Referer, chunk 2)" ; $SuikaWiki::Plugin::Rule{view}->{referer_list} = $def; $SuikaWiki::Plugin::Rule{view_resource}->{referer_list} = $def; $SuikaWiki::Plugin::Rule{form_input}->{referer_list} = $def; }; sub add_referer { #line 1 "(WikiPlugin module source referer.wp2, block Function[Name='add_referer']/Main)" my (undef, %opt) = @_; return unless $opt{wiki}->{db}; return unless $opt{uri}; $opt{page} ||= $opt{wiki}->{var}->{page}; my $o = $opt{o} || {wiki => $opt{wiki}}; unless (ref $opt{uri}) { $opt{uri} = URI->new ($opt{uri})->canonical; } else { $opt{uri} = $opt{uri}->canonical; } local $o->{iwc__param} = { uri_reference => $opt{uri}, }; my $site = ($INTERWIKICORE ||= SuikaWiki::Plugin->module_package ('InterWikiCore'))->get_site_entry_by_uri_reference_match (o => $o, page => $opt{wiki}->{config}->{page}->{InterWikiName}); if ($site) { my $v = 1; my $check = $site->get_attribute_value ('RefererLog', default => '1'); try { $v = $o->{wiki}->{plugin} ->boolean_formatter ('iwc__urireference_operation') ->replace ($check, param => $o); } catch Message::Util::Formatter::error with { my $err = shift; if ($err->{-object}->{-category_name} eq 'iwc__urireference_operation') { my $wiki = $err->{-option}->{param}->{wiki}; SuikaWiki::Plugin->module_package ('Error') ->reporting_formatting_template_error ($err, $err->{option}->{param}->{wiki}, template => $check); } else { $err->throw; } }; return unless $v; } my $ref = $opt{wiki}->{db}->get ('referer', $opt{page}); $ref->{$o->{iwc__param}->{uri_reference}}++; $opt{wiki}->{db}->set ('referer', $opt{page} => $ref); } #line 1 "(WikiPlugin module Referer, chunk 4)" $SuikaWiki::Plugin::Rule{link_to_resource}->{ref__referer_item_weight} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; #line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#link-to-resource#]/ref__referer_item_weight']/Formatting)" $p->{-parent}->append_text ($o->{link}->{option}->{ref__weight});}} #line 1 "(WikiPlugin module Referer, chunk 5)" ; $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) = @_; #line 1 "(WikiPlugin module source referer.wp2, block FormattingRule[name()='[q#link-to-resource#]/ref__referer_item_label']/Formatting)" try { $f->replace ($o->{link}->{src}->{ref__label}, param => $o, -parent => $p->{-parent}); } catch Message::Util::Formatter::error with { my $err = shift; if ($err->{-object}->{-category_name} eq $f->{-category_name}) { my $wiki = $err->{option}->{param}->{wiki}; SuikaWiki::Plugin->module_package ('Error') ->reporting_formatting_template_error ($err, $wiki, template => $o->{link}->{src}->{ref__label}); undef; } else { $err->throw; } };}} #line 1 "(WikiPlugin module Referer, chunk 7)" ; package SuikaWiki::Plugin::Resource; our $BaseResource; $BaseResource->{q#und#}->{q##}->{q#Referer:RefererList:Label#} = q#{%ref--referer-item-weight;} %ref--referer-item-label;#; $BaseResource->{q#und#}->{q##}->{q#Referer:URIReference2Label#} = q#<%link-to-it (label => {%uri-reference;}p);>#; package SuikaWiki::Plugin::Registry; $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#]}}; 1;