/[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.2.1 - (hide annotations) (download)
Wed Aug 11 00:01:59 2004 UTC (21 years, 10 months ago) by wakaba
Branch: paragraph-200404
Changes since 1.8: +2 -5 lines
Experimental paragraph-oriented wiki implementation

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24