ShowPasswordProtection

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Goal

On a site where you want to set password protection on a page-by-page basis, it's handy to know when that protection has been put in place on a particular page. This cookbook item describes how to do so.

Solution

Add the following code to your local config.php file.

   $PageHasReadPassword = '';
   $PageHasEditPassword = '';
   $page = ReadPage($pagename);
   if (isset($page['passwdread'])) $PageHasReadPassword = 'readpw set';
   if (isset($page['passwdedit'])) $PageHasEditPassword = 'editpw set';

Discussion

The two variables can be placed in your site or group .tmpl file wherever you want the flag strings to show up. I put mine at the end of the div that has the search field stuff up at the top ...

    <input class='searchbutton' type='submit' value='Go' /></form>
    <!-- insert flags for passwords -->
    $PageHasReadPassword $PageHasEditPassword</div>

... which puts the little flags right under the search box at the top, visible but not obtrusive.

You can configure the flag strings to whatever you want -- short and cryptic ("RPW," "EPW") or long and verbose ("This page has an edit password set. You will not be able to edit this page without the administrator providing you with a password.")

See Also

Nothing to see here. Move along.

History

  • 19-May-04 - New.

Comments & Bugs

This solution does not work to show whether the passwords have been set in the config file, only if the page has had the passwords set ad hoc.

If you change the code slightly by adding some if statements, the above bug can be sidestepped:

   $PageHasReadPassword = '';
   $PageHasEditPassword = '';
   $page = ReadPage($pagename);
   if (isset($page['passwdread']) ||
      (isset($DefaultPasswords['read']) && $DefaultPasswords['read'] != '')) {
         $PageHasReadPassword = 'readpw set';
   }
   if (isset($page['passwdedit']) ||
      (isset($DefaultPasswords['edit']) && $DefaultPasswords['edit'] != '')) {
          $PageHasEditPassword = 'editpw set';
   }

--Profiles/JamesHunt

Contributors

  • Profiles/DaveHill asked the question on the PmWiki e-mail list.
  • Pm did all the heavy lifting in figuring out the code (14-May-04)

Copyright

None, so far as I know ... pmwiki-2.3.32 -- Last modified by {{}}?

from IP: 85.171.160.186 ip should be disabled by default for security reasons