Extension:PersistUseskin

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
PersistUseskin

Release status: beta

Implementation Parser extension
Description Persists use of &useskin=, if found in query string
Author(s) User:Smd (SmdTalk)
Last version 0.0.1 (2008-Dec-28)
MediaWiki 1.13.3
License GPL
Download see below
Hooks used
GetLocalURL

Check usage (experimental)

Contents

[edit] Description

Persists use of &useskin=, if found in query string. Possibly the shortest MediaWiki extension ever (could be seen as one-liner :) ) ... For more, see comments in Code below


[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/PersistUseskin.php. Note: $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 LocalSettings.php:

require_once( $IP.'/extensions/PersistUseskin.php' );

[edit] Code

<?php
# PersistUseskin MediaWiki Extention
#
#
# Gives any user the choice to view wiki in any of the installed skins, by clicking on a link containing the '&useskin=' query string
# simply remove the  '&useskin=' query string from the adress, to go back to default skin 
# you can then use a link like: 
# [{{SERVER}}{{SCRIPTPATH}}/index.php?title={{PAGENAMEE}}&useskin=monobook monobook] 
# to allow users to persistently browse the wiki in the chosen skin. 
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'PersistUseskin',
        'author' => 'http://www.mediawiki.org/wiki/User:Smd',
        'url' => 'http://www.mediawiki.org/wiki/Extension:PersistUseskin',
        'description' => 'Persists use of &useskin=, if found in query string',
        'version'=>'0.0.1'
);
 
# URL hook list: 
# GetInternalURL Used to modify fully-qualified URLs (useful for squid cache purging) # no trigger for local pages?
# GetLocalURL  Used to modify local URLs as output into page links
# GetFullURL   Used to modify fully-qualified URLs used in redirects/export/offsite data

$wgHooks['GetLocalURL'][] = 'PersistUseskin';
 
 
function PersistUseskin($title, $url, $query) 
{
        # for debug 
 # echo ("PersistUseskin title" . $title . "<br>\r\n" . " url  " . $url . " query " .  $query. "<br>\r\n". "<br>\r\n");
 
        # if we found the 'useskin' query string - simply append it again to local link ...
 if ($_GET["useskin"]) 
                if ($_GET["useskin"] != "" ) 
                        $url .= "&useskin=" . $_GET["useskin"];
 
        # that's it ! :) go back ... 
 
        return true;
}
?>

If Short urls are used, the following change might be required:

--- PersistUseskin.orig      2011-01-26 00:18:47.000000000 +0100
+++ PersistUseskin.php        2011-01-26 00:32:02.000000000 +0100
@@ -31,8 +31,10 @@ function PersistUseskin($title, $url, $q
 
        # if we found the 'useskin' query string - simply append it again to local link ...
        if ($_GET["useskin"]) 
-             if ($_GET["useskin"] != "" ) 
-                     $url .= "&useskin=" . $_GET["useskin"];
+             if ($_GET["useskin"] != "" ) {
+                     $qsa = strrchr ($url, '?') ? '&' : '?';
+                     $url .= $qsa . "useskin=" . $_GET["useskin"];
+             }
 
        # that's it ! :) go back ...

[edit] See also

Extension:ChangeSessionSkin

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox