Added public page creation

This commit is contained in:
Simon DELAGE 2014-09-01 18:37:07 +02:00
parent 75232deb62
commit 19f19f6f92
5 changed files with 52 additions and 17 deletions

1
_template_public.txt Normal file
View File

@ -0,0 +1 @@
====== @NAME@ (@USER@) - Public Page ======

View File

@ -23,16 +23,16 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
global $INFO;
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['do']=='login')) {
$this->init();
$id = $this->home_wiki_page;
$id = $this->private_page;
// if page doesn't exists, create it
if (!page_exists($id) && !checklock($id) && !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->home_wiki_ns.':'.$this->homePage());
// $ns = cleanID($this->private_ns.':'.$this->privatePage());
// New user-namespace ACL:
$ns = cleanID($this->home_wiki_ns).':*';
$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);
@ -75,16 +75,29 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$this->private_page_template = DOKU_INC . $this->getConf('templatepath');
if ($this->getConf('group_by_name')) {
// private:s:simon
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'.strtolower(substr($this->homeNamespace(), 0, 1)).':'. $this->homeNamespace());
$this->private_ns = cleanID($this->getConf('users_namespace').':'.strtolower(substr($this->privateNamespace(), 0, 1)).':'. $this->privateNamespace());
} else {
// private:simon
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'. $this->homeNamespace());
$this->private_ns = cleanID($this->getConf('users_namespace').':'. $this->privateNamespace());
}
// private:simon:start.txt
$this->home_wiki_page= cleanID($this->home_wiki_ns . ':' . $this->homePage());
$this->private_page= cleanID($this->private_ns . ':' . $this->privatePage());
// Public page?
if ($this->getConf('create_public_page')) {
$this->public_page_template = DOKU_INC . $this->getConf('templatepathpublic');
// user:simon.txt
$this->public_page= cleanID($this->getConf('public_pages_ns').':'. $_SERVER['REMOTE_USER']);
// if page doesn't exists, create it
if (!page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) {
//writes the user info to public page
lock($this->public_page);
saveWikiText($this->public_page,$this->_template_public(),$lang['created']);
unlock($this->public_page);
}
}
}
}
function homeNamespace() {
function privateNamespace() {
if ( $this->getConf('use_name_string')) {
global $INFO;
$raw_string = $INFO['userinfo']['name'];
@ -95,14 +108,14 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
return strtolower($_SERVER['REMOTE_USER']);
}
}
function homePage() {
if ( $this->getConf('use_start_page')) {
global $conf;
return $conf['start'];
} else {
return $this->homeNamespace();
}
}
function privatePage() {
if ( $this->getConf('use_start_page')) {
global $conf;
return $conf['start'];
} else {
return $this->homeNamespace();
};
}
function _template_private() {
global $INFO;
$content = io_readFile($this->private_page_template, false);
@ -112,18 +125,27 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$content = str_replace('@USER@',$user,$content);
return $content;
}
function _template_public() {
global $INFO;
$content = io_readFile($this->public_page_template, false);
$name = $INFO['userinfo']['name'];
$user = strtolower($_SERVER['REMOTE_USER']);
$content = str_replace('@NAME@',$name,$content);
$content = str_replace('@USER@',$user,$content);
return $content;
}
//draws a home button, used by calls from main.php in template folder
function homeButton() {
$this->init();
if ($_SERVER['REMOTE_USER']!=null) {
echo '<form class="button btn_show" method="post" action="doku.php?id='.$this->home_wiki_page.'"><input class="button" type="submit" value="Home"/></form>';
echo '<form class="button btn_show" method="post" action="doku.php?id='.$this->private_page.'"><input class="button" type="submit" value="Home"/></form>';
}
}
//draws a home link, used by calls from main.php in template folder
function homeLink() {
$this->init();
if ($_SERVER['REMOTE_USER']!=null) {
echo '<a href="doku.php?id='.$this->home_wiki_page.'">Home</a>';
echo '<a href="doku.php?id='.$this->private_page.'">Home</a>';
}
}
}

View File

@ -6,6 +6,7 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$conf['create_private_ns'] = 1;
$conf['use_name_string'] = 0;
$conf['use_start_page'] = 1;
$conf['users_namespace'] = 'private';
@ -14,3 +15,6 @@ $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';

View File

@ -6,6 +6,7 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$meta['create_private_ns'] = array('onoff');
$meta['use_name_string'] = array('onoff','_caution' => 'warning');
$meta['use_start_page'] = array('onoff');
$meta['users_namespace'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/');
@ -14,3 +15,6 @@ $meta['set_permissions_others'] = array('multichoice','_choices'=>array('0','1',
$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');

View File

@ -6,6 +6,7 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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_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).';
@ -20,3 +21,6 @@ $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 (note that template will not be used if you enable this option).';
$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';