|
Cookbook /
OpenPassSummary:Set a global password which is openly displayed to reduce spam
Version: 2009-05-01B
Prerequisites:
Status: Alpha
Maintainer: Peter Bowers
Questions answered by this recipe
DescriptionSet a global "edit" password to prevent spambots but make sure human authors know the password. NotesThe purpose of this recipe is to display a message in the AuthForm so that users can see the open password if that is the password which is active for this page. But if the page is protected by a page-level or group-level password (i.e., not the "public" or "open" site-level password) then we don't want the message to display. Installation
(:if equal {$editpass} "site" :)%red%(If you don't know a password for this page, try entering "{$OpenPasswd}"
(without the quotes).%% This is an '''open''' password to prevent spamming by robots but still allow
you [as a human who can read the page and follow instructions] to make changes.)(:ifend:)
function MyPasswdVar($pagename, $level)
{
global $PCache, $PasswdVarAuth, $FmtV;
$page = $PCache[$pagename];
if (!isset($page['=passwd'][$level])) {
$page = RetrieveAuthPage($pagename, 'ALWAYS', false, READPAGE_CURRENT);
if ($page) PCache($pagename, $page);
}
$pwsource = $page['=pwsource'][$level];
if (strncmp($pwsource, 'cascade:', 8) == 0)
return( substr($pwsource, 8));
return ($pwsource);
}
# Implement an OPEN PASSWORD on all groups to help prevent spam
if ($action == 'edit') {
$openpasswd = 'my_open_pass'; // CHANGE THIS to the open password you are going to use
$FmtPV['$OpenPasswd'] = "'$openpasswd'"; // for use in Site.AuthForm
$DefaultPasswords['edit'] = crypt($openpasswd);
$FmtPV['$editpass'] = 'MyPasswdVar($pagename,"edit")';
}
There have been some requests to see whether this could be configured in an alternative fashion so that the open password was only displayed (and valid) for certain "open groups" (primarily for commenting purposes). I don't see any problems with the solution below, but it needs someone to do some careful testing... (The function
# Implement an OPEN PASSWORD with simple-password authorization on certain groups, authuser with id:* for all other groups
$pagename = ResolvePageName($pagename);
$group = PageVar($pagename, '$Group');
# CHANGE THIS in the line below so that 'GroupA' and 'GroupB' become the group(s) that you want to have the open password
if ($action == 'edit' && in_array($group, array('GroupA', 'GroupB'))) {
$openpasswd = 'my_open_pass'; // CHANGE THIS to the open password you are going to use
$FmtPV['$OpenPasswd'] = "'$openpasswd'"; // for use in Site.AuthForm
$DefaultPasswords['edit'] = array(crypt($openpasswd), 'id:*');
$FmtPV['$editpass'] = 'MyPasswdVar($pagename,"edit")';
} else {
$DefaultPasswords['edit'] = 'id:*'; // CHANGE THIS if you are wanting some other type of authorization for site-wide editing
$EnableAuthUser = 1;
include_once("scripts/authuser.php");
}
Release Notes
See AlsoContributorsFunction based off of PasswdVar from pmwiki.php, thus credit to PM. Comments
User notes +1: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date * (-) Optional negative comment. Name, date These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |