#?SuikaWikiConfig/2.0

Plugin:
  @Name: WikiPageProp
  @Description:
    @@@: WikiPage property
    @@lang:en
  @License: %%GPL%%
  @Author:
    @@Name:
      @@@@: Wakaba
      @@@lang:ja
      @@@script:Latn
    @@Mail[list]: w@suika.fam.cx
  @Date.RCS: $Date: 2003/11/25 12:39:40 $

PluginConst:
  @NS_XHTML1:
    http://www.w3.org/1999/xhtml

FormattingRule:
  @Category[list]:
    view
    view-resource
    form-input
  @Name: last-modified
  @Description:
    @@@:
      Last-modified date-time of the WikiPage.
      \
      Note: Date-time value returned by this rule might not be 
      the "real" last-modified date-time, in case last-modified 
      value is not updated when content is modified (so called 
      "sage" feature).
    @@lang: en
  @Parameter:
    @@Name: page
    @@Type: WikiName
    @@Default: (current)
    @@Description:
      @@@@: Target WikiPage
      @@@lang:en
  @Formatting:
    __ATTRTEXT:%page__;
    my $page = length $p->{page} ?
                 [split $o->{wiki}->{config}->{name}->{space}->{separator_regex},
                        $p->{page}]:
                 $o->{wiki}->{var}->{page};
    $p->{-parent}->append_text
      ( __FUNCPACK__::unixtime_to_string
           ($o->{wiki}->{db}->get (lastmodified => $page)));
## TODO: format string

FormattingRule:
  @Category[list]: page-link
  @Name: last-modified
  @Description:
    @@@:
      Last-modified date-time of the WikiPage.
      \
      Note: Date-time value returned by this rule might not be
      the "real" last-modified date-time, in case last-modified
      value is not updated when content is modified (so called
      "sage" feature).
    @@lang: en
  @Formatting:
    my $date;
    if (defined $o->{link}->{dest}->{page_lastmodified}) {
      $date = $o->{link}->{dest}->{page_lastmodified};
    } else {
## TODO:
      my $page = [$o->{link}->{dest}->{page_name}];
      $date = $o->{wiki}->{db}->get (lastmodified => $page);
    }
    $p->{-parent}->append_text (__FUNCPACK__::unixtime_to_string ($date));
## TODO: Update to new interface

FormattingRule:
  @Category[list]:
    view
    view-resource
    form-input
  @Name: page-name
  @Description:
    @@@:
      WikiName in string repersentation
    @@lang: en
  @Parameter:
    @@Name:separator
    @@Type:string
    @@Default:(config)
    @@Description:
      @@@@:Separator used to delimit namespace components (ie. path delimiter)
      @@@lang:en
  @Formatting:
    __ATTRTEXT:%page__;
## TODO:
    my $page = length $p->{page} ?
                 [split $o->{wiki}->{config}->{name}->{space}->{separator_regex},
                        $p->{page}]:
                 $o->{wiki}->{var}->{page};
    $p->{-parent}->append_text (join
      (($p->{separator} || $o->{wiki}->{config}->{name}->{space}->{separator}),
       @{$page}));

FormattingRule:
  @Category[list]:page-link
  @Name: page-name
  @Description:
    @@@:WikiName in string representation
    @@lang:en
  @Parameter:
    @@Name:relative
    @@Type:boolean
    @@Default:"0"
    @@Description:
      @@@@:Whether relative to "this" page
      @@@lang:en
  @Formatting:
    __ATTRTEXT:%relative__;
    if ($p->{relative}) {
      $p->{-parent}->append_text ($o->{link}->{dest}->{page_name_relative});
    } else {
      $p->{-parent}->append_text ($o->{link}->{dest}->{page_name});
    }

FormattingRule:
  @Category[list]:page-link
  @Name: page-title
  @Description:
    @@@:Title of the WikiPage
    @@lang:en
  @Parameter:
    @@Name:relative
    @@Type:boolean
    @@Default:"0"
    @@Description:
      @@@@:Whether relative to "this" page
      @@@lang:en
  @Formatting:
    __ATTRTEXT:%relative__;
    if (defined $o->{link}->{dest}->{page_title}) {
      $p->{-parent}->append_text ($o->{link}->{dest}->{page_title});
    } elsif ($p->{relative}) {
      $p->{-parent}->append_text ($o->{link}->{dest}->{page_name_relative});
    } else {
      $p->{-parent}->append_text ($o->{link}->{dest}->{page_name});
    }

