Extension:Picasa2Gallery

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Picasa2Gallery
Release status: stable
ExtensionPicasa2Gallery.jpg
Implementation Tag
Description Generate image gallery from Picasa xml export.
Author(s) Velorex
Latest version 2.0.0 (2009-06-29)
MediaWiki 1.10 - 1.15.0
License No license specified
Download No link
Translate the Picasa2Gallery extension if it is available at translatewiki.net
Check usage and version matrix.

Create a gallery where you don't have to describe the content of gallery picture by picture. Picasa3, a perfect picture organizer made by Google. I have used it for a couple of years and I discovered the possibility of exporting an album to *.xml file containing descriptions of pictures and thumbnails. I have had all my photos alredy sorted in albums and labeled. Therefore I decided to use it as a base of this extension.

If you want to use it, download Picasa3, let it search your photos, resort and labeled them. Then export your albums as a *.xml albums. The Picasa2Gallery also automatically upload the images from Picasa to the MediaWiki server. If the default thumbnail size from Picasa2 is not suitable for you, you can easily change it in the templates directory of Picasa2. (The same you can do with thumbnails frame color, etc.)

Usage[edit]

Type on the page where you want to see your album this tags <album dirName="directory_name"></album> with proper parameters. This extension generates picture gallery from Picasa2 XML export saved in your location.

Example of usage:

<album dirName="directory_name" showTitle=[1|0] showLarge=[1|0] multiSet=[1|0]>Description of the album</album>

Installation[edit]

Download, unzip and copy source files to your extension's directory. To activate this extension, include it from your LocalSettings.php with:

include("extensions/Picasa2.php");

Edit Picasa2.php and change variable $galleryDir to absolute or relative path to your gallery dir with regards to wiki directory. Example:

$galleryDir = "images/gallery/"; - it means /mediawiki/gallery

mw

|-docs
|-......
|-images 
|-......
|-gallery      //create this folder 
|-......
|-extension
      |-....
      |-Picasa2   //Unzip the folder here
      |-....
      |-....
      |-Picasa2.php  //put the file here
      |-....

Parameters[edit]

Here's a complete parameter list:

dirName 
(essential parameter), denotes the name of a directory in $galleryDir path (for setting $galleryDir see bellow). This directory contains the exported Picasa data -- the XML data file (named index.xml, then the path is $galleryDir/directory_name/index.xml) and subdirectories with images and thumbnails.
showTitle 
(optional parameter, default 1(means TRUE))
if it is set to 1, then the album name and the number of photos is displayed
showLarge 
(optional parameter, default 1(means TRUE))
if it is set to 1, then the thumbnails are the link to the enlarged images, otherwise only thumbnails can be seen
multiSet 
(optional parameter, default 1(TRUE))
if it is set to 1, then enlarged images are cross-linked. By enlarging of the one image, you can directly move on previous or next image. Otherwise every image is enlarged separately.

Note[edit]

You can use this extension also with earlier version... but you will see some undef labels in 'edit' mode. You have to edit one file (I am not sure which one now).... Or you can download version 1.0 which can be found on my homepage.. (see download)

Picasa2.php[edit]

Older Versions[edit]

