Change the skin/template/theme (admins can select templates per page/namespace or users can select a template for the whole wiki)
Compatible with DokuWiki
Change the skin/template/theme (admins can select templates per page/namespace or users can select a template for the whole wiki)
Similar to templateconfhelper
Download and install the plugin using the Plugin Manager using the URL given above. Refer to Plugins on how to install plugins manually.
The plugin is also available via git.
% cd <dokuwiki>/lib/plugins % git clone git://github.com/selfthinker/dokuwiki-plugin-loadskin.git loadskin
IMPORTANT
The plugin won't work without the following small changes to DokuWiki's source code! They are necessary in order to allow the plugin to interfere with the template constants used by DokuWiki.
Remove (or comment) the following lines in <dokuwiki>/inc/init.php around line 123:
// define Template baseURL if(!defined('DOKU_TPL')) define('DOKU_TPL', DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); // define real Template directory if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC', DOKU_INC.'lib/tpl/'.$conf['template'].'/');
This plugin can be used in two ways:
Admins can specify different templates for different wiki pages or namespaces or users can use a select box for the whole wiki.
The plugin comes with an admin component you'll find in the admin menu. Use it to specify the templates to be used for different wiki pages or namespaces.
Alternatively the plugin can let the user choose the template for the whole wiki through a template switcher. Your users will need to allow cookies for that (otherwise the template won't switch permanently).
automaticOutput | Automatically output the template switcher on every page (turn this off if you don't want to show the template switcher or want to put it somewhere else) |
|---|---|
excludeTemplates | Exclude templates from template switcher (comma-separated list) |
The template switcher is automatically put before the wiki content. If you like to put it somewhere else (e.g. near the login button or into the sidebar), you need to switch automaticOutput and put the following code into your template to wherever you like to display it:
<?php $loadskinHelper = plugin_load('action', 'loadskin')->loadHelper('loadskin', true); echo $loadskinHelper->showTemplateSwitcher(); ?>
A complete changelog is available here.
Does this plugin do the same thing as the multitemplate template? — Terence J. Grant 2008/08/09 05:38
Yes, but it doesn't require to modify the templates (instead it requires a change in the DokuWiki source which isn't optimal either, however with theinc/preload.phpin the current devel version this shouldn't be no problem). Hope you don't mind the competition. — Michael Klier 2008/08/09 10:14
I'd rather phase out multitemplate in favor of this actually… — Terence J. Grant 2008/08/10 00:34
This worked just as advertised. Very nice.
Now, how hard would it be to make a plug-in that allows individual users to choose a template that suits their visual limitations (low lux, large fonts, etc.)? — Joyful 2008/09/18 06:32
I just implemented a template switcher that can be used by every user to switch to any installed template. — achAnika Henke
ach
2010/11/29 01:46The latest version even stores the template per user if you're logged in. — achAnika Henke
ach
2011/02/07 02:34
Super Plugin!!! Vielen Dank! tokuehn@web.de 05.06.2009
This doesn't work as advertised with my Anteater DW. I want different templates for different namespaces. I see, how the template manager can handle it, but each time I set a new 'property' (namespace → template), the tpl gets applied to the whole wiki
Any ideas? Lnz 2011/01/19 00:04
This is a bug which only affects the admin who has used the template manager. Everyone else (including the admin who opens the wiki in a different browser) is not affected by that bug and it will work as expected for them. The only way to make it go away for the admin currently is to clear the DokuWiki cookie. I will fix it and release a new version (with some more changes) this coming weekend. — achAnika Henke
ach
2011/01/19 02:32
You're right! It only affects the admin… It works as advertised now. Thank you for your quick response -Lnz 2011/01/20
A bit later than planned, but I updated the plugin now, which will fix that problem. The old bug will still be in affect because the old values are stored in the cookie. So, you'd either have to delete your DokuWiki cookie or use the follow “trick”: Add?tpl=*&act=selectto the end of the URL of your wiki, and that should take care of things and revert to your usual settings. — achAnika Henke
ach
2011/02/07 02:34
Here's a patch for per user templates Richard Westwell 09.12.2010
The bad thing about this patch is, that it's not just a patch for the plugin but also changes the DokuWiki core. Template choices per user are supported by the plugin since version 2011-02-07 anyway. — Anika HenkeAnika Henke
ach
2011/05/29 13:31
diff -Naur D:\Sites\dokuwiki.orig/inc/auth.php D:\Sites\dokuwiki.new/inc/auth.php
--- D:\Sites\dokuwiki.orig/inc/auth.php 2010-11-07 16:43:03.000000000 +0000
+++ D:\Sites\dokuwiki.new/inc/auth.php 2010-12-09 14:25:33.677367100 +0000
@@ -789,9 +789,20 @@
return false;
}
+ //Get the Selected / stored Template
+ $selectedtemplate = $_POST['perusertpl'];
+ $themeconfig = DOKU_INC.'conf/loadskin_user.conf';
+ if(@file_exists($themeconfig)) {
+ $themedata = unserialize(io_readFile($themeconfig, false));
+ if(!empty($themedata)) {
+ $storedtemplate = $themedata[$INFO[client]];
+ }
+ }
+
if ($_POST['fullname'] != $INFO['userinfo']['name'] && $auth->canDo('modName')) $changes['name'] = $_POST['fullname'];
if ($_POST['email'] != $INFO['userinfo']['mail'] && $auth->canDo('modMail')) $changes['mail'] = $_POST['email'];
if (!empty($_POST['newpass']) && $auth->canDo('modPass')) $changes['pass'] = $_POST['newpass'];
+ if ($selectedtemplate != $storedtemplate) $changes['perusertpl'] = $selectedtemplate;
if (!count($changes)) {
msg($lang['profnochange'], -1);
@@ -811,6 +822,16 @@
list($user,$sticky,$pass) = explode('|',$cookie,3);
if ($changes['pass']) $pass = PMA_blowfish_encrypt($changes['pass'],auth_cookiesalt());
+ //Save selected template
+ if(@file_exists($themeconfig)) {
+ $themedata = unserialize(io_readFile($themeconfig, false));
+ $themedata[$INFO[client]] = $selectedtemplate;
+ io_saveFile($themeconfig, serialize($themedata));
+ } else {
+ $themedata[$INFO[client]] = $selectedtemplate;
+ io_saveFile($themeconfig, serialize( $themedata));
+ }
+
auth_setCookie($_SERVER['REMOTE_USER'],$pass,(bool)$sticky);
return true;
}
diff -Naur D:\Sites\dokuwiki.orig/inc/html.php D:\Sites\dokuwiki.new/inc/html.php
--- D:\Sites\dokuwiki.orig/inc/html.php 2010-11-07 16:43:04.000000000 +0000
+++ D:\Sites\dokuwiki.new/inc/html.php 2010-12-09 14:19:20.867253100 +0000
@@ -1115,6 +1115,27 @@
$form->addElement(form_makeTag('br'));
$form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
}
+
+ // Show the Drop Down for the Selected Template
+ $selectedtemplate = 'default';
+ $themeconfig = DOKU_INC.'conf/loadskin_user.conf';
+
+ if(@file_exists($themeconfig)) {
+ $themedata = unserialize(io_readFile($themeconfig, false));
+ if(!empty($themedata)) {
+ $selectedtemplate = $themedata[$INFO[client]];
+ }
+ }
+
+ $form->addElement(form_makeListboxField('perusertpl',getTemplates(),$selectedtemplate,'<b>Template</b>'));
+ $form->addElement(form_makeTag('br'));
+ $form->addElement(form_makeTag('br'));
+
$form->addElement(form_makeButton('submit', '', $lang['btn_save']));
$form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
$form->endFieldset();
@@ -1122,6 +1143,28 @@
print '</div>'.NL;
}
+ /**
+ * Returns an array of available templates to choose from
+ *
+ * @author Michael Klier <chi@chimeric.de>
+ */
+ function getTemplates() {
+ $tpl_dir = DOKU_INC.'lib/tpl/';
+ if ($dh = @opendir($tpl_dir)) {
+ while (false !== ($entry = readdir($dh))) {
+ if ($entry == '.' || $entry == '..') continue;
+ if (!preg_match('/^[\w-]+$/', $entry)) continue;
+
+ $file = (is_link(_dir.$entry)) ? readlink($tpl_dir.$entry) : $entry;
+ if (is_dir($tpl_dir.$file)) $list[] = $entry;
+ }
+ closedir($dh);
+ sort($list);
+ $list[] = 'use selector';
+ }
+ return $list;
+ }
+
+
/**
* Preprocess edit form data
*
diff -Naur D:\Sites\dokuwiki.orig/lib/plugins/loadskin/action.php D:\Sites\dokuwiki.new/lib/plugins/loadskin/action.php
--- D:\Sites\dokuwiki.orig/lib/plugins/loadskin/action.php 2010-11-29 00:50:58.000000000 +0000
+++ D:\Sites\dokuwiki.new/lib/plugins/loadskin/action.php 2010-12-09 14:48:04.090599400 +0000
@@ -99,6 +99,22 @@
* @author Anika Henke <anika@selfthinker.org>
*/
function getTpl() {
+
+ // get template from per user setup
+ $themeconfig = DOKU_INC.'conf/loadskin_user.conf';
+
+ global $INFO;
+ io_saveFile('conf/test.conf',serialize($INFO));
+
+ if(@file_exists($themeconfig)) {
+ $themedata = unserialize(io_readFile($themeconfig, false));
+ if(!empty($themedata)) {
+ if ($themedata[$INFO[client]] != 'use selector') {
+ return $themedata[$INFO[client]];
+ }
+ }
+ }
+
+
+
// get template from session
if ($_REQUEST['tpl'])
$_SESSION[DOKU_COOKIE]['loadskinTpl'] = $_REQUEST['tpl'];
I noticed small trouble with javascript loading. All
lib/tpl/<currenttemplate>/script.js should be loaded at the start. But
because I commented out part of init.php definig DOKU_TPLINC as
suggested, script.js in template directory does not get loaded. It's
because DOKU_TPLINC constant is needed when list of scripts to include
is generated. It is in lib/exe/js.php in function js_out().
The plugin is great anyway, but it took me some time to localize reason, why my new template does not uses the script.js, so be warned. — Jan Kreps 2011/03/16 12:38
Thanks for reporting this issue. I added it the bug tracker to better be able to keep track of it. I don't know when I will fix it, as I don't have much time at the moment. — Anika HenkeAnika Henke
ach
2011/05/29 13:31
It could be a great step for Multi-Device-DokuWiki Usinge, to admin a relation list between THEME ↔ HTTP_USER_AGENT.