[pmwiki-users] Script to make a page private (instead of public)

Karl Schilke schilkek at onid.orst.edu
Wed Aug 20 16:32:45 CDT 2008


On Monday, Aug 18, 2008, Lars Grau posted a simple script to provide a  
"make this page public" checkbox on the edit page. I've been looking  
for the opposite functionality; I want a checkbox that sets the read  
password to 'id:*' when checked.

I hacked the script provided by Lars (see below) to provide this,  
calling it from local/config.php when '$action' is "edit", and  
included a checkbox input called 'e_private' in Site.EditForm:

     (:input e_private :) $[Make page private] \\

This much appears to work correctly, in that the read password is set  
or cleared on save, depending on the state of the checkbox.

Now I'd like to have it set the checkbox appropriately, depending on  
the presence of the string 'id:*' in the read password. However, it  
always comes up with the box unchecked.

Changing the test in CheckPassword() to 'if (!strstr($rpw, 'id:*'))  
...' makes it come up checked every time. I gather that either the  
script is not correctly loading the read password, or there's  
something wrong with the string search in CheckPassword().

I know I'm missing something obvious, but could someone please take a  
look at this code and see what's wrong?

Thanks in advance!

     -Karl Schilke, Oregon State University

///////////////////////////////////////////////////////////////////////////////
// Here is my version of Lars' script, renamed 'makeprivate.php':
///////////////////////////////////////////////////////////////////////////////

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

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

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

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

CheckPassword()
     - get current page read password(s)
     - if checkbox "private" is set, make sure "id:*" is SET in
             read passwd field, else REMOVE "id:*" from 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_private"], array(
             ':html' => "<input type='checkbox' $InputFormArgs />",
             'name'  => 'private',
             'value' => 'no'));

     // If password contains "id:*", make private box checked
     if (strstr($rpw, 'id:*')) {
         SDV($InputTags['e_private']['checked'], 'checked');
     }
}

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

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

function MakePrivatePage($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 (@$_REQUEST['private']) {
             // if private requested, and read password does NOT  
contain "id:*",
             // append it to the read password.
             if (!strstr($rpw, 'id:*'))
                 $rpw .= ' id:*'; // Note the BLANK!

         } else {
             // page is no longer private, so check for and remove 'id:*'.
             if (strstr($rpw, 'id:*'))   // If 'id:*' in read passwd,  
remove it.
                 $rpw = str_replace('id:*', '', $rpw);

         }

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



-- 
"Much of the difference between rodent and human intelligence can be
attributed to quantity, not quality." -Kevin Warwick




More information about the pmwiki-users mailing list