<?php
/**
 * WikiMedia Picasa2 extension
 *
 * @package Picasa2
 * @version 0.2
 * @author Velorex - Vaclav Kratochvil  <vaclav@kratochvil.biz>
 *
 * This is a WikiMedia extension that I wrote because I wanted to create
 * a gallery where you don't have to describe the content of gallery picture
 * by picture. My extension consists of several parts:
 *
 * Picasa2 (http://google.picasa.com/), a perfect picture organizer made by
 * Google. I have used it for a couple of years and I discovered the
 * possibility of exporting an album to *.xml file containing descriptions of
 * pictures and thumbnails. Therefore I decided to use it as a base of the
 * extension. So here it is!
 *
 * The second part is Lightbox2, which was written by Lokesh Dhakar
 * (http://www.lokeshdhakar.com/). Thank you Lokesh, great job!
 * Here is the direct link (http://www.huddletogether.com/projects/lightbox2/)
 * Lightbox is a simple, unobtrusive script used to overlay images on
 * the current page. It's a snap to setup and works on all modern browsers.
 * In other words, it is a piece of AJAX technology - javascript which (when you
 * click on the umbnail) displays the enlarged image on the page without
 * reloading of the main page.
 *
 * How it works...
 * Right now, it supports a new MediaWiki tag, <album>, that allows to
 * display an arbitrary number of photos described in the XML file in the album.
 *
 * Usage ...
 * <album dirName="directory_name" showTitle=[1|0] showLarge=[1|0]
 *                             multiSet =[1|0]>Description of the album</album>
 * * dirName - (essential parameter), denotes the name of a directory in
 *    $galleryDir path (for setting $galleryDir see bellow). This directory
 *    contains the exported Picasa data -- the XML data file (named index.xml,
 *    then the path is $galleryDir/directory_name/index.xml) and subdirectories
 *    with images and thumbnails.
 * * showTitle - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    the album name and the number of photos is displayed
 * * showLarge - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    the thumbnails are the link to the enlarged images, otherwise only
 *    thumbnails can be seen
 * * multiSet - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    enlarged images are cross-linked. By enlarging of the one image, you can
 *    directly move on previous or next image. Otherwise every image is enlarged
 *    separately.
 *
 *
 * Note that this is a premiliary version and it was programmed only to satisfy
 * my demands on my site.
 *
 * If you find this software useful, encounter a bug, or would like to
 * have more features, please contact me at vaclav@kratochvil.biz
 *
 *
 * To activate this extension, include it from your LocalSettings.php
 * with: include("extensions/Picasa2.php");
 *
 *___________________________________________________________________________*
 *   ***   ***   ***   ***    E D I T    H E R E    ***   ***   ***   *** *  *

 * type absolute or relative path to your gallery directory with regards to
 * index.php */
  $galleryDir = "/gallery";
/* set default values of album parameters; see more details above*/
  $showTitleDefault = 0;                      /* 1=TRUE, 0=FALSE */
  $showLargeDefault = 1;
  $multiSetDefault  = 1;
/*
 *___________________________________________________________________________*
 *    ***   ***    ***    No need to edit beyond here    ***    ***   ***    *
 */
  if( !defined( 'MEDIAWIKI' ) ) {
    die( "This file is part of MediaWiki and is not a valid entry point\n" );
  }

  include ("./extensions/Picasa2/PicasaAlbum.php");

$wgExtensionFunctions[] = "wfPicasa2Gallery";
$wgHooks['BeforePageDisplay'][] = 'wfPicasa2GalleryJavascriptAndCSS';

$wgExtensionCredits['Picasa2'][]= array(
  'name'         => 'Picasa2Gallery Extension',
  'version'      => '2.0.0',
  'author'       => 'velorex',
  'url'          => 'http://www.kratochvil.biz/',
  'description'  => "This extension is for integrating google's picasa xml galleries to mediawiki.");

function wfPicasa2Gallery() {
   global $wgParser;
   # register the extension with the WikiText parser
   # the first parameter is the name of the new tag.
   # In this case it defines the tag <example> ... </example>
   # the second parameter is the callback function for
   # processing the text between the tags
   $wgParser->setHook( "Album", "wfPrintPicasaAlbum" );
} // wfPicasa2
/*******************************************************************/

/**********************************************************/
function wfPrintPicasaAlbum($input, $argv) {

  global $wgOut, $wgScriptPath, $galleryDir, $showTitleDefault, $showLargeDefault, $multiSetDefault;
  /* check input parameters */
  if(!(isset($argv['dirname']))) {    /*dirName - essential parameter - dir name of exported picasa2 gallery (located in $galleryDir, see above) */
    return wfPrintError('dirName argument not found, this parameter is essential for <album> tag in picasa2 extension');
  }
  $xmlFile = $argv['dirname'];
  $album = new Picasa2Gallery;

  /* create new PicasaAlbum object (see in ./Picasa2/PicasaAlbum.php) */
  if (!($album->loadFromXml("$galleryDir/".$argv['dirname']))) {
    return wfPrintError($album->getErrorMessage());
  }
  /* handle optional parameters and set default value */
  if(!(isset($argv['showtitle']))) /* showTitle - optional parameter - show the title of the album stored in the xml file as well as a number of pictures */
    $showTitle = $showTitleDefault;/* default value is 1 - TRUE */
  else
    $showTitle = $argv['showtitle'];

  if(!(isset($argv['showlarge']))) /* showLarge - optional parameter - enable that the thumbnail serves as a link to large picture */
    $showLarge = $showLargeDefault;/* default value is 1 - TRUE */
  else
    $showLarge = $argv['showlarge'];

  if(!(isset($argv['multiSet']))) /* multiSet - optional parameter - enable to cross-link enlarge pictures*/
    $multiSet = $multiSetDefault; /* default value is 1 - TRUE */
  else
    $multiSet = $argv['multiSet'];


  if ($showTitle)               /* show name of album stored in xml file and count of images */
    $Output .= "<h2><span class=\"mw-headline\">Album: ".$album->getName()." (".$album->getCount().")</span></h2>";

  /* print text contains in <album> text </album> tags */
  $Output .= "<p>$input</p>";

  /* print thumbnails with or without references to large images */
  $Output .= $album->getThumbnailsPrint($showLarge, $multiSet);

  return $Output;
}

function wfPrintError($error = "") { /* print error */
  return "<p><div class=\"errorbox\"><h2>Error:</h2> $error.</div></p>";
}

function wfPicasa2GalleryJavascriptAndCSS ( &$m_pageObj ) {
  global $wgScriptPath;

  $extensionPath = $wgScriptPath."/extensions/Picasa2";
  // Insert javascript script.
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/prototype.js\"></script>\n");
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/scriptaculous.js?load=effects\"></script>\n");
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/lightbox.js\"></script>\n");

  $m_pageObj->addScript("<link rel=\"stylesheet\" href=\"$extensionPath/css/lightbox.css\" type=\"text/css\" media=\"screen\" />\n");
  return true;
}

/*******************************************************************************/

MW 1.14.0[edit]

<?php
/**
 * WikiMedia Picasa2 extension
 *
 * @package Picasa2
 * @version 0.2
 * @author Velorex - Vaclav Kratochvil  <vaclav@kratochvil.biz>
 *
 * This is a WikiMedia extension that I wrote because I wanted to create
 * a gallery where you don't have to describe the content of gallery picture
 * by picture. My extension consists of several parts:
 *
 * Picasa2 (http://google.picasa.com/), a perfect picture organizer made by
 * Google. I have used it for a couple of years and I discovered the
 * possibility of exporting an album to *.xml file containing descriptions of
 * pictures and thumbnails. Therefore I decided to use it as a base of the
 * extension. So here it is!
 *
 * The second part is Lightbox2, which was written by Lokesh Dhakar
 * (http://www.lokeshdhakar.com/). Thank you Lokesh, great job!
 * Here is the direct link (http://www.huddletogether.com/projects/lightbox2/)
 * Lightbox is a simple, unobtrusive script used to overlay images on
 * the current page. It's a snap to setup and works on all modern browsers.
 * In other words, it is a piece of AJAX technology - javascript which (when you
 * click on the umbnail) displays the enlarged image on the page without
 * reloading of the main page.
 *
 * How it works...
 * Right now, it supports a new MediaWiki tag, <album>, that allows to
 * display an arbitrary number of photos described in the XML file in the album.
 *
 * Usage ...
 * <album dirName="directory_name" showTitle=[1|0] showLarge=[1|0]
 *                             multiSet =[1|0]>Description of the album</album>
 * * dirName - (essential parameter), denotes the name of a directory in
 *    $galleryDir path (for setting $galleryDir see bellow). This directory
 *    contains the exported Picasa data -- the XML data file (named index.xml,
 *    then the path is $galleryDir/directory_name/index.xml) and subdirectories
 *    with images and thumbnails.
 * * showTitle - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    the album name and the number of photos is displayed
 * * showLarge - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    the thumbnails are the link to the enlarged images, otherwise only
 *    thumbnails can be seen
 * * multiSet - (optional parameter, default 1(TRUE)); if it is set to 1, then
 *    enlarged images are cross-linked. By enlarging of the one image, you can
 *    directly move on previous or next image. Otherwise every image is enlarged
 *    separately.
 *
 *
 * Note that this is a premiliary version and it was programmed only to satisfy
 * my demands on my site.
 *
 * If you find this software useful, encounter a bug, or would like to
 * have more features, please contact me at vaclav@kratochvil.biz
 *
 *
 * To activate this extension, include it from your LocalSettings.php
 * with: include("extensions/Picasa2.php");
 *
 *___________________________________________________________________________*
 *   ***   ***   ***   ***    E D I T    H E R E    ***   ***   ***   *** *  *

 * type absolute or relative path to your gallery directory with regards to
 * index.php */
  $galleryDir = "/gallery";
/* set default values of album parameters; see more details above*/
  $showTitleDefault = 0;                      /* 1=TRUE, 0=FALSE */
  $showLargeDefault = 1;
  $multiSetDefault  = 1;
/*
 *___________________________________________________________________________*
 *    ***   ***    ***    No need to edit beyond here    ***    ***   ***    *
 */
  if( !defined( 'MEDIAWIKI' ) ) {
    die( "This file is part of MediaWiki and is not a valid entry point\n" );
  }

  include ("./extensions/Picasa2/PicasaAlbum.php");

$wgExtensionFunctions[] = "wfPicasa2Gallery";
$wgHooks['BeforePageDisplay'][] = 'wfPicasa2GalleryJavascriptAndCSS';

$wgExtensionCredits['Picasa2'][]= array(
  'name'         => 'Picasa2Gallery Extension',
  'version'      => '2.0.0',
  'author'       => 'velorex',
  'url'          => 'http://www.kratochvil.biz/',
  'description'  => "This extension is for integrating google's picasa xml galleries to mediawiki.");

function wfPicasa2Gallery() {
   global $wgParser;
   # register the extension with the WikiText parser
   # the first parameter is the name of the new tag.
   # In this case it defines the tag <example> ... </example>
   # the second parameter is the callback function for
   # processing the text between the tags
   $wgParser->setHook( "Album", "wfPrintPicasaAlbum" );
} // wfPicasa2
/*******************************************************************/

/**********************************************************/
function wfPrintPicasaAlbum($input, $argv) {

  global $wgOut, $wgScriptPath, $galleryDir, $showTitleDefault, $showLargeDefault, $multiSetDefault;
  /* check input parameters */
  if(!(isset($argv['dirname']))) {    /*dirName - essential parameter - dir name of exported picasa2 gallery (located in $galleryDir, see above) */
    return wfPrintError('dirName argument not found, this parameter is essential for <album> tag in picasa2 extension');
  }
  $xmlFile = $argv['dirname'];
  $album = new Picasa2Gallery;

  /* create new PicasaAlbum object (see in ./Picasa2/PicasaAlbum.php) */
  if (!($album->loadFromXml("$galleryDir/".$argv['dirname']))) {
    return wfPrintError($album->getErrorMessage());
  }
  /* handle optional parameters and set default value */
  if(!(isset($argv['showtitle']))) /* showTitle - optional parameter - show the title of the album stored in the xml file as well as a number of pictures */
    $showTitle = $showTitleDefault;/* default value is 1 - TRUE */
  else
    $showTitle = $argv['showtitle'];

  if(!(isset($argv['showlarge']))) /* showLarge - optional parameter - enable that the thumbnail serves as a link to large picture */
    $showLarge = $showLargeDefault;/* default value is 1 - TRUE */
  else
    $showLarge = $argv['showlarge'];

  if(!(isset($argv['multiSet']))) /* multiSet - optional parameter - enable to cross-link enlarge pictures*/
    $multiSet = $multiSetDefault; /* default value is 1 - TRUE */
  else
    $multiSet = $argv['multiSet'];


  if ($showTitle)               /* show name of album stored in xml file and count of images */
    $Output .= "<h2><span class=\"mw-headline\">Album: ".$album->getName()." (".$album->getCount().")</span></h2>";

  /* print text contains in <album> text </album> tags */
  $Output .= "<p>$input</p>";

  /* print thumbnails with or without references to large images */
  $Output .= $album->getThumbnailsPrint($showLarge, $multiSet);

  return $Output;
}

function wfPrintError2($error = "") { /* print error */
  return "<p><div class=\"errorbox\"><h2>Error:</h2> $error.</div></p>";
}

function wfPicasa2GalleryJavascriptAndCSS ( &$m_pageObj ) {
  global $wgScriptPath;

  $extensionPath = $wgScriptPath."/extensions/Picasa2";
  // Insert javascript script.
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/prototype.js\"></script>\n");
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/scriptaculous.js?load=effects\"></script>\n");
  $m_pageObj->addScript("<script type=\"text/javascript\" src=\"$extensionPath/js/lightbox.js\"></script>\n");

  $m_pageObj->addScript("<link rel=\"stylesheet\" href=\"$extensionPath/css/lightbox.css\" type=\"text/css\" media=\"screen\" />\n");
  return true;
}

/*******************************************************************************/

Picasa2[edit]

This folder has to be placed in the extension folder. Download.