Open main menu

Extension:FloatingToolbar

MediaWiki extensions manual
OOjs UI icon advanced.svg
Floating Toolbar
Release status: beta
Implementation Skin
Description Adds a strip to the bottom of the window. Contents and visibility are set in LocalSettings.php
Author(s) (User:tdwrighttalk)
Latest version 0.1
License GPLv2
Download No link
$wgFloatingToolbarContents, $wgFloatingToolbarAllUsers, $wgFloatingToolbarLoggedIn
Translate the FloatingToolbar extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?Edit

This extension adds a subtle grey strip to the bottom of the window (stays on the bottom while users scroll) with your text/HTML in it. 3 levels of visibility: none (off), logged in users and all users.

Download instructionsEdit

Please cut and paste the code found below and place it in $IP/extensions/FloatingToolbar/FloatingToolbar.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

InstallationEdit

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

$wgFloatingToolbarContents = 'Your text (or <b>H</b><i>T</i><u>M</u><a href="#">L</a>) here.';
$wgFloatingToolbarAllUsers = false;
$wgFloatingToolbarLoggedIn = true;
require_once("$IP/extensions/FloatingToolbar/FloatingToolbar.php");

Configuration parametersEdit

The contents are modified by changing $wgFloatingToolbarContents.

User rightsEdit

The visibility is set by altering $wgFloatingToolbarAllUsers and $wgFloatingToolbarLoggedIn. Both are booleans. The first dictates whether all users should be able to see the bar. The second dictates whether logged in users should be able to see it. If $wgFloatingToolbarAllUsers is set to true, $wgFloatingToolbarLoggedIn isn't checked.

CodeEdit

<?
/**
 * Floating Toolbar
 * 
 * @version 0.1
 * @author Tom Wright
 * @link http://www.mediawiki.org/wiki/Extension:FloatingToolbar
 */
 
//Extension credits that show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'Floating Toolbar',
	'author' => 'Tom Wright',
	'url' => 'http://www.mediawiki.org/wiki/Extension:FloatingToolbar',
	'version' => '0.5',
	'description' => 'Adds fixed strip with customisable text to the bottom of the window.',
);

$wgHooks['BeforePageDisplay'][] = 'wfFloatingToolbar';

function wfFloatingToolbar(&$out) {
  global $wgFloatingToolbarContents, $wgFloatingToolbarAllUsers, $wgFloatingToolbarLoggedIn, $wgUser;
  if (!$wgFloatingToolbarAllUsers) {
    if ($wgFloatingToolbarLoggedIn) {
      if (!$wgUser->isLoggedIn()) return $out;
    } else {
      return $out;
    }
  }
  $out->mBodytext .= <<<TXT
  <style type="text/css">
	  #floatingtoolbar {
	    position:fixed;
	    padding:0;
	    overflow:hidden;
	    background:#CCC;
	    background:rgba(200, 200, 200, 0.75);

	    /* Set the y vars */
	    top:100%;
	    margin-top:-2em;
	    height:2em;

	    /* Set the x vars */
	    width:90%;
	    left:50%;
	    margin-left:-45%;

	    /* Get the borders right */
	    border:#333 1px solid;
	    border-bottom:0;
	    border-radius: 0.5em 0.5em 0 0;
	    -moz-border-radius: 0.5em 0.5em 0 0;
	  }
	  #floatingtoolbar p {
	    position:relative;
	    width:100%;
	    padding:0.5em 0;
	    text-align:center;
	    line-height:1em;
	    margin:0;

	    font-size:small;
	    color:#000;
	    text-shadow: -0.1em -0.1em 0.2em #CCC, 0.1em 0.1em 0.2em #999;
	  }
	  #floatingtoolbar p a {
	    color:#000;
	    text-decoration:underline;
	  }
	  #floatingtoolbar p a:hover {
	    color:#000;
	    text-decoration:underline;
	    font-style:italic;
	  }
	  #floatingtoolbar_spacer {
	    height:2em;
	    position:relative;
	  }
	</style>
	<div id="floatingtoolbar">
	  <p>
TXT;
  $out->mBodytext .= $wgFloatingToolbarContents;
  $out->mBodytext .= <<<TXT
  </p>
	</div>
	<div id="floatingtoolbar_spacer">&nbsp;</div>
TXT;
  return $out;
}