Added ACL for public pages

This commit is contained in:
Simon DELAGE 2014-09-07 07:20:41 +02:00
parent e83baa691b
commit ac71e08bdf
4 changed files with 28 additions and 20 deletions

View file

@ -60,23 +60,6 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$this->public_page = cleanID($this->getConf('public_pages_ns').':'. $_SERVER['REMOTE_USER']);
// if private page doesn't exists, create it (from template)
if ($this->getConf('create_private_ns') && !page_exists($this->private_page) && !checklock($this->private_page) && !checkwordblock()) {
// set acl's if requested
if ( $this->getConf('set_permissions') == 1 ) {
$acl = new admin_plugin_acl();
// Old user-page ACL (version 3.0.4):
// $ns = cleanID($this->private_ns.':'.$this->privatePage());
// New user-namespace ACL (based on Luitzen van Gorkum and Harmen P. (Murf) de Ruiter suggestions):
$ns = cleanID($this->private_ns).':*';
$acl->_acl_add($this->getConf('users_namespace').':*', '@ALL', (int)$this->getConf('set_permissions_others'));
$acl->_acl_add($this->getConf('users_namespace').':*', '@user', (int)$this->getConf('set_permissions_others'));
$acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE);
}
// If the 2 lines concerning set_permissions_others above allready existed in conf/acl.auth.php file they've been duplicated so let's read the file
$lines = file(DOKU_INC.'conf/acl.auth.php');
// Only keep unique lines (OK, we loose an empty comment line...)
$lines = array_unique($lines);
// 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('templates_path').'/userhomepage_private.txt';
// Create private page
@ -98,6 +81,28 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
// Note that we created public page
$created['public'] = true;
}
// Set ACL?
if ($this->getConf('set_permissions')) {
$acl = new admin_plugin_acl();
$acl->_acl_add($this->getConf('users_namespace').':*', '@ALL', (int)$this->getConf('set_permissions_others'));
$acl->_acl_add($this->getConf('users_namespace').':*', '@user', (int)$this->getConf('set_permissions_others'));
if ($this->getConf('use_name_string')) {
$ns = cleanID($this->private_ns).':*';
$acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE);
} else {
$acl->_acl_add($this->getConf('users_namespace').':%USER%:*', '%USER%', AUTH_DELETE);
}
// ACL for public user pages
$acl->_acl_add($this->getConf('public_pages_ns').':*', '@ALL', AUTH_READ);
$acl->_acl_add($this->getConf('public_pages_ns').':*', '@user', AUTH_READ);
$acl->_acl_add($this->getConf('public_pages_ns').':%USER%', '%USER%', AUTH_EDIT);
}
// If the 2 lines concerning set_permissions_others above allready existed in conf/acl.auth.php file they've been duplicated so let's read the file
$lines = file(DOKU_INC.'conf/acl.auth.php');
// Only keep unique lines (OK, we loose an empty comment line...)
$lines = array_unique($lines);
// Write things back to conf/acl.auth.php
file_put_contents(DOKU_INC.'conf/acl.auth.php', implode($lines));
// If Translation plugin is active, determine if we're at wikistart
if (!plugin_isdisabled('translation')) {
foreach (explode(' ',$conf['plugin']['translation']['translations']) as $lang){

View file

@ -16,5 +16,6 @@ $conf['group_by_name'] = 1;
$conf['edit_before_create'] = 0;
$conf['create_public_page'] = 0;
$conf['public_pages_ns'] = 'user';
$conf['set_permissions_public'] = 1;
$conf['templates_path'] = 'data/pages/wiki';
$conf['templatepath'] = '';

View file

@ -16,5 +16,6 @@ $meta['group_by_name'] = array('onoff');
$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['set_permissions_public'] = array('onoff');
$meta['templates_path'] = array('string');
$meta['templatepath'] = array('string');

View file

@ -7,10 +7,10 @@
*/
$lang['create_private_ns'] = 'Create user\'s private 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_name_string'] = 'Use user\'s full name instead of login for his private namespace (enabling this option will prevent using <code>%USER%</code> ACL wildcard and make ACL more complex).';
$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.';
$lang['set_permissions'] = 'Automatically configure ACL for the namespace set above and give full rights to users on their own namespace.';
$lang['set_permissions_others'] = 'If set permission is enabled, what permission for other people (both <code>@ALL</code> and <code>@user</code> groups) ?';
$lang['set_permissions_others_o_0'] = 'None';
$lang['set_permissions_others_o_1'] = 'Read';
@ -22,5 +22,6 @@ $lang['group_by_name'] = 'Group users\' namespaces by the first character of use
$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 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['set_permissions_public'] = 'Automatically configure ACL for the namespace set above (read access to anyone and edit rigth for each user on his own public plage).';
$lang['templates_path'] = 'Path from DokuWiki root to store templates (userhomepage_private.txt and userhomepage_public.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).';
$lang['templatepath'] = 'Template path from version 3.0.4. Don\'t change it, it is only there for backward compatibility. If this file exists, it will be used as default for new private namespace start page template.';
$lang['templatepath'] = 'Template path from version 3.0.4 if it was installed before. Don\'t change it, it is only there for backward compatibility. If this file exists, it will be used as default for new private namespace start page template.';