Extension talk:Pingbox
[Req.] for defaultOK to return if packet loss = 0%
editI was hoping the defaultOK would return if the pings returned successfully to let us know if the device was there. It appears this script simply returns the defaultOK if the ping script was run successfully. Please correct me if I'm wrong.
Question
editPingbox does not function on mediawiki 1.14. It puts the below error over every page:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/wiki/extensions/pingbox.php:122) in /var/www/wiki/includes/WebResponse.php on line 16
Question
editCan someone tell my if this works for the folowing?
Product Version MediaWiki 1.13.2 PHP 5.1.6 (apache2handler) MySQL 5.0.22
Improved version of Pingbox -- better formatting, MUCH better tooltips using CSS, etc.
editHi all,
Made some improvements to Pingbox and figured I'd post for the common good.
First, add this CSS to the appropriate file. I added it to the end of the main.css file for the skin in use:
/* Tooltips with CSS */
/* 2010-09-30: David Feinzeig */
/* Thanks to http://psacake.com/web/jl.asp */
a.tooltip{
position:relative; /*this is the key*/
z-index:24; background-color:#ccc;
color:#000;
text-decoration:none}
a.tooltip:hover{z-index:25; background-color:#ff0}
a.tooltip span{display: none}
a.tooltip:hover span{ /*the span will display just on :hover state*/
display:block;
position:absolute;
top:2em; left:2em; width:35em;
border:1px solid #0cf;
background-color:#cff; color:#000;
text-align: center}
Second, install this pingbox.php as per the original installation instructions:
<?php
/**
* This file contains the main include file for the Pingbox extension of
* MediaWiki.
*
* Usage: require_once("path/to/pingbox.php"); in LocalSettings.php
*
* This extension requires MediaWiki 1.5 or higher.
* Based on the "inputbox" extension by Erik Moller
*
* @author feinzeig <at> gmail <dot> com
* @copyright Public domain
* @license Public domain
* @package MediaWikiExtensions
* @version 0.1
*/
/**
* Register the Pingbox extension with MediaWiki
*/
$wgExtensionFunctions[] = 'registerPingboxExtension';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Pingbox',
'author' => 'feinzeig <at> gmail <dot> com',
'url' => 'http://www.mediawiki.org/wiki/Extension:Pingbox',
);
/**
* Sets the tag that this extension looks for and the function by which it
* operates
*/
function registerPingboxExtension()
{
global $wgParser;
$wgParser->setHook('pingbox', 'renderPingbox');
}
/**
* Renders an pingbox based on information provided by $input.
*/
function renderPingbox($input, $params) // , &$parser)
{
$pingbox=new Pingbox();
getPBoxOption($pingbox->host,$input,'host');
getPBoxOption($pingbox->defaultok,$input,'defaultok');
getPBoxOption($pingbox->defaultko,$input,'defaultko');
getPBoxOption($pingbox->labelinfo,$input,'labelinfo');
// 2010-09-30: David Feinzeig -- adding showSummary
getPBoxOption($pingbox->showSummary,$input,'showSummary');
// 2010-09-30: David Feinzeig -- adding showTooltip;
getPBoxOption($pingbox->showTooltip,$input,'showTooltip');
$pingbox->checkDefault();
$pingbox->checkLabelInfo();
// 2010-09-30: David Feinzeig -- adding checkShowSummary
$pingbox->checkShowSummary();
// 2010-09-30: David Feinzeig -- adding checkShowTooltip
$pingbox->checkShowTooltip();
$boxhtml=$pingbox->render();
if($boxhtml) {
return $boxhtml;
} else {
return "<br /> <font color='red'>Ping box host = '{$pingbox->host}' not defined.</font>";
}
}
function getPBoxOption(&$value,&$input,$name,$isNumber=false) {
if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
if($isNumber) {
$value=intval($matches[1]);
} else {
$value=htmlspecialchars($matches[1]);
}
}
}
class Pingbox {
var $host,$width;
var $defaultok, $defaultko;
var $labelinfo;
var $result;
// 2010-09-30: David Feinzeig -- adding bits for showSummary and showTooltip
var $showSummary;
var $showTooltip;
function render() {
if($this->host!='') {
return $this->getSimpleForm();
} else {
return false;
}
}
function getSimpleForm() {
global $wgScript;
$action = htmlspecialchars( $wgScript );
$arrResult = array();
$intR = exec('ping -c 2 ' . $this->host, &$arrResult);
// 2010-09-28: David Feinzeig
// $this->result = "Resultat du ping -c2 " . $this->host . " (".$intR."): ";
// $this->result = "Result of 'ping -c2' " . $this->host . " (".$intR."): ";
$this->result = "Result of 'ping -c2 " . $this->host . "':<br />";
foreach($arrResult as $ind => $val)
{
// 2010-09-28: dfeinzeig; removing '\r\n' as it's causing problems with lists in MediaWiki
$this->result .= "<br />" . $val;
}
if (count($arrResult) > 0)
$pingform .= $this->defaultok;
else
$pingform .= $this->defaultko;
// 2010-09-30: David Feinzeig -- adding conditional showTooltip
if($this->showTooltip && count($arrResult) > 0) {
// 2010-09-30: David Feinzeig -- updating tooltip to use CSS tooltips
// $pingform .= " <a href=\"#\" title=\"" . $this->result . "\">" . $this->labelinfo . "</a>";
$pingform .= " <a class=\"tooltip\" href=\"#\">" . $this->labelinfo .
"<span>" . $this->result . "</span>" .
"</a>";
}
// 2010-09-30: David Feinzeig -- adding showSummary info
if($this->showSummary && count($arrResult) > 0) {
$summaryHalves = explode("=", $intR); // split up the text and numbers
$summaryText = explode("/", $summaryHalves[0]); // now separate the text pieces
$summaryNumbers = explode("/", $summaryHalves[1]); // and separate the numbers
array_walk($summaryText, trim(&$value));
$summaryToShow ="[" .
$summaryText[0] . " = " . $summaryNumbers[0] . " // " .
"<font style=\"font-weight:normal; background-color:#ccff00; color:#000000;\">" .
$summaryText[1] . " = " . $summaryNumbers[1] . "</font> // " .
$summaryText[2] . " = " . $summaryNumbers[2] . " // " .
$summaryText[3] . " = " . $summaryNumbers[3] . "]";
$pingform .= " " . $summaryToShow;
}
return $pingform;
}
function checkDefault() {
if( !$this->defaultok || trim( $this->defaultok ) == '' )
$this->defaultok = "<font style=\"font-weight:bold; background-color:#006600;\">OK</font>";
if( !$this->defaultko || trim( $this->defaultko ) == '' )
$this->defaultko = "<font style=\"font-weight:bold; background-color:#ff0000;\">KO</font>";
}
function checkLabelInfo() {
if( !$this->labelinfo || trim( $this->labelinfo ) == '' )
$this->labelinfo = "[?]";
}
// 2010-09-30: David Feinzeig -- adding checkShowSummary
function checkShowSummary() {
// if showSummary is set to equivalent of false, let's set to FALSE
if( trim( $this->showSummary ) == '0' || strtolower(trim($this->showSummary)) == 'false')
$this->showSummary = FALSE;
// otherwise, we'll set to TRUE
else
$this->showSummary = TRUE;
}
// 2010-09-30: David Feinzeig -- adding checkShowTooltip
function checkShowTooltip() {
// if showTooltip is set to equivalent of false, let's set to FALSE
if( trim( $this->showTooltip ) == '0' || strtolower(trim($this->showTooltip)) == 'false')
$this->showTooltip = FALSE;
// otherwise, we'll set to TRUE
else
$this->showTooltip = TRUE;
}
}
?>
Dave
feinzeig <at> gmail <dot> com
- Hi Dave, i just replace my name by our name. --Boly38 15:08, 25 February 2011 (UTC)
Error (mw1.16.5)
editI'm getting the following error om MW1.16.5:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 132987824 bytes) in D:\xampp\htdocs\w\extensions\Pingbox.php on line 98
Here's my pingbox-statement:
<pingbox> host=http://www.google.com defaultok=ok defaultko=ko labelinfo= </pingbox>
Any ideas?