OSDN Git Service

htmlsc(): Just sugar for htmlspecialchars(), and a foundation
[pukiwiki/pukiwiki.git] / lib / pukiwiki.php
index dd58294..b4c4e16 100644 (file)
@@ -1,22 +1,21 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
+// $Id: pukiwiki.php,v 1.23 2011/01/25 15:01:01 henoheno Exp $
 //
 // PukiWiki 1.4.*
-//  Copyright (C) 2002 by PukiWiki Developers Team
-//  http://pukiwiki.org/
+//  Copyright (C) 2002-2007 by PukiWiki Developers Team
+//  http://pukiwiki.sourceforge.jp/
 //
 // PukiWiki 1.3.*
-//  Copyright (C) 2002 by PukiWiki Developers Team
-//  http://pukiwiki.org/
+//  Copyright (C) 2002-2004 by PukiWiki Developers Team
+//  http://pukiwiki.sourceforge.jp/
 //
 // PukiWiki 1.3 (Base)
-//  Copyright (C) 2001,2002 by sng.
-//  <sng@factage.com>
+//  Copyright (C) 2001-2002 by yu-ji <sng@factage.com>
 //  http://factage.com/sng/pukiwiki/
 //
 // Special thanks
-//  YukiWiki by Hiroshi Yuki
-//  <hyuki@hyuki.com>
+//  YukiWiki by Hiroshi Yuki <hyuki@hyuki.com>
 //  http://www.hyuki.com/yukiwiki/
 //
 // This program is free software; you can redistribute it and/or modify
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
-//
-// $Id: pukiwiki.php,v 1.2 2004/08/01 02:22:36 henoheno Exp $
-/////////////////////////////////////////////////
-
-/////////////////////////////////////////////////
-// ¥Ç¡¼¥¿¤ò³ÊǼ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¤äÀßÄê¥Õ¥¡¥¤¥ë¤òÃÖ¤¯¥Ç¥£¥ì¥¯¥È¥ê
 
 if (! defined('DATA_HOME')) define('DATA_HOME', '');
 
 /////////////////////////////////////////////////
-// ¥µ¥Ö¥ë¡¼¥Á¥ó¤Î³ÊǼÀè¥Ç¥£¥ì¥¯¥È¥ê (¾¤Î *.php¥Õ¥¡¥¤¥ë)
+// Include subroutines
 
 if (! defined('LIB_DIR')) define('LIB_DIR', '');
 
