[pmwiki-users] How to add a read password field to the edit form

Lars Grau mail at larsgrau.de
Mon Aug 18 10:50:34 CDT 2008


We finally managed to come up with a first tiny recipe here. I must  
say we're very proud .-)

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 ...

Thanks to everyone who contributed!



<?php if (!defined('PmWiki')) exit();

/*
   PublicPages (v 0.1) -- Aug 18, 2008

   Copyright 2008 - Rob Laux (rob at lx-i.com) & Lars Grau (mail at larsgrau.de 
)

   based on the "EditTitle" Cookbook by Waylan Limberg  
(waylan at gmail.com)
   and hints & code snippets from the pmwiki mailing list provided by
   Peter & Melodye Bowers and "Vince". Thanks!

   See http://www.pmwiki.org/wiki/Cookbook/EditTitle and
   http://article.gmane.org/gmane.comp.web.wiki.pmwiki.user/51555
   for reference

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   // Description:

   We got pmwiki-2.2.0-beta65 running with LDAP authentication and want
   only authenticated users to be able to edit pages. Therefore we set
   the following in config.php:

   $DefaultPasswords['edit'] = 'id:*';

   Now we'd like to add a checkbox "This is a public page" to the edit
   form that does the following: If unchecked (default), the read
   password for the page being edited should be set to "id:*" allowing
   only authenticated users to VIEW the page. If the author activates  
the
   checkbox, the read password should be cleared so anyone can see the  
page.

   // Precondition:

   - You must add an extra checkbox into the Site.EditForm a la

     (:input e_public:) Allow unauthorized users to view this page?

   // Known issues:

   - When setting the password, the page is shown afterwards without  
password
     prompt. For our purpose, this is not crucial as we only allow  
authenticated
     users to edit pages and therefore they can see the page  
afterwards anyway.

*/




// Prepend "CheckPassword" function at the BEGINNING of the  
$EditFunctions array
array_unshift($EditFunctions, 'CheckPassword');

// Insert "AllowPublicPage" function immediately before "PostPage"
array_splice($EditFunctions, array_search('PostPage', $EditFunctions),  
0, 'AllowPublicPage');

// Prepend the extra input field at the BEGINNING of the $EditFields  
array
array_unshift($EditFields, 'public');

/*  /////////////////////////////////////////

     CheckPassword()
	- get current page read password(s)
	- if checkbox "public" is set, make sure "id:*" is NOT SET in
	  read passwd field else SET "id:*" in read passwd field
  */

function CheckPassword($pagename, &$page, &$new) {
   global $InputTags;

   // get current read password(s)
   $rpw = $page['passwdread'];

   // Add input field (checkbox) via SDVA ("Set Default Value Array)
   SDVA($InputTags["e_public"], array(
     ':html' => "<input type='checkbox' \$InputFormArgs />", 'name' =>  
'public',
     'value' => 'yes'));

   // If password does NOT contain "id:*"
   if (!strstr($rpw, 'id:*'))
     SDV($InputTags['e_public']['checked'], 'checked');

}

/*  /////////////////////////////////////////

     AllowPublicPage()
     - should be invoked before the page is stored to set the passwd
	- get current page read password(s)
	- if checkbox "public" is set, REMOVE "id:*" if present
	  else SET "id:*" in read passwd field
  */

function AllowPublicPage($pagename, &$page, &$new) {
   // $EnablePost is used to check if the page is being stored (???)
   global $EnablePost;

   // Get current read password(s)
   $rpw = $page['passwdread'];

   if ($EnablePost) {
   // if checkbox is checked ("public=YES")
   if (@$_REQUEST['public']) {
	// if password contains "id:*"
     if (strstr($rpw, 'id:*'))
       // remove "id:*" from read passwd
       $rpw = str_replace('id:*', '', $rpw);
   // else if checkbox is NOT checked ("public=NO")
   } else {
	// if password does NOT contain "id:*"
     if (!strstr($rpw, 'id:*'))
       // Append " id:*" (Note the BLANK!) at the end of the read  
password field	
       $rpw .= ' id:*';
   }

   // Store the page read password
   $new['passwdread'] = $rpw;
   return;
   }
}




