Extension:ChangeSessionSkin

Credits
This article was inspired by extension „PersistUseskin“ on which idea and code all of this is based. I received patient support by Hoggwild on the Mediawiki User Support Forum that she runs.

What can this extension do?
It allows any user, anonymous or logged-in, to change the display „skin“ (in other programmes called „theme“) for the duration of the current session, or until changed again. This is done by using the useskin=skinname argument added to a request URL. That parameter, if a correct skin is specified, overrides the default skin (as per $wgDefaultSkin for anonymous users) or the skin setting as per the logged-in user's preferences.

The extension hooks into the wikitext-to-HTML rendering process: When it finds a useskin argument in the current („inbound“) request URL, it adds the same to any („outbound“) internal link being rendered on the current page, thus „persisting“ this setting until omitted, changed again or the end of the user's session.

You can manually add the useskin= argument to a URL (and later remove or change it), or place respective links into your pages or into a sidebar menu, or even place them in custom skins. Several scenarios are described below.

Note

 * The useskin=skinname feature is not affected by the $wgSkipSkins configuration setting: You still get to use all skins present in the /skins subdirectory of your Mediawiki installation.
 * In contrast, the useskin=skinname feature is affected by one of the methods to turn skin changing off altogether, as described in Manual:Skin configuration

Usage Scenarios
A facility to change the outer appearance of a page or pages with one click might come in handy in situations like these: The following examples were conceived with the latter „user support“ scenario in mind, however they are usable in other sets of circumstances as well. In this specific scenario: Note that these skins don't actually prevent access from the readers' end to „administrational“ or „internal“ contents and functions. It's all about different views on the same contents with different priorities about what might be interesting or relevant in a given usage context.
 * You are a friendly (or playful) sysop who wants to offer different themes even for anonymous users, like blue, green and red skins (no offense meant) according to everybodys personal taste
 * You are an even friendlier sysop, providing barrier-free (or barrier-reduced) themes for visually impaired or colour-blind users with just one click, of course even before they log in
 * You are a developer wanting to comfortably cycle through available skins to check the effects of your work in all skins
 * You run a wiki, like a user support site, that offers different themes for (a) information seekers (limited, content-oriented navigation only, maybe even deep links to help pages from inside applications) and (b) information providers (with full navigation for editing and structuring contents, categories etc.)
 * There is a skin called ‚pure‘ that shows no sidebar, no page tools and no personal tools, just the article title, text and categories. This can be deep-linked from outside sources and or from within applications, even in frames (note that MW as of 1.16.1 for security reasons restricts usage options when run in frames). The only connection to the „real world“ is a white-on-white login link at the bottom of every page. Logged-in users use Monobook.
 * There is another skin called ‚glass‘. It still doesn't have page tools and personal tools (except the semi-hidden login link as above) but it does have a sidebar - however the navbox is not the same as for logged-in users. The glass navbox (maintained in Mediawiki:Sidebar-anon) is optimised for information seeking while the regular sidebar is designed to support information maintenance and administration in general.

Download instructions
Cut and paste the code found below and place it in. $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation
To install this extension, add the following to the bottom of LocalSettings.php: Then adjust one of the above usage scenarios to your requirements and installation. That may involve configuration work (e.g. customising one of the sidebar menues) and/or PHP and CSS programming when changing a custom skin.

Code
ChangeSessionSkin.php

In addition to installing the extension as such, you have to place clickable links on your screens that actually change the active skin (unless you choose to manually add/remove the ?useskin=skinname or &useskin=skinname argument to your next request URL). You can do that by „skinning“, by „configuring“ and by „editing“ your wiki. The following chapters exemplify these methods.

Skinning Example: The ‚pure‘ skin (Assumes a custom skin named ‚pure‘, see Usage Scenarios above) This code, placed  between display of the sitenotice and display of the title of the article, alongside with the styles (shown here below the code) placed in   or in , will add a skin-changing link or button to the page title but right-justified, its appearance similar to the [edit] section links of monobook. Note: When adding this code to your code or when changing it, make sure that you always know if you are writing PHP (within  tags) or HTML (before the first , and in between ?> ... <?php tags). To customise the name of the skin being switched to, the text being displayed and the tooltip, create these system messages:
 * = name of skin to switch to (defaults to $wgDefaultSkin). Example: Glass
 * = display name of that skin (defaults to "Default Skin"). Example: [+]
 * = tooltip for that link (defaults to "Auf Default Skin umschalten"). Example: Show Navigation Sidebar

Skinning Example: The ‚glass‘ skin (Assumes a custom skin named ‚glass‘, see Usage Scenarios above) This code, placed right below the section of  that displays logo and sidebar elements, will add a skin-changing link to the sidebar below all other sidebar elements. There is no custom css here because the looks of the other sidebar menues/boxes are used. Note: When adding this code to your code or when changing it, make sure that you always know if you are writing PHP (within  tags) or HTML (before the first , and in between ?> ... <?php tags). To customise the name of the skin being switched to, the text being displayed and the tooltip, create these system messages:
 * = Name of box where the link appears (defaults to "SKIN")
 * = name of skin to switch to (defaults to $wgDefaultSkin). Example: Pure
 * = display name of that skin (defaults to "Default Skin"). Example: Navigation Sidebar Off
 * = tooltip for that link (defaults to "Auf Default Skin umschalten"). Example: Hide Navigation Sidebar

Configuration example: Using the sidebar menu (all skins) An entry in Mediawiki:Sidebar like the following would add skin changing capabilities to every skin that displays the sidebar. I leave it to somebody else to write code that determines the currently active skin and switches to the ‚next‘ (and/or ‚previous‘) skin in a list of available skins. That would serve the „developer“ requirement in the usage scenario section above.
 * /wiki/?useskin=pure|Pure
 * /wiki/?useskin=glass|Glass

Editing example: Skin changing links in an article text Again leaning on the ‚pure‘ and ‚glass‘ examples, wiki markup for such links could look like this:

[/wiki/?useskin=glass Navigation on] [/wiki/?useskin=pure Navigation off] [/wiki/ Default Skin] These links will display the respective page in three different clothes. Notice the last one: Through abandoning the useskin= argument, we return to the wiki's default skin (for anonymous users) or the skin as per the user's preferences (for logged-in users).