NewGroupBox

Summary: Input box to create new wiki groups from predefined template pages
Version: 2017-06-17
Prerequisites: PmWiki 2.2.56 (compatible with PHP 5.5)
Status: stable
Maintainer:
Categories: Forms CMS PHP55 PHP72
Users: +2 (view / edit)
Discussion: NewGroupBox-Talk

Questions answered by this recipe

How can I enter the name of a group into a form, and a new page in the new group is created?
How can I create a newgroup from a set of predefined template pages?

Description

This script is based on NewPageBoxPlus, but reverses group and name, so the name entered will be the group name, with a default of {$DefaultName}.
The form can be defined to create other pages by specifying a base=Group.Name parameter.

Download newgroupbox.phpΔ and place it into the cookbook/ folder and add to a local customization file:

include_once("$FarmD/cookbook/newgroupbox.php");

Usage:

(:newgroupbox [parameter=value] [parameter=value] :)

Possible parameters to use inside the markup:

  • base=PageName -- creates new group page as NewName.PageName (PageName does not need to exist). Default is NewName.{$DefaultName}. So if you want HomePage to be your new group page, set base=HomePage.
  • template=Group.PageTemplateName -- use Group.PageTemplateName as template for new page.
  • value="Create New Group" -- label or value for the inside of the field, which disappears when clicking the box. Default is empty: "".
  • size=number -- size of input box, default is 30.
  • label="Button Label" -- label for the button, default "Create a new group called:".
  • button=position -- use "left" or "right" to position button (default is "left").
  • focus=true -- adds onfocus and onblur javascript which will make any initial value disappear when clicking on the box. Default is "".

The following options are only enabled if user has 'edit' authorisation, or var set: $EnableAutoSave = true;

  • save=true -- automatically saves the new page, if it does not exist already.
  • autogroup=true -- automatically creates various group pages according to template pages. See below.
  • autopages=Templates.HomePage,Templates.Page1,Templates.Page2 -- set a list of template pages, which will automatically be created in the new group. Specify also a base=PageName as one of the new pages, so the form can redirect to that page after creating all the new pages. save=1 does not need to be specified, autogroup=1 and template= will be ignored.

Example:

(:newgroupbox base=Index template=Site.NewIndexPage :)

Entering "Name" will create a new page called Name.Index, prefilled with content from Site.NewIndexPage

(:newgroupbox base=HomePage autopages=Templates.HomePage,Templates.Page1,Templates.GroupHeader :)

Entering "Name" will create new pages Name.HomePage, Name.Page1, Name.GroupHeader and redirect to Name.HomePage.

Notes

AutoGroupPages

A number of new group pages can be created automatically using the parameter autopages=[List of template pages]. See parameter autopages= above.

Alternatively by adding the option autogroup=true a {$DefaultName}, GroupHeader and GroupFooter page is created automatically according to template pages in the Templates group, whenever a new group page is created. More or different pages can be added by redefining the $AutoGroupPagesFmt array. This feature can be combined with the save=true option to create new groups with several predefined pages instantly.

Make sure you set the variables in config.php before including the newgroupbox.php script.

Thanks Pm for providing the AutoGroupPages function!

So for instance to create groups with pages MyPage1, MyPage2, omePage, GroupHeader and GroupFooter you add to config.php:

$AutoGroupPagesFmt = array(
    'Templates.MyPage1' => '{$Group}.MyPage1',
    'Templates.MyPage2' => '{$Group}.MyPage2',
    'Templates.HomePage' => '{$Group}.HomePage',
    'Templates.GroupHeader' => '{$Group}.GroupHeader',
    'Templates.GroupFooter' => '{$Group}.GroupFooter',
     );
  include_once("$FarmD/cookbook/newgroupbox.php");

and on the group launching page you put:

(:newgroupbox save=true autogroup=true:)

or for a different display style:

(:newgroupbox label=Go button=right value="Create new group" focus=true save=true autogroup=true:)

And create all five template pages in the Templates group with the relevant content to prepopulate your new group pages.

To have the function AutoGroupPages available generally, i.e. creating the default auto pages everytime a new page is created, not just through newpagebox, set in config.php

$EditFunctions[] = 'AutoGroupPages'; 
$EnableAutoSave = true;

Release Notes

  • 2017-06-17: Updated for PHP 7.2 compatibility
  • 2015-05-14: Updated for PHP 5.5 compatibility, fixed Lambda in created page name, use {$DefaultName} to set group's default page name (in line with PmWiki)
  • 2008-04-28: Added filter to exclude non-url characters. Fixed Call-time pass-by-reference error.
  • 2007-05-19: Added check to stop overwriting a page defined with $AutoGroupPagesFmt
  • 2007-05-02: Fixed buggy action=PageUrl
  • 2007-01-25: Optimised code so HTML output is minimised. Hidden fields are only added when needed by the markup. Removed size default.
  • 2006-11-27: Added var SDV($EnableAutoSave, false);. Automatic saving of new group pages is now possible only if a) user is authorised at 'edit' level, or $EnableAutoSave = true;
  • 2006-10-28: Added $RecipeInfo
  • 2006-08-17: Added ability for autopages and autogroup to post changes to (All)RecentChanges. Tidied up code. Swapped key => value around in $AutoGroupPagesFmt.
  • 2006-08-05: Added parameter autopages= to set a list of template pages for automatic group creation.
  • 2006-08-01: Added support to create automatically a number of pages for a new group. See AutoGroupPages above.
  • 2006-07-31: Changed default group page from Group.HomePage to Group.Group. If a Group.HomePage shall be created, add parameter base=HomePage to markup.
  • 2006-05-01: changed HandleAction to newgroup to avoid possible conflicts with newpagebox script. Added call to SaveAttributes when save=true, which saves link targets.
  • 2006-04-11: initial release

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

Contributors

Comments

See discussion at NewGroupBox-Talk

User notes +2: 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.