| 1 |
#?SuikaWikiConfig/2.0 |
| 2 |
|
| 3 |
Plugin: |
| 4 |
@Name: WikiPageProp |
| 5 |
@Description: |
| 6 |
@@@: WikiPage property |
| 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/04/01 04:40:27 $ |
| 17 |
@RequiredModule[list]: |
| 18 |
WikiFormat |
| 19 |
@Use: |
| 20 |
use Message::Util::Error; |
| 21 |
|
| 22 |
PluginConst: |
| 23 |
@NS_XHTML1: |
| 24 |
http://www.w3.org/1999/xhtml |
| 25 |
|
| 26 |
FormattingRule: |
| 27 |
@Category[list]: |
| 28 |
view |
| 29 |
view-resource |
| 30 |
form-input |
| 31 |
@Name: last-modified |
| 32 |
@Description: |
| 33 |
@@@: |
| 34 |
Last-modified date-time of the WikiPage. |
| 35 |
\ |
| 36 |
Note: Date-time value returned by this rule might not be |
| 37 |
the "real" last-modified date-time, in case last-modified |
| 38 |
value is not updated when content is modified (so called |
| 39 |
"sage" feature). |
| 40 |
@@lang: en |
| 41 |
@Parameter: |
| 42 |
@@Name: page |
| 43 |
@@Type: WikiName |
| 44 |
@@Default: (current) |
| 45 |
@@Description: |
| 46 |
@@@@: Target WikiPage |
| 47 |
@@@lang:en |
| 48 |
@Formatting: |
| 49 |
__ATTRTEXT:%page__; |
| 50 |
my $page = length $p->{page} ? |
| 51 |
[split $o->{wiki}->{config}->{name}->{space}->{separator_regex}, |
| 52 |
$p->{page}]: |
| 53 |
$o->{wiki}->{var}->{page}; |
| 54 |
my $lm; |
| 55 |
try { |
| 56 |
$lm = $o->{wiki}->{db}->get (lastmodified => $page); |
| 57 |
} catch SuikaWiki::DB::Util::Error with { |
| 58 |
my $err = shift; |
| 59 |
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 60 |
$lm = 0; |
| 61 |
}; |
| 62 |
$p->{-parent}->append_text ( __FUNCPACK__::unixtime_to_string ($lm)); |
| 63 |
## TODO: format string |
| 64 |
|
| 65 |
FormattingRule: |
| 66 |
@Category[list]: page-link |
| 67 |
@Name: last-modified |
| 68 |
@Description: |
| 69 |
@@@: |
| 70 |
Last-modified date-time of the WikiPage. |
| 71 |
\ |
| 72 |
Note: Date-time value returned by this rule might not be |
| 73 |
the "real" last-modified date-time, in case last-modified |
| 74 |
value is not updated when content is modified (so called |
| 75 |
"sage" feature). |
| 76 |
@@lang: en |
| 77 |
@Formatting: |
| 78 |
my $date; |
| 79 |
if (defined $o->{link}->{dest}->{page_lastmodified}) { |
| 80 |
$date = $o->{link}->{dest}->{page_lastmodified}; |
| 81 |
} else { |
| 82 |
## TODO: |
| 83 |
my $page = $o->{link}->{dest}->{page_name}; |
| 84 |
try { |
| 85 |
$date = $o->{wiki}->{db}->get (lastmodified => $page); |
| 86 |
} catch SuikaWiki::DB::Util::Error with { |
| 87 |
my $err = shift; |
| 88 |
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 89 |
$date = 0; |
| 90 |
}; |
| 91 |
} |
| 92 |
$p->{-parent}->append_text (__FUNCPACK__::unixtime_to_string ($date)); |
| 93 |
## TODO: Update to new interface |
| 94 |
|
| 95 |
FormattingRule: |
| 96 |
@Category[list]: |
| 97 |
view |
| 98 |
view-resource |
| 99 |
form-input |
| 100 |
@Name: page-name |
| 101 |
@Description: |
| 102 |
@@@: |
| 103 |
WikiName in string repersentation |
| 104 |
@@lang: en |
| 105 |
@Parameter: |
| 106 |
@@Name:separator |
| 107 |
@@Type:string |
| 108 |
@@Default:(config) |
| 109 |
@@Description: |
| 110 |
@@@@:Separator used to delimit namespace components (ie. path delimiter) |
| 111 |
@@@lang:en |
| 112 |
@Formatting: |
| 113 |
__ATTRTEXT:%page__; |
| 114 |
$p->{-parent}->append_text ($o->{wiki}->{var}->{page}->stringify |
| 115 |
(wiki => $o->{wiki})); |
| 116 |
|
| 117 |
FormattingRule: |
| 118 |
@Category[list]:page-link |
| 119 |
@Name: page-name |
| 120 |
@Description: |
| 121 |
@@@:WikiName in string representation |
| 122 |
@@lang:en |
| 123 |
@Parameter: |
| 124 |
@@Name:relative |
| 125 |
@@Type:boolean |
| 126 |
@@Default:"0" |
| 127 |
@@Description: |
| 128 |
@@@@:Whether WikiName should be relative to "this" page |
| 129 |
@@@lang:en |
| 130 |
@Formatting: |
| 131 |
__ATTRTEXT:%relative__; |
| 132 |
if ($p->{relative}) { |
| 133 |
$p->{-parent}->append_text |
| 134 |
($o->{link}->{dest}->{page_name_relative}->stringify |
| 135 |
(wiki => $o->{wiki})); |
| 136 |
} else { |
| 137 |
$p->{-parent}->append_text |
| 138 |
($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki})); |
| 139 |
} |
| 140 |
|
| 141 |
FormattingRule: |
| 142 |
@Category[list]:page-link |
| 143 |
@Name: page-title |
| 144 |
@Description: |
| 145 |
@@@:Title of the WikiPage |
| 146 |
@@lang:en |
| 147 |
@Parameter: |
| 148 |
@@Name:relative |
| 149 |
@@Type:boolean |
| 150 |
@@Default:"0" |
| 151 |
@@Description: |
| 152 |
@@@@:Whether relative to "this" page |
| 153 |
@@@lang:en |
| 154 |
@Formatting: |
| 155 |
__ATTRTEXT:%relative__; |
| 156 |
if (defined $o->{link}->{dest}->{page_title}) { |
| 157 |
## ISSUE: Is this work now? |
| 158 |
$p->{-parent}->append_text ($o->{link}->{dest}->{page_title}); |
| 159 |
} elsif ($p->{relative}) { |
| 160 |
$p->{-parent}->append_text |
| 161 |
($o->{link}->{dest}->{page_name_relative}->stringify |
| 162 |
(wiki => $o->{wiki})); |
| 163 |
} else { |
| 164 |
$p->{-parent}->append_text |
| 165 |
($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki})); |
| 166 |
} |
| 167 |
|
| 168 |
FormattingRule: |
| 169 |
@Category[list]:page-link |
| 170 |
@Name:page-headline |
| 171 |
@Description: |
| 172 |
@@@:Headline summary of the WikiPage |
| 173 |
@@lang:en |
| 174 |
@Formatting: |
| 175 |
$p->{-parent}->append_text (__FUNCPACK__->get_headsummary |
| 176 |
($o->{link}->{dest}->{page_name}, |
| 177 |
wiki => $o->{wiki})); |
| 178 |
|
| 179 |
FormattingRule: |
| 180 |
@Category[list]: form-input |
| 181 |
@Name: wpp--next-anchor-index |
| 182 |
@Description: |
| 183 |
@@@: Next "anchor index" number |
| 184 |
@@lang: en |
| 185 |
@Formatting: |
| 186 |
my $page = $o->{wiki}->{var}->{page}; |
| 187 |
my $content; |
| 188 |
my $content_prop; |
| 189 |
try { |
| 190 |
$content = $o->{wiki}->{db}->get (content => $page); |
| 191 |
$content_prop = $o->{wiki}->{db}->get (content_prop => $page); |
| 192 |
|
| 193 |
## Get Format Handler |
| 194 |
my $format = SuikaWiki::Plugin->module_package ('WikiFormat') |
| 195 |
->handler (\$content, |
| 196 |
content_prop => $content_prop, |
| 197 |
wiki => $o->{wiki}); |
| 198 |
|
| 199 |
$p->{-parent}->append_text ($format->next_index_for_anchor |
| 200 |
(\$content, |
| 201 |
content_prop => $content_prop, |
| 202 |
wiki => $o->{wiki}, |
| 203 |
page => $page)); |
| 204 |
|
| 205 |
} catch SuikaWiki::DB::Util::Error with { |
| 206 |
my $err = shift; |
| 207 |
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 208 |
} catch SuikaWiki::Format::Definition::error with { |
| 209 |
# |
| 210 |
}; |
| 211 |
|
| 212 |
Function: |
| 213 |
@Name: unixtime_to_string |
| 214 |
@Description |
| 215 |
@@@: |
| 216 |
Convert internal date-time format to other (possibly human readable) |
| 217 |
format. |
| 218 |
\ |
| 219 |
Note: Currently, only one fixed format is supported, whilst |
| 220 |
future version is expected to support highly customizable |
| 221 |
formatting supported by Message::Field::Date. |
| 222 |
@@lang:en |
| 223 |
@Main: |
| 224 |
my @date = gmtime shift; |
| 225 |
sprintf '%04d-%02d-%02d %02d:%02d:%02d +00:00', |
| 226 |
$date[5] + 1900, |
| 227 |
$date[4] + 1, |
| 228 |
@date[3,2,1,0]; |
| 229 |
|
| 230 |
Function: |
| 231 |
@Name: get_headsummary |
| 232 |
@Description: |
| 233 |
@@@: Returns headline summary |
| 234 |
@@lang:en |
| 235 |
@Main: |
| 236 |
my (undef, $page, %opt) = @_; |
| 237 |
$page ||= $opt{wiki}->{var}->{page}; |
| 238 |
|
| 239 |
my $s; |
| 240 |
try { |
| 241 |
if ($opt{wiki}->{db}->exist (wpp__headsummary => $page)) { |
| 242 |
$s = $opt{wiki}->{db}->get (wpp__headsummary => $page); |
| 243 |
} else { |
| 244 |
my $content = $opt{wiki}->{db}->get (content => $page); |
| 245 |
|
| 246 |
## Get Format Handler |
| 247 |
my $format = SuikaWiki::Plugin->module_package ('WikiFormat') |
| 248 |
->handler (\$content, |
| 249 |
wiki => $opt{wiki}); |
| 250 |
$s = $format->headsummary (\$content, wiki => $opt{wiki}); |
| 251 |
|
| 252 |
$s =~ tr/\x0D//d; |
| 253 |
if (length ($s) > 500) { |
| 254 |
$s = substr ($s, 0, 500); |
| 255 |
$s =~ s/[^\x09\x0A\x20-\x7E]+$//; |
| 256 |
$s .= '...'; |
| 257 |
} |
| 258 |
if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/) { |
| 259 |
$s = $1; |
| 260 |
} |
| 261 |
$s =~ s/[\x09\x0A\x20]+/\x20/gs; |
| 262 |
$s =~ s/\([^\(\)]+\)//g; |
| 263 |
$s =~ s/\[[^\[\]]+\]//g; |
| 264 |
$s =~ s/>>[0-9]+//g; |
| 265 |
$s =~ s/<[^<>]+>//g; |
| 266 |
$s =~ s/{[^{}]+}//g; |
| 267 |
$s =~ s/20[0-9][0-9]-[01][0-9]-[0-3][0-9][T\x20]*[0-2][0-9]:[0-5][0-9]:[0-5][0-9](?:\s*[+-][0-9][0-9]:[0-9][0-9])?//g; |
| 268 |
$s =~ s/ [Aa]n? / /g; |
| 269 |
$s =~ s/ [Aa]t / @ /g; |
| 270 |
$s =~ s/ [Tt]he / /g; |
| 271 |
$s =~ s/,? and / & /g; |
| 272 |
$s =~ s!,? or ! / !g; |
| 273 |
$s =~ s! not !n't !g; |
| 274 |
$s =~ s! (?:i|ha)s !'s !g; |
| 275 |
$s =~ s! are !'re !g; |
| 276 |
$s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge; |
| 277 |
$s =~ s![.,]\x20?$!!g; |
| 278 |
$s =~ s/\x20+/\x20/g; |
| 279 |
if (length ($s) > 400) { |
| 280 |
$s = substr ($s, 0, 400); |
| 281 |
$s =~ s/[^\x20-\x7E]+$//s; # Remove broken EUC-JP char |
| 282 |
$s .= '...'; |
| 283 |
} |
| 284 |
$opt{wiki}->{db}->set (wpp__headsummary => $page => $s); |
| 285 |
} |
| 286 |
} catch SuikaWiki::DB::Util::Error with { |
| 287 |
my $err = shift; |
| 288 |
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 289 |
$s = undef; |
| 290 |
}; |
| 291 |
return $s; |
| 292 |
|
| 293 |
ViewFragment: |
| 294 |
@Name: ws--post-content |
| 295 |
@Description: |
| 296 |
@@@: After content body -- last modified date and time of the WikiPage |
| 297 |
@@lang:en |
| 298 |
@Order: 800 |
| 299 |
@Formatting: |
| 300 |
%block ( |
| 301 |
id => last-modified, |
| 302 |
content => {%res(name=>{LastModified=});%last-modified;}p, |
| 303 |
); |
| 304 |
|
| 305 |
Resource: |
| 306 |
@LastModified=: |
| 307 |
@@@: |
| 308 |
Last modified: |
| 309 |
@@lang: en |