/[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.4 - (show annotations) (download)
Sun Feb 8 08:52:03 2004 UTC (22 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +28 -21 lines
SuikaWiki 3 WikiName interface supported

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/02/01 12:18:14 $
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
135 ($o->{link}->{dest}->{page_name_relative}->stringify
136 (wiki => $o->{wiki}));
137 } else {
138 $p->{-parent}->append_text
139 ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
140 }
141
142 FormattingRule:
143 @Category[list]:page-link
144 @Name: page-title
145 @Description:
146 @@@:Title of the WikiPage
147 @@lang:en
148 @Parameter:
149 @@Name:relative
150 @@Type:boolean
151 @@Default:"0"
152 @@Description:
153 @@@@:Whether relative to "this" page
154 @@@lang:en
155 @Formatting:
156 __ATTRTEXT:%relative__;
157 if (defined $o->{link}->{dest}->{page_title}) {
158 ## ISSUE: Is this work now?
159 $p->{-parent}->append_text ($o->{link}->{dest}->{page_title});
160 } elsif ($p->{relative}) {
161 $p->{-parent}->append_text
162 ($o->{link}->{dest}->{page_name_relative}->stringify
163 (wiki => $o->{wiki}));
164 } else {
165 $p->{-parent}->append_text
166 ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
167 }
168
169 FormattingRule:
170 @Category[list]:page-link
171 @Name:page-headline
172 @Description:
173 @@@:Headline summary of the WikiPage
174 @@lang:en
175 @Formatting:
176 $p->{-parent}->append_text (__FUNCPACK__->get_headsummary
177 ($o->{link}->{dest}->{page_name},
178 wiki => $o->{wiki}));
179
180 FormattingRule:
181 @Category[list]: form-input
182 @Name: wpp--next-anchor-index
183 @Description:
184 @@@: Next "anchor index" number
185 @@lang: en
186 @Formatting:
187 my $page = $o->{wiki}->{var}->{page};
188 my $content;
189 try {
190 $content = $o->{wiki}->{db}->get (content => $page);
191
192 ## Get Format Handler
193 my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
194 ->handler (\$content,
195 wiki => $o->{wiki});
196
197 $p->{-parent}->append_text ($format->next_index_for_anchor
198 (\$content, wiki => $o->{wiki},
199 page => $page));
200
201 } catch SuikaWiki::DB::Util::Error with {
202 #
203 } catch SuikaWiki::Format::Definition::error with {
204 #
205 };
206
207 Function:
208 @Name: unixtime_to_string
209 @Description
210 @@@:
211 Convert internal date-time format to other (possibly human readable)
212 format.
213 \
214 Note: Currently, only one fixed format is supported, whilst
215 future version is expected to support highly customizable
216 formatting supported by Message::Field::Date.
217 @@lang:en
218 @Main:
219 my @date = gmtime shift;
220 sprintf '%04d-%02d-%02d %02d:%02d:%02d +00:00',
221 $date[5] + 1900,
222 $date[4] + 1,
223 @date[3,2,1,0];
224
225 Function:
226 @Name: get_headsummary
227 @Description:
228 @@@: Returns headline summary
229 @@lang:en
230 @Main:
231 my (undef, $page, %opt) = @_;
232 $page ||= $opt{wiki}->{var}->{page};
233
234 my $s;
235 try {
236 if ($opt{wiki}->{db}->exist (wpp__headsummary => $page)) {
237 $s = $opt{wiki}->{db}->get (wpp__headsummary => $page);
238 } else {
239 my $content = $opt{wiki}->{db}->get (content => $page);
240
241 ## Get Format Handler
242 my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
243 ->handler (\$content,
244 wiki => $opt{wiki});
245 $s = $format->headsummary (\$content, wiki => $opt{wiki});
246
247 $s =~ tr/\x0D//d;
248 if (length ($s) > 500) {
249 $s = substr ($s, 0, 500);
250 $s =~ s/[^\x09\x0A\x20-\x7E]+$//;
251 $s .= '...';
252 }
253 if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/) {
254 $s = $1;
255 }
256 $s =~ s/[\x09\x0A\x20]+/\x20/gs;
257 $s =~ s/\([^\(\)]+\)//g;
258 $s =~ s/\[[^\[\]]+\]//g;
259 $s =~ s/>>[0-9]+//g;
260 $s =~ s/<[^<>]+>//g;
261 $s =~ s/{[^{}]+}//g;
262 $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;
263 $s =~ s/ [Aa]n? / /g;
264 $s =~ s/ [Aa]t / @ /g;
265 $s =~ s/ [Tt]he / /g;
266 $s =~ s/,? and / & /g;
267 $s =~ s!,? or ! / !g;
268 $s =~ s! not !n't !g;
269 $s =~ s! (?:i|ha)s !'s !g;
270 $s =~ s! are !'re !g;
271 $s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge;
272 $s =~ s![.,]\x20?$!!g;
273 $s =~ s/\x20+/\x20/g;
274 if (length ($s) > 400) {
275 $s = substr ($s, 0, 400);
276 $s =~ s/[^\x20-\x7E]+$//s; # Remove broken EUC-JP char
277 $s .= '...';
278 }
279 $opt{wiki}->{db}->set (wpp__headsummary => $page => $s);
280 }
281 } catch SuikaWiki::DB::Util::Error with {
282 $s = undef;
283 };
284 return $s;
285
286 ViewFragment:
287 @Name: ws--post-content
288 @Description:
289 @@@: After content body -- last modified date and time of the WikiPage
290 @@lang:en
291 @Order: 800
292 @Formatting:
293 %block (
294 id => last-modified,
295 content => {%res(name=>{LastModified=});%last-modified;}p,
296 );
297
298 Resource:
299 @LastModified=:
300 @@@:
301 Last modified:
302 @@lang: en

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24