FormattingRule:
  @Category[list]:page-link
  @Name:page-headline
  @Description:
    @@@:Headline summary of the WikiPage
    @@lang:en
  @Formatting:
    $p->{-parent}->append_text 
      (__FUNCPACK__::_temp_get_headline
         ([split $o->{wiki}->{config}->{name}->{space}->{separator_reg},
                 $o->{link}->{dest}->{page_name}]));

Function:
  @Name: unixtime_to_string
  @Description
    @@@:
      Convert internal date-time format to other (possibly human readable) 
      format.
      \
      Note: Currently, only one fixed format is supported, whilst 
      future version is expected to support highly customizable 
      formatting supported by Message::Field::Date.
    @@lang:en
  @Main:
    my @date = gmtime shift;
    sprintf '%04d-%02d-%02d %02d:%02d:%02d +00:00',
            $date[5] + 1900,
            $date[4] + 1,
            @date[3,2,1,0];

Function:
  @Name: _temp_get_headline
  @Description:
    @@@: Returns headline summary of SuikaWiki/0.9 document
    @@lang:en
  @Main:
    my ($page, %option) = @_;
            my $SubjectLine = SuikaWiki::Plugin->cache ('headline');
            unless (defined $SubjectLine->{$page}) {
                $SubjectLine->{$page} = do {
                  my $s=SuikaWiki::Plugin->get_data (content => $page);
                  $s =~ tr/\x0D//d;
                  $s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
                  $s =~ s/\x0A\x0A.*//s;
                  if (length ($s) > 500) {
                    $s = substr ($s, 0, 500);
                    $s =~ s/[^\x09\x0A\x20-\x7E]+$//s;
                    $s .= '...';
                  }
                  #if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/s) {
                  #  $s = $1;
                  #}
                  $s =~ s/[\x09\x0A\x20]+/\x20/gs;
                  $s =~ s/^[-=*>,:]+//;
                  $s =~ s/'''?//g;
                  $s =~ s/\[\[([^]]+)\]\]/$1/g;
                  $s =~ s/__&&([^&]+)&&__/$1/g;
 $s =~ s/\[[A-Z]+(?:\([^)]+\))?\[([^]]+)\](?:\s\[([^]]+)\])?\]/$1$2/g;
                  $s =~ s/\([^\(\)]+\)//g;
                  $s =~ s/\[[^\[\]]+\]//g;
                  $s =~ s/>>[0-9]+//g;
                  $s =~ s/<[^<>]+>//g;
                  $s =~ s/20[0-9][0-9]-[01][0-9]-[0-3][0-9]\x20*[0-2][0-9]:[0-5][0-9]//g;
                  $s =~ s/ [Aa]n? / /g;
                  $s =~ s/ [Aa]t / @ /g;
                  $s =~ s/ [Tt]he / /g;
                  $s =~ s/,? and / & /g;
                  $s =~ s!,? or ! / !g;
                  $s =~ s! not !n't !g;
                  $s =~ s! (?:i|ha)s !'s !g;
                  $s =~ s! are !'re !g;
                  $s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge;
                 $s =~ s![.,]\x20?$!!g;
                  $s =~ s/\x20+/\x20/g;
                  if (length ($s) > 400) {
                    $s = substr ($s, 0, 400);
                    $s =~ s/[^\x20-\x7E]+$//s;
                    $s .= '...';
                  }
                $s};
            }
            $SubjectLine->{$page};

ViewFragment:
  @Name: ws--post-content
  @Description:
    @@@: After content body -- last modified date and time of the WikiPage
    @@lang:en
  @Order: 800
  @Formatting:
        %block (
          id => last-modified,
          content => {%res(name=>{LastModified=});%last-modified;}p,
        );

Resource:
  @LastModified=:
    @@@:
      Last modified: 
    @@lang: en