L.-

On 11.08.2008, at 16:55, Vince Administration wrote:

> Lars,
> Somewhat related, Hans helped me create a recipe that would add an  
> edit password basically of
> id:$AuthUser  when creating a profile page.
> http://www.pmwiki.org/wiki/Cookbook/FoxPageManagement
> The key is a small php program that adds the password before saving.
> http://www.pmwiki.org/pmwiki/uploads/Cookbook/foxsetpwedit.php
>
> PHP isn't really so hard if you have enough examples close to what  
> you want to do.
>      Vince
>
> On Aug 11, 2008, at 9:11 AM, Lars Grau wrote:
>
>> Peter, thanks for your quick anwer!
>>
>> I see the $EditFunctions array is a good place to hook in. I assume
>> you are suggesting to write an own recipe for this, right? I am aware
>> of the $page['passwdread'] variable and I have checked the file you
>> suggested, but I am definitely not able to strip out the code  
>> pieces I
>> need from that file or to code an own recipe.
>>
>> I have had a look at the cookbook recipe called "EditTitle" before  
>> ( http://pmwiki.org/wiki/Cookbook/EditTitle
>>  ) to take that as a basis but I figured out that I am not capable of
>> doing this...
>>
>> This would be my first recipe, but I need way more code ... or  
>> someone
>> to do it for me .-)
>>
>> L.- (Rookie)
>>
>>
>> On 11.08.2008, at 14:08, Peter Bowers wrote:
>>
>>> You can look at the code in WikiSh.php for wshChmod() to see how to
>>> set a password and potentially append to it.  Basically it's a
>>> question of reading & setting a value in $page['passwdread'].
>>>
>>> Probably you could hook into the $EditFunctions with another  
>>> function
>>> that will do what you want it to do.
>>>
>>> Hope that gets you started in the right direction.
>>>
>>> -Peter
>>>
>>> On Mon, Aug 11, 2008 at 12:40 PM, Lars Grau <mail at larsgrau.de>  
>>> wrote:
>>>>
>>>> We have pmwiki-2.2.0-beta65 running with LDAP authentication. We
>>>> allow
>>>> only authenticated users to edit pages. ( In config.php:
>>>> $DefaultPasswords['edit'] = 'id:*'; )
>>>>
>>>> Now we'd like to add a checkbox "This is a public page" to the edit
>>>> form that does the following: If unchecked (default), the read
>>>> password for the page being edited should be set to "id:*" allowing
>>>> only authenticated users to VIEW the page. If the author activates
>>>> the
>>>> checkbox, the read password should be cleared.
>>>>
>>>> Can anyone point us into a direction how to do this via a cookbook
>>>> recipe or even better - provide the code? We're familiar with PHP  
>>>> in
>>>> general, but we'd like to keep PmWiki as close to the original
>>>> distribution for future updates and therefore need support in
>>>> "hooking" this into the software.
>>>>
>>>> Tricky sidenote: To be even more precise, if a read password has
>>>> already been set by "?action=attr" (i.e. "secret"), we'd like the
>>>> recipe to append the "id:*" rather than over-writing the entire
>>>> attribute. Same applies for clearing the field. The "id:*" should  
>>>> be
>>>> removed, but everything else should remain untouched.
>>>>
>>>> Thanks a lot in advance.
>>>>
>>>> Larsen.-
>>>>
>>>> _______________________________________________
>>>> pmwiki-users mailing list
>>>> pmwiki-users at pmichaud.com
>>>> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>>>>
>>
>>
>>
>>
>> _______________________________________________
>> pmwiki-users mailing list
>> pmwiki-users at pmichaud.com
>> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>>
>
>


Mobil: +49 (0)170 / 965 38 80

++++++++++++++++++++++++++++++++++++++++++++++++
Lars Grau, Grosse Hamburger 28, DE-10115 Berlin
T: +49 (0) 30 / 65 70 16-66, Fax: -68
mail at larsgrau.de





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20080818/86d27628/attachment-0001.html 


More information about the pmwiki-users mailing list