Extension:Full Local Image

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Full Local Image
Release status: stable
Implementation Parser function
Description Creates two parser-functions, localimage and fullimage, they work similar to the localurl and fullurl functions except they return the path to an image not a article.
Author(s) Daniel Friesen (Dantmantalk)
MediaWiki all versions
License No license specified
Download see below
Changelog
Translate the Full Local Image extension if it is available at translatewiki.net
Check usage and version matrix.

This Extension is under development for WikiIndex to allow the url of a local image to be inserted into a page in the same way {{fullurl:Articlename}} and {{localurl:Articlename}} are used. The main purpose for this is embedding local images into a page using the external embedding method so that the image can be used as a link.

Note: This extension is still under development and is targeted currently for the MediaWiki 1.6.5 versions.

Parserfunctions[edit]

This extension adds 2 parserfunctions that can be used.

{{fullimage:Imagename.ext}} {{localimage:Imagename.ext}}

Fullimage adds the full url to the image to the page, and Localimage adds the url to the page without the http://www.yoursite.com on it.

Code[edit]

To install add the following files to your wiki and use this in your LocalSettings.php to install it:

require_once( "extensions/FullLocalImage.php" );


extensions/FullLocalImage.php[edit]

<?php
/**
 * @Extension Full/Local Image
 * @Author Daniel Friesen (aka: Dantman )
 * @Description Creates 2 parserfunctions. Localimage and Fullimage, they work similar
 *      to the Localurl and Fullurl functions except they return the path to a image not a article.
 */


$wgExtensionFunctions[] = 'wfFLImage';
$wgHooks['LanguageGetMagic'][] = 'wfFLImageLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'Full/Local Image',
	'author' => 'Daniel Friesen (aka: Dantman )',
	'url' => 'http://www.mediawiki.org/wiki/Extension:Full_Local_Image'
);

function wfFLImage() {
	global $wgParser;
	
	$wgParser->setFunctionHook( 'Localimage', array( 'wgFLImageFuncts', 'Localimage' ), SFH_NO_HASH );
	$wgParser->setFunctionHook( 'Fullimage', array( 'wgFLImageFuncts', 'Fullimage' ), SFH_NO_HASH );
}

class wgFLImageFuncts {
	function Localimage ( &$parser, $name = '', $arg = null ) {
		$img = Image::newFromName( $name );
		if( $img != NULL ) return $img->getURL();
		return '';
	}
	function Fullimage ( &$parser, $name = '', $arg = null ) {
		global $wgServer;
		$img = Image::newFromName( $name );
		if( $img != NULL ) return $wgServer . $img->getURL();
		return '';
	}
}

# Register the magic words
function wfFLImageLanguageGetMagic( &$magicWords,$langCode = 0 ) {
	$magicWords['Localimage'] = array(0,'Localimage');
	$magicWords['Fullimage'] = array(0,'Fullimage');
	return true;
}

Changelog[edit]

  • 31/10/2006 - Updated code. (Untested)
  • 31/10/2006 - Added this page. (Under Development)