Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

SkinChange

Summary: change skin via query or cookie setting
Version: 2011-12-02
Status: Stable
Prerequisites: pmwiki-2.0
Maintainer: Pm
Categories: Skins Layout
Discussion: SkinChange-Talk
Users: +9 (view / edit)

Question

  • How can I allow users to change their skin based on a query parameter or cookie setting?

Answer

The skinchange.phpΔ script enables query parameters of the form

  • "?skin=", or
  • "?setskin="

to be added to a page url to allow users to view pages with a different skin.

  • The ?setskin= query stores a cookie on the browser that causes a different skin to be used for all subsequent pages.
  • The ?skin= only changes skin for the currently displayed page.

To use this script, download it into the cookbook directory of your installation. To allow browsers to use any skin already loaded into the skins directory, simply set $EnableAutoSkinList and include the recipe:

$EnableAutoSkinList = 1;
include_once('cookbook/skinchange.php');

To restrict browsers to specific skins, create a $PageSkinList array mapping values for ?skin= or ?setskin= to the skin to be used:

$PageSkinList = array(
    'pmwiki' => 'pmwiki',
    'classic' => 'myclassicskin',
    'jh' => 'jhskin');
include_once('cookbook/skinchange.php');

These example links set the skin just for viewing a single page:

These example links store a cookie in your browser so that all future visits to this site will show that skin.

If $EnableAutoSkinList is also set, then entries in $PageSkinList take precedence. If a browser requests a skin that isn't available, then PmWiki defaults to the skin already defined by $Skin.

By default, the setskin cookie that is created will expire after one year. You can set it to expire at the end of the browser session by setting $SkinCookieExpires=0;

For wiki-code that will automatically generate a list of available skins, see SkinList.

Skinchange and Wiki Farms

Like most other PmWiki customizations, instructions from more specific files override those from less specific files, in a chain like this:

  • farmconfig.php
  • field's config.php
  • GroupName.php
  • GroupName.PageName.php

Enable skinchange farmwide

  1. Just follow the directions above, but put the code in your farmconfig.php

Override skinchange for a particular field

  1. put $Skin = 'your_skin'; in the field's config.php

Centrally manage the skin list, set default skin per field, and allow user to choose skin per field

  1. put your skins array in your farmconfig.php
  2. to set a field's default skin, put $Skin = 'your_skin'; in the field's config.php
  3. to enable skin changing for a field, put @include_once("$FarmD/cookbook/skinchange.php"); in the field's config.php. Users can change skins for this field without affecting the skin choices for other fields.

Centrally manage the skin list, set default skin per field, and allow user to choose skin for entire farm

  1. put your skins array in your farmconfig.php
  2. enable skin changing for the farm by putting @include_once("$FarmD/cookbook/skinchange.php"); in farmconfig.php
  3. to set a field's default skin, put SDV($Skin, 'your_skin'); in the field's config.php. If the user has deliberately changed skins, this will be overriden by their farm-wide choice.

Automatic Browser Based Skin Change

You can also perform a skin change based on browser detection. Refer to WikiOnPDA.

Change for One Session Only (or by time, or ....)

To change the skin setting to a per-session one (cleared when browser closed), simply set:

$SkinCookieExpires = 0;

You could also allow the expiration time as an options, by adding:

    if (isset($_REQUEST['skinexpires']))
        $SkinCookieExpires = 0 + $_REQUEST['skinexpires'];

Then one can do ?setskin=foo&skinexpires=86400 to get the setting to last for 24 hours. Or, to be really fancy, perhaps:

    if (isset($_REQUEST['skinexpires'])) {
        list($g0,$g1) = DRange($_REQUEST['skinexpires']);
        $SkinCookieExpires = $g0;
    }

Then one can actually use a real date for expiration, as in:

    ...?setskin=foo&skinexpires=2009-01-01
    ...?setskin=foo&skinexpires=tomorrow

Comments

Note: after PmWiki 2.2.x beta, pages in headers, footers, sidebars needs to use the * to reference the page variable of the page calling the sidebar/header/footer included files: [[{*$Name}?skin=marathon]] etc. This is only used on pages that will be included in other pages when you want to use the variables from the current page, otherwise the $Name is Group/SideBar or Group/GroupHeader

Question : skinchange is useful but it adds something like ?n=Site.Science?skin=simple to the URL.

How can i avoid the ?skin=simple

Contributors

  • Pm, original script (25-Feb-2004)
  • Pm, updated for PmWiki 2 (9-Nov-2004)
  • mhg?, Comments and examples (20-Jan-2005)
Category: Skins, Layout

User notes +9: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Skins listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on May 20, 2014, at 11:46 PM