Editing Flickr Extension

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
This is a little [[Mediawiki]] Extension to include [[Wikipedia:Flickr|Flickr]] thumbnails. This example gets the X most interesting pictures (yes, Flickr really sorts like "sort"=>"interestingness-desc", by the users rating) for the tag you specify. You can use this to '''instantly put some related pictures on Wiki pages that dont have pictures yet'''. This is just a quick example, and can be heavily extended. Feel free to do so.
+
I have written this little [[Mediawiki]] Extension to include [[Flickr]] thumbnails. This first example gets the X most interesting pictures (yes, Flickr really sorts like "sort"=>"interestingness-desc", by the users rating) for the tag you specify. You can use this to put some related pictures on Wiki pages that dont have pictures yet very quickly.
 +
 
 +
What you type:
 +
 
 +
<nowiki><flickr>Leary</flickr></nowiki>
  
 +
 +
What you get:
 +
 +
<flickr>Leary</flickr>
  
 
What you type:
 
What you type:
Line 10: Line 18:
  
 
<flickr limit=5>Fnord</flickr>
 
<flickr limit=5>Fnord</flickr>
 
If you wish to just insert one photo, of your choice, then you require this Flickr extension : http://wiki.edsimpson.co.uk/index.php/Flickr_Extension (which requires no additional PEAR or phpFlickr libraries).
 
  
 
The <nowiki><flickr></nowiki>-tag surrounds a keyword/Flickr Tag and optionally you can use limit to change the amount of thumbnails being shown, the maximum for tag-length is 255 chars and the maximum for limit is 10.
 
The <nowiki><flickr></nowiki>-tag surrounds a keyword/Flickr Tag and optionally you can use limit to change the amount of thumbnails being shown, the maximum for tag-length is 255 chars and the maximum for limit is 10.
Line 18: Line 24:
  
 
=== Source ===
 
=== Source ===
<highlightSyntax>  
+
 
 +
<pre>
 
<?php
 
<?php
 
# Flickr > Mediawiki MashUp Test (Web 2.3)
 
# Flickr > Mediawiki MashUp Test (Web 2.3)
 
# mutante from http://s23.org/wiki
 
# mutante from http://s23.org/wiki
 
# inspired by "iX" magazine issue July 2006, p.62  article "Bildergeflimmer"
 
# inspired by "iX" magazine issue July 2006, p.62  article "Bildergeflimmer"
# greets: cosmea,took,DrOwl,Kunda,Finn,hundfred,kdoz... and all of S23
+
# greets to cosmea
  
 
$wgExtensionFunctions[] = "wfFlickrExtension";
 
$wgExtensionFunctions[] = "wfFlickrExtension";
Line 33: Line 40:
 
$wgParser->setHook( "flickr", "renderFlickr" );
 
$wgParser->setHook( "flickr", "renderFlickr" );
 
   }
 
   }
 
$wgExtensionCredits['parserhook'][] = array(
 
        'name' => 'Flicker extension',
 
        'author' => '[[User:mutante|mutante]]',
 
        'url' => 'http://s23.org/wiki/Flickr Extension',
 
        'version' => '0.23',
 
        'description' => 'Lets users insert \'most interesting\' [[Flickr]] thumbnails into wiki pages.'
 
);
 
  
 
function renderFlickr( $input, $argv ) {
 
function renderFlickr( $input, $argv ) {
Line 46: Line 45:
  
  
# How many pictures to show , upper limit 10, if not good,set default to 3
+
# How many pictures to show , limit < 10
# Make really sure the input is integer
+
 
if (is_numeric($argv["limit"]) && is_int(intval($argv["limit"])) && $argv["limit"]>0 && $argv["limit"] <11) {
+
if (is_numeric($argv["limit"]) && $argv["limit"]>=0 && $argv["limit"] <=11) {
$limit=intval($argv["limit"]);
+
$limit=$argv["limit"];
 
} else {
 
} else {
 
$limit=3;
 
$limit=3;
 
}
 
}
  
# What is the tag
+
# just in case
$input = mysql_real_escape_string($input);
+
$input = mysql_escape_string($input);
  
 
# If not too long, set Input Text as Tag
 
# If not too long, set Input Text as Tag
 +
 
if (!is_string($input) || strlen($input)>255) {
 
if (!is_string($input) || strlen($input)>255) {
 
$input="error";
 
$input="error";
Line 64: Line 64:
 
}
 
}
  
require_once("./extensions/phpFlickr-2.0.0/phpFlickr.php");
+
require_once("phpFlickr.php");
  
$f = new phpFlickr("<your Flickr API key here>");
+
$f = new phpFlickr("<Your FlickrAPI key here>");
 
$f->enableCache("fs","./flickr_cache");
 
$f->enableCache("fs","./flickr_cache");
  
 
+
# get the X most interesting pictures for this tag
# get the X most interesting pictures for tag "flower"
 
 
$photos_interesting = $f->photos_search(array("tags"=>"$tag", "sort"=>"interestingness-desc","per_page"=>$limit));
 
$photos_interesting = $f->photos_search(array("tags"=>"$tag", "sort"=>"interestingness-desc","per_page"=>$limit));
  
 
# output a table with the pictures
 
# output a table with the pictures
  
$output="<table><tr><td colspan='$limit'>The $limit most interesting photos from Flickr for the tag <b>'$tag'</b></td></tr><tr>";
+
$output="<table><tr><td colspan='$limit'>The $limit most interesting photos from Flickr for the tag <b>'$tag'</b></td></tr><t$
 
if (is_array ($photos_interesting['photo']) && count($photos_interesting['photo'])>0) {
 
if (is_array ($photos_interesting['photo']) && count($photos_interesting['photo'])>0) {
 
foreach ($photos_interesting['photo'] as $photo) {
 
foreach ($photos_interesting['photo'] as $photo) {
$output.="<td><a href=http://www.flickr.com/photos/$photo[owner]/$photo[id]><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></a></td>";
+
$output.="<td><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></td>";
 
}
 
}
 
$output.="</tr></table>";
 
$output.="</tr></table>";
Line 86: Line 85:
 
return $output;
 
return $output;
 
         }
 
         }
 +
?>
  
 
?>
 
?>
</highlightSyntax>  
+
</pre>
  
 +
As always, this is just a quick example, and can be heavily extended. Feel free to do so.
  
 
[[Category:Mediawiki Extensions]]
 
[[Category:Mediawiki Extensions]]

Please note that all contributions to s23 are considered to be released under the Creative Commons Attribution Share Alike (see s23:Copyrights for details) unless another license is specified on a specific page. If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
When uploading your own work you can choose from different cc license types, a GNU license like GFDL or you can declare it entirely Public domain. Use the according license template on a page. If no specific license is specified, Creative Commons Attribution Share Alike will apply. You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!

Cancel Editing help (opens in new window)