<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>We finally managed to come up with a first tiny recipe here. I must say we're very proud .-)<div><br></div><div>I have attached our cookbook recipe here. It's working well but I'd be very happy if anyone could please review and comment on it to see if we have build in some major bugs or weaknesses for future releases or whatever ...</div><div><br></div><div><div>Thanks to everyone who contributed!</div><div><br></div><div><br></div><div><br></div></div><div><div>&lt;?php if (!defined('PmWiki')) exit();</div><div><br></div><div>/*</div><div>&nbsp;&nbsp;PublicPages (v 0.1) -- Aug 18, 2008</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;Copyright 2008 - Rob Laux (<a href="mailto:rob@lx-i.com">rob@lx-i.com</a>) &amp; Lars Grau (<a href="mailto:mail@larsgrau.de">mail@larsgrau.de</a>)</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;based on the "EditTitle" Cookbook by Waylan Limberg (<a href="mailto:waylan@gmail.com">waylan@gmail.com</a>)</div><div>&nbsp;&nbsp;and hints &amp; code snippets from the pmwiki mailing list provided by&nbsp;</div><div>&nbsp;&nbsp;Peter &amp; Melodye Bowers and "Vince". Thanks!</div><div><br></div><div>&nbsp;&nbsp;See <a href="http://www.pmwiki.org/wiki/Cookbook/EditTitle">http://www.pmwiki.org/wiki/Cookbook/EditTitle</a> and</div><div>&nbsp;&nbsp;<a href="http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/51555">http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/51555</a></div><div>&nbsp;&nbsp;for reference&nbsp;</div><div><br></div><div>&nbsp;&nbsp;This program is free software; you can redistribute it and/or modify</div><div>&nbsp;&nbsp;it under the terms of the GNU General Public License as published</div><div>&nbsp;&nbsp;by the Free Software Foundation; either version 2 of the License, or</div><div>&nbsp;&nbsp;(at your option) any later version.</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;// Description:&nbsp;</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;We got pmwiki-2.2.0-beta65 running with LDAP authentication and want</div><div>&nbsp;&nbsp;only authenticated users to be able to edit pages. Therefore we set&nbsp;</div><div>&nbsp;&nbsp;the following in config.php:</div><div><br></div><div>&nbsp;&nbsp;$DefaultPasswords['edit'] = 'id:*';</div><div><br></div><div>&nbsp;&nbsp;Now we'd like to add a checkbox "This is a public page" to the edit</div><div>&nbsp;&nbsp;form that does the following: If unchecked (default), the read</div><div>&nbsp;&nbsp;password for the page being edited should be set to "id:*" allowing</div><div>&nbsp;&nbsp;only authenticated users to VIEW the page. If the author activates the</div><div>&nbsp;&nbsp;checkbox, the read password should be cleared so anyone can see the page.</div><div><br></div><div>&nbsp;&nbsp;// Precondition:</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;- You must add an extra checkbox into the Site.EditForm a la</div><div><br></div><div>&nbsp;&nbsp; &nbsp;(:input e_public:) Allow unauthorized users to view this page?</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;// Known issues:</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;- When setting the password, the page is shown afterwards without password&nbsp;</div><div>&nbsp;&nbsp; &nbsp;prompt. For our purpose, this is not crucial as we only allow authenticated&nbsp;</div><div>&nbsp;&nbsp; &nbsp;users to edit pages and therefore they can see the page afterwards anyway.</div><div>&nbsp;&nbsp;</div><div>*/</div><div><br></div><div><br></div><div><br></div><div><br></div><div>// Prepend "CheckPassword" function at the BEGINNING of the $EditFunctions array</div><div>array_unshift($EditFunctions, 'CheckPassword');</div><div><br></div><div>// Insert "AllowPublicPage" function immediately before "PostPage"</div><div>array_splice($EditFunctions, array_search('PostPage', $EditFunctions), 0, 'AllowPublicPage');</div><div><br></div><div>// Prepend the extra input field at the BEGINNING of the $EditFields array</div><div>array_unshift($EditFields, 'public');</div><div><br></div><div>/* &nbsp;/////////////////////////////////////////</div><div><br></div><div>&nbsp;&nbsp; &nbsp;CheckPassword()&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- get current page read password(s)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- if checkbox "public" is set, make sure "id:*" is NOT SET in&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;read passwd field else SET "id:*" in read passwd field</div><div>&nbsp;*/</div><div>&nbsp;</div><div>function CheckPassword($pagename, &amp;$page, &amp;$new) {</div><div>&nbsp;&nbsp;global $InputTags;</div><div><br></div><div>&nbsp;&nbsp;// get current read password(s)&nbsp;</div><div>&nbsp;&nbsp;$rpw = $page['passwdread'];</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;// Add input field (checkbox) via SDVA ("Set Default Value Array)</div><div>&nbsp;&nbsp;SDVA($InputTags["e_public"], array(</div><div>&nbsp;&nbsp; &nbsp;':html' => "&lt;input type='checkbox' \$InputFormArgs />", 'name' => 'public',&nbsp;</div><div>&nbsp;&nbsp; &nbsp;'value' => 'yes'));</div><div><br></div><div>&nbsp;&nbsp;// If password does NOT contain "id:*"</div><div>&nbsp;&nbsp;if (!strstr($rpw, 'id:*'))</div><div>&nbsp;&nbsp; &nbsp;SDV($InputTags['e_public']['checked'], 'checked');</div><div><br></div><div>}</div><div><br></div><div>/* &nbsp;/////////////////////////////////////////</div><div><br></div><div>&nbsp;&nbsp; &nbsp;AllowPublicPage()&nbsp;</div><div>&nbsp;&nbsp; &nbsp;- should be invoked before the page is stored to set the passwd</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- get current page read password(s)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- if checkbox "public" is set, REMOVE "id:*" if present&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;else SET "id:*" in read passwd field</div><div>&nbsp;*/</div><div>&nbsp;</div><div>function AllowPublicPage($pagename, &amp;$page, &amp;$new) {</div><div>&nbsp;&nbsp;// $EnablePost is used to check if the page is being stored (???)</div><div>&nbsp;&nbsp;global $EnablePost;</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;// Get current read password(s)&nbsp;</div><div>&nbsp;&nbsp;$rpw = $page['passwdread'];</div><div><br></div><div>&nbsp;&nbsp;if ($EnablePost) {</div><div>&nbsp;&nbsp;// if checkbox is checked ("public=YES")</div><div>&nbsp;&nbsp;if (@$_REQUEST['public']) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// if password contains "id:*"</div><div>&nbsp;&nbsp; &nbsp;if (strstr($rpw, 'id:*'))</div><div>&nbsp;&nbsp; &nbsp; &nbsp;// remove "id:*" from read passwd</div><div>&nbsp;&nbsp; &nbsp; &nbsp;$rpw = str_replace('id:*', '', $rpw);</div><div>&nbsp;&nbsp;// else if checkbox is NOT checked ("public=NO")</div><div>&nbsp;&nbsp;} else {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// if password does NOT contain "id:*"</div><div>&nbsp;&nbsp; &nbsp;if (!strstr($rpw, 'id:*'))</div><div>&nbsp;&nbsp; &nbsp; &nbsp;// Append " id:*" (Note the BLANK!) at the end of the read password field<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>&nbsp;&nbsp; &nbsp; &nbsp;$rpw .= ' id:*';</div><div>&nbsp;&nbsp;}</div><div><br></div><div>&nbsp;&nbsp;// Store the page read password</div><div>&nbsp;&nbsp;$new['passwdread'] = $rpw;</div><div>&nbsp;&nbsp;return;</div><div>&nbsp;&nbsp;}</div><div>}</div><div><br></div></div><div><br></div><div><br></div><div><br></div><div>L.-<br><div><br><div><div>On 11.08.2008, at 16:55, Vince Administration wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Lars,<br>Somewhat related, Hans helped me create a recipe that would add an edit password basically of<br>id:$AuthUser &nbsp;when creating a profile page.<br><a href="http://www.pmwiki.org/wiki/Cookbook/FoxPageManagement">http://www.pmwiki.org/wiki/Cookbook/FoxPageManagement</a><br>The key is a small php program that adds the password before saving.<br>http://www.pmwiki.org/pmwiki/uploads/Cookbook/foxsetpwedit.php<br><br>PHP isn't really so hard if you have enough examples close to what you want to do.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Vince<br><br>On Aug 11, 2008, at 9:11 AM, Lars Grau wrote:<br><br><blockquote type="cite">Peter, thanks for your quick anwer!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I see the $EditFunctions array is a good place to hook in. I assume<br></blockquote><blockquote type="cite">you are suggesting to write an own recipe for this, right? I am aware<br></blockquote><blockquote type="cite">of the $page['passwdread'] variable and I have checked the file you<br></blockquote><blockquote type="cite">suggested, but I am definitely not able to strip out the code pieces I<br></blockquote><blockquote type="cite">need from that file or to code an own recipe.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I have had a look at the cookbook recipe called "EditTitle" before ( http://pmwiki.org/wiki/Cookbook/EditTitle<br></blockquote><blockquote type="cite"> &nbsp;) to take that as a basis but I figured out that I am not capable of<br></blockquote><blockquote type="cite">doing this...<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This would be my first recipe, but I need way more code ... or someone<br></blockquote><blockquote type="cite">to do it for me .-)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">L.- (Rookie)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On 11.08.2008, at 14:08, Peter Bowers wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">You can look at the code in WikiSh.php for wshChmod() to see how to<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">set a password and potentially append to it. &nbsp;Basically it's a<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">question of reading &amp; setting a value in $page['passwdread'].<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Probably you could hook into the $EditFunctions with another function<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">that will do what you want it to do.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Hope that gets you started in the right direction.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">-Peter<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">On Mon, Aug 11, 2008 at 12:40 PM, Lars Grau &lt;mail@larsgrau.de> wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">We have pmwiki-2.2.0-beta65 running with LDAP authentication. We<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">allow<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">only authenticated users to edit pages. ( In config.php:<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">$DefaultPasswords['edit'] = 'id:*'; )<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Now we'd like to add a checkbox "This is a public page" to the edit<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">form that does the following: If unchecked (default), the read<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">password for the page being edited should be set to "id:*" allowing<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">only authenticated users to VIEW the page. If the author activates<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">checkbox, the read password should be cleared.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Can anyone point us into a direction how to do this via a cookbook<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">recipe or even better - provide the code? We're familiar with PHP in<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">general, but we'd like to keep PmWiki as close to the original<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">distribution for future updates and therefore need support in<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">"hooking" this into the software.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Tricky sidenote: To be even more precise, if a read password has<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">already been set by "?action=attr" (i.e. "secret"), we'd like the<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">recipe to append the "id:*" rather than over-writing the entire<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">attribute. Same applies for clearing the field. The "id:*" should be<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">removed, but everything else should remain untouched.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Thanks a lot in advance.<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Larsen.-<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">_______________________________________________<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">pmwiki-users mailing list<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">pmwiki-users@pmichaud.com<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">http://www.pmichaud.com/mailman/listinfo/pmwiki-users<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">pmwiki-users mailing list<br></blockquote><blockquote type="cite">pmwiki-users@pmichaud.com<br></blockquote><blockquote type="cite">http://www.pmichaud.com/mailman/listinfo/pmwiki-users<br></blockquote><blockquote type="cite"><br></blockquote><br><br></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><div class="AppleMailSignature" id="1582F48F-54DF-48BA-AC55-6B39B3CD424E"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Lucida Grande" size="3" style="font: normal normal normal 12px/normal 'Lucida Grande'; "><br class="Apple-interchange-newline">Mobil: +49 (0)170 /&nbsp;965 38 80</font></div></div><div><br class="khtml-block-placeholder"></div><div>++++++++++++++++++++++++++++++++++++++++++++++++</div><div>Lars Grau, Grosse Hamburger 28, DE-10115 Berlin</div><div>T: +49 (0) 30 / 65 70 16-66, Fax: -68</div><div><a href="mailto:mail@larsgrau.de">mail@larsgrau.de</a></div></div><br class="khtml-block-placeholder"></div><div><br class="khtml-block-placeholder"></div><br class="Apple-interchange-newline"></span></div></span><br class="Apple-interchange-newline"> </div><br></div></div></div></body></html>