* is_edit_auth() が欲しい [#s5c62ddc] - ページ: [[BugTrack2]] - 投稿者: [[sonots]] - 優先順位: 低 - 状態: 提案 - カテゴリー: その他 - 投稿日: 2006-06-25 (日) 04:41:11 - バージョン: ** メッセージ [#q4ea43a4] 凍結に対しては 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.4.7 前に言えればよかったナァ))。 ***第2弾 [#eef3add2] --- 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; +} + ?> -------- ** check_editable()で代替可能か [#z68656b8] - lib/auth.phpのcheck_editable, check_readableで代替可能かと思われます。 -- [[Ratbeta]] &new{2006-06-25 (日) 17:03:34}; -- いいえ、check_editable は basic_auth を表示してしまいます。 -- [[sonots]] &new{2006-06-26 (月) 16:18:53}; -- パスワードを要求するものと、要求しないものの違いです。前述の通り is_freeze のような関数となります。 -- [[sonots]] &new{2006-06-26 (月) 16:20:49}; - check_editable($page, false, false); のようにすると true/false が返ってきます。$auth_flag が basic 認証をするかどうか、$exit_flag が exit するかどうか、だと思います(( 認証に失敗した場合 (( 詳しくないので間違えていたらすみません )) ))。 -- [[0]] &new{2006-06-26 (月) 23:18:01}; -- いいえ、$auth_flag は basic 認証プロンプトを出すかどうかのフラグであり、check_editable は依然として edit_auth されていない、もしくは edit_auth されているが basic 認証が通っている場合に true を返す関数となります。そのページが edit_auth されているかの判定とは異なります((これ自体2,3ヶ月前に作った関数でどうしてその経緯に至ったのかちょっと忘れていました orz)) -- [[sonots]] &new{2006-06-27 (火) 03:54:06}; -- あ、そのページ自体に何らかの編集制限がかかっているかどうかのみのチェックで、編集権限があるかどうかは関係ないって意味ですか。$user が入っているので勘違いしてしまいました。(( $user を拾ってくる場面が思いつかなくて (^^; ))。あれば便利かも知れないですね。もし作るなら大体の部分は is_read_auth と is_edit_auth で共用できそうですね。(( ちなみに上記、認証をするかどうか -> 出すかどうか って事です )) -- [[0]] &new{2006-06-29 (木) 22:30:02}; -- $user はいつか再利用される時を考えてとりあえずつけておいた記憶があります。 -- [[sonots]] &new{2006-06-30 (金) 02:53:51}; #comment ** 実装周り [#b236edd6] - なるほど。何度も呼ばれた時を考えるともう少し軽くできるかもしれません。元のコードがこうなっている可能性を感じますが (^^; そうしたら認証機構そのものの見直しネタになりそうですね。 -- [[henoheno]] &new{2006-06-26 (月) 23:45:53}; - basic_auth を参考にして作ったものにすぎないので、一つにまとめる、や再利用などはできるとは思います。上は、私がプラグインで用いるにあたって本体の改造をするわけにはいかないので、そのときにプラグイン中で定義していた関数を持ってきたにすぎません。 -- [[sonots]] &new{2006-06-27 (火) 04:19:08}; -- なるほど、経緯がわかりました。であれば「この件だけに関し((無関係な件を混ぜ込んで、要点をぼかしたり、パッチを大きくしてはいけないという意味))、自分がlib/auth.php に手を加える事ができる立場であったらどうするか」を検討された結果をいただけますか? このままではコードが単に冗長になってしまいます (^^; 風呂敷は折りたたんでから広げる必要があります。 -- [[henoheno]] &new{2006-06-29 (木) 00:05:31}; -- 了解しました。時間を見つけて取り組もうと思います。 -- [[sonots]] &new{2006-06-30 (金) 02:56:48}; - とりあえず [[上>#eef3add2]] のようになりました。さらに @@ -170,8 +170,7 @@ - $user_list = auth_user_list($page, $auth_pages); - if (empty($user_list)) return TRUE; // No limit + if (! is_auth($page, '', $auth_pages)) return TRUE; @@ -187,8 +186,7 @@ - ! in_array($_SERVER['PHP_AUTH_USER'], $user_list) || - ! isset($auth_users[$_SERVER['PHP_AUTH_USER']]) || + ! is_auth($page, $_SERVER['PHP_AUTH_USER'], $auth_pages) || ともできるのですが、$user_list を内部的に二度作ることになるので、やるべきではないかな、と。ダブルチェックお願いします。 -- [[sonots]] &new{2006-06-30 (金) 11:11:17}; - 後は$user 引数が必要かどうか、と is_freeze のように static 変数でキャッシュを作るかどうかでしょうか。$user 引数は @@ -187,8 +186,7 @@ のような使い方をするための引数ですが、他にいつ使うのか・・・ $user を使うかどうかでキャッシュ配列も変わるので・・・ -- [[sonots]] &new{2006-06-30 (金) 11:28:04}; #comment