#author("2022-03-20T01:02:56+09:00","","")
#author("2022-03-20T01:03:23+09:00","","")
* 利用者ページと下書き機能 [#qc12c794]

- ページ: [[BugTrack]]
- 投稿者: [[零鐵]]
- 優先順位: 低
- 状態: 提案
- カテゴリー: 本体新機能
- 投稿日: 2022-01-07 (金) 14:51:15
- バージョン: 1.5.3

** メッセージ [#ca53be02]
Wikipediaにあるような利用者ページと下書きのような機能が欲しいです。

( [[BugTrack/2543]] より分離 )

** 実装案 ([[はいふん]]) [#kb5f5bae]
私の捉え方が間違っているかもしれませんがつくってみました。

:lib/auth.php|
関数追加
 /**
  * Set registration user page auth
  */
 function set_registration_user_page_auth()
 {
 	global $user_registration;
 	global $auth_user, $edit_auth_pages, $read_auth_pages;
 	if ($user_registration) {
 		$edit_auth_pages["#" . preg_quote(sprintf(PLUGIN_USER_PAGE, '')) . '.*' . "#"] = "user_registration"; 
 		$edit_auth_pages["#" . preg_quote(sprintf(PLUGIN_USER_PAGE, $auth_user)) . '.*' . "#"] = $auth_user; 
		$read_auth_pages["#" . preg_quote(sprintf(PLUGIN_USER_PAGE, '')) . '.*/' . preg_quote(sprintf(PLUGIN_USER_DRAFT_PAGE, '')) . '.*' . "#"] = "user_registration"; 
		$read_auth_pages["#" . preg_quote(s printf(PLUGIN_USER_PAGE, $auth_user). '/' . sprintf(PLUGIN_USER_DRAFT_PAGE, '')) . '.*' . "#"] = $auth_user; 
 	}
 }

:lib/pukiwiki.php|
 /////////////////////////////////////////////////
 // Main
 if ($vars['page'] === FALSE) {
 	die_invalid_pagename();
 	exit;
 }
 if (manage_page_redirect()) {
 	exit;
 }
 $retvars = array();
 $is_cmd = FALSE;
 if (isset($vars['cmd'])) {
 	$is_cmd  = TRUE;
 	$plugin = & $vars['cmd'];
 } else if (isset($vars['plugin'])) {
 	$plugin = & $vars['plugin'];
 } else {
 	$plugin = '';
 }
 if ($plugin != '') {
 	user_registration();
 	ensure_valid_auth_user();
 +	set_registration_user_page_auth();


:plugin/edit.inc.php|
 function plugin_edit_action()
 {
 -	global $vars, $_title_edit, $auth_user, $_title_cannotedit_not_login;
 +	global $vars, $_title_edit, $auth_user, $user_registration, $_title_cannotedit_not_login;
 
 	if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
 
 	// Create initial pages
 	plugin_edit_setup_initial_pages();
 
 	$page = isset($vars['page']) ? $vars['page'] : '';
 	check_editable($page, true, true);
 	check_readable($page, true, true);
 
 	if (PLUGIN_EDIT_WRITE_USER_ONLY && !$auth_user) {
 		$body = $title = str_replace('$1',
 			htmlsc(strip_bracket($page)), $_title_cannotedit_not_login);
 		$page = str_replace('$1', make_search($page), $_title_cannotedit_not_login);
 		catbody($title, $page, $body);
 		exit;
 	}
 
 +	// User Page
 +	if ($user_registration) {
 +		if (preg_match('/' . preg_quote(sprintf(PLUGIN_USER_PAGE, ""), '/') . '(.*)/x' . get_preg_u(), $page, 
 $matches)) {
 +			$username = explode('/', $matches[1])[0];
 +			if ($username != $auth_user) die_message('the page is not found.');
 +		}
 +	}
 	
 	if (isset($vars['preview'])) {
 		return plugin_edit_preview($vars['msg']);
 	} else if (isset($vars['template'])) {
 		return plugin_edit_preview_with_template();
 	} else if (isset($vars['write'])) {
 		return plugin_edit_write();
 	} else if (isset($vars['cancel'])) {
 		return plugin_edit_cancel();
 	} else if (isset($vars['draft'])) {
 +		return plugin_edit_write(true);
 	}
&br;
 -function plugin_edit_write()
 +function plugin_edit_write($draft = false)
 {
 	global $vars;
 	global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
 	global $notimeupdate, $_msg_invalidpass, $do_update_diff_table;
 	global $auth_user;
 
 	$page   = isset($vars['page'])   ? $vars['page']   : '';
 	$add    = isset($vars['add'])    ? $vars['add']    : '';
 	$digest = isset($vars['digest']) ? $vars['digest'] : '';
 
 	$vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
 	$msg = & $vars['msg']; // Reference
 
 	$retvars = array();
 
 	// Collision Detection
 	$oldpagesrc = join('', get_source($page));
 	$oldpagemd5 = md5($oldpagesrc);
 	if ($digest !== $oldpagemd5) {
 		$vars['digest'] = $oldpagemd5; // Reset
 
 		$original = isset($vars['original']) ? $vars['original'] : '';
 		$old_body = remove_author_info($oldpagesrc);
 		list($postdata_input, $auto) = do_update_diff($old_body, $msg, $original);
 
 		$retvars['msg' ] = $_title_collided;
 		$retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
 		$retvars['body'] .= $do_update_diff_table;
 		$retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
 		return $retvars;
 	}
 
 	// Action?
 	if ($add) {
 		// Add
 		if (isset($vars['add_top']) && $vars['add_top']) {
 			$postdata  = $msg . "\n\n" . @join('', get_source($page));
 		} else {
 			$postdata  = @join('', get_source($page)) . "\n\n" . $msg;
 		}
 	} else {
 		// Edit or Remove
 		$postdata = & $msg; // Reference
 	}
 
 	// NULL POSTING, OR removing existing page
 	if ($postdata === '') {
 +		if ($draft) {
 +			page_write(sprintf(PLUGIN_USER_PAGE, $auth_user) . "/" . sprintf(PLUGIN_USER_DRAFT_PAGE, $page), $postdata);
 +		} else {
 			page_write($page, $postdata);
 +		}
 		$retvars['msg' ] = $_title_deleted;
 		$retvars['body'] = str_replace('$1', htmlsc($page), $_title_deleted);
 		return $retvars;
 	}
 
 	// $notimeupdate: Checkbox 'Do not change timestamp'
 	$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
 	if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
 		// Enable only administrator & password error
 		$retvars['body']  = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
 		$retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
 		return $retvars;
 	}
 +	if ($draft) {
 +		page_write(sprintf(PLUGIN_USER_PAGE, $auth_user) . "/" . sprintf(PLUGIN_USER_DRAFT_PAGE, $page), $postdata, $notimeupdate != 0 && $notimestamp);
 +	} else {
 		page_write($page, $postdata, $notimeupdate != 0 && $notimestamp);
 +	}
 	pkwk_headers_sent();
 -	header('Location: ' . get_page_uri($page, PKWK_URI_ROOT);
 +	header('Location: ' . get_page_uri($draft ? sprintf(PLUGIN_USER_PAGE, $auth_user) . "/" . sprintf(PLUGIN_USER_DRAFT_PAGE, $page) : $page, PKWK_URI_ROOT));
 	exit;
 }

:html.php|
 function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
 {
 	global $vars, $rows, $cols;
 	-global $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, $_msg_help;
 	+global $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, $_msg_help, $_btn_draft;
 	global $_btn_template, $_btn_load, $load_template_func;
&br;
 	// 'margin-bottom', 'float:left', and 'margin-top'
 	// are for layout of 'cancel button'
 	$h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
 	$h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
 +	$draft_tag = '';
 +	if (!preg_match('/' . preg_quote(sprintf(PLUGIN_USER_PAGE, ""), '/') . ".*" . preg_quote(sprintf(PLUGIN_USER_DRAFT_PAGE, ""), '/') . '(.*)/x' . get_preg_u(), $page, $matches)) {
 +		$draft_tag = $auth_user ? '<input type="submit" name="draft" value="' . $_btn_draft . '" accesskey="d" />' : "";
 +	}
 	$body = <<<EOD
 <div class="edit_form">
   <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0;">
 $template
   $addtag
   <input type="hidden" name="cmd"    value="edit" />
   <input type="hidden" name="page"   value="$s_page" />
   <input type="hidden" name="digest" value="$s_digest" />
   <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
   <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
   <textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
   <br />
   <div style="float:left;">
    <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
    <input type="submit" name="write"   value="$_btn_update" accesskey="s" />
 +   $draft_tag
    $add_top
    $add_notimestamp
   </div>

:ja.lng.php|
 $_btn_cancel    = 'キャンセル';
 +$_btn_draft     = '下書き保存';
 $_btn_notchangetimestamp = 'タイムスタンプを変更しない';

:en.lng.php|
 $_btn_cancel    = 'Cancel';
 +$_btn_draft     = 'Save as draft';
 $_btn_notchangetimestamp = 'Do not change timestamp';

:pukiwiki.ini.php(追記)|
 // User Page
 define('PLUGIN_USER_PAGE', 'User/%s');
 
 // Draft Page
 define('PLUGIN_USER_DRAFT_PAGE', 'draft/%s');

--------
- 「実装案 (はいふん)」 はいふんさん、実装案ありがとうございます。動かしてなくてざっと見ただけですが PLUGIN_USER_PAGE, PLUGIN_USER_DRAFT_PAGE ってどんな値なのですか? -- [[umorigu]] &new{2022-03-19 (土) 00:14:21};
- すいません。追記しました。すっかり定義していた部分を忘れていました。 -- [[はいふん]] &new{2022-03-20 (日) 01:03:23};

#comment

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 5.6.40-0+deb8u12. HTML convert time: 0.048 sec.

OSDN