Extension:ChangeSessionSkin
|
ChangeSessionSkin Release status: beta |
|||
|---|---|---|---|
| Implementation | User interface | ||
| Description | Change skin for the duration of the current session without changing the preferences. Available for anonymous and logged-in users. | ||
| Author(s) | BRFR, Smd (BRFRTalk) | ||
| Last version | 0.26 (February 2011) | ||
| MediaWiki | 1.15.3 (others not tested) | ||
| License | GPL | ||
| Download | No link | ||
|
|||
|
available Check usage (experimental) |
|||
Contents |
[edit] 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.
[edit] 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.
[edit] 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
[edit] 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:
- 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.)
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:
- 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.
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.
[edit] Download instructions
Cut and paste the code found below and place it in $IP/extensions/ChangeSessionSkin.php. $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following to the bottom of LocalSettings.php:
require_once("$IP/extensions/ChangeSessionSkin.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.
[edit] Code
ChangeSessionSkin.php
<?php /** * ChangeSessionSkin MediaWiki Extention * Based on extension PersistUseskin [http://www.mediawiki.org/wiki/Extension:PersistUseskin] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License foe more details. * * If you did not receive a copy of the GNU General Public License along with * this program, see <http: *www.gnu.org/licenses/>. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * If the "incoming" request URL contains the "&useskin=" parameter (when using pretty URLs, this * can also be "?useskin="), then this extension subsequently adds that parameter to all internal * URLs that MW creates in the HTML rendering process. Thus, clicking on a link containing the * '&useskin=' query string, this change of skins will be persistent during the session (if not * changed again) but it will not be written to the user's preferences, nor be written to the data- * base at all. Hence, this function is available to anonymous users, too. * * If you simply remove '&useskin=' from any one URL clicked or entered, the user goes back to the * default skin (if anonymous) or to his/her preference skin. * * Wikitext for a simple skin changer: * [{{SERVER}}{{SCRIPTPATH}}/index.php?title={{PAGENAME}}&useskin=monobook MonoBook] * to allow users to persistently browse the wiki in the chosen skin. Note that this extension * can handle standard and "pretty" URLs but that this specific example is not certain to work * in installations with "pretty URLs" because, if no other URL argument is present, then * "?useskin=monobook" has to be used but that can't be known nor checked in wikitext. However, * if the link is produced in the .php of a skin (rather than in an article), the code can react * to this situation. */ if ( !defined( 'MEDIAWIKI' ) ) { echo "This file is part of MediaWiki, it is not a valid entry point.\n"; exit( 1 ); } $wgExtensionCredits['parserhook'][] = array( 'name' => 'Change Session Skin', 'author' => 'http://www.mediawiki.org/wiki/User:Smd<br>http://www.mediawiki.org/wiki/User:BRFR', 'url' => 'http://www.mediawiki.org/wiki/Extension:ChangeSessionSkin', 'description' => "Persists use of the skin given in ''useskin='', if found in query string", 'version'=>'0.26' ); $wgHooks['GetLocalURL'][] = 'ChangeSessionSkin'; function ChangeSessionSkin($title, $url, $query) { # If we find the 'useskin' query string - simply append it again to every internal link. # '$url' is an [[internal link]] after being rendered into HTML, at the time when this hook is called. global $wgRequest; $u = $wgRequest->getText( 'useskin' ); // using $_GET["useskin"] had unwanted side effects if ( $u ) { if ( $u != "" ) { # if there is already a "?" in the URL (like in "?title="), # then append "&useskin=", else "?useskin=" if ( strpos( $url, '?' ) === false) { $url .= "?useskin=" . $u; } else { $url .= "&useskin=" . $u; } } } # that's it ! :) go back ... return true; }
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 $IP/skins/pure.php between display of the sitenotice and display of the title of the article, alongside with the styles (shown here below the code) placed in $IP/skins/pure/main.css or in Mediawiki:Pure.css, 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 <?php ... ?> tags) or HTML (before the first <?php, after the last ?>, and in between ?> ... <?php tags).
<?php /** * @FIXME - Can't handle yet the word 'useskin' or the name of the skin in anything but all-lowercase. * @FIXME - Fails if the incoming URL has "?useskin=" as first arg *and* followed by other args with "&" */ # Show an extra link right next to the page title that redisplays the current page but with # another skin. How do we know what the URL of the current page is? From $wgRequest! But if # there is a 'useskin=' arg already present (if so, must have our skinname in it), it must # be removed before adding our own 'useskin=' to the link target. ?><span class="h1-setskin"><a href=<?php $sk = 'pure'; // sorry for this, should be obtained from a global or object $r = $wgRequest->getRequestURL(); // returns relative URL in either ?title= or "pretty" syntax $r = str_replace( '?useskin=' . $sk,'',$r ); $r = str_replace( '&useskin=' . $sk,'',$r ); if ( strpos( $r, '?' ) === false ) {$rc = "?";} else {$rc = "&";} $m1 = 'selectsessionskin1-tooltip'; // assemble the <a></a> tag with URL+useskin, display text and tooltip $tooltip = wfMsg( $m1 ); // function returns some string that contains $m1 itself if message $m1 // does not exist in the Mediawiki namespace if ((!$tooltip) || ($tooltip == "") || ( strpos( $tooltip,$m1 ) > 0 ) ) {$tooltip ='Auf Default Skin umschalten';} $m2 = 'selectsessionskin1-message'; $display = wfMsg( $m2 ); if ((!$display) || ($display == "") || ( strpos( $display,$m2 ) > 0 ) ) {$display ='Default Skin';} global $wgDefaultSkin; $m3 = 'selectsessionskin1-skinname'; $newskin = wfMsg( $m3 ); if ((!$newskin) || ($newskin == "") || ( strpos( $newskin,$m3 ) > 0 ) ) {$newskin = $wgDefaultSkin;} # "Target=_New" is dirty here ... it's based on assumptions about a specific use of the change skin feature echo $r . $rc . 'useskin=' . $newskin . ' title="' . $tooltip . '" Target="_new" >' . $display . '</a>'; ?>
/* Custom styles */ /* Skin "pure" uses class="h1-setskin" for a link to switch to another skin (e.g. "navigation on") */ .h1-setskin { margin-top: 1.1em; font-size: 100%; /* 53%; */ color:#4444ff; float:right; /* looks similar to editsection */ }
To customise the name of the skin being switched to, the text being displayed and the tooltip, create these system messages:
Mediawiki:Selectsessionskin1-skinname= name of skin to switch to (defaults to $wgDefaultSkin). Example: GlassMediawiki:Selectsessionskin1-message= display name of that skin (defaults to "Default Skin"). Example: [+]Mediawiki:Selectsessionskin1-tooltip= 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 $IP/skins/glass.php 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 <?php ... ?> tags) or HTML (before the first <?php, after the last ?>, and in between ?> ... <?php tags).
<?php /** * @FIXME - Can't handle yet the word 'useskin' or the name of the skin in anything but all-lowercase. * @FIXME - Fails if the incoming URL has "?useskin=" as first arg *and* followed by other args with "&" */ # Place the "mavigation off" link just under the last menu in the sidebar ( = redisplay the # current page but with another skin). "id=" taken from from function "customBox" so screen # formatting is identical to navboxes. # How do we know what the URL of the current page is? From $wgRequest! But if there is a # 'useskin=' arg already present (if so, must have our skinname in it), it must be removed # before adding our own 'useskin='. $sk = 'glass'; // sorry for this, should be obtained from a global or object $r = $wgRequest->getRequestURL() ; // returns relative URL in either ?title= or "pretty" syntax $r = str_replace( '?useskin=' . $sk,'',$r ); $r = str_replace( '&useskin=' . $sk,'',$r ); if ( strpos( $r, '?' ) === false ) {$rc = "?";} else {$rc = "&";} $m0 = 'selectsessionskin0-headline'; // assemble the link with a box headline, URL+useskin, display text and tooltip $headline = wfMsg( $m0 ); // function returns some string that contains $m1 tself if a message called $m1 // does not exist in Mediawiki: if ((!$headline) || ($headline == "") || ( strpos( $headline,$m0 ) > 0 ) ) {$headline ='Skin';} $m1 = 'selectsessionskin0-tooltip'; $tooltip = wfMsg( $m1 ); if ((!$tooltip) || ($tooltip == "") || ( strpos( $tooltip,$m1 ) > 0 ) ) {$tooltip ='Auf Default Skin umschalten';} $m2 = 'selectsessionskin0-message'; $display = wfMsg( $m2 ); if ((!$display) || ($display == "") || ( strpos( $display,$m2 ) > 0 ) ) {$display ='Default Skin';} global $wgDefaultSkin; $m3 = 'selectsessionskin0-skinname'; $newskin = wfMsg( $m3 ); if ((!$newskin) || ($newskin == "") || ( strpos( $newskin,$m3 ) > 0 ) ) {$newskin = $wgDefaultSkin;} ?><div class='generated-sidebar portlet' id='p-setskin'> <h5><?php echo $headline; ?></h5> <div class='pBody'> <ul> <li id='p-setskin-1'><a href="<?php echo $r . $rc . 'useskin=' . $newskin; ?>" title="<?php echo $tooltip; ?>"><?php echo $display; ?></a></li> </ul> </div><!-- pBody --> </div><!-- p-setskin -->
To customise the name of the skin being switched to, the text being displayed and the tooltip, create these system messages:
Mediawiki:Selectsessionskin0-headline= Name of box where the link appears (defaults to "SKIN")Mediawiki:Selectsessionskin0-skinname= name of skin to switch to (defaults to $wgDefaultSkin). Example: PureMediawiki:Selectsessionskin0-message= display name of that skin (defaults to "Default Skin"). Example: Navigation Sidebar OffMediawiki:Selectsessionskin0-tooltip= 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.
** {{SERVER}}/wiki/{{FULLPAGENAMEE}}?useskin=pure|Pure
** {{SERVER}}/wiki/{{FULLPAGENAMEE}}?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:
<!-- These links require "pretty URLs" -->
[{{SERVER}}/wiki/{{PAGENAMEE}}?useskin=glass Navigation on]
[{{SERVER}}/wiki/{{PAGENAMEE}}?useskin=pure Navigation off]
[{{SERVER}}/wiki/{{PAGENAMEE}} 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).
[edit] See also
- Manual:Parameters to index.php: User preference overriding
- Extension „PersistUseskin“
- List of simple extensions
- Manual:Interface/Sidebar
- Manual:Skinning
- Manual:$wgSkipSkins
- Manual:$wgDefaultSkin
- Manual:Skin configuration: Remove Skin tab from User Preferences
