Extension:PersistUseskin

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
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)
Latest version 0.0.1 (2008-Dec-28)
MediaWiki 1.13.3
License GPL
Download see below
Hooks used
GetLocalURL

Translate the PersistUseskin extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Description[edit | edit source]

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


Download instructions[edit | edit source]

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.

Installation[edit | edit source]

To install this extension, add the following to LocalSettings.php:

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

Code[edit | edit source]

<?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 ...

See also[edit | edit source]

Extension:ChangeSessionSkin