/[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.8 - (hide annotations) (download)
Sun Apr 25 07:06:50 2004 UTC (22 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: release-3-0-0
Branch point for: paragraph-200404
Changes since 1.7: +7 -2 lines
LeafProp database module added; content_prop implemented; Media type property implemented

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 wakaba 1.8 $Date: 2004/04/01 04:40:27 $
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 wakaba 1.7 $p->{-parent}->append_text ($o->{wiki}->{var}->{page}->stringify
115     (wiki => $o->{wiki}));
116 wakaba 1.1
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 wakaba 1.3 @@@@:Whether WikiName should be relative to "this" page
129 wakaba 1.1 @@@lang:en
130     @Formatting:
131     __ATTRTEXT:%relative__;
132     if ($p->{relative}) {
133 wakaba 1.4 $p->{-parent}->append_text
134     ($o->{link}->{dest}->{page_name_relative}->stringify
135     (wiki => $o->{wiki}));
136 wakaba 1.1 } else {
137 wakaba 1.4 $p->{-parent}->append_text
138     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
139 wakaba 1.1 }
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 wakaba 1.3 ## ISSUE: Is this work now?
158 wakaba 1.1 $p->{-parent}->append_text ($o->{link}->{dest}->{page_title});
159     } elsif ($p->{relative}) {
160 wakaba 1.4 $p->{-parent}->append_text
161     ($o->{link}->{dest}->{page_name_relative}->stringify
162     (wiki => $o->{wiki}));
163 wakaba 1.1 } else {
164 wakaba 1.4 $p->{-parent}->append_text
165     ($o->{link}->{dest}->{page_name}->stringify (wiki => $o->{wiki}));
166 wakaba 1.1 }
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 wakaba 1.4 $p->{-parent}->append_text (__FUNCPACK__->get_headsummary
176     ($o->{link}->{dest}->{page_name},
177     wiki => $o->{wiki}));
178 wakaba 1.1
179 wakaba 1.2 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 wakaba 1.3 my $content;
188 wakaba 1.8 my $content_prop;
189 wakaba 1.3 try {
190     $content = $o->{wiki}->{db}->get (content => $page);
191 wakaba 1.8 $content_prop = $o->{wiki}->{db}->get (content_prop => $page);
192 wakaba 1.4
193     ## Get Format Handler
194     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
195     ->handler (\$content,
196 wakaba 1.8 content_prop => $content_prop,
197 wakaba 1.4 wiki => $o->{wiki});
198    
199     $p->{-parent}->append_text ($format->next_index_for_anchor
200 wakaba 1.8 (\$content,
201     content_prop => $content_prop,
202     wiki => $o->{wiki},
203 wakaba 1.4 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