/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/WikiPageProp.wp2
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/WikiPageProp.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Thu Mar 11 08:05:38 2004 UTC (22 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +3 -2 lines
Typo fixes

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiPageProp
5     @Description:
6     @@@: WikiPage property
7     @@lang:en
8 wakaba 1.6 @License: %%Perl%%
9 wakaba 1.1 @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.6 @Date.RCS:
16     $Date: 2004/02/18 07:18:30 $
17 wakaba 1.2 @RequiredModule[list]:
18     WikiFormat
19 wakaba 1.3 @Use:
20     use Message::Util::Error;
21 wakaba 1.1
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 wakaba 1.3 my $lm;
55     try {
56     $lm = $o->{wiki}->{db}->get (lastmodified => $page);
57     } catch SuikaWiki::DB::Util::Error with {
58 wakaba 1.5 my $err = shift;
59     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
60 wakaba 1.3 $lm = 0;
61 wakaba 1.4 };
62 wakaba 1.3 $p->{-parent}->append_text ( __FUNCPACK__::unixtime_to_string ($lm));
63 wakaba 1.1 ## 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 wakaba 1.3 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 wakaba 1.5 my $err = shift;
88     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
89 wakaba 1.3 $date = 0;
90     };
91 wakaba 1.1 }
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     ## TODO:
115     my $page = length $p->{page} ?
116     [split $o->{wiki}->{config}->{name}->{space}->{separator_regex},
117     $p->{page}]:
118     $o->{wiki}->{var}->{page};
119     $p->{-parent}->append_text (join
120     (($p->{separator} || $o->{wiki}->{config}->{name}->{space}->{separator}),
121     @{$page}));
122    
123     FormattingRule:
124     @Category[list]:page-link
125     @Name: page-name
126     @Description:
127     @@@:WikiName in string representation
128     @@lang:en
129     @Parameter:
130     @@Name:relative
131     @@Type:boolean
132     @@Default:"0"
133     @@Description:
134 wakaba 1.3 @@@@:Whether WikiName should be relative to "this" page
135 wakaba 1.1 @@@lang:en
136     @Formatting:
137     __ATTRTEXT:%relative__;
138     if ($p->{relative}) {
139 wakaba 1.4 $p->{-parent}->append_text
140     ($o->{link}->{dest}->{page_name_relative}->stringify
141     (wiki => $o->{wiki}));
142 wakaba 1.1 } else {
143 wakaba 1.4 $p->{-parent}->append_text
144     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
145 wakaba 1.1 }
146    
147     FormattingRule:
148     @Category[list]:page-link
149     @Name: page-title
150     @Description:
151     @@@:Title of the WikiPage
152     @@lang:en
153     @Parameter:
154     @@Name:relative
155     @@Type:boolean
156     @@Default:"0"
157     @@Description:
158     @@@@:Whether relative to "this" page
159     @@@lang:en
160     @Formatting:
161     __ATTRTEXT:%relative__;
162     if (defined $o->{link}->{dest}->{page_title}) {
163 wakaba 1.3 ## ISSUE: Is this work now?
164 wakaba 1.1 $p->{-parent}->append_text ($o->{link}->{dest}->{page_title});
165     } elsif ($p->{relative}) {
166 wakaba 1.4 $p->{-parent}->append_text
167     ($o->{link}->{dest}->{page_name_relative}->stringify
168     (wiki => $o->{wiki}));
169 wakaba 1.1 } else {
170 wakaba 1.4 $p->{-parent}->append_text
171     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
172 wakaba 1.1 }
173    
174     FormattingRule:
175     @Category[list]:page-link
176     @Name:page-headline
177     @Description:
178     @@@:Headline summary of the WikiPage
179     @@lang:en
180     @Formatting:
181 wakaba 1.4 $p->{-parent}->append_text (__FUNCPACK__->get_headsummary
182     ($o->{link}->{dest}->{page_name},
183     wiki => $o->{wiki}));
184 wakaba 1.1
185 wakaba 1.2 FormattingRule:
186     @Category[list]: form-input
187     @Name: wpp--next-anchor-index
188     @Description:
189     @@@: Next "anchor index" number
190     @@lang: en
191     @Formatting:
192     my $page = $o->{wiki}->{var}->{page};
193 wakaba 1.3 my $content;
194     try {
195     $content = $o->{wiki}->{db}->get (content => $page);
196 wakaba 1.4
197     ## Get Format Handler
198     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
199     ->handler (\$content,
200     wiki => $o->{wiki});
201    
202     $p->{-parent}->append_text ($format->next_index_for_anchor
203     (\$content, wiki => $o->{wiki},
204     page => $page));
205    
206 wakaba 1.3 } catch SuikaWiki::DB::Util::Error with {
207 wakaba 1.5 my $err = shift;
208     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
209 wakaba 1.4 } catch SuikaWiki::Format::Definition::error with {
210     #
211 wakaba 1.3 };
212 wakaba 1.2
213 wakaba 1.1 Function:
214     @Name: unixtime_to_string
215     @Description
216     @@@:
217     Convert internal date-time format to other (possibly human readable)
218     format.
219     \
220     Note: Currently, only one fixed format is supported, whilst
221     future version is expected to support highly customizable
222     formatting supported by Message::Field::Date.
223     @@lang:en
224     @Main:
225     my @date = gmtime shift;
226     sprintf '%04d-%02d-%02d %02d:%02d:%02d +00:00',
227     $date[5] + 1900,
228     $date[4] + 1,
229     @date[3,2,1,0];
230    
231     Function:
232 wakaba 1.3 @Name: get_headsummary
233 wakaba 1.1 @Description:
234 wakaba 1.3 @@@: Returns headline summary
235 wakaba 1.1 @@lang:en
236     @Main:
237 wakaba 1.3 my (undef, $page, %opt) = @_;
238     $page ||= $opt{wiki}->{var}->{page};
239    
240     my $s;
241     try {
242     if ($opt{wiki}->{db}->exist (wpp__headsummary => $page)) {
243     $s = $opt{wiki}->{db}->get (wpp__headsummary => $page);
244     } else {
245     my $content = $opt{wiki}->{db}->get (content => $page);
246    
247     ## Get Format Handler
248     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
249     ->handler (\$content,
250     wiki => $opt{wiki});
251     $s = $format->headsummary (\$content, wiki => $opt{wiki});
252    
253     $s =~ tr/\x0D//d;
254     if (length ($s) > 500) {
255     $s = substr ($s, 0, 500);
256     $s =~ s/[^\x09\x0A\x20-\x7E]+$//;
257     $s .= '...';
258     }
259     if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/) {
260     $s = $1;
261     }
262     $s =~ s/[\x09\x0A\x20]+/\x20/gs;
263     $s =~ s/\([^\(\)]+\)//g;
264     $s =~ s/\[[^\[\]]+\]//g;
265     $s =~ s/>>[0-9]+//g;
266     $s =~ s/<[^<>]+>//g;
267     $s =~ s/{[^{}]+}//g;
268     $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;
269     $s =~ s/ [Aa]n? / /g;
270 wakaba 1.1 $s =~ s/ [Aa]t / @ /g;
271     $s =~ s/ [Tt]he / /g;
272     $s =~ s/,? and / & /g;
273     $s =~ s!,? or ! / !g;
274     $s =~ s! not !n't !g;
275     $s =~ s! (?:i|ha)s !'s !g;
276     $s =~ s! are !'re !g;
277     $s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge;
278 wakaba 1.3 $s =~ s![.,]\x20?$!!g;
279     $s =~ s/\x20+/\x20/g;
280     if (length ($s) > 400) {
281     $s = substr ($s, 0, 400);
282     $s =~ s/[^\x20-\x7E]+$//s; # Remove broken EUC-JP char
283     $s .= '...';
284     }
285     $opt{wiki}->{db}->set (wpp__headsummary => $page => $s);
286     }
287     } catch SuikaWiki::DB::Util::Error with {
288 wakaba 1.5 my $err = shift;
289     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
290 wakaba 1.3 $s = undef;
291     };
292     return $s;
293 wakaba 1.1
294     ViewFragment:
295     @Name: ws--post-content
296     @Description:
297     @@@: After content body -- last modified date and time of the WikiPage
298     @@lang:en
299     @Order: 800
300     @Formatting:
301     %block (
302     id => last-modified,
303     content => {%res(name=>{LastModified=});%last-modified;}p,
304     );
305    
306     Resource:
307     @LastModified=:
308     @@@:
309     Last modified:
310     @@lang: en

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24