Extension:DynBox/DynBox.php

From MediaWiki.org

Jump to: navigation, search

[edit] Source Code

<?php
/**
 * DynBox extension for MediaWiki
 * Display customisable Dynamic HTML CSS Boxs for news
 *
 * @file
 * @ingroup Extensions
 * @author Romain GEORGES
 * @date 12/25/2008
 * @version 0.3
 * @link http://www.mediawiki.org/wiki/Extension:DynBox Documentation
 * Install by copying the DynBox.php file into $IP/extensions/
 * and add require_once("$IP/extensions/DynBox.php"); in your wiki's LocalSettings.php
 */
 
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'DynBox',
	'version' => '0.3',
	'author' => 'Romain GEORGES',
	'description' => 'Dynamic Box :Display customisable Dynamic HTML CSS Boxs for news',
	'url' => 'http://www.mediawiki.org/wiki/Extension:DynBox',
);
 
// Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
	$wgHooks['ParserFirstCallInit'][] = 'wfDynBoxExtension';
} else {
	$wgExtensionFunctions[] = 'wfDynBoxExtension';
}
 
function wfDynBoxExtension() {
	global $wgParser;
	$wgParser->setHook( 'dynbox', 'renderDynBox' );
	return true;
}
 
function renderDynBox( $input, $argv ) {
	$py = ( empty( $argv['posy'] ) ) ? '10px' : $argv['posy'];
	$px = ( empty( $argv['posx'] ) ) ? '10px' : $argv['posx'];
	$bgcolor = ( empty( $argv['bgcolor'] ) ) ? 'white' : $argv['bgcolor'];
	$bbgcolor = ( empty( $argv['boxbgcolor'] ) ) ? 'red' : $argv['boxbgcolor'];
	$bcolor = ( empty( $argv['boxcolor'] ) ) ? 'white' : $argv['boxcolor'];
	$ibgcolor = ( empty( $argv['iconbgcolor'] ) ) ? 'red' : $argv['iconbgcolor'];
	$icolor = ( empty( $argv['iconcolor'] ) ) ? 'white' : $argv['iconcolor'];
	$color = ( empty( $argv['color'] ) ) ? 'black' : $argv['color'];
	$title = ( empty( $argv['title'] ) ) ? 'News!' : $argv['title'];
	$output = "<style type='text/css'>\n";
	$salt = rand();
	$output .= ".dynbox_$salt { position:absolute; top:".$py."; right:".$px.";z-index:3; }\n";
	$output .= ".dynbox_$salt a { color:".$icolor.";background:".$ibgcolor.";font:bold 10px verdana, sans-serif;text-decoration:none;display:block;padding:1px;border:1px solid black; }\n";
	$output .= ".dynbox_$salt a:hover { color:".$bcolor.";background:".$bbgcolor.";width:200px; }\n";
	$output .= ".dynbox_$salt a span { display:none; }\n";
	$output .= ".dynbox_$salt a:hover span { color:".$color.";background:".$bgcolor.";font:normal 12px verdana, sans-serif;border:1px solid black;display:block;padding:5px; }\n";
	$output .= "</style>\n";
	$output .= "<div class='dynbox_$salt'><a href='#'>". $argv['title']."<span>\n";
	$output .= "$input";
	$output .= "</span></a></div>\n";
	return $output;
}
Personal tools