is_edit_auth() が欲しい

第一弾

凍結に対しては is_freeze がありますが、 ほぼ同等の効果のある編集制限に対しては is_edit_auth がありません。 プラグインを作成していて欲しいときがあるので、Pukiwiki API にほしいです。

//referred lib/auth.php#basic_auth
function is_edit_auth($page, $user = '')
{
	global $edit_auth, $edit_auth_pages, $auth_method_type;
	if (! $edit_auth) {
		return FALSE;
	}
	// Checked by:
	$target_str = '';
	if ($auth_method_type == 'pagename') {
		$target_str = $page; // Page name
	} else if ($auth_method_type == 'contents') {
		$target_str = join('', get_source($page)); // Its contents
	}

	foreach($edit_auth_pages as $regexp => $users) {
		if (preg_match($regexp, $target_str)) {
			if ($user == '' || in_array($user, explode(',', $users))) {
				return TRUE;
			}
		}
	}
	return FALSE;
}

is_read_auth もあったほうがいいとは思います*1


check_editable()で代替可能か

実装周り

第2弾

--- auth.php.orig	2006-06-29 18:01:39.137336000 -0700
+++ auth.php	2006-06-29 18:52:38.930193600 -0700
@@ -170,19 +170,7 @@
 {
 	global $auth_method_type, $auth_users, $_msg_auth;
 
-	// Checked by:
-	$target_str = '';
-	if ($auth_method_type == 'pagename') {
-		$target_str = $page; // Page name
-	} else if ($auth_method_type == 'contents') {
-		$target_str = join('', get_source($page)); // Its contents
-	}
-
-	$user_list = array();
-	foreach($auth_pages as $key=>$val)
-		if (preg_match($key, $target_str))
-			$user_list = array_merge($user_list, explode(',', $val));
-
+	$user_list = auth_user_list($page, $auth_pages);
 	if (empty($user_list)) return TRUE; // No limit
 
 	$matches = array();
@@ -224,4 +212,48 @@
 		return TRUE;
 	}
 }
+
+// is_auth
+function is_edit_auth($page, $user = '')
+{
+	global $edit_auth, $edit_auth_pages;
+	return $edit_auth ? is_auth($page, $user, $edit_auth_pages) : FALSE;
+}
+
+function is_read_auth($page, $user = '')
+{
+	global $read_auth, $read_auth_pages;
+	return $read_auth ? is_auth($page, $user, $read_auth_pages) : FALSE;
+}
+
+// whether the specified page is restricted and the specified user has possible permissions for the page
+function is_auth($page, $user = '', $auth_pages)
+{
+	global $auth_users;
+	$user_list = auth_user_list($page, $auth_pages);
+	if (empty($user_list)) return FALSE;
+	if ($user == '' || (in_array($user, $user_list) && isset($auth_users[$user]))) return TRUE;
+	return FALSE;
+}
+
+function auth_user_list($page, $auth_pages)
+{
+	global $auth_method_type;
+
+	// Checked by:
+	$target_str = '';
+	if ($auth_method_type == 'pagename') {
+		$target_str = $page; // Page name
+	} else if ($auth_method_type == 'contents') {
+		$target_str = join('', get_source($page)); // Its contents
+	}
+
+	$user_list = array();
+	foreach($auth_pages as $key=>$val)
+		if (preg_match($key, $target_str))
+			$user_list = array_merge($user_list, explode(',', $val));
+
+	return $user_list;
+}
+
 ?>

キャッシュ周り


確認: is_edit_auth() / is_auth() の存在意義



*1 1.4.7 前に言えればよかったナァ
*2 認証に失敗した場合 *3
*3 詳しくないので間違えていたらすみません
*4 これ自体2,3ヶ月前に作った関数でどうしてその経緯に至ったのかちょっと忘れていました orz
*5 $user を拾ってくる場面が思いつかなくて (^^;
*6 ちなみに上記、認証をするかどうか -> 出すかどうか って事です
*7 無関係な件を混ぜ込んで、要点をぼかしたり、パッチを大きくしてはいけないという意味
*8 そうした動作が期待される
*9 第二段のコードはそうじゃなく、関数のインターフェースが設定関係の実装に強く依存しているので、設定の体系を整理したくなった時に、多数の関数が思い切り影響を受ける => 将来的な足枷になりうる

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2017-10-14 (土) 00:17:29
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.235 sec.

SourceForge