|
Cookbook /
NewGroupBoxSummary: Input box to create new wiki groups from predefined template pages
Version: 2008-04-28
Prerequisites: pmwiki 2.1
Status: stable
Maintainer:
Download: newgroupbox.phpΔ
Questions answered by this recipeHow 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? DescriptionThis script is based on NewPageBoxPlus, but reverses group and name, so the name entered will be the group name, with a default HomePage. 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:
Possible parameters to use inside the markup:
The following options are only enabled if user has 'edit' authorisation, or var set:
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. NotesAutoGroupPagesA 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 HomePage, 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, HomePage, 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
CommentsThis works great, Hans! FYI, I am working on a course instruction wiki that would feature multiple courses separated into groups. NewGroupBox offers authors the ability to create a new 'course' without having to know a whole lot about how groups are constructed. Being able to specify the template is even cooler. Since there are several different pages that need to be edited for a new course (sidebar, menus, etc.) the next thing I'd like to do is figure out how to have a single entry "Group" and a bunch of different buttons that open up edit windows for each page within that previously-nonexistent group. Anyhow, thanks again. -- JonHaupt Jon, you could have one newgroupbox form to create an initial page from a template page. Use save=true in the newgroupbox, and populate the template page with newpagebox forms, each using a different template to create all the necessary standard pages in the target group. all templae pages can be in one location, for instance a Template group. -- HansB Hmm yeah, that's a great idea, sort of a temporary group-creation page. I've sort of done this already by creating edit links within the sidebar once you're in these groups that lead to pages using templates, but I like the idea of having a course help screen of sorts. -- JonHaupt
Hi Hans. I reckon NewGroupBox should have a different action name from NewPageBoxPlus (both use It is fixed now, and link targets get saved as well with save=true. -- HansB May 01, 2006, at 02:37 AM Hans, would it be possible to make it default that the new page name is the same as the new group name? So that if, for example, I made a new group Foo, then the new page created would be Foo.Foo rather than Foo.HomePage? That's the usual default when making new groups from scratch and I hate to lose that functionality. -- Kathryn Andersen July 29, 2006, at 08:50 PM Thanks for pointing this out! I changed the default now as to your suggestion. If HomePage shall be the default new group page one needs to add now base=HomePage to the markup. ~HansB RecentChanges Hi, Hans: I notice that creation of new pages with "save=true" via any of these variations doesn't add an entry to any (All)RecentChanges. I have a strong preference for having as much activity as possible reported, in some way or the other (there are other recipes I'd like to use but can't due to this problem of "invisible" activity). This recipe is so terrific that I'll probably use it anyhow, but it would sure be nice if you could find a way to add a "save=true" transaction to (All)RecentChanges. Thanks! TeganDowling August 16, 2006, at 01:05 PM (All)RecentChanges get updated on my (local) testsite. The script does call the function PostRecentChanges when save=true. So I don't know what is going on for you :-(
PS: The autogroup pages are (by design) (at the moment) not appearing in (All)RecentChanges ~HansB
of course, the autogroup method is what I was thinking of. So, you will/may have the autogroup method call PostRecentChanges eventually? - TeganDowling
I am working on it right now, I got it half working, for autogroup, but not for autopages... And I like to be able to disable it via a variable. Can you suggest a better name for $EnablePostRecentChangesForAutoGroupPages ? HansB
save=true It seems to make no sense to use "autogroup=true" without also using "save=true". Should you make autogroup=true automatically set save=true, as you did with autopages? Thanks again, TeganDowling August 16, 2006, at 01:18 PM Perhaps. But autogroup=true does the automatic creation of certain group pages, whereas save=true saves the page specified with base= automatically. Without save=true this page would open to be edited by the user. There may be ocasions where this is desirable I thought, so better keep that option. ~HansB
Call-time pass-by-reference has been deprecated. Error with PHP 5. Easy to fix; edit line 126. Sam Wilson May 12, 2007, at 02:36 AM I don't know what you mean nor what you suggesting to change. Can you explain please? HansB
In PHP it is not neccessary to pass (as parameters) references to variables; it is enough that the function being called marks the parameters as references. In this case: the function AutoGroupPages($pagename, &$page, &$new) (line 144 of version 2007-05-02) doesn't need to be called as AutoGroupPages($pagename, &$page, &$new) as it is in line 126, becuase PHP already knows that the second two parameters are references; the two ampersands can simply be dropped. (This applies to recent versions of PHP, > 5.0.5 I think, but I'm not sure about that.) Hope this helps. Sam Wilson May 12, 2007, at 08:44 PM
Oh, and another thing: User submitting form must have edit permissions on form page? I'm not quite sure if I've got this correct, but it looks to be (and my site was behaving this way) as if the person submitting the NewGroupBox form must have edit permissions on the page on which the form is, if I am trying to use NewGroupBox to create a collection of pages for a new group. However, it always blanks out whatever page I name in the base parameter. I am unable to pre-populate that page with information from my template. Am I abusing this recipe, or missing some underlying concept? Travis Risner March 18, 2008 at 6:00 PM ET. Hi - NewGroupBox works great until you start entering special characters (#$%^...) into the form. Note what happens in the following cases:
overtones99? April 26, 2008, at 03:32 PM Fixed now. - HansB April 28, 2008, at 11:21 AM Hi - i've modified a version of NewGroupBox for myself that implements Captcha. See below for the additions one would make to the code (highlighted in blue): beware - some of the longer lines have been cut in half so that they wrap w/o making the page too wide -- if running into compile problems, you may need to restore some of the longer lines to their full length
# add form function. The values for parameter defaults can be changed here
function NewGroupBox($pagename, $opt) {
global $ScriptUrl,
// ao - added captcha global vars //
... hi - i'm noticing that when i use newgroupbox to create a new group, the creation date for the new page is always incorrectly given as 31 Dec 1969... i'm currently using the following code (from the bottom of PageVariables to get the creation date: # add page variable in format yyyy-mm-dd
When i create a group the "natural" way - i.e. by typing a new group and page into the address bar and then saving the new page - i get the correct creation date...
ah, just figured this one out - it appears 'ctime' was added to NewPageBoxPlus, but not to NewGroupBox. here's what i added to the recipe in order to get a correct creation time:
if (@$_REQUEST['save'] AND ($EnableAutoSave==1 OR CondAuth($pagename,'edit'))) {
//if(PageExists($newpage)) Redirect($newpage, $urlfmt);
if(PageExists($newpage)) Redirect($nameTakenErrorRedirect); // my own code, different than newgroupbox
if (@$_REQUEST['template'] && PageExists($_REQUEST['template'])) {
$p = RetrieveAuthPage($_REQUEST['template'], 'read', false, READPAGE_CURRENT);
if ($p['text'] > '') $new['text'] = $p['text'];
$new['author'] = $Author;
}
$new['ctime'] = $Now; // was included in newpageboxplus, but not in newgroupbox
. . . and so forth
and then one must also add $Now to the global variables defined at the top of the function block...
... passing http variables into NewGroupBox & NewPageBoxPlus not working i recently appended to my 'Site.PageNotFound' an amended invitation to create the Page or Group the user was trying to reach. depending on whether it's the Page or the Group that's nonexistent, the link leads to an upload page where either NewGroupBox and NewPageBoxPlus are loaded. the link to this page has an http variable appended to it containing the Page (or Group), in the form: on the CreateNewGroup page, the http variable is passed into the NewGroupBox "value"-parameter via an http request (see EasyHttpRequests). the problem i was running into was that after hitting submit, nothing would happen - it would just redirect to the Uploads page, and no page or group would be created. if i deleted the default input of the variable, and re-typed it in manually and then submitted, it would successfully create and redirect me to the new group/page. i discovered that the problem in this scenario is relieved by commenting out the following line (in both NewGroupBox & NewPageBoxPlus): it makes sense that one wouldn't want the user to accidentally create a page with the name of the default text; however, this precaution preempts one from successfully submitting http variables... i wonder if there's a clever and efficient way to permit the variables and prevent the default submission? overtones99? June 29, 2008, at 05:37 AM ... See AlsoContributors |