Automatic Creation of Userpages on registration

Last edited by JavaWoman:
Modified links pointing to docs server
Mon, 28 Jan 2008 00:10 UTC [diff]


Based on a request in the SuggestionBox, this code will automatically create the page of a newly registered user. Therefore it uses another page, you can choose, as template.
Code is mostly borrowed from Clonepage-handler (thanks!).

Note that this needs some testing, for example it will surely fail, if you don't give the user the right to load (view?) the template-page.

The user is redirected to WelcomeUser after registration. If you don't want that, just delete the $this->Redirect(WelcomeUser); line after inserting the code.

1. Additions to Wikka.config.php


add the following to lines to the config-array:
  1. "createuserpage" => "on",
  2. "userpagetemplate" => "YourTemplatePage"


Perhaps you want to change YourTemplatePage to the page which will be the template for the new users.

2. Changes to actions/usersettings.php


add after

                                // log in
                                $this->SetUser($this->LoadUser($name));


                                $createuserpage = $this->GetConfigValue('createuserpage');
                    if ($createuserpage == 'on')
                                {
                                    $from = $this->GetConfigValue('userpagetemplate');
            $note = 'automatic creation';
            $thepage=$this->LoadPage($from); # load the source page
            if ($thepage) $pagecontent = $thepage['body']; # get its content
            $this->SavePage($name, $pagecontent, $note); #create target page
            $this->Redirect(WelcomeUser);
                                }


3. Todo and comments

- make the note for the creation a config-option (i love having everything configurable ;) --NilsLindenberg
- document
- test a little bit more
- offtopic: urgent note to myself: before registering ten times, should not forget to "comment-in" the code [don't ask ;)]





CategoryUserContributions
Comments
Comment by TimoK
2005-03-09 14:15:55
Works nice, although I have a little 'problem': On most of my wikkis editing of pages is restricted to known users. I would like to make an exception for the userpages tho, but therefor they would have to be created regardless of ACL and given special ACL to.
I could modify action/usersettings.php to simply create the page without the use of SavePage() and setting the ACL would be no problem either, but it would be a dirty hack and maybe this "feature" is considered useful enough to think about a clean solution together and implementing it.
Comment by TimoK
2005-03-28 12:40:49
Ok, I 'fixed' my problem.
In the config_array I added:
"userpage_override_acl" => "1",
in wikka.php I modified the SavePage function like this
function SavePage($tag, $body, $note, $autocreation = FALSE)
{
// get current user
$user = $this->GetUserName();

// TODO: check write privilege
if ($autocreation && $this->config["userpage_override_acl"]) {
$writing_user = $this->config["default_write_acl"];
} else {
$writing_user = $user;
}
if ($this->HasAccess("write", $tag, $writing_user))
{
...
And in actions/usersettings.php I use
$this->SavePage($name, $pagecontent, $note, TRUE); #create target page
instead of
$this->SavePage($name, $pagecontent, $note); #create target page
Comment by BloodshotEye
2010-08-24 04:05:53
I'm using Wikka 1-2.p1 and can't get a welcome page to show on new registrations.

I created a page called WelcomeUser in CategoryWiki and made the change to usersettings.php - I put the edited file into /plugins/actions. Also I added the inrtuctions into Wikka.config.php

Can someone tell me where I went wrong? - could it have something to do with the fact we're using InheritACLs and ACLsWithUserGroups?

Cheers,
Comment by BrianKoontz
2010-08-24 20:30:44
I just tried this and it worked fine for me. The line of interest in usersettings.php is:

//create URL
$url = $this->Href();

Changing this to the following should work:

$url = $this->Href('', 'WelcomeUser');

Also, make sure the action_path var in wikka.config.php is set to 'plugins/actions,actions'. Also, you'll need to ensure plugins/actions/usersettings is created as well (the dir structure in plugins should mirror the actions dir exactly).
Comment by BloodshotEye
2010-08-25 02:09:23
Hi Brian,
This is the only line I could find in the default usersettings.php:
//create URL
//$url = $this->config['base_url'].$this->tag;

I changed it to:
$url = $this->Href('', 'WelcomeUser');

Unfortunately it made no difference. After logging in (there is also a registration Recaptcha) the page remains on usersettings.php

wikka.config.php is correctly set

When you say "the dir structure in plugins should mirror the actions dir exactly" you mean only user edited files (eg required by an action), need be moved there?
Comment by BrianKoontz
2010-08-25 21:00:59
I'm sorry, I was in the wrong version! (Too many version on my dev machine...)

There were some changes in 1.3 that cleaned up some dubious logic in usersettings.php. What is happening is that the previous page is being cached as a "go_back" page. This is in lines 530-536 of usersettings.php.

A quick fix, until you update to 1.3, is to do the following:

Comment out lines 530-538 and line 541

Hardcode in the page you want users to be redirect to when they log in in line 540:

$redirect_url = $this->Href('', 'WelcomePage');
$this->Redirect($redirect_url.$params)

The problem with changing $url in line 132 is that it's also used by the logout block, so the user ends up logging out and being redirected to your WelcomePage. If this is OK, then by all means modify line 132 instead!

Disregard my comment about the dir structure in plugins...you should have plugins/actions/usersettings.php

Sorry for the confusion!
Comment by BloodshotEye
2010-08-26 13:09:29
Sorry Brian, I tried this and it still goes to the standard page after login - must be a user error somewhere. I have your e-mail address, so if you don't mind I'll send you both usersettings.php and wikka.config.php - just to see if I have properly done what you say.

I'm keen to get this right because a carefully crafted welcome page is a great way for a new user to get up and running.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki