Added event to replace user interwiki link

Issue #11
This commit is contained in:
Simon DELAGE 2015-06-19 02:33:37 +02:00
parent f97060f118
commit ca512439bb
6 changed files with 52 additions and 1 deletions

View file

@ -19,10 +19,12 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'init',array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'acl',array());
$controller->register_hook('COMMON_USER_LINK', 'AFTER', $this, 'replaceUserLink',array());
}
function init(&$event, $param) {
global $conf;
$this->helper = plugin_load('helper','userhomepage');
// If templates_path option starts with 'data/pages' it can automatically be adapted but should be changed
if (substr($this->getConf('templates_path'),0,10) == 'data/pages') {
@ -319,4 +321,45 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
return $content;
}
function replaceUserLink(&$event, $param) {
global $INFO;
global $conf;
if (($conf['showuseras'] == "username_link") and ($this->getConf('userlink_replace'))) {
$classes = $this->getConf('userlink_classes');
$this->username = $event->data['username'];
$this->name = $event->data['name'];
$this->link = $event->data['link'];
$this->userlink = $event->data['userlink'];
$this->textonly = $event->data['textonly'];
// Logged in as...
if (strpos($this->name, '<bdi>') !== false) {
$privateId = $this->helper->getPrivateID();
$publicId = $this->helper->getPublicID();
if ((page_exists($privateId)) && (page_exists($publicId))) {
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" title="'.$this->getLang('privatenamespace').'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" title="'.$this->getLang('publicpage').'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
} elseif (page_exists($publicId)) {
$return = '<bdi>'.$INFO['userinfo']['name'].'</bdi> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" title="'.$this->getLang('publicpage').'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
} elseif (page_exists($privateId)) {
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" title="'.$this->getLang('privatenamespace').'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<bdi>'.$_SERVER['REMOTE_USER'].'</bdi>)';
} else {
$return = null;
}
// ... or Last modified...
} else {
// No change for this right now
$return = null;
}
if ($return != null) {
$event->data = array(
'username' => $this->username,
'name' => $this->name,
'link' => $this->link,
'userlink' => $return,
'textonly' => $this->textonly
);
}
}
}
}

View file

@ -24,3 +24,5 @@
$conf['acl_user_templates'] = '1';
$conf['no_acl'] = 0;
$conf['action'] = 'edit';
$conf['userlink_replace'] = 1;
$conf['userlink_classes'] = 'interwiki wikilink1';

View file

@ -24,3 +24,5 @@
$meta['acl_user_templates'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
$meta['no_acl'] = array('onoff');
$meta['action'] = array('multichoice','_choices'=>array('edit','show'));
$meta['userlink_replace'] = array('onoff');
$meta['userlink_classes'] = array('string');

View file

@ -56,3 +56,5 @@
$lang['action'] = 'Action on first redirection to public page after it\'s creation (or private namespace start page).';
$lang['action_o_edit'] = 'Edit (Default)';
$lang['action_o_show'] = 'Show';
$lang['userlink_replace'] = 'Enable replacement of [<code>Logged in as</code>] interwiki link, depending on pages created by Userhomepage (only works if <code>showuseras</code> option is set to interwiki link).';
$lang['userlink_classes'] = 'Space separated list of CSS classes to apply to [<code>Logged in as</code>] interwiki links (default: <code>interwiki iw_user wikilink1 uhp_private</code>, add <code>iw_user</code> for template\'s default icon).';

View file

@ -56,3 +56,5 @@
$lang['action'] = 'Action à la première redirection vers la page publique après sa création (ou la page d\'accueil de l\'espace de nom privé).';
$lang['action_o_edit'] = 'Editer (Défaut)';
$lang['action_o_show'] = 'Afficher';
$lang['userlink_replace'] = 'Activer le remplacement du lien interwiki [<code>Connecté en tant que</code>], selon les pages créées par Userhomepage (ne fonctionne que si l\'option <code>showuseras</code> est configurée pour le lien interwiki).';
$lang['userlink_classes'] = 'Liste séparée par des espaces de classes CSS à appliquer aux liens de la chaîne [<code>Connecté en tant que</code>] (défaut: <code>interwiki iw_user wikilink1 uhp_private</code>, ajoutez <code>iw_user</code> pour l\'icône par défaut du thème).';

View file

@ -1,7 +1,7 @@
base userhomepage
author Simon Delage
email simon.geekitude@gmail.com
date 2015-06-18
date 2015-06-19
name User Homepage
desc Automatically create user's private namespace and/or public page and redirects users to private namespace on login.
url https://www.dokuwiki.org/plugin:userhomepage