/[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.3 - (show annotations) (download)
Sun Feb 1 12:18:14 2004 UTC (22 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +78 -54 lines
(get_headsummary): New

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24