Extension:GalleryRemoteAlbum/Source
From MediaWiki.org
<?php /** * GalleryRemoteAlbum WikiMedia extension * * @package GalleryRemoteAlbum * @version 0.1 * @author Geoffrey Hing <geoff@terrorware.com> * * This is a WikiMedia extension that I wrote because I wanted to be able * to include multiple thumbnails from a Gallery2 gallery (for more info * on the software, see http://gallery.sf.net) running on a different * server than the one where the MediaWiki is installed. It uses the * Gallery Remote protocol as described at http://gallery.menalto.com/modules.php?op=modload&name=phpWiki&file=index&pagename=Gallery%20Remote%20Documents * to fetch the image urls from Gallery. Right now it only supports a new * MediaWiki tag, <randomalbum>, that allows for the display of an arbitrary * number of random photos from the album to be displayed. It only has the * support I needed in order to build the site for the Plan-It-X Fest Tour * 2005 Documentation Project Wiki (http://pixfestdoc.terrorware.com). * If you find this software useful, encounter a bug, or would like to * see more features, please contact me at geoff@terrorware.com. * * For a more full-featured integration of Gallery as a backend to * WikiMedia, check out the Gallery2wiki extension (http://www.transarte.net/mediawiki/index.php/Gallery2wiki) which allows for the manipulation of albums * within MediaWiki. I wrote this extension because Gallery2wiki doesn't * support the display of an "album" and I don't know if it will work for * a remote gallery. * * To activate this extension, include it from your LocalSettings.php * with: include("extensions/GalleryRemoteAlbum.php"); */ ini_set('include_path', '/kunden/homepages/33/d92846465/htdocs/pear/lib' . PATH_SEPARATOR . ini_get('include_path')); require_once('HTTP/Request.php'); $wgExtensionFunctions[] = "wfGalleryRemoteAlbum"; // Configuration variables $gr2_base_url = 'http://www.mosquitoinc.org/gallery2/main.php'; function wfGalleryRemoteAlbum() { 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( "randomalbum", "renderRandomAlbum" ); } // wfGalleryRemoteAlbum // The callback function for converting the input text to HTML output function renderRandomAlbum( $input, $argv ) { // TODO: Mediawiki doesn't seem to support parameters in the extension // tag (though the docs and example extension claim to in the argv // argument), so just parse it from the input. i.e.: // <randomalbum>album_name,num</randomalbum> $split_input = explode(',', $input); $album_name = $split_input[0]; $num = $split_input[1]; //$album_name = $argv['album_name']; //$num = $argv['num']; get_image_names($album_name, $image_names, $dl_base_url, $show_base_url); if (count($image_names) < $num) { $num = count($image_names); } $rand_keys = array_rand($image_names, $num); $rand_image_names = array(); foreach ($rand_keys as $key) { $rand_image_names[$key] = $image_names[$key]; } return display_images($rand_image_names, $album_name, $dl_base_url, $show_base_url); } function get_image_names($album_name, &$image_names, &$dl_base_url, &$show_base_url) { global $gr2_base_url; $request = new HTTP_Request($gr2_base_url, array("method" => "post", "saveBody" => true)); $request->addQueryString('g2_controller', 'remote:GalleryRemote'); $request->addQueryString('g2_form[cmd]', 'fetch-album-images'); $request->addQueryString('g2_form[protocol-version]', '2.9'); $request->addQueryString('g2_form[set_albumName]', $album_name); $request->sendRequest(); $response = $request->getResponseBody(); # Get the base URL for accessing items and item pages in the gallery preg_match('/baseurl=(.*)/', $response, $matches); $dl_base_url = $matches[1]; $show_base_url = str_replace("Download", "Show", $dl_base_url); $lines = preg_split('/\n/', $response); $image_num = 0; $image_name = ''; $thumb_name = ''; foreach ($lines as $line) { #echo "$line<br />"; # DEBUG if (preg_match('/^image\.name\.(\d+)=(\d+)$/', $line, $matches)) { $image_num = $matches[1]; $image_name = $matches[2]; } if (preg_match('/^image\.thumbName\.(\d+)=(\d+)$/', $line, $matches)) { $thumb_name = $matches[2]; $image_names[$image_num] = array("image_name" => $image_name, "thumb_name" => $thumb_name); } } } // get_image_names function display_images($image_names, $album_name, $dl_base_url, $show_base_url) { $output = "<div id=\"galleryAlbum\" style=\"border: 2px dashed\">\n"; foreach ($image_names as $image) { $output .= sprintf("<div style=\"float: left; margin: 5px 5px 5px 5px\"><a href=\"%s%s\"><img src=\"%s%s\" border=0 /></a></div>", $show_base_url, $image['image_name'], $dl_base_url, $image['thumb_name']); } $output .= sprintf("<div id=\"galleryAlbumLink\" style=\"margin: 5px 5px 5px 5px; clear: both\"><a href=\"%s%s\">View/Add Additional Photos and Video</a></div>", $show_base_url, $album_name); $output .= "</div>\n"; return $output; } // display_images // This is how you get a list of all the albums /* $request = new HTTP_Request($gr2_base_url, array("method" => "post", "saveBody" => true)); $request->addQueryString('g2_controller', 'remote:GalleryRemote'); $request->addQueryString('g2_form[cmd]', 'fetch-albums-prune'); $request->addQueryString('g2_form[protocol-version]', '2.2'); $request->sendRequest(); $response = $request->getResponseBody(); echo $response; */ ?>
