OSDN Git Service

(no commit message)
[fswiki/sandbox.git] / kgsoft / plugin / core.pm
1 ##########################################################################################
2 #
3 # ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼¥×¥é¥°¥¤¥ó¡Ê³Ø½¬µ¡Ç½Ìµ¤·ÈÇ¡Ë
4 #¡Êcore::EditPage¥×¥é¥°¥¤¥ó¡Ê¥Ú¡¼¥¸¤ÎÊÔ½¸¡Ë¤Î¥ª¡¼¥Ð¡¼¥é¥¤¥É¡Ë
5 #
6 ##########################################################################################
7 use strict;
8
9 use plugin::core::EditPage;
10
11 # plugin::core::EditPage¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
12 package plugin::core::EditPage;
13
14 sub do_action {
15         my $self = shift;
16         my $wiki = shift;
17         my $cgi = $wiki->get_CGI;
18         
19         my $pagename = $cgi->param("page");
20         my $format   = $wiki->get_edit_format();
21         my $content  = $cgi->param("content");
22         my $sage     = $cgi->param("sage");
23         my $template = $cgi->param("template");
24         my $artno    = $cgi->param("artno");
25         my $time     = $wiki->get_last_modified($pagename);
26         
27         my $buf = "";
28         my $login = $wiki->get_login_info();
29
30         if($pagename eq ""){
31                 return $wiki->error("¥Ú¡¼¥¸¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
32         }
33         if($pagename =~ /([\|\[\]])|^:|([^:]:[^:])/){
34                 return $wiki->error("¥Ú¡¼¥¸Ì¾¤Ë»ÈÍѤǤ­¤Ê¤¤Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£");
35         }
36         if(!$wiki->can_modify_page($pagename)){
37                 return $wiki->error("¥Ú¡¼¥¸¤ÎÊÔ½¸¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
38         }
39         
40         #--------------------------------------------------------------------------
41         # Êݸ½èÍý
42         if($cgi->param("save") ne ""){
43                 if($wiki->page_exists($pagename)){
44                         if($cgi->param("lastmodified") < $time){
45                                 return $wiki->error("¥Ú¡¼¥¸¤Ï´û¤ËÊ̤Υ桼¥¶¤Ë¤è¤Ã¤Æ¹¹¿·¤µ¤ì¤Æ¤¤¤Þ¤¹¡£");
46                         }
47                 }
48
49 #--------------------------------------------------------------------------------------------------
50   if($content){
51     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($content)){
52       my $time = Util::format_date(time());
53       my $file = $wiki->config('log_dir')."/spam_page.txt";
54       if(open(SPAM_LOG, ">>$file")){
55         print SPAM_LOG "-" x 70 . "\n";
56         print SPAM_LOG "$pagename:$artno ($time)\n";
57         print SPAM_LOG "-" x 70 . "\n";
58         print SPAM_LOG "$content\n";
59         close(SPAM_LOG);
60       }
61       my $error_message = $wiki->error("ÊÔ½¸¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥àʸ¾Ï¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
62       $content = Util::escapeHTML($content);
63       $content =~ s/\n/<br>/g;
64       $error_message .= "<p>\n";
65       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
66       $error_message .= "<div>¡ã¥Ú¡¼¥¸Ì¾¡ä</div>\n";
67       $error_message .= "<div>$pagename</div>\n";
68       $error_message .= "<div>¡ãËÜʸ¡ä</div>\n";
69       $error_message .= "<div>$content</div>\n";
70       $error_message .= "</p>\n";
71       return $error_message;
72     }
73   }
74 #--------------------------------------------------------------------------------------------------
75 \r
76                 #my $save_content = $content;
77                 my $mode = $wiki->get_edit_format();
78                 my $save_content = $wiki->convert_to_fswiki($content,$mode);
79
80                 # ¥Ñ¡¼¥ÈÊÔ½¸¤Î¾ì¹ç
81                 if($artno ne ""){
82                         $save_content = &make_save_source($wiki->get_page($pagename),$save_content,$artno,$wiki);
83                 }
84                 # FrontPage¤Ïºï½üÉÔ²Ä
85                 if($pagename eq $wiki->config("frontpage") && $save_content eq ""){
86                         $buf = "<b>".&Util::escapeHTML($wiki->config("frontpage"))."¤Ïºï½ü¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£</b>\n";
87
88                 # ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï½èÍý¤ò¼Â¹Ô¤·¤Æ¥á¥Ã¥»¡¼¥¸¤òÊÖµÑ
89                 } else {
90                         $wiki->save_page($pagename,$save_content,$sage);
91                         
92                         if($content ne ""){
93                                 $wiki->redirect($pagename);
94                         } else {
95                                 if($artno eq ""){
96                                         $wiki->set_title($pagename."¤òºï½ü¤·¤Þ¤·¤¿");
97                                         return $cgi->escapeHTML($pagename)."¤òºï½ü¤·¤Þ¤·¤¿¡£";
98                                 } else {
99                                         $wiki->set_title($pagename."¤Î¥Ñ¡¼¥È¤òºï½ü¤·¤Þ¤·¤¿");
100                                         return $cgi->escapeHTML($pagename)."¤Î¥Ñ¡¼¥È¤òºï½ü¤·¤Þ¤·¤¿¡£";
101                                 }
102                         }
103                 }
104         #--------------------------------------------------------------------------
105         # ¥×¥ì¥Ó¥å¡¼½èÍý
106         } elsif($cgi->param("preview") ne ""){
107                 $time = $cgi->param("lastmodified");
108                 $buf = "°Ê²¼¤Î¥×¥ì¥Ó¥å¡¼¤ò³Îǧ¤·¤Æ¤è¤í¤·¤±¤ì¤Ð¡ÖÊݸ¡×¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£<br>";
109                 if($content eq ""){
110                         if($pagename eq $wiki->config("frontpage") && $artno eq ""){
111                                 $buf = $buf."<b>¡Ê".&Util::escapeHTML($wiki->config("frontpage"))."¤Ïºï½ü¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£¡Ë</b>";
112                         } else {
113                                 if($artno eq ""){
114                                         $buf = $buf."<b>¡Ê¥Ú¡¼¥¸ÆâÍƤ϶õ¤Ç¤¹¡£¹¹¿·¤¹¤ë¤È¤³¤Î¥Ú¡¼¥¸¤Ïºï½ü¤µ¤ì¤Þ¤¹¡£¡Ë</b>";
115                                 } else {
116                                         $buf = $buf."<b>¡Ê¥Ú¡¼¥¸ÆâÍƤ϶õ¤Ç¤¹¡£¹¹¿·¤¹¤ë¤È¤³¤Î¥Ñ¡¼¥È¤Ïºï½ü¤µ¤ì¤Þ¤¹¡£¡Ë</b>";
117                                 }
118                         }
119                 }
120                 $content = $wiki->convert_to_fswiki($content,$format);
121                 $buf = $buf."<br>".$wiki->process_wiki($content);
122
123         } elsif($wiki->page_exists($pagename)) {
124                 #¥Ú¡¼¥¸¤¬Â¸ºß¤¹¤ë¾ì¹ç
125                 if($artno eq ""){
126                         $content = $wiki->get_page($pagename);
127                 } else {
128                         $content = &read_by_part($wiki->get_page($pagename),$artno);
129                 }
130         } elsif($template ne ""){
131                 #¥Æ¥ó¥×¥ì¡¼¥È¤ò»ØÄꤵ¤ì¤¿¾ì¹ç
132                 $content = $wiki->get_page($template);
133         }
134         
135         #--------------------------------------------------------------------------
136         # ÆþÎÏ¥Õ¥©¡¼¥à
137         $wiki->set_title($pagename."¤ÎÊÔ½¸",1);
138
139         my $tmpl = HTML::Template->new(filename=>$wiki->config('tmpl_dir')."/editform.tmpl",
140                                    die_on_bad_params => 0);
141
142         $tmpl->param({SCRIPT_NAME   => $wiki->config('script_name'),
143                                   PAGE_NAME     => $pagename,
144                                   CONTENT       => $wiki->convert_from_fswiki($content,$format),
145                                   LAST_MODIFIED => $time,
146                                   ACTION        => 'EDIT',
147                                   EXISTS_PAGE   => $wiki->page_exists($pagename),
148                                   SAGE          => $sage});
149         
150         if($artno ne ""){
151                 $tmpl->param(OPTIONAL_PARAMS=>[{NAME=>'artno',VALUE=>$artno}]);
152         }
153
154         $buf .= $tmpl->output();
155
156         # ¥×¥é¥°¥¤¥ó¤òÁÞÆþ
157         $buf .= $wiki->get_editform_plugin();
158         
159         return $buf;
160 }
161
162 1;