/[pub]/suikawiki/script/wiki.cgi
Suika

Contents of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Sat Sep 28 10:54:27 2002 UTC (22 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.25: +33 -13 lines
2002-09-28  Wakaba <w@suika.fam.cx>

	* wiki.cgi:
	- Intoduce text/css mode.
	- Anchorize news: URIs.
	- (armor_name): Bug fix of not anchorizing traditional Wiki name.
	- Indenting heading 3-5 in TOC.
	- Multi-comment support.
	- (print_footer): Embed #comment.
	- (print_editform): Use NewPageTemplate when new page.
	* wiki-style.css: Removed.

1 wakaba 1.9 #!/usr/bin/perl
2 wakaba 1.16 #!perl
3 wakaba 1.9 #
4 wakaba 1.16 # wiki.cgi - This is YukiWiki, yet another Wiki clone.
5 wakaba 1.9 #
6 wakaba 1.16 # Copyright (C) 2000-2002 by Hiroshi Yuki.
7 wakaba 1.9 # <hyuki@hyuki.com>
8     # http://www.hyuki.com/yukiwiki/
9     #
10 wakaba 1.16 # This program is free software; you can redistribute it and/or
11     # modify it under the same terms as Perl itself.
12 wakaba 1.9 #
13 wakaba 1.16 ##############################
14     #
15     # walwiki.cgi based on yukiwiki.cgi - Yet another WikiWikiWeb clone.
16     #
17     # WalWikiの現バージョンは、YukiWiki 2.0.beta1をベースにしています。
18     #
19     # * 更新内容
20     #
21     # 2.0.beta1.wal.1 on 2002/05/19,22:32:19
22     # (1) Footerの変更
23     # (2) WikiNameの拡張 : PerlCEも包含、PPMInstallは含まない
24     # (3) 別名リンク([別名 URL])に対応。
25     # (4) ISBNをアマゾン.jpのAsociateプログラムリンクに変換。
26     # (5) [[#box:InterWikiName]]でInterWikiなテキストボックス生成
27     # (6) HTMLモード対応。
28     #
29     # 旧2.0.alpha0.wal.3版までの修正の内、以下に変更があります。
30     # ・以下はYukiWiki2に実装されたため、独自コードはなくなりました。
31     # - インラインの画像変換
32     # - YukiWikiDB対応
33     # - テーブル
34     # - DB関連モジュールuseのeval化
35     # - BracketNameによるキーからブラケットを排除
36     # ・ISBN番号への対応はWalWiki2.0より、InterWikiへのAdd-Onになりました。
37     # [[ISBN http://www.amazon.co.jp/exec/obidos/ASIN/isbn($1)/walrdigi-22]]のように登録。
38 wakaba 1.9 #
39 wakaba 1.16 #=======================================
40    
41     # Walrus add (debug) start
42     my $walrus_log;
43     my $walrus_debugging = 0;
44     # Walrus add (debug) end
45    
46     # Libraries.
47     use strict;
48     use lib qw(./WalWiki/lib);
49     use CGI qw(:standard);
50     use CGI::Carp qw(fatalsToBrowser);
51     use Yuki::RSS;
52     use Yuki::DiffText qw(difftext);
53     use Yuki::YukiWikiDB;
54     use AnyDBM_File;
55     require 'jcode.pl';
56     # use Jcode;
57     use Fcntl;
58     my $version = '2.0.beta1.2002-05-29';
59 wakaba 1.17 my $walversion;
60 wakaba 1.9 ##############################
61 wakaba 1.16 #
62     # You MUST modify following '$modifier_...' variables.
63     #
64     my $modifier_mail = 'w@suika.fam.cx'; # Your mail address, like 'walrus@digit.que.ne.jp'.
65     my $modifier_url = 'http://suika.fam.cx/~wakaba/'; # Your web page, like 'http://digit.que.ne.jp/work/'.
66     my $modifier_name = '和'; # Your name, like 'Makio Tsukamoto'.
67     # my $modifier_dbtype = 'AnyDBM_File'; # Fast, not available on some server, page size limited.
68     # my $modifier_dbtype = 'dbmopen'; # Fast, not available on some server, page size limited.
69     my $modifier_dbtype = 'YukiWikiDB'; # Slow, available on all environment.
70     # my $modifier_sendmail = '/usr/sbin/sendmail -t -n'; # Your sendmail.
71     my $modifier_sendmail = ''; # If you don't need mail notification.
72 wakaba 1.17 my $modifier_dir_data = './wikidata'; # Your data directory.
73 wakaba 1.16 my $modifier_rss_title = "WalWiki $walversion";
74     my $modifier_rss_link = 'http://suika.fam.cx/~wakaba/-temp/wiki2/wiki'; # Blank is not allowed.
75     my $modifier_rss_description = 'This is WalWiki, yet another Wiki clone based on YukiWiki';
76 wakaba 1.9 ##############################
77 wakaba 1.16 #
78     # You MAY modify following variables.
79     #
80     my $file_touch = "$modifier_dir_data/touched.txt";
81     my $file_resource = "$modifier_dir_data/resource.txt";
82     my $file_FrontPage = "$modifier_dir_data/frontpage.txt";
83     my $file_conflict = "$modifier_dir_data/conflict.txt";
84     my $file_format = "$modifier_dir_data/format.txt";
85     my $url_cgi = 'wiki';
86 wakaba 1.25 my $url_stylesheet = $url_cgi.'?mycmd=TEXT_CSS;mypage=WikiHTMLStyle';
87 wakaba 1.16 my $icontag = '<img src="/icons/folder" alt="*" width="40" height="40" />';
88     my $maxrecent = 50;
89 wakaba 1.9 my $cols = 80;
90     my $rows = 20;
91     ##############################
92 wakaba 1.16 #
93     # You MAY, but do NOT NEED modify following variables.
94     #
95     my $dataname = "$modifier_dir_data/wiki";
96     my $infoname = "$modifier_dir_data/info";
97     my $diffname = "$modifier_dir_data/diff";
98     my $editchar = '?';
99     my $subject_delimiter = ' - ';
100     my $use_autoimg = 1; # automatically convert image URL into <img> tag.
101     my $use_exists = 0; # If you can use 'exists' method for your DB.
102     ##############################
103     my $InterWikiName = 'InterWikiName';
104     my $RecentChanges = 'RecentChanges';
105     my $AdminChangePassword = 'AdminChangePassword';
106     my $CompletedSuccessfully = 'CompletedSuccessfully';
107 wakaba 1.18 my $FrontPage = 'HomePage';
108 wakaba 1.16 my $IndexPage = 'IndexPage';
109     my $SearchPage = 'SearchPage';
110     my $CreatePage = 'CreatePage';
111     my $ErrorPage = 'ErrorPage';
112     my $RssPage = 'RssPage';
113 wakaba 1.26 my $NAME_OF_WikiPageLicense = 'WikiPageLicense';
114 wakaba 1.16 my $AdminSpecialPage = 'Admin Special Page'; # must include spaces.
115     ##############################
116     # my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]+)+)\b'; # Walrus del (2)
117     my $wiki_name = '\b([A-Z][a-z]+([A-Z][a-z]*)+)\b'; # Walrus add (2)
118     my $bracket_name = '\[\[(\S+?)\]\]';
119     my $embedded_name = '\[\[(#\S+?)\]\]';
120     my $interwiki_definition = '\[\[(\S+?)\ (\S+?)\]\]';
121 wakaba 1.25 my $interwiki_name = 'i:([^:]+):([^:].*)';
122 wakaba 1.16 ##############################
123     my $embed_comment = '[[#comment]]';
124     my $embed_rcomment = '[[#rcomment]]';
125 wakaba 1.25 my $embed_comment_Name_Prompt = '名前:';
126     my $DEFAULT_embed_comment_name = '名無しさん';
127 wakaba 1.16 my $embed_interwiki = '^\[\[#(box|text|password):(\S+)\]\]$'; # Walrus add (5)
128 wakaba 1.22 my %embed_command = (
129     searched => '^\[\[#searched:([^\]]+)\]\]$',
130     );
131 wakaba 1.16 ##############################
132     my $info_LastModified = 'LastModified';
133     my $info_IsFrozen = 'IsFrozen';
134     my $info_AdminPassword = 'AdminPassword';
135     ##############################
136     my $kanjicode = 'euc';
137     my $charset = 'EUC-JP';
138     my $lang = 'ja';
139     my %fixedpage = (
140     $IndexPage => 1,
141     $CreatePage => 1,
142     $ErrorPage => 1,
143     $RssPage => 1,
144     $RecentChanges => 1,
145     $SearchPage => 1,
146     $AdminChangePassword => 1,
147     $CompletedSuccessfully => 1,
148 wakaba 1.18 #$FrontPage => 1,
149 wakaba 1.16 );
150     my %form;
151     my %database;
152     my %infobase;
153     my %diffbase;
154     my %resource;
155     my %interwiki;
156     ##############################
157     my %page_command = (
158     $IndexPage => 'index',
159     $SearchPage => 'searchform',
160     $CreatePage => 'create',
161     $RssPage => 'rss',
162     $AdminChangePassword => 'adminchangepasswordform',
163 wakaba 1.18 #$FrontPage => 'FrontPage',
164 wakaba 1.16 );
165     my %command_do = (
166     read => \&do_read,
167 wakaba 1.25 TEXT_CSS => \&do_output_css,
168 wakaba 1.16 edit => \&do_edit,
169     adminedit => \&do_adminedit,
170     adminchangepasswordform => \&do_adminchangepasswordform,
171     adminchangepassword => \&do_adminchangepassword,
172     write => \&do_write,
173     index => \&do_index,
174     searchform => \&do_searchform,
175     search => \&do_search,
176     create => \&do_create,
177     createresult => \&do_createresult,
178     FrontPage => \&do_FrontPage,
179     comment => \&do_comment,
180     rss => \&do_rss,
181     diff => \&do_diff,
182     interwikibox => \&do_interwiki_box, # Walrus add (5)
183     );
184     ##############################
185     my @ignore_html_page = ('FrontPage'); # Walrus add (6)
186     my @ignore_html_tags = ('a', 'br', 'img'); # Walrus add (6)
187     my $walversion = '2.0.beta1.wal.1'; # Walrus add (1)
188 wakaba 1.9 ##############################
189 wakaba 1.16 # &test_convert;
190 wakaba 1.9 &main;
191     exit(0);
192 wakaba 1.16 ##############################
193 wakaba 1.9
194     sub main {
195 wakaba 1.16 &init_resource;
196     &open_db;
197     &init_form;
198     &init_InterWikiName;
199     if ($command_do{$form{mycmd}}) {
200     &{$command_do{$form{mycmd}}};
201 wakaba 1.9 } else {
202 wakaba 1.16 &do_FrontPage;
203 wakaba 1.9 }
204 wakaba 1.16 &close_db;
205 wakaba 1.9 }
206    
207     sub do_read {
208 wakaba 1.26 &print_header($form{mypage});
209     my $content = $database{$form{mypage}};
210     my $cf = 'SuikaWiki/0.9';
211     $cf = $1 if $content =~ s#^(?:/\*\s*|\#\?)?([A-Z][A-Za-z0-9-]+/[0-9.]+(?:\s[^\x0D\x0A]+)?)[\x0D\x0A]+##s;
212     if ($cf =~ m#^SuikaWiki/0.9(?:$|\s)#) {
213     &print_content($content, $cf);
214     print &text_to_html (q([[#comment]]));
215     } else {
216     print "<pre>@{[&escape($content)]}</pre>";
217     }
218     my ($r, $c) = get_search_result ($form{mypage});
219 wakaba 1.22 if ($c) {
220 wakaba 1.26 print q{<h2 id="SEE-ALSO">See also</h2>};
221 wakaba 1.22 print $r;
222     }
223 wakaba 1.26 &print_footer($form{mypage});
224 wakaba 1.9 }
225    
226 wakaba 1.25 sub do_output_css {
227     my $content = $database{$form{mypage}};
228     if ($content =~ m#^\s*/\*\s*W3C-CSS#) {
229     print "Content-Type: text/css; charset=$charset\n";
230     print "\n";
231     print $content;
232     } else {
233     print "Status: 406 Unsupported Media Type\n";
234     &print_header('WikiPageIsNotCSS');
235     &print_content($database{WikiPageIsNotCSS});
236     &print_footer('WikiPageIsNotCSS');
237     }
238     }
239    
240 wakaba 1.9 sub do_edit {
241 wakaba 1.16 my ($page) = &unarmor_name(&armor_name($form{mypage}));
242     &print_header($page);
243     if (not &is_editable($page)) {
244     &print_message($resource{cantchange});
245     } elsif (&is_frozen($page)) {
246     &print_message($resource{cantchange});
247     } else {
248     &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>0);
249 wakaba 1.9 }
250 wakaba 1.16 &print_footer($page);
251 wakaba 1.9 }
252    
253 wakaba 1.16 sub do_adminedit {
254     my ($page) = &unarmor_name(&armor_name($form{mypage}));
255     &print_header($page);
256     if (not &is_editable($page)) {
257     &print_message($resource{cantchange});
258 wakaba 1.9 } else {
259 wakaba 1.16 &print_message($resource{passwordneeded});
260     &print_editform($database{$page}, &get_info($page, $info_LastModified), admin=>1);
261 wakaba 1.9 }
262 wakaba 1.16 &print_footer($page);
263 wakaba 1.9 }
264    
265 wakaba 1.16 sub do_adminchangepasswordform {
266     &print_header($AdminChangePassword);
267     &print_passwordform;
268     &print_footer($AdminChangePassword);
269     }
270 wakaba 1.9
271 wakaba 1.16 sub do_adminchangepassword {
272     if ($form{mynewpassword} ne $form{mynewpassword2}) {
273     &print_error($resource{passwordmismatcherror});
274     }
275     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
276     if ($validpassword_crypt) {
277     if (not &valid_password($form{myoldpassword})) {
278     &send_mail_to_admin(<<"EOD", "AdminChangePassword");
279     myoldpassword=$form{myoldpassword}
280     mynewpassword=$form{mynewpassword}
281     mynewpassword2=$form{mynewpassword2}
282 wakaba 1.9 EOD
283 wakaba 1.16 &print_error($resource{passworderror});
284 wakaba 1.9 }
285 wakaba 1.16 }
286     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
287     my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z');
288     my $salt1 = $token[(time | $$) % scalar(@token)];
289     my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)];
290     my $crypted = crypt($form{mynewpassword}, "$salt1$salt2");
291     &set_info($AdminSpecialPage, $info_AdminPassword, $crypted);
292    
293     &print_header($CompletedSuccessfully);
294     &print_message($resource{passwordchanged});
295     &print_footer($CompletedSuccessfully);
296     }
297    
298     sub do_index {
299     &print_header($IndexPage);
300     print qq(<ul>);
301     foreach my $page (sort keys %database) {
302     if (&is_editable($page)) {
303 wakaba 1.24 print qq(<li><a href="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
304 wakaba 1.16 # print qq(<li>@{[&get_info($page, $info_IsFrozen)]}</li>);
305     # print qq(<li>@{[0 + &is_frozen($page)]}</li>);
306 wakaba 1.9 }
307     }
308 wakaba 1.16 print qq(</ul>);
309     &print_footer($IndexPage);
310 wakaba 1.9 }
311    
312 wakaba 1.16 sub do_write {
313     if (&frozen_reject()) {
314     return;
315 wakaba 1.9 }
316    
317     if (not &is_editable($form{mypage})) {
318 wakaba 1.16 &print_header($form{mypage});
319     &print_message($resource{cantchange});
320     &print_footer($form{mypage});
321 wakaba 1.9 return;
322     }
323    
324 wakaba 1.16 if (&conflict($form{mypage}, $form{mymsg})) {
325 wakaba 1.9 return;
326     }
327    
328 wakaba 1.16 # Making diff
329 wakaba 1.9 {
330 wakaba 1.16 &open_diff;
331     my @msg1 = split(/\n/, $database{$form{mypage}});
332 wakaba 1.9 my @msg2 = split(/\n/, $form{mymsg});
333 wakaba 1.16 $diffbase{$form{mypage}} = &difftext(\@msg1, \@msg2);
334     &close_diff;
335 wakaba 1.9 }
336    
337     if ($form{mymsg}) {
338 wakaba 1.16 $database{$form{mypage}} = $form{mymsg};
339     &send_mail_to_admin($form{mypage}, "Modify");
340     if ($form{mytouch}) {
341     &set_info($form{mypage}, $info_LastModified, '' . localtime);
342     &update_recent_changes;
343     }
344     &set_info($form{mypage}, $info_IsFrozen, 0 + $form{myfrozen});
345 wakaba 1.22 &print_header($CompletedSuccessfully, -goto => $url_cgi.'?'.&encode($form{mypage}));
346 wakaba 1.16 &print_message($resource{saved});
347     &print_content("$resource{continuereading} @{[&armor_name($form{mypage})]}");
348     &print_footer($CompletedSuccessfully);
349     } else {
350     &send_mail_to_admin($form{mypage}, "Delete");
351     delete $database{$form{mypage}};
352     delete $infobase{$form{mypage}};
353     if ($form{mytouch}) {
354     &update_recent_changes;
355     }
356     &print_header($form{mypage});
357     &print_message($resource{deleted});
358     &print_footer($form{mypage});
359 wakaba 1.9 }
360     }
361    
362 wakaba 1.16 sub do_searchform {
363     &print_header($SearchPage);
364     &print_searchform("");
365     &print_footer($SearchPage);
366 wakaba 1.9 }
367    
368 wakaba 1.16 sub do_search {
369 wakaba 1.22 my $word = $form{mymsg};
370 wakaba 1.16 &print_header($SearchPage);
371 wakaba 1.22 &print_searchform(&escape($word));
372 wakaba 1.24 print scalar get_search_result ($word, -output_not_found => 1);
373 wakaba 1.16 &print_footer($SearchPage);
374 wakaba 1.9 }
375    
376 wakaba 1.22 sub get_search_result ($;%) {
377     my $word = shift;
378     my %option = @_;
379     my $counter = 0;
380     my $r = '';
381     foreach my $page (sort keys %database) {
382     next if $page eq $RecentChanges;
383     if ( index ($database{$page}, $word) > 0
384     || index ($page, $word) > 0
385     || index ($word, $page) > 0
386     ) {
387 wakaba 1.26 $r .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}" class="wiki">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>);
388 wakaba 1.22 $counter++;
389     }
390     }
391     $r = qq|<ul>$r</ul>| if $r;
392     get_message ($resource{notfound})
393     if $counter == 0 && $option{-output_not_found};
394     wantarray? ($r, $counter): $r;
395     }
396    
397 wakaba 1.16 sub do_create {
398     &print_header($CreatePage);
399     print <<"EOD";
400     <form action="$url_cgi" method="post">
401     <input type="hidden" name="mycmd" value="edit">
402     <strong>$resource{newpagename}</strong><br>
403     <input type="text" name="mypage" value="" size="20">
404     <input type="submit" value="$resource{createbutton}"><br>
405     </form>
406     EOD
407     &print_footer($CreatePage);
408 wakaba 1.9 }
409    
410 wakaba 1.16 sub do_FrontPage {
411     open(FILE, $file_FrontPage) or &print_error("($file_FrontPage)");
412     my $content = join('', <FILE>);
413     &code_convert(\$content, $kanjicode);
414     close(FILE);
415     &print_header($FrontPage);
416     &print_content($content);
417     &print_footer($FrontPage);
418 wakaba 1.9 }
419    
420     sub print_error {
421     my ($msg) = @_;
422 wakaba 1.16 &print_header($ErrorPage);
423     print qq(<p><strong class="error">$msg</strong></p>);
424     &print_footer($ErrorPage);
425 wakaba 1.9 exit(0);
426     }
427    
428 wakaba 1.16 sub print_header {
429 wakaba 1.22 my ($page,%option) = @_;
430 wakaba 1.16 my $bodyclass = "normal";
431     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
432     $bodyclass = "frozen";
433 wakaba 1.22 }
434     if ($option{-goto}) {
435     print qq{Refresh: 0; url="$option{-goto}"\n};
436 wakaba 1.9 }
437 wakaba 1.16 my $cookedpage = &encode($page);
438 wakaba 1.24 my $escapedpage = &escape($page);
439 wakaba 1.9 print <<"EOD";
440 wakaba 1.16 Content-type: text/html; charset=$charset
441 wakaba 1.18 Content-Language: $lang
442     Content-Style-Type: text/css
443 wakaba 1.9
444 wakaba 1.16 <!DOCTYPE html
445     PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
446     "http://www.w3.org/TR/html4/loose.dtd">
447     <html lang="$lang">
448     <head>
449 wakaba 1.24 <title>$escapedpage @{[&escape(&get_subjectline($page))]}</title>
450 wakaba 1.16 <link rel="index" href="$url_cgi?$IndexPage">
451 wakaba 1.26 <link rel="copyright" href="$url_cgi?$NAME_OF_WikiPageLicense">
452 wakaba 1.24 <link rev="made" href="mailto:@{[&escape($modifier_mail)]}">
453     <link rel="stylesheet" type="text/css" href="@{[&escape($url_stylesheet)]}">
454 wakaba 1.9 </head>
455 wakaba 1.16 <body class="$bodyclass">
456 wakaba 1.22 EOD
457     &print_navigate_links ($page);
458     print <<EOD;
459     <h1 class="header"><a
460     title="$resource{searchthispage}"
461 wakaba 1.23 href="$url_cgi?mycmd=search;mymsg=$cookedpage">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</h1>
462 wakaba 1.22 EOD
463     }
464    
465     sub print_navigate_links (@) {
466     my ($page) = @_;
467     my $editable = 0;
468     my $admineditable = 0;
469     if (&is_frozen($page) and $form{mycmd} =~ /^(read|write)$/) {
470     $editable = 0;
471     $admineditable = 1;
472     } elsif (&is_editable($page) and $form{mycmd} =~ /^(read|write)$/) {
473     $admineditable = 1;
474     $editable = 1;
475     } else {
476     $editable = 0;
477     }
478     my $cookedpage = &encode($page);
479     print <<EOH;
480 wakaba 1.16 <div class="tools">
481     @{[ $admineditable
482     ? qq(<a title="$resource{admineditthispage}" href="$url_cgi?mycmd=adminedit;mypage=$cookedpage">$resource{admineditbutton}</a> | )
483     : qq()
484     ]}
485     @{[ $editable
486 wakaba 1.22 ? qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedpage" accesskey="E">$resource{editbutton} <kbd>E</kbd></a> | )
487 wakaba 1.16 : qq()
488     ]}
489     @{[ $admineditable
490     ? qq(<a href="$url_cgi?mycmd=diff;mypage=$cookedpage">$resource{diffbutton}</a> | )
491     : qq()
492     ]}
493     <a href="$url_cgi?$CreatePage">$resource{createbutton}</a> |
494     <a href="$url_cgi?$IndexPage">$resource{indexbutton}</a> |
495     <a href="$url_cgi?$RssPage">$resource{rssbutton}</a> |
496     <a href="$url_cgi?$FrontPage">$FrontPage</a> |
497     <a href="$url_cgi?$SearchPage">$resource{searchbutton}</a> |
498     <a href="$url_cgi?$RecentChanges">$resource{recentchangesbutton}</a>
499     </div>
500 wakaba 1.22 EOH
501 wakaba 1.9 }
502    
503 wakaba 1.16 sub print_footer {
504     my ($page) = @_;
505     $walrus_log = ($walrus_debugging) ? &text_to_html("----\n$walrus_log") : ''; # Walrus add (debug)
506     # Walrus mod (1) start
507 wakaba 1.25 my $cvslog = '$Revision: 1.24 $ $Date: 2002/08/30 04:31:11 $';
508 wakaba 1.22 print_navigate_links ($page);
509     print <<"EOD";
510 wakaba 1.16 <div class="footer">
511 wakaba 1.9 <p>
512 wakaba 1.16 <a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />
513     based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />
514 wakaba 1.18 <a href="/gate/cvs/wakaba/wiki/" title="CVS Repository">
515 wakaba 1.19 $cvslog
516 wakaba 1.18 </a>
517 wakaba 1.9 </p>
518 wakaba 1.18 <div class="navigation">
519     [<a href="/" title="このサーバーの首頁">/</a>
520     <a href="/map" title="このサーバーの案内">地図</a>
521     <a href="/search/" title="このサーバーの検索">検索</a>]
522     </div>
523 wakaba 1.10 </div>
524 wakaba 1.19 $walrus_log
525 wakaba 1.16 </body>
526     </html>
527 wakaba 1.12 EOD
528 wakaba 1.16 # print <<"EOD";
529     # <hr>
530     # <address class="footer">
531     # <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version
532     # &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />
533     # Modified by <a href="$modifier_url">$modifier_name</a>.
534     # </address>
535     # <p class="footer">
536     # <a href="http://www.hyuki.com/yukiwiki/">$icontag</a>
537     # </p>
538     # </body>
539     # </html>
540     # EOD
541     # Walrus mod (1) end
542 wakaba 1.9 }
543    
544 wakaba 1.16 sub escape {
545     my $s = shift;
546     $s =~ s|\r\n|\n|g;
547 wakaba 1.23 $s =~ s|&|&amp;|g;
548 wakaba 1.16 $s =~ s|<|&lt;|g;
549     $s =~ s|>|&gt;|g;
550     $s =~ s|"|&quot;|g;
551     return $s;
552     }
553    
554     sub unescape {
555     my $s = shift;
556     # $s =~ s|\n|\r\n|g;
557 wakaba 1.23 $s =~ s|&lt;|<|g;
558     $s =~ s|&gt;|>|g;
559     $s =~ s|&quot;|"|g;
560     $s =~ s|&amp;|&|g;
561 wakaba 1.16 return $s;
562     }
563    
564 wakaba 1.26 sub print_content ($;$) {
565     my ($rawcontent, $format) = @_;
566 wakaba 1.16 print &text_to_html($rawcontent, toc=>1);
567 wakaba 1.9 }
568    
569 wakaba 1.16 sub text_to_html {
570     my ($txt, %option) = @_;
571 wakaba 1.9 my (@txt) = split(/\n/, $txt);
572 wakaba 1.16 my (@toc);
573     my $tocnum = 0;
574     my (@saved, @result);
575     unshift(@saved, "</p>");
576     push(@result, "<p>");
577 wakaba 1.9 foreach (@txt) {
578     chomp;
579 wakaba 1.25 if (/^\*\*\*\*\*([^\x0D\x0A]*)/) {
580     push(@toc, qq(----- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
581 wakaba 1.18 push(@result, splice(@saved), qq(<h6 id="i$tocnum">) . &inline($1) . '</h6>');
582     $tocnum++;
583 wakaba 1.25 } elsif (/^\*\*\*\*([^\x0D\x0A]*)/) {
584     push(@toc, qq(---- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
585 wakaba 1.18 push(@result, splice(@saved), qq(<h5 id="i$tocnum">) . &inline($1) . '</h5>');
586     $tocnum++;
587 wakaba 1.25 } elsif (/^\*\*\*([^\x0D\x0A]*)/) {
588     push(@toc, qq(--- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
589 wakaba 1.18 push(@result, splice(@saved), qq(<h4 id="i$tocnum">) . &inline($1) . '</h4>');
590     $tocnum++;
591 wakaba 1.25 } elsif (/^\*\*([^\x0D\x0A]*)/) {
592 wakaba 1.16 # if (/^\*\*(.*)/) {
593     # Walrus mod (6) end
594 wakaba 1.25 push(@toc, qq(-- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
595 wakaba 1.16 push(@result, splice(@saved), qq(<h3><a name="i$tocnum"> </a>) . &inline($1) . '</h3>');
596     $tocnum++;
597 wakaba 1.25 } elsif (/^\*([^\x0D\x0A]*)/) {
598     push(@toc, qq(- <a href="#i$tocnum">@{[&escape($1)||$tocnum]}</a>\n));
599 wakaba 1.16 push(@result, splice(@saved), qq(<h2><a name="i$tocnum"> </a>) . &inline($1) . '</h2>');
600     $tocnum++;
601 wakaba 1.25 } elsif (/^(={1,6})(.*)/) {
602 wakaba 1.18 &back_push('ol', length($1), \@saved, \@result);
603     push(@result, '<li>' . &inline($2) . '</li>');
604 wakaba 1.25 } elsif (/^(-{1,6})(.*)/) {
605 wakaba 1.16 &back_push('ul', length($1), \@saved, \@result);
606 wakaba 1.13 push(@result, '<li>' . &inline($2) . '</li>');
607 wakaba 1.9 } elsif (/^:([^:]+):(.*)/) {
608 wakaba 1.16 &back_push('dl', 1, \@saved, \@result);
609 wakaba 1.9 push(@result, '<dt>' . &inline($1) . '</dt>', '<dd>' . &inline($2) . '</dd>');
610 wakaba 1.18 } elsif (/^(>{1,5})(.*)/) {
611 wakaba 1.16 &back_push('blockquote', length($1), \@saved, \@result);
612 wakaba 1.9 push(@result, &inline($2));
613     } elsif (/^\s*$/) {
614     push(@result, splice(@saved));
615     unshift(@saved, "</p>");
616     push(@result, "<p>");
617     } elsif (/^(\s+.*)$/) {
618 wakaba 1.16 &back_push('pre', 1, \@saved, \@result);
619 wakaba 1.18 #push(@result, &escape($1)); # Not &inline, but &escape
620 wakaba 1.26 push(@result, &inline($1));
621 wakaba 1.16 # } elsif (/^\,(.*)$/) { # Walrus del (BF)
622     } elsif (/^\,(.*?)[\x0D\x0A]*$/) { # Walrus add (BF)
623     &back_push('table', 1, \@saved, \@result, ' border="1"');
624     #######
625     # This part is taken from Mr. Ohzaki's Perl Memo and Makio Tsukamoto's WalWiki.
626     # XXXXX
627     my $tmp = "$1,";
628     my @value = map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_} ($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
629     my @align = map {(s/^\s+//) ? ((s/\s+$//) ? ' align="center"' : ' align="right"') : ''} @value;
630     my @colspan = map {($_ eq '==') ? 0 : 1} @value;
631     for (my $i = 0; $i < @value; $i++) {
632     if ($colspan[$i]) {
633     while ($i + $colspan[$i] < @value and $value[$i + $colspan[$i]] eq '==') {
634     $colspan[$i]++;
635     }
636     $colspan[$i] = ($colspan[$i] > 1) ? sprintf(' colspan="%d"', $colspan[$i]) : '';
637     $value[$i] = sprintf('<td%s%s>%s</td>', $align[$i], $colspan[$i], &inline($value[$i]));
638     } else {
639     $value[$i] = '';
640     }
641     }
642     push(@result, join('', '<tr>', @value, '</tr>'));
643     # XXXXX
644     #######
645 wakaba 1.26 } elsif (/^\[INS\[/) {
646     push(@result, "<ins>");
647     } elsif (/^\]INS\]/) {
648     push(@result, "</ins>");
649     } elsif (/^\[DEL\[/) {
650     push(@result, "<del>");
651     } elsif (/^\]DEL\]/) {
652     push(@result, "</del>");
653     } elsif (/^\[PRE\[/) {
654     push(@result, "<pre>");
655     } elsif (/^\]PRE\]/) {
656     push(@result, "</pre>");
657 wakaba 1.9 } else {
658     push(@result, &inline($_));
659     }
660     }
661     push(@result, splice(@saved));
662 wakaba 1.16
663     if ($option{toc}) {
664     # Convert @toc (table of contents) to HTML.
665     # This part is taken from Makio Tsukamoto's WalWiki.
666     my (@tocsaved, @tocresult);
667     foreach (@toc) {
668 wakaba 1.25 if (/^(-{1,6})(.*)$/) {
669 wakaba 1.16 &back_push('ul', length($1), \@tocsaved, \@tocresult);
670     push(@tocresult, '<li>' . $2 . '</li>');
671     }
672     }
673     push(@tocresult, splice(@tocsaved));
674     return join("\n", @tocresult, @result);
675     } else {
676     return join("\n", @result);
677     }
678 wakaba 1.9 }
679    
680     sub back_push {
681 wakaba 1.16 my ($tag, $level, $savedref, $resultref, $attr) = @_;
682     while (@$savedref > $level) {
683     push(@$resultref, shift(@$savedref));
684     }
685     if ($savedref->[0] ne "</$tag>") {
686     push(@$resultref, splice(@$savedref));
687     }
688     while (@$savedref < $level) {
689     unshift(@$savedref, "</$tag>");
690     push(@$resultref, "<$tag$attr>");
691 wakaba 1.9 }
692     }
693    
694 wakaba 1.16 sub inline {
695     my ($line) = @_;
696     $line = &escape($line);
697 wakaba 1.18 $line =~ s|'''([^']+?)'''|<strong>$1</strong>|g;
698     $line =~ s|''([^']+?)''|<em>$1</em>|g;
699 wakaba 1.16 $line =~ s|(\d\d\d\d-\d\d-\d\d \(\w\w\w\) \d\d:\d\d:\d\d)|<span class="date">$1</span>|g; # Date
700     $line =~ s!
701 wakaba 1.18 (
702 wakaba 1.25 (?:&lt;(?:mailto|http|https|ftp|urn|news):[\x21-\x7E]*)&gt;
703 wakaba 1.18 |
704     ($bracket_name) # [[likethis]], [[#comment]], [[Friend:remotelink]]
705     |
706     ($interwiki_definition) # [[Friend http://somewhere/?q=sjis($1)]]
707     #|
708     # ($wiki_name)
709     )
710 wakaba 1.16 !
711     &make_link($1)
712     !gex;
713     return $line;
714     }
715    
716     sub make_link {
717     my $chunk = shift;
718     # Walrus add (3) start
719 wakaba 1.21 $chunk =~ s/^&lt;(.*)&gt;$/$1/;
720 wakaba 1.16 my $name = $chunk;
721     if ($chunk =~ /^\[\[([^ ]+?) ([^ ]+?)\]\]$/ and $form{mypage} ne $InterWikiName) {
722     ($name, $chunk) = ($1, $2);
723     } elsif ($chunk =~ /^mailto:(.*)$/) {
724     $name = $1;
725     }
726 wakaba 1.25 if ($use_autoimg and $name =~ /^(http|https|ftp):.+\.(png|gif|jpe?g)/) {
727 wakaba 1.16 $name = qq(<img src="$name">) ;
728     }
729     $name = &unarmor_name($name);
730     # Walrus add (3) end
731 wakaba 1.25 if ($chunk =~ /^(http|https|ftp|news):/) {
732 wakaba 1.16 # Walrus mod (3) start
733     # if ($use_autoimg and $chunk =~ /\.(gif|png|jpeg|jpg)$/) {
734     # return qq(<a href="$chunk"><img src="$chunk"></a>);
735     # } else {
736     # return qq(<a href="$chunk">$chunk</a>);
737     # }
738 wakaba 1.21 return qq(&lt;<a href="$chunk">$name</a>&gt;);
739 wakaba 1.16 # Walrus mod (3) end
740 wakaba 1.18 } elsif ($chunk =~ m#^urn:[0-9A-Za-z_:;/.-]+#) {
741     return qq|&lt;<a href="/uri-res/N2L?${name}">$name</a>&gt;|;
742     } elsif ($chunk =~ /^mailto:(.*)/) {
743 wakaba 1.16 # return qq(<a href="$chunk">$2</a>); # Walrus del (3)
744 wakaba 1.18 return qq(&lt;<a href="$chunk">$name</a>&gt;); # Walrus add (3)
745 wakaba 1.16 } elsif ($chunk =~ /^$interwiki_definition$/) {
746     # return qq(<span class="InterWiki">$chunk</span>); # Walrus del (3)
747     return qq(<span class="InterWiki">$name</span>); # Walrus add (3)
748     } elsif ($chunk =~ /^$embedded_name$/) {
749     return &embedded_to_html($chunk);
750     } else {
751     $chunk = &unarmor_name($chunk);
752     $chunk = &unescape($chunk); # To treat '&' or '>' or '<' correctly.
753     my $cookedchunk = &encode($chunk);
754     if ($chunk =~ /^$interwiki_name$/) {
755     my ($intername, $localname) = ($1, $2);
756     my $remoteurl = $interwiki{$intername};
757     if ($remoteurl) {
758     # $remoteurl =~ s/\b(euc|sjis|ykwk|asis)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus del (4)
759     $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $localname)/e; # Walrus add (4)
760     # return qq(<a href="$remoteurl">$chunk</a>); # Walrus del (3)
761 wakaba 1.24 return qq(<a href="$remoteurl">@{[&escape($name)]}</a>); # Walrus add (3)
762 wakaba 1.16 } else {
763     # return $chunk; # Walrus del (3)
764 wakaba 1.24 return &escape($name); # Walrus add (3)
765 wakaba 1.16 }
766     } elsif ($database{$chunk}) {
767     my $subject = &escape(&get_subjectline($chunk, delimiter => ''));
768     # return qq(<a title="$subject" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3)
769 wakaba 1.26 return qq(<a title="$subject" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3)
770 wakaba 1.16 } elsif ($page_command{$chunk}) {
771     # return qq(<a title="$chunk" href="$url_cgi?$cookedchunk">$chunk</a>); # Walrus del (3)
772 wakaba 1.24 return qq(<a title="$chunk" href="$url_cgi?$cookedchunk" class="wiki">@{[&escape($name)]}</a>); # Walrus add (3)
773 wakaba 1.16 } else {
774 wakaba 1.24 return qq(<a title="$resource{editthispage}" href="$url_cgi?mycmd=edit;mypage=$cookedchunk" class="wiki">@{[&escape($name)]}<span class="mark">$editchar</span></a>);
775 wakaba 1.9 }
776     }
777     }
778    
779 wakaba 1.16 sub print_message {
780     my ($msg) = @_;
781     print qq(<p><strong>$msg</strong></p>);
782 wakaba 1.9 }
783    
784 wakaba 1.22 sub get_message {
785     my ($msg) = @_;
786     qq(<p><strong>$msg</strong></p>);
787     }
788    
789 wakaba 1.16 sub init_form {
790     if (param()) {
791     foreach my $var (param()) {
792     $form{$var} = param($var);
793     }
794     } else {
795     $ENV{QUERY_STRING} = $FrontPage;
796     }
797    
798     my $query = &decode($ENV{QUERY_STRING});
799     if ($page_command{$query}) {
800     $form{mycmd} = $page_command{$query};
801     $form{mypage} = $query;
802     } elsif ($query =~ /^($wiki_name)$/) {
803     $form{mycmd} = 'read';
804     $form{mypage} = $1;
805     } elsif ($database{$query}) {
806     $form{mycmd} = 'read';
807     $form{mypage} = $query;
808     }
809    
810     # mypreview_edit -> do_edit, with preview.
811     # mypreview_adminedit -> do_adminedit, with preview.
812     # mypreview_write -> do_write, without preview.
813     foreach (keys %form) {
814     if (/^mypreview_(.*)$/) {
815     $form{mycmd} = $1;
816     $form{mypreview} = 1;
817     }
818     }
819 wakaba 1.9
820 wakaba 1.16 #
821     # $form{mycmd} is frozen here.
822     #
823    
824     $form{mymsg} = &code_convert(\$form{mymsg}, $kanjicode);
825     $form{myname} = &code_convert(\$form{myname}, $kanjicode);
826     }
827    
828     sub update_recent_changes {
829     my $update = "- @{[&get_now]} @{[&armor_name($form{mypage})]} @{[&get_subjectline($form{mypage})]}";
830     my @oldupdates = split(/\r?\n/, $database{$RecentChanges});
831     my @updates;
832     foreach (@oldupdates) {
833     /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format.
834     my $name = &unarmor_name($1);
835     if (&is_exist_page($name) and ($name ne $form{mypage})) {
836     push(@updates, $_);
837     }
838     }
839     if (&is_exist_page($form{mypage})) {
840     unshift(@updates, $update);
841     }
842     splice(@updates, $maxrecent + 1);
843     $database{$RecentChanges} = join("\n", @updates);
844     if ($file_touch) {
845     open(FILE, "> $file_touch");
846     print FILE localtime() . "\n";
847     close(FILE);
848     }
849 wakaba 1.9 }
850    
851 wakaba 1.16 sub get_subjectline {
852     my ($page, %option) = @_;
853     if (not &is_editable($page)) {
854     return "";
855     } else {
856     # Delimiter check.
857     my $delim = $subject_delimiter;
858     if (defined($option{delimiter})) {
859     $delim = $option{delimiter};
860     }
861 wakaba 1.9
862 wakaba 1.16 # Get the subject of the page.
863     my $subject = $database{$page};
864 wakaba 1.25 $subject =~ s#^SuikaWiki/0.9[^\x0D\x0A]*[\x0D\x0A]+##s;
865 wakaba 1.16 $subject =~ s/\r?\n.*//s;
866     return "$delim$subject";
867     }
868 wakaba 1.9 }
869    
870 wakaba 1.16 sub send_mail_to_admin {
871     my ($page, $mode) = @_;
872     return unless $modifier_sendmail;
873     my $message = <<"EOD";
874     To: $modifier_mail
875     From: $modifier_mail
876     Subject: [Wiki]
877     MIME-Version: 1.0
878     Content-Type: text/plain; charset=ISO-2022-JP
879     Content-Transfer-Encoding: 7bit
880    
881     --------
882     MODE = $mode
883     REMOTE_ADDR = $ENV{REMOTE_ADDR}
884     REMOTE_HOST = $ENV{REMOTE_HOST}
885     --------
886     $page
887     --------
888     $database{$page}
889     --------
890     EOD
891     &code_convert(\$message, 'jis');
892     open(MAIL, "| $modifier_sendmail");
893     print MAIL $message;
894     close(MAIL);
895 wakaba 1.9 }
896    
897 wakaba 1.16 sub open_db {
898     if ($modifier_dbtype eq 'dbmopen') {
899     dbmopen(%database, $dataname, 0666) or &print_error("(dbmopen) $dataname");
900     dbmopen(%infobase, $infoname, 0666) or &print_error("(dbmopen) $infoname");
901     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
902     tie(%database, "AnyDBM_File", $dataname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $dataname");
903     tie(%infobase, "AnyDBM_File", $infoname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $infoname");
904     } else {
905     tie(%database, "Yuki::YukiWikiDB", $dataname) or &print_error("(tie Yuki::YukiWikiDB) $dataname");
906     tie(%infobase, "Yuki::YukiWikiDB", $infoname) or &print_error("(tie Yuki::YukiWikiDB) $infoname");
907 wakaba 1.9 }
908     }
909    
910 wakaba 1.16 sub close_db {
911     if ($modifier_dbtype eq 'dbmopen') {
912     dbmclose(%database);
913     dbmclose(%infobase);
914     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
915     untie(%database);
916     untie(%infobase);
917     } else {
918     untie(%database);
919     untie(%infobase);
920     }
921     }
922 wakaba 1.9
923 wakaba 1.16 sub open_diff {
924     if ($modifier_dbtype eq 'dbmopen') {
925     dbmopen(%diffbase, $diffname, 0666) or &print_error("(dbmopen) $diffname");
926     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
927     tie(%diffbase, "AnyDBM_File", $diffname, O_RDWR|O_CREAT, 0666) or &print_error("(tie AnyDBM_File) $diffname");
928     } else {
929     tie(%diffbase, "Yuki::YukiWikiDB", $diffname) or &print_error("(tie Yuki::YukiWikiDB) $diffname");
930     }
931     }
932 wakaba 1.9
933 wakaba 1.16 sub close_diff {
934     if ($modifier_dbtype eq 'dbmopen') {
935     dbmclose(%diffbase);
936     } elsif ($modifier_dbtype eq 'AnyDBM_File') {
937     untie(%diffbase);
938     } else {
939     untie(%diffbase);
940     }
941 wakaba 1.9 }
942    
943 wakaba 1.16 sub print_searchform {
944     my ($word) = @_;
945     print <<"EOD";
946     <form action="$url_cgi" method="get">
947     <input type="hidden" name="mycmd" value="search">
948     <input type="text" name="mymsg" value="$word" size="20">
949     <input type="submit" value="$resource{searchbutton}">
950     </form>
951     EOD
952 wakaba 1.9 }
953    
954 wakaba 1.16 sub print_editform {
955     my ($mymsg, $lastmodified, %mode) = @_;
956     my $frozen = &is_frozen($form{mypage});
957    
958     if ($form{mypreview}) {
959     if ($form{mymsg}) {
960     unless ($mode{conflict}) {
961     print qq(<h3>$resource{previewtitle}</h3>\n);
962     print qq($resource{previewnotice}\n);
963     print qq(<div class="preview">\n);
964     &print_content($form{mymsg});
965     print qq(</div>\n);
966     }
967     } else {
968     print qq($resource{previewempty});
969     }
970     $mymsg = &escape($form{mymsg});
971 wakaba 1.9 } else {
972 wakaba 1.25 $mymsg = &escape($mymsg || $database{NewPageTemplate});
973 wakaba 1.9 }
974    
975 wakaba 1.16 my $edit = $mode{admin} ? 'adminedit' : 'edit';
976 wakaba 1.24 my $escapedmypage = &escape($form{mypage});
977     my $escapedmypassword = &escape($form{mypassword});
978 wakaba 1.16
979     print <<"EOD";
980     <form action="$url_cgi" method="post">
981 wakaba 1.24 @{[ $mode{admin} ? qq($resource{frozenpassword} <input type="password" name="mypassword" value="$escapedmypassword" size="10"><br>) : "" ]}
982 wakaba 1.16 <input type="hidden" name="myLastModified" value="$lastmodified">
983 wakaba 1.24 <input type="hidden" name="mypage" value="$escapedmypage">
984 wakaba 1.25 <textarea cols="$cols" rows="$rows" name="mymsg" tabindex="1">$mymsg</textarea><br>
985 wakaba 1.16 @{[
986     $mode{admin} ?
987     qq(
988     <input type="radio" name="myfrozen" value="1" @{[$frozen ? qq(checked="checked") : ""]}>$resource{frozenbutton}
989     <input type="radio" name="myfrozen" value="0" @{[$frozen ? "" : qq(checked="checked")]}>$resource{notfrozenbutton}<br>)
990     : ""
991     ]}
992     @{[
993     $mode{conflict} ? "" :
994     qq(
995     <input type="checkbox" name="mytouch" value="on" checked="checked">$resource{touch}<br>
996     <input type="submit" name="mypreview_$edit" value="$resource{previewbutton}">
997 wakaba 1.22 <input type="submit" name="mypreview_write" value="$resource{savebutton}" accesskey="S"><kbd>S</kbd><br>
998 wakaba 1.16 )
999     ]}
1000     </form>
1001     EOD
1002     unless ($mode{conflict}) {
1003     # Show the format rule.
1004     open(FILE, $file_format) or &print_error("($file_format)");
1005     my $content = join('', <FILE>);
1006     &code_convert(\$content, $kanjicode);
1007 wakaba 1.9 close(FILE);
1008 wakaba 1.16 print &text_to_html($content, toc=>0);
1009 wakaba 1.9 }
1010     }
1011    
1012 wakaba 1.16 sub print_passwordform {
1013     print <<"EOD";
1014     <form action="$url_cgi" method="post">
1015     <input type="hidden" name="mycmd" value="adminchangepassword">
1016     $resource{oldpassword} <input type="password" name="myoldpassword" size="10"><br>
1017     $resource{newpassword} <input type="password" name="mynewpassword" size="10"><br>
1018     $resource{newpassword2} <input type="password" name="mynewpassword2" size="10"><br>
1019     <input type="submit" value="$resource{changepasswordbutton}"><br>
1020     </form>
1021     EOD
1022 wakaba 1.9 }
1023    
1024 wakaba 1.16 sub is_editable {
1025     my ($page) = @_;
1026     if (&is_bracket_name($page)) {
1027     return 0;
1028     } elsif ($fixedpage{$page}) {
1029     return 0;
1030     } elsif ($page =~ /\s/) {
1031     return 0;
1032     } elsif ($page =~ /^\#/) {
1033     return 0;
1034     } elsif ($page =~ /^$interwiki_name$/) {
1035     return 0;
1036     } else {
1037     return 1;
1038     }
1039 wakaba 1.9 }
1040    
1041 wakaba 1.16 # armor_name:
1042     # WikiName -> WikiName
1043     # not_wiki_name -> [[not_wiki_name]]
1044     sub armor_name {
1045     my ($name) = @_;
1046 wakaba 1.25 #if ($name =~ /^$wiki_name$/) {
1047     # return $name;
1048     #} else {
1049 wakaba 1.16 return "[[$name]]";
1050 wakaba 1.25 #}
1051 wakaba 1.9 }
1052    
1053 wakaba 1.16 # unarmor_name:
1054     # [[bracket_name]] -> bracket_name
1055     # WikiName -> WikiName
1056     sub unarmor_name {
1057     my ($name) = @_;
1058     if ($name =~ /^$bracket_name$/) {
1059     return $1;
1060     } else {
1061     return $name;
1062     }
1063 wakaba 1.9 }
1064    
1065 wakaba 1.16 sub is_bracket_name {
1066     my ($name) = @_;
1067     if ($name =~ /^$bracket_name$/) {
1068     return 1;
1069     } else {
1070     return 0;
1071 wakaba 1.9 }
1072     }
1073    
1074 wakaba 1.16 sub decode {
1075     my ($s) = @_;
1076     $s =~ tr/+/ /;
1077     $s =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg;
1078     return $s;
1079     }
1080 wakaba 1.9
1081 wakaba 1.16 sub encode {
1082     my ($s) = @_;
1083     my $encoded = '';
1084     foreach my $ch (split(//, $s)) {
1085     if ($ch =~ /[A-Za-z0-9_]/) {
1086     $encoded .= $ch;
1087     } else {
1088     $encoded .= '%' . sprintf("%02X", ord($ch));
1089     }
1090     }
1091     return $encoded;
1092     }
1093 wakaba 1.9
1094 wakaba 1.16 sub init_resource {
1095     open(FILE, $file_resource) or &print_error("(resource)");
1096     while (<FILE>) {
1097     chomp;
1098     next if /^#/;
1099     my ($key, $value) = split(/=/, $_, 2);
1100     $resource{$key} = &code_convert(\$value, $kanjicode);
1101     }
1102     close(FILE);
1103     }
1104 wakaba 1.9
1105 wakaba 1.16 sub conflict {
1106     my ($page, $rawmsg) = @_;
1107     if ($form{myLastModified} eq &get_info($page, $info_LastModified)) {
1108     return 0;
1109     }
1110     open(FILE, $file_conflict) or &print_error("(conflict)");
1111     my $content = join('', <FILE>);
1112     &code_convert(\$content, $kanjicode);
1113     close(FILE);
1114     &print_header($page);
1115     &print_content($content);
1116     &print_editform($rawmsg, $form{myLastModified}, frozen=>0, conflict=>1);
1117     &print_footer($page);
1118     return 1;
1119     }
1120    
1121     sub get_now {
1122     my (@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
1123     my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time);
1124     $year += 1900;
1125     $mon++;
1126     $mon = "0$mon" if $mon < 10;
1127     $day = "0$day" if $day < 10;
1128     $hour = "0$hour" if $hour < 10;
1129     $min = "0$min" if $min < 10;
1130     $sec = "0$sec" if $sec < 10;
1131     $weekday = $week[$weekday];
1132     return "$year-$mon-$day ($weekday) $hour:$min:$sec";
1133     }
1134    
1135     # [[YukiWiki http://www.hyuki.com/yukiwiki/wiki.cgi?euc($1)]]
1136     sub init_InterWikiName {
1137     my $content = $database{$InterWikiName};
1138     while ($content =~ /\[\[(\S+) +(\S+)\]\]/g) {
1139     my ($name, $url) = ($1, $2);
1140     $interwiki{$name} = $url;
1141     }
1142     }
1143 wakaba 1.9
1144 wakaba 1.16 sub interwiki_convert {
1145     my ($type, $localname) = @_;
1146     if ($type eq 'sjis' or $type eq 'euc') {
1147     &code_convert(\$localname, $type);
1148     return &encode($localname);
1149     } elsif ($type eq 'ykwk') {
1150     # for YukiWiki1
1151     if ($localname =~ /^$wiki_name$/) {
1152     return $localname;
1153     } else {
1154     &code_convert(\$localname, 'sjis');
1155     return &encode("[[" . $localname . "]]");
1156     }
1157     } elsif ($type eq 'asis') {
1158     return $localname;
1159     # Walrus add (4) start
1160     } elsif ($type eq 'isbn') {
1161     $localname = join('', ($localname =~ /[0-9x]/g)) if ($localname =~ /^(\d-?){9}[\dx]$/);
1162     return $localname;
1163     # Walrus add (4) end
1164     } else {
1165     return $localname;
1166     }
1167     }
1168 wakaba 1.9
1169 wakaba 1.16 sub get_info {
1170     my ($page, $key) = @_;
1171     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1172     return $info{$key};
1173     }
1174 wakaba 1.9
1175 wakaba 1.16 sub set_info {
1176     my ($page, $key, $value) = @_;
1177     my %info = map { split(/=/, $_, 2) } split(/\n/, $infobase{$page});
1178     $info{$key} = $value;
1179     my $s = '';
1180     for (keys %info) {
1181     $s .= "$_=$info{$_}\n";
1182     }
1183     $infobase{$page} = $s;
1184     }
1185 wakaba 1.9
1186 wakaba 1.16 sub frozen_reject {
1187     my ($isfrozen) = &get_info($form{mypage}, $info_IsFrozen);
1188     my ($willbefrozen) = $form{myfrozen};
1189     if (not $isfrozen and not $willbefrozen) {
1190     # You need no check.
1191     return 0;
1192     } elsif (valid_password($form{mypassword})) {
1193     # You are admin.
1194     return 0;
1195     } else {
1196     &print_error($resource{passworderror});
1197     return 1;
1198     }
1199     }
1200 wakaba 1.9
1201 wakaba 1.16 sub valid_password {
1202     my ($givenpassword) = @_;
1203     my ($validpassword_crypt) = &get_info($AdminSpecialPage, $info_AdminPassword);
1204     if (crypt($givenpassword, $validpassword_crypt) eq $validpassword_crypt) {
1205     return 1;
1206     } else {
1207     return 0;
1208     }
1209     }
1210 wakaba 1.9
1211 wakaba 1.16 sub is_frozen {
1212     my ($page) = @_;
1213     if (&get_info($page, $info_IsFrozen)) {
1214     return 1;
1215     } else {
1216     return 0;
1217     }
1218     }
1219 wakaba 1.9
1220 wakaba 1.16 sub do_comment {
1221     my ($content) = $database{$form{mypage}};
1222     my $datestr = &get_now;
1223 wakaba 1.25 my $namestr = " ''[[@{[$form{myname}||$DEFAULT_embed_comment_name]}]]'' : ";
1224     #if ($content =~ s/(\Q$embed_comment\E)/- $datestr$namestr$form{mymsg}\n$1/) {
1225     # ;
1226     #} else {
1227     # $content =~ s/(\Q$embed_rcomment\E)/$1\n- $datestr$namestr$form{mymsg}/;
1228     #}
1229     my $i = 0; my $o = 0;
1230     $content =~ s{(\Q$embed_comment\E|\Q$embed_rcomment\E)}{
1231     my $embed = $1;
1232     if ($i == $form{comment_index}) {
1233     if ($embed eq $embed_comment) {
1234     $embed = "- $datestr$namestr$form{mymsg}\n$embed"; $o = 1;
1235     } else {
1236     $embed .= "\n- $datestr$namestr$form{mymsg}"; $o = 1;
1237     }
1238     }
1239     $i++; $embed;
1240     }ge;
1241     unless ($o) {
1242     $content .= "- $datestr$namestr$form{mymsg}\n";
1243 wakaba 1.16 }
1244     if ($form{mymsg}) {
1245     $form{mymsg} = $content;
1246     $form{mytouch} = 'on';
1247     &do_write;
1248     } else {
1249     $form{mycmd} = 'read';
1250     &do_read;
1251     }
1252     }
1253 wakaba 1.9
1254 wakaba 1.25 my $_O_COMMENT_INDEX = 0;
1255 wakaba 1.16 sub embedded_to_html {
1256     my ($embedded) = @_;
1257     if ($embedded eq $embed_comment or $embedded eq $embed_rcomment) {
1258     my $lastmodified = &get_info($form{mypage}, $info_LastModified);
1259     return <<"EOD";
1260     <form action="$url_cgi" method="post">
1261     <input type="hidden" name="mycmd" value="comment">
1262     <input type="hidden" name="mypage" value="$form{mypage}">
1263     <input type="hidden" name="myLastModified" value="$lastmodified">
1264     <input type="hidden" name="mytouch" value="on">
1265 wakaba 1.25 <input type="hidden" name="comment_index" value="@{[$_O_COMMENT_INDEX++]}">
1266     $embed_comment_Name_Prompt
1267 wakaba 1.16 <input type="text" name="myname" value="" size="10">
1268 wakaba 1.26 <input type="text" name="mymsg" value="" size="60">
1269 wakaba 1.16 <input type="submit" value="$resource{commentbutton}">
1270     </form>
1271     EOD
1272 wakaba 1.22 } elsif ($embedded =~ /$embed_command{searched}/) {
1273     return get_search_result ($1);
1274 wakaba 1.16 # Walrus add (5) start
1275     } elsif ($embedded =~ /$embed_interwiki/ and my $remoteurl = $interwiki{$2}) {
1276     $_ = &make_interwiki_box($1, $2);
1277     return ($_) ? $_ : $embedded;
1278     # Walrus add (5) end
1279     } else {
1280     return $embedded;
1281     }
1282     }
1283 wakaba 1.9
1284 wakaba 1.16 # Walrus add (5) start
1285     sub do_interwiki_box {
1286     my $remoteurl = $interwiki{$form{'myintername'}};
1287     if ($remoteurl) {
1288     $remoteurl =~ s/\b(euc|sjis|ykwk|asis|isbn)\(\$1\)/&interwiki_convert($1, $form{'mylocalname'})/e;
1289     print "Location: $remoteurl\n\n";
1290     exit(1);
1291     } else {
1292     &do_read;
1293     }
1294     }
1295     # Walrus add (5) end
1296 wakaba 1.9
1297 wakaba 1.16 # Walrus add (5) start
1298     sub make_interwiki_box {
1299     my ($localname, $intername) = @_;
1300     my %ignoretype = (
1301     'box' => 'text',
1302     'text' => 'text',
1303     'pass' => 'password',
1304     'password' => 'password'
1305     );
1306     my $converted = ($ignoretype{$localname}) ? <<EOD : undef;
1307     <form action="$url_cgi" method="post">
1308     <input type="hidden" name="mycmd" value="interwikibox">
1309     <input type="hidden" name="mypage" value="$form{mypage}">
1310     <input type="hidden" name="myintername" value="$intername">
1311     $intername:
1312     <input type="$ignoretype{$localname}" name="mylocalname" value="" size="10">
1313     <input type="submit" value="Submit">
1314     </form>
1315     EOD
1316     }
1317     # Walrus add (5) end
1318 wakaba 1.9
1319 wakaba 1.16 sub code_convert {
1320     my ($contentref, $kanjicode) = @_;
1321     # &Jcode::convert($contentref, $kanjicode); # for Jcode.pm
1322     &jcode::convert($contentref, $kanjicode); # for jcode.pl
1323     return $$contentref;
1324     }
1325    
1326     sub test_convert {
1327     my $txt = &text_to_html(<<"EOD", toc=>1);
1328     *HEADER1
1329     **HEADER1-1
1330     -ITEM1
1331     -ITEM2
1332     -ITEM3
1333     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1334     PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1335     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1336    
1337     PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1338     PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1339     PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1340     **HEADER1-2
1341     :TERM1:DESCRIPTION1 AND ''BOLD''
1342     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1343     PAR1PAR1PAR1PAR1PAR1PAR1''BOLD''PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1344     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1345     :TERM2:DESCRIPTION2
1346     :TERM3:DESCRIPTION3
1347     ----
1348     *HEADER2
1349     **HEADER2-1
1350     http://www.hyuki.com/
1351     **HEADER2-2
1352 wakaba 1.9
1353 wakaba 1.16 [[YukiWiki2]]
1354 wakaba 1.9
1355 wakaba 1.16 PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1356     PAR1PAR1PAR1PAR1PAR1PAR1'''''BOLD ITALIC'''''PAR1PAR1PAR1PAR1PAR1
1357     PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1PAR1
1358     >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1359     >PAR2PAR2PAR2PAR2PAR2PAR2'''ITALIC'''PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1360     >PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2PAR2
1361    
1362     LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0LEVEL0
1363    
1364     >LEVEL1
1365     >LEVEL1
1366     >LEVEL1
1367     >>LEVEL2
1368     >>LEVEL2
1369     >>LEVEL2
1370     >>>LEVEL3
1371     -HELLO-1
1372     --HELLO-2
1373     (HELLO-2, HELLO-2, HELLO-2)
1374     ---HELLO-3
1375     (HELLO-3, HELLO-3, HELLO-3)
1376     --HELLO-2
1377     ---HELLO-3
1378     --HELLO-2
1379     ---HELLO-3
1380     >>>LEVEL3
1381     >>>LEVEL3
1382     >>>LEVEL3
1383     >>>LEVEL3
1384     EOD
1385     print $txt;
1386     exit;
1387     }
1388 wakaba 1.9
1389 wakaba 1.16 sub do_diff {
1390     if (not &is_editable($form{mypage})) {
1391     &do_read;
1392     return;
1393     }
1394     &open_diff;
1395     my $title = $form{mypage};
1396     &print_header($title);
1397     $_ = &escape($diffbase{$form{mypage}});
1398     &close_diff;
1399     print qq(<h3>$resource{difftitle}</h3>);
1400     print qq($resource{diffnotice});
1401     print qq(<pre class="diff">);
1402     foreach (split(/\n/, $_)) {
1403     if (/^\+(.*)/) {
1404     print qq(<b class="added">$1</b>\n);
1405     } elsif (/^\-(.*)/) {
1406     print qq(<s class="deleted">$1</s>\n);
1407     } elsif (/^\=(.*)/) {
1408     print qq(<span class="same">$1</span>\n);
1409     } else {
1410     print qq|??? $_\n|;
1411     }
1412     }
1413     print qq(</pre>);
1414     print qq(<hr>);
1415     &print_footer($title);
1416     }
1417 wakaba 1.9
1418 wakaba 1.16 sub do_rss {
1419     my $rss = new Yuki::RSS(
1420     version => '1.0',
1421     encoding => $charset,
1422     );
1423     $rss->channel(
1424     title => $modifier_rss_title,
1425     link => $modifier_rss_link,
1426     description => $modifier_rss_description,
1427     );
1428     my $recentchanges = $database{$RecentChanges};
1429     my $count = 0;
1430     foreach (split(/\n/, $recentchanges)) {
1431     last if ($count >= 15);
1432     /^\- \d\d\d\d\-\d\d\-\d\d \(...\) \d\d:\d\d:\d\d (\S+)/; # date format.
1433     my $title = &unarmor_name($1);
1434     my $escaped_title = &escape($title);
1435     my $link = $modifier_rss_link . '?' . &encode($title);
1436     my $description = $escaped_title . &escape(&get_subjectline($title));
1437     $rss->add_item(
1438     title => $escaped_title,
1439     link => $link,
1440     description => $description,
1441     );
1442     $count++;
1443     }
1444     # print RSS information (as XML).
1445     print <<"EOD"
1446     Content-type: text/xml
1447 wakaba 1.9
1448 wakaba 1.16 @{[$rss->as_string]}
1449     EOD
1450     }
1451 wakaba 1.9
1452 wakaba 1.16 sub is_exist_page {
1453     my ($name) = @_;
1454     if ($use_exists) {
1455     return exists($database{$name});
1456     } else {
1457     return $database{$name};
1458     }
1459     }
1460 wakaba 1.9
1461 wakaba 1.16 1;
1462     __END__
1463     =head1 NAME
1464 wakaba 1.9
1465 wakaba 1.16 wiki.cgi - This is YukiWiki, yet another Wiki clone.
1466 wakaba 1.9
1467 wakaba 1.16 =head1 DESCRIPTION
1468 wakaba 1.9
1469 wakaba 1.16 YukiWiki is yet another Wiki clone.
1470 wakaba 1.9
1471 wakaba 1.16 YukiWiki can treat Japanese WikiNames (enclosed with [[ and ]]).
1472     YukiWiki provides 'InterWiki' feature, RDF Site Summary (RSS),
1473     and some embedded commands (such as [[#comment]] to add comments).
1474 wakaba 1.9
1475 wakaba 1.16 Read F<readme_en.txt> (English) or F<readme_ja.txt> (Japanese) in more detail.
1476 wakaba 1.9
1477 wakaba 1.16 =head1 AUTHOR
1478 wakaba 1.9
1479 wakaba 1.16 Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/yukiwiki/
1480 wakaba 1.9
1481 wakaba 1.16 =head1 LICENSE
1482 wakaba 1.9
1483 wakaba 1.16 Copyright (C) 2000-2002 by Hiroshi Yuki.
1484 wakaba 1.9
1485 wakaba 1.16 This program is free software; you can redistribute it and/or
1486     modify it under the same terms as Perl itself.
1487 wakaba 1.9
1488     =cut

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24