Badge time.png   The Paragon Wiki Archive documents the state of City of Heroes/Villains as it existed on December 1, 2012.

User:Digitizer/Sandbox

From Paragon Wiki Archive
Jump to: navigation, search

Introduction

Below is an example of an extension I wrote that will allow members to embed iFrames in the wiki pages. I mainly did this because I created a interactive map web page that I thought would be nice to add to the city zone pages. You can see an example of this on my SG's wiki site at Interactive Map. Mind you this map was done about I4 or so and and I should add shopes, new contacts, badge and plaque locations possible. I personally think that the urls that these iFrames point to should be stored on The Paragon Wiki.com site. The following php page could be set up to not output anything if the src url is not set to a location on paragonwiki.com pretty easily. Or we could limit it to a White List of sites.

Updated

I added a white list to the code for added security. This white list can be strictly set to paragonwiki.com domain only. The next step is to add the error messages to the standard wiki error messages.

Usage

<iframe name="map" width="300" height="300" frameborder="0">url<iframe>

Installation

If interested all you need to do is create a file called iFrame.php copy the code below and save it in the file and then place it in the a folder on the wiki site at extensions/iFrame next you simply need to add require_once("$IP/extensions/iFrame/iFrame.php"); to the LocalSettings.php file in the root wiki directory.


<?php

$wgExtensionFunctions[] = 'wfiFrame';

$wgExtensionCredits['parserhook']['iFrame'] = array(
	'name' => 'iFrame',
	'author' => 'Robert Wagner',
	'url' => 'http://www.mediawiki.org/wiki/Extension:iFrame',
	'description' => 'you to enbed a iFrame in a wiki page.',
);

function wfiFrame() {
	global $wgParser;
	$wgParser->setHook( 'iframe', 'RenderiFrame' );
}

function RenderiFrame($input, $argv)
{
	if(strlen($input) == 0)
		return "Page was not set in input.";

	$approved = false;

	// If we find "://" we know we could be working with an external 
	// site so we need to check it with our white list.
	if(strpos($input, "://") !== false)
	{
		$whitelist = array('paragonwiki.com');
		foreach($whitelist as $site)
		{
			
			$approved = strpos($input, $site) == (strpos($input, "://") + 3);

			if($approved)
				break;
		}
	}

	if(!$approved)
		return "The page you choose to embed is not approved.";

	$output = "<IFRAME";

	$output .= " src=\"" . $input . "\"";
	$output .= isset($argv['name']) ? " name=\"" . $argv['name'] . "\"" : "";
	$output .= isset($argv['scrolling']) ? " scrolling=\"" . $argv['scrolling'] . "\"" : "";
	$output .= isset($argv['width']) ? " width=\"" . $argv['width'] . "\"" : "";
	$output .= isset($argv['height']) ? " height=\"" . $argv['height'] . "\"" : "";
	$output .= isset($argv['frameborder']) ? " frameborder=\"" . $argv['frameborder'] . "\"" : " frameborder=\"0\"";

 	$output .= "></IFRAME>";

	return $output;
}
?>
</div>