Extension:PollDaddy

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
PollDaddy
Release status: beta
Implementation Tag
Description Allows embedding of polldaddy.com polls on a page
Author(s) Jabberwock @ Lostpedia
Latest version 1.3 (2008-11-09)
Database changes No
License GNU General Public License 2.0 or later
Download See the code section
polldaddy
Translate the PollDaddy extension if it is available at translatewiki.net
Check usage and version matrix.

The PollDaddy extension allows to insert polldaddy.com polls on a page. It was originally based off of Sylvain Machefert's GoogleVideo and YouTube video extensions, but has been re-written to use parameters within the tag to make it more elegant and secure.

Usage[edit]

Put the following code into the page where you want to display a poll, replacing "12345" with the correct poll ID number:

<polldaddy pollid="12345"/>

Installation[edit]

  • Copy the source code and place the file(s) in a directory called PollDaddy in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/PollDaddy/PollDaddy.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Source Code[edit]

<?php
/**
 * An extension that allows embedding of polldaddy.com polls into MediaWiki
 *
 * @file
 * @ingroup Extensions
 *
 * @author Jabberwock @ Lostpedia
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 * @link https://www.mediawiki.org/wiki/Extension:PollDaddy Documentation
 *
 * Version 1.3
 *
 * Changes:  	1.2: --use parameters from tag instead of delimited $input
 *		1.3: --polldaddy no longer supporting flash polls.  Using javascript instead
 *		     --width and height no longer required		
 *
 * Tag:  <polldaddy pollid="12345"/>
 */
# Confirm MW environment
if ( !defined( 'MEDIAWIKI' ) ) {
	die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}

// Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
	$wgHooks['ParserFirstCallInit'][] = 'wfPolldaddy';
} else {
	$wgExtensionFunctions[] = 'wfPolldaddy';
}

// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'PollDaddy',
	'version' => '1.3',
	'description' => 'Display polls from polldaddy.com',
	'author' => 'Jabberwock',
	'url' => 'https://www.mediawiki.org/wiki/Extension:PollDaddy'
);

function wfPolldaddy() {
	global $wgParser;
	$wgParser->setHook('polldaddy', 'renderPolldaddy');
	return true;
}

# The callback function for converting the input text to HTML output
function renderPolldaddy( $input, $params ) {
	//$v = htmlspecialchars($params['v']);
	$pollid = htmlspecialchars($params['pollid']);

	if( $pollid == null ) {
		$output = '<i>Poll Error:  no poll specified!</i>';
		return $output;
	}
	$output = '<script type="text/javascript" language="javascript" src="http://s3.polldaddy.com/p/'.$pollid.'.js"></script><noscript> <a href ="http://answers.polldaddy.com/poll/'.$pollid.'/" >Link</a>  <br/> <span style="font-size:9px;"> (<a href ="http://www.polldaddy.com">  surveys</a>)</span></noscript>';

	return $output;
}

See also[edit]