Extension:DynamicSidebar

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

Release status: beta

Implementation Skin, MyWiki
Description Provides dynamic sidebars based on user pages, groups, and categories.
Author(s) Ryan Lane (Ryan laneTalk)
Last version 1.0a (2010-02-23)
MediaWiki 1.17+ (after r62972)
License GPL 2 or later
Download Download snapshot
Subversion [Help]

Browse source code
View code changes

Example http://ryandlane.com/wiki
Hooks used
SkinBuildSidebar

Check usage (experimental)

This extension is based loosely on SidebarEx from Jean-Lou Dupont.

DynamicSidebar is an extension that extends the capabilities of the sidebar for logged in users. If allowed, users can add their own custom sidebars via "User:<username>/Sidebar". Administrators can add sidebars for groups, and userpage categories via "MediaWiki:Sidebar/Group:<group>", and "MediaWiki:Sidebar/Category:<category>".

Contents

[edit] Installation

Download the snapshot from SVN, expand it into your extensions directory, then add the following line to the bottom of LocalSettings.php:

require( "$IP/extensions/DynamicSidebar/DynamicSidebar.php" );

[edit] Configuration

The following options are available:

// Enable debugging
$wgDebugLogGroups["dynamic-sidebar"] = "/tmp/sidebar-debug.txt";
 
// Allow users to create their own custom sidebars under User:<username>/Sidebar
// Default: true
$wgDynamicSidebarUseUserpages = true;
 
// Allow group sidebars under MediaWiki:Sidebar/Group:<group>
// Default: true
$wgDynamicSidebarUseGroups = true;
 
// Allow category based sidebars under MediaWiki:Sidebar/Category:<category>
// Default: true
$wgDynamicSidebarUseCategories = true;

[edit] Usage

[edit] Custom user sidebars

$wgDynamicSidebarUseUserpages must be enabled, then an administrator must add the following in "MediaWiki:Sidebar":

* USER-SIDEBAR

This string will be replaced with the user's sidebar.

Users should add their sidebar to "User:<username>/Sidebar".

[edit] Group sidebars

$wgDynamicSidebarUseGroups must be enabled, then an administrator must add the following in "MediaWiki:Sidebar":

* GROUP-SIDEBAR

This string will be replaced with the user's group sidebars.

Administrators must add a sidebar for each group at "MediaWiki:Sidebar/Group:<group>". If a user is in multiple groups, sidebars will be shown for each group.

[edit] Category sidebars

$wgDynamicSidebarUseCategories must be enabled, then an administrator must add the following in "MediaWiki:Sidebar":

* CATEGORY-SIDEBAR

This string will be replaced with the sidebars of the categories on the user's userpage.

Administrators must add a sidebar for each category at "MediaWiki:Sidebar/Category:<category>". If a user's userpage has multiple categories, sidebars will be shown for each category. Users can add sidebars by adding a category to their userpage.

[edit] Compatibility with earlier versions of MediaWiki

Add the addToSidebarPlain() function to includes/Skin.php; here's a patch for 1.14:

--- /webapps/wiki/includes/Skin.php       2009-01-06 21:37:01.000000000 -0600
+++ /webapps/sandbox/includes/Skin.php    2010-02-25 17:06:39.000000000 -0600
@@ -1870,6 +1870,66 @@
                wfRunHooks('SkinBuildSidebar', array($this, &$bar));
                if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
                wfProfileOut( __METHOD__ );
                return $bar;
        }
+
+       /**
+       * Add content from plain text
+       * @since 1.17
+       * @param &$bar array
+       * @param $text string
+       */
+       function addToSidebarPlain( &$bar, $text ) {
+               $lines = explode( "\n", $text );
+               $heading = '';
+               foreach( $lines as $line ) {
+                       if( strpos( $line, '*' ) !== 0 ) {
+                               continue;
+                       }
+                       if( strpos( $line, '**') !== 0 ) {
+                               $heading = trim( $line, '* ' );
+                               if( !array_key_exists( $heading, $bar ) ) {
+                                       $bar[$heading] = array();
+                               }
+                       } else {
+                               if( strpos( $line, '|' ) !== false ) { // sanity check
+                                       $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
+                                       $link = wfMsgForContent( $line[0] );
+                                       if( $link == '-' ) {
+                                               continue;
+                                       }
+
+                                       $text = wfMsgExt( $line[1], 'parsemag' );
+                                       if( wfEmptyMsg( $line[1], $text ) ) {
+                                               $text = $line[1];
+                                       }
+                                       if( wfEmptyMsg( $line[0], $link ) ) {
+                                               $link = $line[0];
+                                       }
+
+                                       if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
+                                               $href = $link;
+                                       } else {
+                                               $title = Title::newFromText( $link );
+                                               if ( $title ) {
+                                                       $title = $title->fixSpecialName();
+                                                       $href = $title->getLocalURL();
+                                               } else {
+                                                       $href = 'INVALID-TITLE';
+                                               }
+                                       }
+
+                                       $bar[$heading][] = array(
+                                           'text' => $text,
+                                           'href' => $href,
+                                           'id' => 'n-' . strtr( $line[1], ' ', '-' ),
+                                           'active' => false
+                                           );
+                               } else {
+                                       continue;
+                               }
+                       }
+               }
+       }
+
 }

[edit] See Also

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