use strict;
package SuikaWiki::Plugin::Registry;


our %Info;
$Info{q#PropEdit#}->{Name} = q#PropEdit#;
$Info{q#PropEdit#}->{q#Version#} = q#2005.0315.0839#;
$Info{q#PropEdit#}->{q#InterfaceVersion#} = q#2.9.1#;
$Info{q#PropEdit#}->{q#mkpluginVersion#} = q#2.1.21#;
$Info{q#PropEdit#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0#;
$Info{q#PropEdit#}->{q#Date.RCS#} = q#$Date: 2010/05/16 23:05:50 $#;
$Info{q#PropEdit#}->{RequiredPlugin} = [q#WikiEdit#, q#WikiFormCore#];
$Info{q#PropEdit#}->{Description} = [[q#WikiPage Property Editor#, q#en#, q##]];
$Info{q#PropEdit#}->{License} = [[q#%%Perl%%#, q##, q##]];
$Info{q#PropEdit#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#w@suika.fam.cx#]], [q##]]];

push @SuikaWiki::View::Implementation::CommonViewDefs, {
  condition => {q#mode#, q#pe__propedit#, q#http_method#, [q#GET#, q#HEAD#]},
  object_class => q#SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__propedit1050215083940d0B_#,
};
package SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__propedit1050215083940d0B_;


our @ISA = q#SuikaWiki::View::template#;

sub main ($$$) {
  my ($self, $opt, $opt2) = @_;
  require SuikaWiki::Output::HTTP;
  $opt2->{output} = SuikaWiki::Output::HTTP->new
    (wiki => $self->{view}->{wiki},
     view => $self->{view}, viewobj => $self);
  for (@{$self->{view}->{wiki}->{var}->{client}->{used_for_negotiate}},
       'Accept-Language') {
    $opt2->{output}->add_negotiate_header_field ($_);
  }
  
  $opt2->{template} = q#%html-document (
title => {%res(name=>{PropEdit:WebPageTitle});}p,
link-meta => {%template (name => links);
%html-meta(name => ROBOTS, content => NOINDEX);}p,
content => {
%template (
name => ws--page,
-content => {
%section (
title => {%res (name => {PropEdit:Title});}p, heading,
content => {
%pe--propedit (template => {
%resource-as-plain-text (name => {PropEdit:Template});
}p);
}p,
);
},
);
}p,
);#;
  $opt2->{o} = bless {
                      ## SuikaWiki 3 WikiPlugin interface
                        wiki => $self->{view}->{wiki},
                        plugin => $self->{view}->{wiki}->{plugin},
                        var => {},
                      }, 'SuikaWiki::Plugin';  
  $opt2->{output}->{status_code} = 200;
  
  $opt2->{output}->{entity}->{media_type} = q#text/html#;

  $opt2->{output}->{entity}->{charset} = $self->{view}->{wiki}->{config}->{charset}->{output};
  $opt2->{output}->set_expires (%{$self->{view}->{wiki}->{config}->{entity}->{expires}->{q#edit#}});
  $opt2->{output}->{entity}->{body_is_octet_stream} = 0;
  
  $self->{view}->{wiki}->init_db;
  $self->main_pre ($opt, $opt2);
  
  require Message::Markup::XML::Serialize::HTML;
  use Message::Util::Error;
  try {
    $opt2->{output}->{entity}->{body} 
      = Message::Markup::XML::Serialize::HTML::html_simple
        (SuikaWiki::Plugin->formatter ('view')
        ->replace ($opt2->{template}, param => $opt2->{o}));
  } $self->{view}->{wiki}->{config}->{catch}->{ formatter_view };
  $opt2->{output}->output (output => 'http-cgi');
  
  $self->main_post ($opt, $opt2);
}

push @SuikaWiki::View::Implementation::CommonViewDefs, {
  condition => {q#mode#, q#-pe__conflict#, q#http_method#, [q#GET#]},
  object_class => q#SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__conflict10502150839409v13#,
};
package SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__conflict10502150839409v13;


our @ISA = q#SuikaWiki::View::template#;

sub main ($$$) {
  my ($self, $opt, $opt2) = @_;
  require SuikaWiki::Output::HTTP;
  $opt2->{output} = SuikaWiki::Output::HTTP->new
    (wiki => $self->{view}->{wiki},
     view => $self->{view}, viewobj => $self);
  for (@{$self->{view}->{wiki}->{var}->{client}->{used_for_negotiate}},
       'Accept-Language') {
    $opt2->{output}->add_negotiate_header_field ($_);
  }
  
  $opt2->{template} = q#%html-document (
title => {%res(name=>{PropEdit:Conflict:WebPageTitle});}p,
link-meta => {%template (name => links);
%html-meta(name => ROBOTS, content => NOINDEX);}p,
content => {
%template (
name => ws--page,
-content => {
%section (
title => {%res (name => {PropEdit:Conflict:Title});}p, heading,
content => {
%paragraph (content => {
%res (name => {PropEdit:Conflict:Description});
}p);
%pe--propedit (template => {
%resource-as-plain-text (name => {PropEdit:Template});
}p,
);
}p);},
);
}p,
);#;
  $opt2->{o} = bless {
                      ## SuikaWiki 3 WikiPlugin interface
                        wiki => $self->{view}->{wiki},
                        plugin => $self->{view}->{wiki}->{plugin},
                        var => {},
                      }, 'SuikaWiki::Plugin';  
  $opt2->{output}->{status_code} = 409;
  
  $opt2->{output}->{entity}->{media_type} = q#text/html#;

  $opt2->{output}->{entity}->{charset} = $self->{view}->{wiki}->{config}->{charset}->{output};
  $opt2->{output}->set_expires (%{$self->{view}->{wiki}->{config}->{entity}->{expires}->{q#error#}});
  $opt2->{output}->{entity}->{body_is_octet_stream} = 0;
  
  $self->{view}->{wiki}->init_db;
  $self->main_pre ($opt, $opt2);
  
  require Message::Markup::XML::Serialize::HTML;
  use Message::Util::Error;
  try {
    $opt2->{output}->{entity}->{body} 
      = Message::Markup::XML::Serialize::HTML::html_simple
        (SuikaWiki::Plugin->formatter ('view')
        ->replace ($opt2->{template}, param => $opt2->{o}));
  } $self->{view}->{wiki}->{config}->{catch}->{ formatter_view };
  $opt2->{output}->output (output => 'http-cgi');
  
  $self->main_post ($opt, $opt2);
}

package SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0;

$SuikaWiki::Plugin::Rule{view}->{pe__propedit} = {q#Parameter#, {q#template#, {q#Type#, q#template#, q#Default#, q#(required)#, q#Description#, [[q#Template of the content#, q#en#, q##]]}, q#page#, {q#Type#, q#WikiName#, q#Default#, q#(auto)#, q#Description#, [[q#WikiPage to be edited#, q#en#, q##]]}}, q#Description#, [[q#A property editor form#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;

#line 1 "(WikiPlugin module source propedit.wp2, block FormattingRule[name()='[q#view#]/pe__propedit']/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};$p->{q#template#} = do { my $r = $f->parse_attr ($p=>q#template#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page});
my $template = $p->{template};
my $content = ($SuikaWiki::Plugin::Registry::Info{q#WikiEdit#}->{module_name} || SuikaWiki::Plugin->module_package (q#WikiEdit#))->get_content ($o, $page);
local $o->{var}->{content} = $content->{content};
local $o->{var}->{content_prop} = $content->{content_prop};
local $o->{var}->{source}->{prop} = sub {
my %opt = @_;
my $key = $opt{p}->{id};
my $uri = $opt{o}->{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#prop#}->{$key}->{uri};
my $rv = {};
if ($uri) {
if (my $nv = $opt{o}->{wiki}->{input}->parameter ('PE--CTRL--'.$key)) {
$rv->{value} = $nv;
$rv->{class} = [qw/pe--from-parameter/];
} else {
$rv->{value} = $opt{o}->{var}->{content_prop}
->get_attribute_value ($uri,
default => $opt{p}->{default});
}
} else {
$rv->{value} = $opt{p}->{default};
}
$rv;
};
($SuikaWiki::Plugin::Registry::Info{q#WikiFormCore#}->{module_name} || SuikaWiki::Plugin->module_package (q#WikiFormCore#))->make_form_in_html
($p->{-parent}, $template,
wiki => $o->{wiki},
o => $o,
index => -1,
local_id_prefix => 'PE--CTRL--',
output => {
mode => 'pe--write',
page => $page,
submit_button => 1,
hidden => sub {
my ($hidden, $o) = @_;
for ($hidden->append_new_node (type => '#element',
namespace_uri => q#http://www.w3.org/1999/xhtml#,
local_name => 'input')) {
$_->set_attribute (type => 'hidden');
$_->set_attribute (name => 'pe--seq');
$_->set_attribute (value => $o->{var}->{content_prop}
->get_attribute_value (q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#seq#,
default => 0));
$_->option (use_EmptyElemTag => 1);
}
},
});}}
#line 1 "(WikiPlugin module PropEdit, chunk 1)"
;

push @{$SuikaWiki::View::Implementation::TemplateFragment{q#links#}},   {
    Main => q#%link-wiki(mode => pe--propedit, up-to-date,
rel => edit, class => wiki-cmd,
description => {%res(name=>{PropEdit:Link:Description});}p);#,
    Order => 0,
    Description => [[q#Link to property edit mode of the WikiPage#, q#en#, q##]],
  };

push @SuikaWiki::View::Implementation::CommonViewDefs, {
  condition => {q#mode#, q#pe__write#, q#http_method#, [q#POST#]},
  object_class => q#SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__write1050215083940kTAg#,
};
package SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0::pe__write1050215083940kTAg;


our @ISA = q#SuikaWiki::View::template#;

#line 1 "(WikiPlugin module source propedit.wp2, block ViewDefinition[Mode='pe__write']/Use)"
use Message::Util::Error;

sub main ($$) {
my ($self, $opt, $opt2) = @_;

#line 1 "(WikiPlugin module source propedit.wp2, block ViewDefinition[Mode='pe__write']/method[Name='main'])"
my $wiki = $self->{view}->{wiki};
$wiki->{var}->{db}->{read_only}->{'content'} = 1;
$wiki->{var}->{db}->{read_only}->{'content_prop'} = 0;
$wiki->{var}->{db}->{read_only}->{'lastmodified'} = 1;
$wiki->{var}->{db}->{read_only}->{'referer'} = 0;
$wiki->init_db;
my $page = $wiki->{var}->{page};
my $old_content = $wiki->{db}->get (content => $page);
my $prop = $wiki->{db}->get (content_prop => $page);
my $seq = $wiki->{input}->parameter ('pe--seq') || 0;
if ($seq != $prop->get_attribute_value (q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#seq#, default => 0)) {
$self->{view}->{wiki}->view_in_mode (mode => '-pe--conflict');
throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
}
my %pprop;
$pprop{my $page_name = $page->stringify (wiki => $wiki)}
= {prop => $prop, page => $page};
my $this_page_name = $page_name;
MODIFICATION: {
my $old_mt;
my $new_mt;
my %depend;
KEY: for my $key (grep s/^PE--CTRL--//, $wiki->{input}->parameter_names) {
my $propinfo = $wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#prop#}->{$key};
next KEY unless $propinfo->{uri};
my $new_value = [$wiki->{input}->parameter ('PE--CTRL--'.$key)];
if (@$new_value == 1) {
if ($propinfo->{is_list}) {
$new_value = [split /\x0A|\x0D\x0A?/, $new_value->[0]];
}
if ($propinfo->{type} eq q#http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt\#media-type#) {
next KEY if $new_value->[0] eq '#asis';
}
}
my $old_value = $prop->get_attribute_value ($propinfo->{uri});
if (ref $old_value and @$new_value == @$old_value) {
CHK: {
for my $i (0..$#$new_value) {
last CHK if $old_value->[$i] ne $new_value->[$i];
}
next KEY;
}
} elsif (not ref $old_value and @$new_value == 1) {
next KEY if $old_value eq $new_value->[0];
}
if ($propinfo->{uri} eq q#http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt\#media-type#) {
$old_mt = $old_value;
$new_mt = $new_value->[0];
}
if (@$new_value) {
if ($propinfo->{is_list}) {
$prop->set_attribute ($propinfo->{uri} => $new_value);
} elsif (length $new_value->[0]) {
$prop->set_attribute ($propinfo->{uri} => $new_value->[0]);
} else {
$prop->remove_attribute ($propinfo->{uri});
}
if ($propinfo->{type} eq q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw\#WikiName# and
defined $propinfo->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#revWNList#}) {
PV: for my $wn (@$new_value) {
my $wiki_name = $wiki->name ($wn);
unless ($pprop{$wn}->{prop}) {
$pprop{$wn}->{prop}
= $wiki->{db}->get (content_prop => $wiki_name);
$pprop{$wn}->{page} = $wiki_name;
}
my $pv = $pprop{$wn}->{prop}->get_attribute_value
($propinfo->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#revWNList#},
as_array => 1);
for (@$pv) {
next PV if $_ eq $this_page_name;
}
push @$pv, $this_page_name;
$pprop{$wn}->{prop}->set_attribute
($propinfo->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#revWNList#} => $pv);
$pprop{$wn}->{modified} = 1;
}
}
} else {
$prop->remove_attribute ($propinfo->{uri});
}
$pprop{$page_name}->{modified} = 1;
$depend{$key} = $propinfo->{depend} if $propinfo->{depend};
}
DEPEND: for my $sub (keys %depend) {
for my $main (@{$depend{$sub}}) {
unless ($prop->get_attribute ($wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#prop#}
->{$main}->{uri})) {
$prop->remove_attribute ($wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#prop#}
->{$sub}->{uri});
next DEPEND;
}
}
}
last MODIFICATION unless $pprop{$page_name}->{modified};
for my $wn (keys %pprop) {
next unless $pprop{$wn}->{modified};
my $prop = $pprop{$wn}->{prop};
my $seq = $prop->get_attribute_value (q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#seq#, default => 0);
$prop->set_attribute (q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#seq# => $seq + 1);
try {
$self->{view}->{wiki}->{db}->set
(content_prop => $pprop{$wn}->{page} => $prop);
} catch SuikaWiki::DB::Util::Error with {
my $err = shift;
if ($err->{-type} eq 'ERROR_REPORTED') {
$err->throw;
} else {
$self->{view}->{wiki}->view_in_mode (mode => '-wdb--fatal-error');
throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED';
}
};
}
if ($new_mt) {
my $format = ($SuikaWiki::Plugin::Registry::Info{q#WikiFormat#}->{module_name} || SuikaWiki::Plugin->module_package (q#WikiFormat#))
->handler (\$old_content,
serialized_media_type => $old_mt,
content_prop => $prop,
wiki => $wiki);
$format->content_type_changed_from (wiki => $wiki,
page => $page,
old_content => \$old_content,
new_content => \$old_content,
new_serialized_media_type => $new_mt,
content_prop => $prop);
}
my $format = ($SuikaWiki::Plugin::Registry::Info{q#WikiFormat#}->{module_name} || SuikaWiki::Plugin->module_package (q#WikiFormat#))
->handler (\$old_content,
serialized_media_type => $new_mt,
content_prop => $prop,
wiki => $wiki);
$format->content_prop_modified (wiki => $wiki,
page => $page,
content_prop => $prop);
} # MODIFICATION
my $new_mode = $self->{view}->{wiki}->{input}->parameter
('we--mode-modified');
$new_mode =~ s/[^0-9A-Za-z._-]+//g;
my $uri = $self->{view}->{wiki}->uri_reference
(page => $page,
mode => $new_mode,
up_to_date => 1,
param => {we__mode_modified => $new_mode});
require SuikaWiki::Output::HTTP;
my $output = SuikaWiki::Output::HTTP->new
(wiki => $self->{view}->{wiki});
$output->set_redirect (uri => $uri, status_code => 303);
$output->output (output => 'http-cgi');}

#line 1 "(WikiPlugin module PropEdit, chunk 3)"

package SuikaWiki::Plugin::plugin::PropEdit1050215083940axZ0;

$SuikaWiki::Plugin::Rule{form_input}->{pe__texts} = {q#Parameter#, {}, q#Description#, [[q#Multiple texts input#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;

#line 1 "(WikiPlugin module source propedit.wp2, block FormattingRule[name()='[q#form-input#]/pe__texts']/Formatting)"
$p->{q#id#} = do { my $r = $f->parse_attr ($p=>q#id#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};$f->parse_attr ($p=>q#label#, $o, -non_parsed_to_node => 1, %opt);
my $id = ($SuikaWiki::Plugin::Registry::Info{q#WikiFormCore#}->{module_name} || SuikaWiki::Plugin->module_package (q#WikiFormCore#))
->control_id ($o,
local_id => $p->{id},
require_local_id => 1);
my $has_label = 0;
if ($p->{label}->count) {
$has_label = 1;
for ($p->{-parent}->append_new_node
(type => '#element',
namespace_uri => q#http://www.w3.org/1999/xhtml#,
local_name => 'label')) {
$_->set_attribute (for => $id->{global_id});
$_->append_node ($p->{label});
}
$p->{-parent}->append_new_node
(type => '#element',
namespace_uri => q#http://www.w3.org/1999/xhtml#,
local_name => 'br')
->option (use_EmptyElemTag => 1);
}
for ($p->{-parent}->append_new_node (type => '#element',
namespace_uri => q#http://www.w3.org/1999/xhtml#,
local_name => 'textarea')) {
$_->set_attribute (name => $id->{local_id});
$_->set_attribute (id => $id->{global_id}) if $has_label;
$p->{q#size#} = do { my $r = $f->parse_attr ($p=>q#size#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};$p->{q#lines#} = do { my $r = $f->parse_attr ($p=>q#lines#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};$p->{q#description#} = do { my $r = $f->parse_attr ($p=>q#description#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
$_->set_attribute (cols => ($p->{size}||20)*2);	## Length
$_->set_attribute (title => $p->{description}) if $p->{description};
$_->set_attribute (disabled => 'disabled') if $o->{form}->{disabled};
$p->{q#class#} = do { my $r = $f->parse_attr ($p=>q#class#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
my @class = split /\s+/, $p->{class};
push @class, 'require' if $o->{form}->{require}->{id}->{$p->{id}};
$p->{q#source#} = do { my $r = $f->parse_attr ($p=>q#source#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
my $items = 5;
if ($p->{source}) {
if (ref $o->{var}->{source}->{$p->{source}}) {
my $d = $o->{var}->{source}->{$p->{source}}
->(p=>$p, o=>$o, type => q#http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit\#texts#);
$_->append_text (ref $d->{value} eq 'ARRAY' ?
join "\n", @{$d->{value}} : $d->{value});
push @class, @{$d->{class}||[]};
$items = @{$d->{value}} + 1 if ref $d->{value} eq 'ARRAY';
} else {
$_->append_text (ref $o->{var}->{$p->{source}} eq 'ARRAY' ?
join "\n", @{$o->{var}->{$p->{source}}} :
$o->{var}->{$p->{source}});
$items = @{$o->{var}->{$p->{source}}} + 1
if ref $o->{var}->{$p->{source}} eq 'ARRAY';
}
} else {
$p->{q#default#} = do { my $r = $f->parse_attr ($p=>q#default#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
$_->append_text ($p->{default});	## Default value
}
$_->set_attribute (rows => ($p->{lines} || $items));	## Lines
$_->set_attribute (class => join ' ', @class) if @class;
}}}
#line 1 "(WikiPlugin module PropEdit, chunk 4)"
;

package SuikaWiki::Plugin::Resource;

our $BaseResource;
$BaseResource->{q#en#}->{q##}->{q#Edit:SaveAnd:pe--propedit:Description#} = q#Save modified property values and show this property-editing mode again.#;
$BaseResource->{q#en#}->{q##}->{q#Edit:SaveAnd:pe--propedit:Label#} = q#Editing Properties#;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:Conflict:Description#} = q#Properties for WikiPage %link-to-wikipage (label => {%link-to-it ( label => {%page-name;}p);}); has been modified during you are editing them. Please ensure that third-party's modification does not affect your submitting changes. #;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:Conflict:Title#} = q#Confliction - Editing Content Properties#;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:Conflict:WebPageTitle#} = q#CONFLICTION - %page-name; (Editing Content Properties)#;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:Link:Description#} = q#Edit properties of this WikiPage#;
$BaseResource->{q#und#}->{q##}->{q#PropEdit:Template#} = q##;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:Title#} = q#Editing Content Properties#;
$BaseResource->{q#en#}->{q##}->{q#PropEdit:WebPageTitle#} = q#%page-name; (Editing Content Properties)#;
package SuikaWiki::Plugin::Registry;

$Info{q#PropEdit#}->{provide} = {q#rule#, {q#form_input#, [q#pe__texts#], q#view#, [q#pe__propedit#]}, q#viewfragment#, [{q#Name#, q#links#}], q#viewdef#, [{q#Description#, [q#Editing WikiPage Properties#, q#en#, q##], q#Name#, q#pe__propedit#}, {q#Description#, [q#Editing WikiPage Properties -- Report Confliction#, q#en#, q##], q#Name#, q#-pe__conflict#}, {q#Description#, [q#Saving modified (new) WikiPage properties#, q#en#, q##], q#Name#, q#pe__write#}]};

1;