-/////////////////////////////////////////////////
-// ¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÆɤ߹þ¤ß
-
-require('func.php');
-require('file.php');
-require('plugin.php');
-require('html.php');
-require('backup.php');
-
-require('convert_html.php');
-require('make_link.php');
-require('diff.php');
-require('config.php');
-require('link.php');
-require('trackback.php');
-require('auth.php');
-require('proxy.php');
-require('mail.php');
-if (!extension_loaded('mbstring')) {
-       require('mbstring.php');
+require(LIB_DIR . 'func.php');
+require(LIB_DIR . 'file.php');
+require(LIB_DIR . 'plugin.php');
+require(LIB_DIR . 'html.php');
+require(LIB_DIR . 'backup.php');
+
+require(LIB_DIR . 'convert_html.php');
+require(LIB_DIR . 'make_link.php');
+require(LIB_DIR . 'diff.php');
+require(LIB_DIR . 'config.php');
+require(LIB_DIR . 'link.php');
+require(LIB_DIR . 'auth.php');
+require(LIB_DIR . 'proxy.php');
+if (! extension_loaded('mbstring')) {
+       require(LIB_DIR . 'mbstring.php');
 }
 
-// ½é´ü²½: ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß
-require('init.php');
+// Defaults
+$notify = 0;
+
+// Load *.ini.php files and init PukiWiki
+require(LIB_DIR . 'init.php');
+
+// Load optional libraries
+if ($notify) {
+       require(LIB_DIR . 'mail.php'); // Mail notification
+}
 
 /////////////////////////////////////////////////
-// ¥á¥¤¥ó½èÍý
+// Main
 
-$base = $defaultpage;
 $retvars = array();
+$page  = isset($vars['page'])  ? $vars['page']  : '';
+$refer = isset($vars['refer']) ? $vars['refer'] : '';
+
+if (isset($vars['cmd'])) {
+       $plugin = & $vars['cmd'];
+} else if (isset($vars['plugin'])) {
+       $plugin = & $vars['plugin'];
+} else {
+       $plugin = '';
+}
 
-// Plug-in action
-if (!empty($vars['plugin'])) {
-       if (!exist_plugin_action($vars['plugin'])) {
-               $s_plugin = htmlspecialchars($vars['plugin']);
-               $msg = "plugin=$s_plugin is not implemented.";
-               $retvars = array('msg'=>$msg,'body'=>$msg);
+// Spam filtering
+if ($spam && $method != 'GET') {
+       // Adjustment
+       $_spam   = ! empty($spam);
+       $_plugin = strtolower($plugin);
+       $_ignore = array();
+
+       switch ($_plugin) {
+               case 'search': $_spam = FALSE; break;
+               case 'edit':
+                       $_page = & $page;
+                       if (isset($vars['add']) && $vars['add']) {
+                               $_plugin = 'add';
+                       } else {
+                               $_ignore[] = 'original';
+                       }
+                       break;
+               case 'bugtrack': $_page = & $vars['base'];  break;
+               case 'tracker':  $_page = & $vars['_base']; break;
+               case 'read':     $_page = & $page;  break;
+               default: $_page = & $refer; break;
        }
-       else {
-               $retvars = do_plugin_action($vars['plugin']);
-               if ($retvars !== FALSE) {
-                       $base = array_key_exists('refer',$vars) ? $vars['refer'] : '';
+
+       if ($_spam) {
+               require(LIB_DIR . 'spam.php');
+
+               if (isset($spam['method'][$_plugin])) {
+                       $_method = & $spam['method'][$_plugin];
+               } else if (isset($spam['method']['_default'])) {
+                       $_method = & $spam['method']['_default'];
+               } else {
+                       $_method = array();
                }
+               $exitmode = isset($spam['exitmode']) ? $spam['exitmode'] : '';
+
+               // Hack: ignorance several keys
+               if ($_ignore) {
+                       $_vars = array();
+                       foreach($vars as $key => $value) {
+                               $_vars[$key] = & $vars[$key];
+                       }
+                       foreach($_ignore as $key) {
+                               unset($_vars[$key]);
+                       }
+               } else {
+                       $_vars = & $vars;
+               }
+
+               pkwk_spamfilter($method . ' to #' . $_plugin, $_page, $_vars, $_method, $exitmode);
        }
 }
-// Command action
-else if (!empty($vars['cmd'])) {
-       if (!exist_plugin_action($vars['cmd'])) {
-               $s_cmd = htmlspecialchars($vars['cmd']);
-               $msg = "cmd=$s_cmd is not implemented.";
+
+// Plugin execution
+if ($plugin != '') {
+       if (exist_plugin_action($plugin)) {
+               $retvars = do_plugin_action($plugin);
+               if ($retvars === FALSE) exit; // Done
+
+               // Rescan $vars (Some plugins rewrite it)
+               if (isset($vars['cmd'])) {
+                       $base = isset($vars['page'])  ? $vars['page']  : '';
+               } else {
+                       $base = isset($vars['refer']) ? $vars['refer'] : '';
+               }
+       } else {
+               $msg = 'plugin=' . htmlsc($plugin) . ' is not implemented.';
                $retvars = array('msg'=>$msg,'body'=>$msg);
-       }
-       else {
-               $retvars = do_plugin_action($vars['cmd']);
-               $base = $vars['page'];
+               $base    = & $defaultpage;
        }
 }
 
-if ($retvars !== FALSE) {
-       $title = htmlspecialchars(strip_bracket($base));
-       $page = make_search($base);
-
-       if (array_key_exists('msg',$retvars) and $retvars['msg'] != '') {
-               $title = str_replace('$1',$title,$retvars['msg']);
-               $page = str_replace('$1',$page,$retvars['msg']);
-       }
+// Page output
+$title = htmlsc(strip_bracket($base));
+$page  = make_search($base);
+if (isset($retvars['msg']) && $retvars['msg'] != '') {
+       $title = str_replace('$1', $title, $retvars['msg']);
+       $page  = str_replace('$1', $page,  $retvars['msg']);
+}
 
-       if (array_key_exists('body',$retvars) and $retvars['body'] != '') {
-               $body = $retvars['body'];
+if (isset($retvars['body']) && $retvars['body'] != '') {
+       $body = & $retvars['body'];
+} else {
+       if ($base == '' || ! is_page($base)) {
+               $base  = & $defaultpage;
+               $title = htmlsc(strip_bracket($base));
+               $page  = make_search($base);
        }
-       else {
-               if ($base == '' or !is_page($base)) {
-                       $base = $defaultpage;
-                       $title = htmlspecialchars(strip_bracket($base));
-                       $page = make_search($base);
-               }
 
-               $vars['cmd'] = 'read';
-               $vars['page'] = $base;
-               $body = convert_html(get_source($base));
-               $body .= tb_get_rdf($vars['page']);
-               ref_save($vars['page']);
-       }
+       $vars['cmd']  = 'read';
+       $vars['page'] = & $base;
 
-       // ** ½ÐÎϽèÍý **
-       catbody($title,$page,$body);
+       $body  = convert_html(get_source($base));
 }
-// ** ½ªÎ» **
+
+// Output
+catbody($title, $page, $body);
+exit;
 ?>