Added more flexibility for templates

This commit is contained in:
Simon DELAGE 2014-09-03 01:45:56 +02:00
parent 71d672d3e6
commit 96781dbd83
6 changed files with 26 additions and 12 deletions

View file

@ -16,6 +16,23 @@ require_once (DOKU_PLUGIN . '/acl/admin.php');
class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
function register(&$controller) {
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array());
$controller->register_hook('AUTH_LOGIN_CHECK', 'AFTER', $this, 'templates',array());
}
function templates(&$event, $param) {
if (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt')) {
if (!copy(DOKU_INC.'lib/plugins/userhomepage/userhomepage_private_template.txt', DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt')) {
echo ' An error occured while attempting to copy private template.';
} else {
echo ' Successfully copied private template.';
}
}
if (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt')) {
if (!copy(DOKU_INC.'lib/plugins/userhomepage/userhomepage_public_template.txt', DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt')) {
echo ' An error occured while attempting to copy public template.';
} else {
echo ' Successfully copied public template.';
}
}
}
function redirect(&$event, $param) {
global $conf;
@ -55,7 +72,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
// Write things back to conf/acl.auth.php
file_put_contents(DOKU_INC.'conf/acl.auth.php', implode($lines));
// Read private start page template
$this->private_page_template = DOKU_INC . $this->getConf('templatepath');
$this->private_page_template = DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt';
// Create private page
lock($this->private_page);
saveWikiText($this->private_page,$this->_template_private(),$lang['created']);
@ -67,7 +84,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
// If public page doesn't exists, create it (from template)
if ($this->getConf('create_public_page') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) {
// Read public page template
$this->public_page_template = DOKU_INC . $this->getConf('templatepathpublic');
$this->public_page_template = DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt';
// Create public page
lock($this->public_page);
saveWikiText($this->public_page,$this->_template_public(),$lang['created']);

View file

@ -13,8 +13,7 @@ $conf['users_namespace'] = 'private';
$conf['set_permissions'] = 1;
$conf['set_permissions_others'] = '0';
$conf['group_by_name'] = 1;
$conf['templatepath'] = 'lib/plugins/userhomepage/_template_private.txt';
$conf['edit_before_create'] = 0;
$conf['create_public_page'] = 0;
$conf['public_pages_ns'] = 'user';
$conf['templatepathpublic'] = 'lib/plugins/userhomepage/_template_public.txt';
$conf['templates_path'] = 'data/pages/wiki';

View file

@ -13,8 +13,7 @@ $meta['users_namespace'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/');
$meta['set_permissions'] = array('onoff');
$meta['set_permissions_others'] = array('multichoice','_choices'=>array('0','1','2','4','8','16'));
$meta['group_by_name'] = array('onoff');
$meta['templatepath'] = array('string');
$meta['edit_before_create'] = array('onoff');
$meta['create_public_page'] = array('onoff');
$meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/','_caution' => 'warning');
$meta['templatepathpublic'] = array('string');
$meta['templates_path'] = array('string');

View file

@ -7,7 +7,7 @@
*/
$lang['create_private_ns'] = 'Create user\'s private namespace';
$lang['use_name_string'] = 'Use user\'s full name instead of login for his namespace and homepage (will break <code>%USER%</code> wildcard in ACL for that namespace).';
$lang['use_name_string'] = 'Use user\'s full name instead of login for his namespace (will break <code>%USER%</code> wildcard in ACL for that namespace).';
$lang['use_start_page'] = 'Use the wiki\'s start page string instead of the user\'s namespace string set above for the start page of his namespace.';
$lang['users_namespace'] = 'Namespace under which user namespaces are created (can be anything but <code>user</code> without messing up with Dokuwiki default behaviour).';
$lang['set_permissions'] = 'Automatically configure acl for the namespace set above and give full rights to users on their own namespace.';
@ -18,9 +18,8 @@ $lang['set_permissions_others_o_2'] = 'Edit';
$lang['set_permissions_others_o_4'] = 'Create';
$lang['set_permissions_others_o_8'] = 'Upload';
$lang['set_permissions_others_o_16'] = 'Delete';
$lang['group_by_name'] = 'Group users\' namespaces by the first character of user name ?';
$lang['templatepath'] = 'Doku relative path to the template file for user\'s namespace start page.';
$lang['edit_before_create'] = 'Allow users to edit their namespace start page before create.';
$lang['group_by_name'] = 'Group users\' namespaces by the first character of user name?';
$lang['edit_before_create'] = 'Allow users to edit their namespace start page before create (this will only work if you disable [create_public_page]).';
$lang['create_public_page'] = 'Create a public page for user';
$lang['public_pages_ns'] = 'Namespace under wich public pages ar created. If a value other than \'user\' is used, ?????????????????';
$lang['templatepathpublic'] = 'lib/plugins/userhomepage/_template_public.txt';
$lang['public_pages_ns'] = 'Namespace under wich public pages are created. If a value other than <code>user</code> is used, you will have to manually handle interwiki user link used by <code>showuseras</code> option (in Display settings).';
$lang['templates_path'] = 'Path from DokuWiki root to store templates (userhomepage_private_template.txt and userhomepage_public_template.txt). Examples: <code>data/pages/wiki</code> (wich will make templates editable within DokuWiki) or <code>lib/plugins/userhomepage</code> (usefull in a farm setup to centralize templates).';