/[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.5 - (hide annotations) (download)
Wed Feb 18 07:18:30 2004 UTC (22 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +9 -2 lines
WikiDB Error reporting bug fixed

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiPageProp
5     @Description:
6     @@@: WikiPage property
7     @@lang:en
8     @License: %%GPL%%
9     @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.5 @Date.RCS: $Date: 2004/02/08 08:52:03 $
16 wakaba 1.2 @RequiredModule[list]:
17     WikiFormat
18 wakaba 1.3 @Use:
19     use Message::Util::Error;
20 wakaba 1.1
21     PluginConst:
22     @NS_XHTML1:
23     http://www.w3.org/1999/xhtml
24    
25     FormattingRule:
26     @Category[list]:
27     view
28     view-resource
29     form-input
30     @Name: last-modified
31     @Description:
32     @@@:
33     Last-modified date-time of the WikiPage.
34     \
35     Note: Date-time value returned by this rule might not be
36     the "real" last-modified date-time, in case last-modified
37     value is not updated when content is modified (so called
38     "sage" feature).
39     @@lang: en
40     @Parameter:
41     @@Name: page
42     @@Type: WikiName
43     @@Default: (current)
44     @@Description:
45     @@@@: Target WikiPage
46     @@@lang:en
47     @Formatting:
48     __ATTRTEXT:%page__;
49     my $page = length $p->{page} ?
50     [split $o->{wiki}->{config}->{name}->{space}->{separator_regex},
51     $p->{page}]:
52     $o->{wiki}->{var}->{page};
53 wakaba 1.3 my $lm;
54     try {
55     $lm = $o->{wiki}->{db}->get (lastmodified => $page);
56     } catch SuikaWiki::DB::Util::Error with {
57 wakaba 1.5 my $err = shift;
58     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
59 wakaba 1.3 $lm = 0;
60 wakaba 1.4 };
61 wakaba 1.3 $p->{-parent}->append_text ( __FUNCPACK__::unixtime_to_string ($lm));
62 wakaba 1.1 ## TODO: format string
63    
64     FormattingRule:
65     @Category[list]: page-link
66     @Name: last-modified
67     @Description:
68     @@@:
69     Last-modified date-time of the WikiPage.
70     \
71     Note: Date-time value returned by this rule might not be
72     the "real" last-modified date-time, in case last-modified
73     value is not updated when content is modified (so called
74     "sage" feature).
75     @@lang: en
76     @Formatting:
77     my $date;
78     if (defined $o->{link}->{dest}->{page_lastmodified}) {
79     $date = $o->{link}->{dest}->{page_lastmodified};
80     } else {
81     ## TODO:
82 wakaba 1.3 my $page = $o->{link}->{dest}->{page_name};
83     try {
84     $date = $o->{wiki}->{db}->get (lastmodified => $page);
85     } catch SuikaWiki::DB::Util::Error with {
86 wakaba 1.5 my $err = shift;
87     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
88 wakaba 1.3 $date = 0;
89     };
90 wakaba 1.1 }
91     $p->{-parent}->append_text (__FUNCPACK__::unixtime_to_string ($date));
92     ## TODO: Update to new interface
93    
94     FormattingRule:
95     @Category[list]:
96     view
97     view-resource
98     form-input
99     @Name: page-name
100     @Description:
101     @@@:
102     WikiName in string repersentation
103     @@lang: en
104     @Parameter:
105     @@Name:separator
106     @@Type:string
107     @@Default:(config)
108     @@Description:
109     @@@@:Separator used to delimit namespace components (ie. path delimiter)
110     @@@lang:en
111     @Formatting:
112     __ATTRTEXT:%page__;
113     ## TODO:
114     my $page = length $p->{page} ?
115     [split $o->{wiki}->{config}->{name}->{space}->{separator_regex},
116     $p->{page}]:
117     $o->{wiki}->{var}->{page};
118     $p->{-parent}->append_text (join
119     (($p->{separator} || $o->{wiki}->{config}->{name}->{space}->{separator}),
120     @{$page}));
121    
122     FormattingRule:
123     @Category[list]:page-link
124     @Name: page-name
125     @Description:
126     @@@:WikiName in string representation
127     @@lang:en
128     @Parameter:
129     @@Name:relative
130     @@Type:boolean
131     @@Default:"0"
132     @@Description:
133 wakaba 1.3 @@@@:Whether WikiName should be relative to "this" page
134 wakaba 1.1 @@@lang:en
135     @Formatting:
136     __ATTRTEXT:%relative__;
137     if ($p->{relative}) {
138 wakaba 1.4 $p->{-parent}->append_text
139     ($o->{link}->{dest}->{page_name_relative}->stringify
140     (wiki => $o->{wiki}));
141 wakaba 1.1 } else {
142 wakaba 1.4 $p->{-parent}->append_text
143     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
144 wakaba 1.1 }
145    
146     FormattingRule:
147     @Category[list]:page-link
148     @Name: page-title
149     @Description:
150     @@@:Title of the WikiPage
151     @@lang:en
152     @Parameter:
153     @@Name:relative
154     @@Type:boolean
155     @@Default:"0"
156     @@Description:
157     @@@@:Whether relative to "this" page
158     @@@lang:en
159     @Formatting:
160     __ATTRTEXT:%relative__;
161     if (defined $o->{link}->{dest}->{page_title}) {
162 wakaba 1.3 ## ISSUE: Is this work now?
163 wakaba 1.1 $p->{-parent}->append_text ($o->{link}->{dest}->{page_title});
164     } elsif ($p->{relative}) {
165 wakaba 1.4 $p->{-parent}->append_text
166     ($o->{link}->{dest}->{page_name_relative}->stringify
167     (wiki => $o->{wiki}));
168 wakaba 1.1 } else {
169 wakaba 1.4 $p->{-parent}->append_text
170     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
171 wakaba 1.1 }
172    
173     FormattingRule:
174     @Category[list]:page-link
175     @Name:page-headline
176     @Description:
177     @@@:Headline summary of the WikiPage
178     @@lang:en
179     @Formatting:
180 wakaba 1.4 $p->{-parent}->append_text (__FUNCPACK__->get_headsummary
181     ($o->{link}->{dest}->{page_name},
182     wiki => $o->{wiki}));
183 wakaba 1.1
184 wakaba 1.2 FormattingRule:
185     @Category[list]: form-input
186     @Name: wpp--next-anchor-index
187     @Description:
188     @@@: Next "anchor index" number
189     @@lang: en
190     @Formatting:
191     my $page = $o->{wiki}->{var}->{page};
192 wakaba 1.3 my $content;
193     try {
194     $content = $o->{wiki}->{db}->get (content => $page);
195 wakaba 1.4
196     ## Get Format Handler
197     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
198     ->handler (\$content,
199     wiki => $o->{wiki});
200    
201     $p->{-parent}->append_text ($format->next_index_for_anchor
202     (\$content, wiki => $o->{wiki},
203     page => $page));
204    
205 wakaba 1.3 } catch SuikaWiki::DB::Util::Error with {
206 wakaba 1.5 my $err = shift;
207     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
208 wakaba 1.4 } catch SuikaWiki::Format::Definition::error with {
209     #
210 wakaba 1.3 };
211 wakaba 1.2
212 wakaba 1.1 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 wakaba 1.3 @Name: get_headsummary
232 wakaba 1.1 @Description:
233 wakaba 1.3 @@@: Returns headline summary
234 wakaba 1.1 @@lang:en
235     @Main:
236 wakaba 1.3 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 wakaba 1.1 $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 wakaba 1.3 $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 wakaba 1.5 my $err = shift;
288     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
289 wakaba 1.3 $s = undef;
290     };
291     return $s;
292 wakaba 1.1
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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24