[pmwiki-devel] idea: categories defining properties

Hans design5 at softflow.co.uk
Thu Nov 29 08:21:57 CST 2007


Tuesday, November 27, 2007, 10:34:23 PM, ben wrote:

> * A user-friendly way to assign pages to categories.  Freebase uses an
> AJAX-powered combo box, but we could go lower-tech with a select-multiple
> and a text input.

In PmWiki a 'category' is just a page in a group 'Category' (and it
does not need to exist even), and we are using a custom link in the
page text to link to this category page [[!SomeCategory]]. then the
link= paramete rin pagelist can display all pages which ar elinke dto
a category(page). So categories are not page attributes.

If you talk about multiple select boxes for assigning categories the
question spring to my mind: how are the categories added to the page
text? We would need to insert links to the category pages. Or are you
suggesting that categories should become page attributes, or a page
attribute, like 'text', 'csum', 'author'? Then a custom field on an
edit form can write the custom attribute, like a list of categories.

> * Conditional markup to test what categories the page currently belongs to
>  (Does this already exist?)

This is connected with the above: if categories are links in the page
text we could extract them with  a markup expression. If categories
are page attributes we can also extract them with  a different markup
expression, or better as a page variable. The list of categories in
form of a list of comma-separated page names we can use in a pagelist.

> * A new recipe to customize EditForm and SiteHeader to display the
> appropriate form fields and templates.

A general custom EditForm can be built which can show input controls
according to which categories the page is connected to. It can use a
pagelist to add input form elements for instance from each category
page the page is connected to.

I just tested the last and it works fine. I also wrote a markup
expression which extracts category links from  a page, and this works
fine within the pagelist employed in the edit form. I am not sure what
the custom controls from category pages should do, but the potential
is there to write any custom page attributes, which will make the page
more like  a data base record, or to employ some form processing script
and write page text variables or whatever into the page text.

And there is also the editform=PAGENAME parameter, which one could
add to ?action=edit and load a custom edit form on edit.

Here is a markup expression for extracting a category list:

# {(catlist PAGENAME)} extracts a list of full pagenames
# of all category links on a page
$MarkupExpr['catlist'] = 'CategoryList($pagename, $args[0])';
function CategoryList($pn, $arg='') {
        global $CategoryGroup;
        if($arg) $pn = MakePageName($pn, $arg);
        $page = RetrieveAuthPage($pn, 'read', true);
        $pat = '/\\[\\[\\!(.*?)\\]\\]/';
        if(preg_match_all($pat, $page['text'], $matches)) {
        foreach($matches[1] as $i=>$m)
                $matches[1][$i] = $CategoryGroup.".".$m;
        return implode(",", $matches[1]);
        }
}

Here is a pagelist directive for use in a custom edit form:

(:pagelist name={(catlist {*$FullName})} fmt=#catform :)

and here is the #catform pagelist template, which will load any
category specific edit form elements, from the category page's
#editform section:

[@
[[#catform]]
(:include Category.{=$Name}#editform :)
[[#catformend]]
@]


Hans




More information about the pmwiki-devel mailing list