Extension:SysopSidebar

From MediaWiki.org

Jump to: navigation, search
This extension requires patches to core MediaWiki code when used with MediaWiki 1.9 and before. Extensions implemented using patches may be disabled by or interfere with upgrades and security patches. If you would like to use this extension, we strongly recommend you upgrade to a version later than 1.9. Alternatively, if a suitable alternative without a patch is available, we recommend you use that extension instead.


         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
SysopSidebar

Release status: beta

Implementation  Skin
Description Provides a means of customizing the 'sidebar' based upon the user's membership to the 'sysop' group.
Author(s)  user:jldupont
Last Version  v1.0
License No license specified
Download 'Source and patches'

check usage (experimental)

Contents

[edit] NOTE

Please see Extension:SidebarEx as replacement; I will not be supporting this extension anymore. Jean-Lou Dupont 12:28, 31 October 2007 (UTC)

[edit] Dependancy

ExtensionClass 'extension'

[edit] Compatibility

  • Native support for MW > 1.10
  • Requires patch for earlier version (file SkinTemplate.php)
    • Brings the hook 'SkinTemplateOutputPageBeforeExec' from MW 1.10

[edit] Usage

Modify the page 'MediaWiki:Sidebar/Sysop' to your liking.

[edit] Changes to LocalSettings.php

require_once("$IP/extensions/ExtensionClass.php");
require_once("$IP/extensions/SysopSidebar.php");

[edit] Code

<?php
/*
 * SysopSidebar.php
 * 
 * MediaWiki extension
 * @author: Jean-Lou Dupont (http://www.bluecortex.com)
 *
 * Purpose:  Provides a means of adding page links to the
 * ========  'sidebar' for the 'sysop' users.
 *           The page links are configured through:
 *           'MediaWiki:Sidebar/Sysop' 
 *
 * Features:
 * *********
 *
 * DEPENDANCY:  ExtensionClass extension (>v1.5)
 * 
 * Tested Compatibility:  MW 1.10
 * Patches for MW 1.8.x and MW 1.9.x available
 *
 * INSTALLATION NOTES:
 * -------------------
 * Add to LocalSettings.php
 *  require("extensions/ExtensionClass.php");
 *  require("extensions/SysopToolBox.php");
 *
 * History:
 * - v1.0
 *
 */
 
SysopSidebarClass::singleton();
 
class SysopSidebarClass extends ExtensionClass
{
	// constants.
	const thisName = 'SysopSidebar';
	const thisType = 'other';  // must use this type in order to display useful info in Special:Version
	const pageName = 'MediaWiki:Sidebar/Sysop';
 
	// variables.
	var $foundPage;
 
	public static function &singleton( ) // required by ExtensionClass
	{ return parent::singleton( ); }
 
	function SysopSidebarClass()
	{
		parent::__construct(); 			// required by ExtensionClass
 
		global $wgExtensionCredits;
		$wgExtensionCredits['other'][] = array( 
			'name'        => self::thisName, 
			'version'     => 'v1.0 $LastChangedRevision: 115 $',
			'author'      => 'Jean-Lou Dupont', 
			'url'         => 'http://www.bluecortex.com',
			'description' => 'MediaWiki:Sidebar/Sysop page '
		);
 
		$this->foundPage = false;
	}
	public function setup() { parent::setup(); } // nothing special to do in this case.
 
	public function hSkinTemplateOutputPageBeforeExec( &$skin, &$tpl )
	{
		// make sure we are dealing with a 'sysop' user.
		if (!$this->isSysop()) return true; // continue hook-chain
 
		$a = $this->getArticle(self::pageName);
		if (empty($a))
		{
			$this->foundPage = false;
			return true;
		}
		else $this->foundPage = true;
 
		$text = $a->getContent();
		$bar  = $this->processSidebarText( $text );
 
		// get current sidebar text
		$cbar = $tpl->data['sidebar'];
 
		// add our own here
		$tpl->set( 'sidebar', array_merge($cbar, $bar) );		
 
		return true;
	}
	private function processSidebarText( &$textSideBar )
	// copied from SkinTemplate MW 1.8.x SVN
	{
		$bar = array();
		$lines = explode( "\n", $textSideBar );
		foreach ($lines as $line) {
			if (strpos($line, '*') !== 0)
				continue;
			if (strpos($line, '**') !== 0) {
				$line = trim($line, '* ');
				$heading = $line;
			} else {
				if (strpos($line, '|') !== false) { // sanity check
					$line = explode( '|' , trim($line, '* '), 2 );
					$link = wfMsgForContent( $line[0] );
					if ($link == '-')
						continue;
					if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
						$text = $line[1];
					if (wfEmptyMsg($line[0], $link))
						$link = $line[0];
					$href = self::makeInternalOrExternalUrl( $link );
					$bar[$heading][] = array(
						'text' => $text,
						'href' => $href,
						'id' => 'n-' . strtr($line[1], ' ', '-'),
						'active' => false
					);
				} else { continue; }
			}
		}
		return $bar;	
	}
	static function makeInternalOrExternalUrl( $name )
	// copied from SkinTemplate MW 1.8.x SVN	 
	{
		if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
			return $name;
		} else {
			return self::makeUrl( $name );
		}
	}
 
	static function makeUrl( $name, $urlaction = '' )
	// copied from SkinTemplate MW 1.8.x SVN 
	{
		$title = Title::newFromText( $name );
		self::checkTitle( $title, $name );
		return $title->getLocalURL( $urlaction );
	}
 
	static function checkTitle( &$title, &$name )
	// copied from SkinTemplate MW 1.8.x SVN 
	{
		if( !is_object( $title ) ) {
			$title = Title::newFromText( $name );
			if( !is_object( $title ) ) {
				$title = Title::newFromText( '--error: link target missing--' );
			}
		}
	}
 
} // END CLASS DEFINITION

[edit] See also