Automatic Creation of Userpages on registration
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:
- "createuserpage" => "on",
- "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));
$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);
}
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 ;)]
- Nils, nice idea - one extra feature I would like to see here is the automatic creation of a main header with the user name, so as to produce something like =====NilsLindenberg===== on page creation. This can either be done 'online' during page generation or by preg_replacing a placeholder on the template page. -- DarTar
- How about a short "who" action without you are? Do actions work in headers? --NilsLindenberg
- I was also thinking that on registration the user should be redirected either to his/her own new page, or to WelcomeUser which could have a dynamic link to the current user's page. --JavaWoman
- Yes, I definitely agree that on registration, the user should be redirected to WelcomeUser (which might also contain a dynamic welcome message like: Hi, ). -- DarTar
- Well, this is the case now. Except from the dynamic message. That is something the admin of a wiki has to/can do :) --NilsLindenberg
- I know that. But it is to the admin of a wiki, if he includes such thing into the template-page, or not. Not of the user-registration :) --NilsLindenberg
- Oh, I see what you mean now, Nils. The idea was to include such a "dynamic welcome" in the WelcomeUser page though - where it would be just the action. But then we'd have to create such a page on an install - for now it's only here... Hmmm. --JavaWoman
CategoryUserContributions
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.
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
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,
//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).
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?
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!
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.