3 $AuthFunction = 'AuthPlatal';
5 $Conditions['logged'] = logged();
6 $Conditions['identified'] = identified();
7 $Conditions['has_perms'] = has_perms();
8 $Conditions['public'] = 'true';
9 $Conditions['only_public'] = !identified();
11 $HandleAuth['diff'] = 'edit';
12 $HandleAuth['source'] = 'edit';
14 $InputTags['e_textarea'][':html'] =
15 "<textarea \$InputFormArgs
16 onkeydown='if (event.keyCode==27) event.returnValue=false;'
17 >{literal}\$EditText{/literal}</textarea>";
19 // impossible to see the diff without the source because of the smarty tags
20 $DiffShow['source'] = 'y';
23 $DiffStartFmt = "{literal}<div class='diffbox'><div class='difftime'>\$DiffTime \$[by] <span class='diffauthor' title='\$DiffHost'>\$DiffAuthor</span></div>";
24 $DiffEndFmt = "</div>{/literal}";
26 // compute permissions based on the permission string (key)
27 // if could is true, compute permission that could be enabled with a mdp
28 // if smarty is true, return a string to insert in a smarty if tag
29 // otherwise return true or false
30 function authPerms($pagename, $key, $could=false
, $smarty=false
)
32 $words = explode(' ', $key);
33 $auth = $smarty?
"":false
;
35 foreach ($words as $word) {
36 if (strpos($word, '@') === 0) $word = substr($word,1);
38 if ($word == 'and:') {
42 $parts = explode(':', $word);
45 if ($cond == 'identified' && $could) {
49 $iauth = '$'.$cond.($param?
(' eq "'.$param.'"'):'');
52 if (strpos($cond, "smarty.") === 0)
54 $vars = explode('.', $cond);
58 case 'session':$iauth = Session
::get($vars[2]) == $param; break;
59 case 'request':$iauth = Env
::get($vars[2]) == $param; break;
62 else $iauth = CondText($pagename, 'if '.$cond.' '.$param, true
);
67 $auth = ($auth?
"($auth) and ":"").$iauth;
72 $auth = ($auth?
"($auth) or ":"").$iauth;
79 $auth = "($auth) or \$wiki_admin";
83 // try to find the best permission for a given page and a given level of auth
84 // in order: page > group > site
85 function TryAllAuths($pagename, $level, $page_read, $group_read)
87 global $DefaultPasswords;
88 if (isset($page_read['passwd'.$level]) && $page_read['passwd'.$level] != '*') {
89 return array('page', $page_read['passwd'.$level]);
91 if (isset($group_read['passwd'.$level]) && $group_read['passwd'.$level] != '*') {
92 return array('group', $group_read['passwd'.$level]);
94 if (isset($DefaultPasswords[$level])) {
95 return array('site', $DefaultPasswords[$level]);
97 return array('none', '');
100 function auth_pmwiki_to_smarty($text, $pass)
102 $ifc = authPerms("", $pass, false
, true
);
103 if (!$ifc) return "";
104 return "{if $ifc}\n".$text."{/if}";
107 // for read pages: will come only once so we have to be careful
108 // and translate any auth from the wiki to smarty auth
109 function AuthPlatal($pagename, $level, $authprompt, $since)
115 $page_read = ReadPage($pagename, $since);
116 $groupattr = FmtPageName('$Group/GroupAttributes', $pagename);
117 $group_read = ReadPage($groupattr, $since);
119 $levels = array('read', 'attr', 'edit', 'upload');
121 foreach ($levels as $l)
123 list($from, $pass) = TryAllAuths($pagename, $l, $page_read, $group_read);
124 $passwds[$l] = $pass;
125 $pwsources[$l] = $from;
128 $canedit = authPerms($pagename, $passwds['edit'], true
, true
);
129 $canattr = authPerms($pagename, $passwds['attr'], true
, true
);
130 $panel = "{if ($canedit) or ($canattr)}\n";
131 $panel .= ">>frame<<\n";
132 $panel .= "[[{\$FullName} |Voir la page]]\\\\\n";
133 $panel .= "{if ($canedit)}\n";
134 $panel .= "[[{\$FullName}?action=edit |Editer]]\\\\\n";
135 $panel .= "[[{\$FullName}?action=diff |Historique]]\\\\\n";
136 $panel .= "[[{\$FullName}?action=upload |Upload]]\\\\\n";
137 $panel .= "{/if}{if ($canattr)}\n";
138 $panel .= "[[{\$FullName}?action=attr |Droits]]\\\\\n";
139 $panel .= "[[{\$Group}/GroupAttributes?action=attr|Droits du groupe]]\\\\\n";
144 if ((identified() && has_perms()) ||
authPerms($pagename, $passwds[$level]))
146 $page_read['=passwd'] = $passwds;
147 $page_read['=pwsource'] = $pwsources;
148 // if try to read, add the permission limitation as a smarty if tag
149 if ($level == 'read')
151 $page_read['text'] = auth_pmwiki_to_smarty($page_read['text'], $passwds['read']);
152 $page_read['text'] = $panel.$page_read['text'];
154 // print_r($page_read); die();
158 // if we arrive here, the user doesn't have enough permission to access page
160 // maybe it is because he is not identified
161 if ($authprompt && !identified())
163 new_identification_page();
167 new_identification_page();
169 $page->trig('Erreur : page Wiki inutilisable sur plat/al');
171 $page->trig("Tu n'as pas le droit d'accéder à ce service");
174 // don't return false or pmwiki will send an exit breaking smarty page