4 This plugin allows to lock individual pages with a password, so they
5 will be editable only when this is given again. You can't use this in
6 conjunction to another auth plugin, this one is standalone.
7 It will probably be of little use for most Wiki setups, and certainly
8 requires an adminstrator to manage it with 'ewikictl' from time to time.
11 #-- switch ewiki into virtual paging mode ;)
12 define("EWIKI_PROTECTED_MODE", 1);
15 $ewiki_plugins["auth_perm"][] = "ewiki_auth_perm_password_locks";
16 $ewiki_plugins["edit_form_append"][] = "ewiki_edit_field_pwlock";
17 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_pwlock";
20 $ewiki_t["de"]["lock page with"] = "Seite schützen mit";
21 $ewiki_t["de"]["password"] = "Paßwort";
24 #-- this prints the password query <form>
25 function ewiki_auth_login_password(&$data, &$author, &$ring, $force) {
31 if ($pw = $_POST["unlock_password"]) {
33 setcookie("unlock_password", $pw, time()+7*24*3600, "/", $_SERVER["SERVER_NAME"]);
39 $pw = $_REQUEST["unlock_password"];
43 $ok = ($pw == $data["meta"]["password"]);
47 $ewiki_errmsg = ewiki_t( <<<END
48 <h2>_{This page is locked}</h2>
49 <form action="{$_SERVER['REQUEST_URI']}" method="POST" enctype="multipart/form-data">
50 _{password} <input type="password" size="16" name="unlock_password">
52 <input type="submit" value="_{access}">
62 #-- this separates password-protected pages from all others
63 function ewiki_auth_perm_password_locks($id, &$data, $action, $ring, $force) {
66 "edit", "delete", "export", "any_other_action",
69 #-- only protect pages with passwords for editing
70 if (in_array($action, $PROTECT)) {
71 if (empty($data["meta"]["password"])) {
75 $ok = ewiki_auth_login_password($data, $ewiki_author, $ewiki_ring,
80 #-- strip password here, so it won't display accidently
81 elseif ($action == "info") {
82 unset($data["meta"]["password"]);
85 #-- pages we don't care
88 // return(NULL); // for tri-state boolean ["auth_perm"]
93 #-- add password field on edit/ page
94 function ewiki_edit_field_pwlock($id, &$data, $action) {
95 $o = ewiki_t('<br /><br />_{lock page with} <b>_{password}</b> <input type="password" name="lock_password" size="16" value="').htmlentities($data["meta"]["password"]).'"><br />';
100 #-- store password into page db entry {meta} field
101 function ewiki_edit_save_pwlock(&$save, &$old_data) {
103 $pw = $_REQUEST["lock_password"];
106 #-- keep in {meta} field
107 $save["meta"]["password"] = $pw;
109 #-- copy it immediately
110 if ($_REQUEST["unlock_password"] != $pw) {
111 setcookie("unlock_password", $pw, time()+7*24*3600, "/");
112 $_COOKIE["unlock_password"] = $pw;
113 $_REQUEST["unlock_password"] = $pw;