|
Cookbook /
CustomAttrFormSummary: How to customise the prompt on the attributes page (?action=attr)
Version: 2009-07-24
Prerequisites: pmwiki 2.1 for changing the prompt; 2.2.5 for changing the actual inputs
Status:
Maintainer:
Discussion: CustomAttrForm-Talk
Questions answered by this recipeHow can I customise my Attributes page (?action=attr)? DescriptionThis page describes how to customise the prompt on the attributes page (?action=attr). The process of changing what is displayed when visiting any Attributes page is a two-parter - currently, one must deal with 1) the message at the top of the page separately from 2) the actual input fields presented at the bottom of the page. The following sections deal with these two separate set-up tasks. Changing the prompt messageThe default message on any page called via MyGroup.MyPage Attributes Enter new attributes for this page below. Leaving a field blank will leave the attribute unchanged. To clear an attribute, enter 'clear'. If you want to create your own custom prompt message, simply
NOTE: This only changes the text above the password inputs on the attributes page, but doesn't change the inputs themselves - the inputs have to be dealt with separately. We'll talk about that below.
Example: CustomAttrForm with 3-Tiered AuthThe following example (and the one in the next section) assumes a 3-tiered approach (admin-, attr-, & edit-users) to password set-up, geared for Group Projects that have their own Group on the wiki, with a Group "Admin" who maintains the group, and a single 'edit' password assigned for anyone else who is eligible to participate and add content. This setup only uses passwords, and no usernames. There are obviously other ways to do this, and differing scenarios, but this is the setup I find useful and hopefully it'll be useful for illustrating. It assumes the following password-setup:
And so here specifically are the roles and abilities that we've set up:
Here's an example of a CustomAttrForm (pasted into
/* THESE ARE THE INSTRUCTIONS FOR THE ADMIN & ATTR FORMS FOR CHANGING PASSWORDS */
(:linebreaks:)
[-[[{*$Group}/ | < Back to {*$Group}]]-]
!!{*$Groupspaced} :: Passwords
>>indent<<
/* INSTRUCTIONS FOR ADMIN, WITH REMINDERS, ETC - FOR ANY PAGE ON THE WIKI */
(:if expr auth admin && name GroupAttributes:)
Enter new default attributes for ''all pages'' in the group: '''''{*$Group}'''''.
(:if expr auth admin && !name GroupAttributes:)
Enter new attributes for this page only: '''''{*$Group}/{*$Name}'''''.
(:if auth admin:)
Leaving a field blank will leave the attribute unchanged.
Some common password inputs:
* To clear an attribute, enter ''clear''.
* To allow a page to be edited even if a group or site password is set, enter ''@nopass''
* To lock a page for everybody but the admin, enter ''@lock''
* To assign the any of the site's site-wide passwords, enter \
''@_site_edit'', ''@_site_read'', ''@_site_admin'' or ''@_site_upload''
/* MESSAGE FOR ATTR USERS, i.e. THE GROUP-ADMIN, ONLY ON THE GROUPATTRIBUTES PAGE */
/* Exclude any Groups that you don't want to display this message */
(:elseif expr auth attr && name GroupAttributes && !group Site,Main,PmWiki:)
Enter your new, ''case-sensitive'' password below.
Leaving a field blank will leave the password unchanged.
You may need to login again after changing your password.
/* Instruction on implementing Group Passwords */
'''For Groups:'''
## Decide on two separate passwords -- an ''adminPassword'' and an ''editPassword''.
*** The ''adminPassword'' is for you to maintain the group
*** The ''editPassword'' is for everyone in the group to edit pages and add content.
## Fill out the password blanks like this:
-->''Set new edit password:'' adminPassword editPassword
-->''[-(that's right, put both passwords in, with a space in between them)-]''
-->''Set new attribute password:'' adminPassword
-->''[-(the term "attribute" is PmWiki-lingo referring to the ability to change passwords -\
only the group admin should be able to do this)-]''
->That should do it.
If you run into any problems, just contact the [[mailto:webmaster@mysite.com | webmaster]] for some help.
(:ifend:)
>><<
overtones99 July 24, 2009, at 10:13 PM To the Group-Admin (auth attr), the message on the GroupAttributes page should now look like: My Group :: PasswordsEnter your new, case-sensitive password below.
Leaving a field blank will leave the password unchanged.
You may need to login again after changing your password.
For Groups:
That should do it.
If you run into any problems, just contact the webmaster -> mailto:webmaster [snail] mysite [period] com for some help. And for the Admin of the entire site (auth admin), the message on any Attributes page should now look like: My Group :: PasswordsEnter new attributes for this page below.
Leaving a field blank will leave the attribute unchanged.
To clear an attribute, enter 'clear'.
Some common password inputs include:
Changing the fieldsThe following information applies to PmWiki 2.2.5 (not-yet-released as of 7/25/09) and beyond, due to a bug in the core that previously prevented the following from working correctly... When visiting an Attributes page via
Example: MyPrintAttrForm FunctionFor this scenario, please imagine the 3-tiered password structure (admin, attr, edit) that was used in the previous example. We have created a new function,
# Have the HandleAttrFmt function call our function instead
$HandleAttrFmt = array(&$PageStartFmt, &$PageAttrFmt, 'function:MyPrintAttrForm', &$PageEndFmt);
# Our new function, substituting for PrintAttrForm in pmwiki.php
function MyPrintAttrForm($pagename) {
# ALL OF THIS TOP PART IS THE SAME AS IN THE ORIGINAL PrintAttrForm FUNCTION
global $PageAttributes, $PCache, $FmtV;
echo FmtPageName("<form action='\$PageUrl' method='post'>
<input type='hidden' name='action' value='postattr' />
<input type='hidden' name='n' value='\$FullName' />
<table><br>",$pagename);
$page = $PCache[$pagename];
foreach($PageAttributes as $attr=>$p) {
if (!$p) continue;
if (strncmp($attr, 'passwd', 6) == 0) {
$setting = PageVar($pagename, '$Passwd'.ucfirst(substr($attr, 6)));
$value = '';
} else { $setting = @$page[$attr]; $value = @$page[$attr]; }
$prompt = FmtPageName($p,$pagename);
# THIS IS WHERE YOU MIGHT ADD SOME CONDITIONALS,
# LIMITING CERTAIN INPUTS TO ONLY APPEAR ON CERTAIN PAGES OR FOR CERTAIN USERS
# IT'S A LOOP, GOING THROUGH EACH OF THE ATTRIBUTES COLLECTED IN THE $PageAttributes ARRAY
## my 3-tiered Group Version: only display 'edit' & 'attr' for attr-users
if( # if admin, show all
CondAuth($pagename, 'admin')
||
# if user has attr-privileges, show 'edit' and 'attr' fields
( strpos($attr,'edit')==true || strpos($attr,'attr')==true )
)
{
# this is simply the Input field that will appear for each attribute
# for which the above conditional proves true - probably want to leave this alone
echo "<tr><td><i>$prompt</i></td>
<td><input type='text' name='$attr' value='$value' /></td>
<td>$setting</td></tr>";
}
}
echo FmtPageName("</table><input type='submit' value='$[Save]' /></form>", $pagename);
}
overtones99 July 24, 2009, at 10:13 PM NotesRelease notes
See also
ContributorsCommentsSee discussion at CustomAttrForm-Talk User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |