MediaWiki extension: DynamicSkin - InfoDabble
| InfoDabble (DynamicSkin) Release status: beta | |
|---|---|
| Type: | User interface |
| Description: | This extension allows the skin layout and content to be defined using normal wikitext articles instead of PHP script files. |
| Author: | Eric Hartwell |
| Version: | 0.9 (August 23, 2007) |
| MediaWiki: | 1.10 |
| Download: | Code |
|
[edit] What can this extension do?
This extension builds on DynamicSkin to generate a customizable version of Paul Gu's Gumax 3.0 MediaWiki skin.
Strictly speaking, this isn't an extension at all, but a skin: it's installed in the /skins directory, and does not use any extension hooks or global variables. However, unlike a regular skin, it doesn't define the layout or appearance. Instead it provides a framework for dynamically changing them.
While DynamicSkin makes it easy to customize skins without any code changes, it's written as a base class so you can add additional code in a derived class.
[edit] Usage
This is the skin used for this site. It uses DynamicSkin to generate a customizable version of Paul Gu's Gumax 3.0 MediaWiki skin. The actual layout is defined in MediaWiki:InfoDabbleSkin.
[edit] Conditional skin content
| Default InfoDabble skin |
|---|
&DOCTYPE&
&HEAD_START&
<meta name="robots" content="index,follow" />
&STYLES& &SCRIPTS&
&BODY_START&
<div id="globalWrapper">
<div id="container-top"></div><div id="internal"></div>
<div id="container">&SITENOTICE&
<div id="header"><a name="top" id="contentTop"></a>
&LOGO& {{#if: &&USERID&&|&PERSONAL&}}
&SIDEBAR=MediaWiki:InfoDabbleSidebar&
{{#if: &&USERID&&|&SEARCH=image&
&PAGETOOLS&|&SEARCH=image,search& }}
</div>
<div id="mBody"><div id="mainContent"><div id="content">
<a name="top" id="top"></a>&SITENOTICE&
{{#ifeq:{{PAGENAME}}|Main Page||&TITLE&}}
<div id="bodyContent">
{{#ifeq:{{PAGENAME}}|Main Page||&SUBTITLE&}}
&UNDELETE& &USERMSG& &JUMPLINKS&
&CONTENTS&
{{#if: &&USERID&&|&CATLINKS&}}
<div class="visualClear"></div>
</div>
</div></div></div>
<div id="contentBottom">
{{#if: &&USERID&&| <div id="personalTools">&TOOLBOX&</div>}}
&CUSTOMTOOLBAR=footer,Footer,lastmod,about,disclaimer,
{{#if: &&USERID&&||anonlogin,}}
<a href="http://mediawiki.org">Powered by MediaWiki</a>,
<a href="http://www.ehartwell.com/InfoDabble/InfoDabbleSkin">
Skin by Eric Hartwell</a>,
<a href="http://paulgu.com">Design by Paul Gu</a>&
</div>
</div>
<div id="container-bottom"></div>
</div>
&END&
|
See the DynamicSkin page for a full explanation of the &TAGS& and &&VARIABLES&&. Here are some highlights:
&LOGO& {{#if: &&USERID&&|&PERSONAL&}}
- Only show the personal tools (preferences, watch, logout, etc.) if the user is logged in. The Login command is added to the footer.
&SIDEBAR=MediaWiki:InfoDabbleSidebar&
- Use the page MediaWiki:InfoDabbleSidebar to define the navigation sidebar (the tabs at the top of each page).
{{#if: &&USERID&&|&SEARCH=image&
&PAGETOOLS&|&SEARCH=image,search& }}
- Hide the "Go" button for anonymous users. Use graphic buttons for "Search" and "Go".
- Hide the page tools (edit, discussion, delete, etc.) from anonymous users.
{{#ifeq:{{PAGENAME}}|Main Page||&TITLE&}}
{{#ifeq:{{PAGENAME}}|Main Page||&SUBTITLE&}}
- Hide the page title and subtitle on the main page.
{{#if: &&USERID&&|&CATLINKS&}}
- Hide the page categories from anonymous users.
{{#if: &&USERID&&| <div id="personalTools">&TOOLBOX&</div>}}
- Hide the personal tools (What links here, Upload File, Special pages, etc.) from anonymous users.
&CUSTOMTOOLBAR=footer,Footer,lastmod,about,disclaimer,
{{#if: &&USERID&&||anonlogin,}}
<a href="http://mediawiki.org">Powered by MediaWiki</a>,
<a href="http://www.ehartwell.com/InfoDabble/InfoDabbleSkin">
Skin by Eric Hartwell</a>,
<a href="http://paulgu.com">Design by Paul Gu</a>&
- Custom toolbar for footer. Standard: last modified, about InfoDabble, disclaimers
- Display Login link for anonymous users
- Text link for Powered by MediaWiki
- Text links for skin credits
[edit] Installation
Copy DynamicSkin.php and InfoDabble.php to the /skins directory.
[edit] Parameters
| Tag | Function |
|---|---|
| &META& | HTML META tag. |
| &Anything else& | Uses default from DynamicSkin |
[edit] Changes to LocalSettings.php
There are no changes to LocalSettings.php.
[edit] Code
<?php /* ---------------------------------------------------------------------------- * InfoDabble Skin (DynamicSkin for modified gumax skin/styles) * ---------------------------------------------------------------------------- * 'gumax' style sheet for CSS2-capable browsers. Loosely based on monobook * @Version 3.1 * @Author Paul Y. Gu, <gu.paul@gmail.com> * @Copyright paulgu.com 2006 - http://www.paulgu.com/ * @License: GPL (http://www.gnu.org/copyleft/gpl.html) License information: Contributions by Eric Hartwell are offered to the community for any use whatsoever with no restrictions other than that credit be given, at least in the source code (Creative Commons Attribution 3.0 License). However, parts of this module and the classes it uses are licensed under the GNU General Public License 2 which restricts your rights to use them. * 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 for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * http://www.gnu.org/copyleft/gpl.html * ---------------------------------------------------------------------------- */ // initialize if( !defined('MEDIAWIKI') ) { die("This Skin file is not a valid Entry Point."); } require_once('skins/DynamicSkin.php'); // Inherit main code from SkinTemplate, set the CSS and template filter class SkinInfoDabble extends SkinDynamicSkin { function initPage(&$out) { $this->initDynamicSkin( $out, 'InfoDabble', 'InfoDabble', 'InfoDabbleSkinTemplate'); } } // Custom overrides for InfoDabble skin class InfoDabbleSkinTemplate extends DynamicSkinTemplate { # Returns HTML text for the specified tag function translate_tag( $tag ) { // Start with default contents $out = parent::translate_tag( $tag ); // See if we need special processing for this tag $basetag = explode( '=', $tag, 2); switch ( strtoupper($basetag[0]) ) { // The Gumax skin displays skin links inline with '|' as a delimiter // Build the lists normally then go back and insert delimiters case "ACTIONS": case "LOGIN": case "PERSONAL": case "TOOLBOX": case "CUSTOMTOOLBAR": return( $this->tweakLists( $out ) ); // The Gumax skin displays the page toolbar as a normal menu and not a tab bar. // Change the class name so XXXFixes.css fixes won't be applied. Then tweak lists. case "PAGETOOLS": $out = str_replace( 'p-cactions', 'contentActions', $out ); return( $this->tweakLists( $out ) ); case "DOCTYPE": // Add microsoft vml namespace if ( !array_key_exists( 'v', $this->data['xhtmlnamespaces'] ) ) { $this->data['xhtmlnamespaces']['v'] = 'urn:schemas-microsoft-com:vml'; $out = parent::translate_tag( $tag ); } return( $out ); // Use the base class default otherwise. default: return( $out ); } } // The Gumax skin displays skin links inline with '|' as a delimiter. Adjust existing HTML. static function tweakLists( $html ) { $html = preg_replace( '$</li>$', ' | </li>', $html ); // Delimit after each list element $html = preg_replace( '$ \| </li></ul>$', '</li></ul>', $html ); // .. except the last return( $html ); } # Get skin's text (function override) static function getDefaultSkinText( ) { return( '&DOCTYPE& &HEAD_START& <meta name="robots" content="index,follow" />&STYLES& &SCRIPTS& &BODY_START&<div id="globalWrapper"> <div id="container-top"></div><div id="internal"></div><div id="container">&SITENOTICE& <div id="header"><a name="top" id="contentTop"></a>&LOGO& {{#if: &&USERID&&|&PERSONAL&}} &SIDEBAR=MediaWiki:InfoDabbleSidebar& {{#if: &&USERID&&|&SEARCH=image& &PAGETOOLS&|&SEARCH=image,search& }} </div><div id="mBody"><div id="mainContent"><div id="content"> <a name="top" id="top"></a>&SITENOTICE& {{#ifeq:{{PAGENAME}}|Main Page||&TITLE&}} <div id="bodyContent">{{#ifeq:{{PAGENAME}}|Main Page||&SUBTITLE&}} &UNDELETE& &USERMSG& &JUMPLINKS& &CONTENTS& {{#if: &&USERID&&|&CATLINKS&}}<div class="visualClear"></div> </div></div></div></div> <div id="contentBottom"> {{#if: &&USERID&&| <div id="personalTools">&TOOLBOX&</div>}} &CUSTOMTOOLBAR=footer,Footer,lastmod,about,disclaimer,{{#if: &&USERID&&||anonlogin,}} <a href="http://mediawiki.org">Powered by MediaWiki</a>, <a href="http://www.ehartwell.com/InfoDabble/InfoDabbleSkin">Skin by Eric Hartwell</a>, <a href="http://paulgu.com">Design by Paul Gu</a>& </div></div><div id="container-bottom"></div></div>&END&' ); } } ?>
[edit] Implementation
[edit] Tips, tricks, and hoops
- MediaWiki builds the list of skin names from the list of .php files in the skins/ subdirectory. When it goes to load a skin, it looks for the class "Skin"+<skin name> (
$className = 'Skin'.$skinName;). This means that if DynamicSkin is saved in a file named MySkin.php, the main template class must be called SkinMySkin, or the skin won't be loaded. - The name of the default skin in LocalSettings.php is in lower case, i.e. if the skin file is InfoDabble.php, LocalSettings.php must say
$wgDefaultSkin = 'infodabble';
[edit] Version history
- 2007.8.23 Initial version