|
Cookbook /
EditAttributesSummary: Edit a page's title, description and other attributes using separate EditForm fields
Version: 2009-08-28
Prerequisites: PmWiki 2.2.x
Status: beta
Maintainer: Eemeli Aro
Discussion: EditAttributes-Talk
Download: editattr.phpΔ
Questions answered by this recipe
DescriptionBy default, each PmWiki page is stored not only with its text, but with some additional attributes or meta information as well, such as the page's title and description, the character set the page is saved in, and information about the last page edit. EditAttributes allows you to directly edit these attributes as well as adding your own. EditAttributes is partly based on and partly duplicates the functionality of Mike Shanley's EditMore, which in turn is based on Waylan Limberg's EditTitle. Unlike those recipes, EditAttributes is easily customisable for completely new attributes. To install this recipe:
ConfigurationNOTE: The format of EditAttributes is configured using an array
The example given above in the installation instructions sets up the page title, description and keywords to be stored both as a directive in the page text and as a separate page attribute; this is in fact the normal state of affairs for PmWiki. If using the above, you'll also need to add the following to Site.EditForm: (:input e_title:) (:input e_description:) (:input e_keywords:) If these are not present, editing and saving a page may clear these values. The general form for these input directives is For another example, I currently use the following: $EditAttrFields = array(
'title' => array(
'attribute' => 2,
'markup' => array( '\(:title (.*?):\)' => '' ),
'filter' => 'EditAttrAutofillTitle',
'input' => array( 'tabindex' => 1 ) ),
'description' => array(
'attribute' => 2,
'markup' => array( '\(:description (.*?):\)' => '' ),
'input' => array( 'tabindex' => 2 ) )
);
The The title's NotesEffectively, this recipe is a byproduct of a partial thought towards implementing something like what Pm describes here — a way to keep information about users in page attributes. In order to be able to do that, we need a way of editing them; hence EditAttributes. It is quite possible to define edit fields for already existing attributes such as page read or edit passwords, but viewing or editing these will require the same permissions as otherwise. Also, some attributes, such as those pertaining to the current modification, are overwritten by PageStore::write() when posting the page; hence modifying them is essentially useless. If you want to require a field to be non-empty in order to save a page, set its Page markup is inserted to the end of a page, not the beginning. Doing it this ways means that an included page can't overwrite the current page's title with the normal page directive markup. Accessing any new page attributes is for now left to the user, as this may vary significantly between use cases. For the simplest approach, you may use as a reference $FmtPV['$Description'] => '@$page["description"]'
Which sets up a page variable Example: page text variable checkboxThe following allows you to toggle the value of the page text variable on Site.EditForm: in $EditAttrFields['myPTV'] = array(
'markup' => '(:myPTV:$1:)',
'input' => array(':html' => "<input type='checkbox' \$InputFormArgs />"));
Example: ctimeFor a more complex example, the Bloge recipe uses EditAttributes to make the page on Site.EditForm: in $EditAttrFields['ctime'] = array( 'attribute' => 2, 'filter' => 'BlogeFilterCtime' );
function BlogeFilterCtime($pagename, $fn, &$new) {
global $Now, $MessagesFmt, $TimeFmt, $EnablePost;
$ct = trim($new['ctime']);
$t = empty($ct)
? $Now
: preg_match('/^\d{9,}$/', $ct)
? intval($ct)
: strtotime($ct);
if (!$t) {
$t = $Now;
$MessagesFmt[] = "<h3 class='wikimessage'>$[Error parsing time:] $ct</h3>";
}
$new['ctime'] = $EnablePost ? $t : strftime($TimeFmt, $t);
}
Release Notes
See AlsoContributorsCommentsSee discussion at EditAttributes-Talk User notes +4: 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. |