<?php // vim: ts=4 sw=4 sts=4 fdm=marker ai noet:
// $Id: newpage.inc.php,v 1.5 2005/02/11 14:47:42 ishii Exp $
//
// Newpage plugin

// {{{ plugin_newpage_convert()

function plugin_newpage_convert()
{
	global $script, $vars, $_btn_edit, $_msg_newpage, $BracketName;

	if (PKWK_READONLY) return ''; // Show nothing

	$newpage = '';
	if (func_num_args()) list($newpage) = func_get_args();
	if (! preg_match('/^' . $BracketName . '$/', $newpage)) $newpage = '';

	$s_page    = htmlspecialchars(isset($vars['refer']) ? $vars['refer'] : $vars['page']);
	$s_newpage = htmlspecialchars($newpage);
	$ret = <<<EOD
<form action="$script" method="post">
 <div>
  <input type="hidden" name="plugin" value="newpage" />
  <input type="hidden" name="refer"  value="$s_page" />
  $_msg_newpage:
  <input type="text"   name="page"   value="$s_newpage" size="30" />
  <input type="submit" value="$_btn_edit" />
 </div>
</form>
EOD;

	return $ret;
}

// }}}
// {{{ plugin_newpage_action()

function plugin_newpage_action()
{
	global $vars, $_btn_edit, $_msg_newpage;

	if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');

	if ($vars['page'] == '') {
		$retvars['msg']  = $_msg_newpage;
		$retvars['body'] = plugin_newpage_convert();
		return $retvars;
	} else {
		$page    = strip_bracket($vars['page']);
		$r_page  = rawurlencode(isset($vars['refer']) ?
			get_fullname($page, $vars['refer']) : $page);
		$r_refer = rawurlencode($vars['refer']);

		pkwk_headers_sent();
		header('Location: ' . get_script_uri() .
			'?cmd=read&page=' . $r_page . '&refer=' . $r_refer);
		exit;
	}
}

// }}}

?>
