×
Create a new article
Write your page title here:
We currently have 3185 articles on s23. Type your article name above or click on one of the titles below and start writing!



s23
3185Articles

Difference between revisions of "Flickr Extension"

imported>mutante
m
imported>mutante
m (adding extension credits that are used)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
I have written this little Mediawiki Extension to include Flickr thumbnails, this gets the x most interesting (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.
+
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.
  
What you type:
 
 
<nowiki><flickr>Leary</flickr></nowiki>
 
 
 
What you get:
 
 
<flickr>Leary</flickr>
 
  
 
What you type:
 
What you type:
Line 18: Line 10:
  
 
<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 24: Line 18:
  
 
=== 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 to cosmea
+
# greets: cosmea,took,DrOwl,Kunda,Finn,hundfred,kdoz... and all of S23
  
 
$wgExtensionFunctions[] = "wfFlickrExtension";
 
$wgExtensionFunctions[] = "wfFlickrExtension";
Line 40: Line 33:
 
$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 45: Line 46:
  
  
# How many pictures to show , limit < 10
+
# How many pictures to show , upper limit 10, if not good,set default to 3
 
+
# Make really sure the input is integer
if (is_numeric($argv["limit"]) && $argv["limit"]>=0 && $argv["limit"] <=11) {
+
if (is_numeric($argv["limit"]) && is_int(intval($argv["limit"])) && $argv["limit"]>0 && $argv["limit"] <11) {
$limit=$argv["limit"];
+
$limit=intval($argv["limit"]);
 
} else {
 
} else {
 
$limit=3;
 
$limit=3;
 
}
 
}
  
# just in case
+
# What is the tag
$input = mysql_escape_string($input);
+
$input = mysql_real_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("phpFlickr.php");
+
require_once("./extensions/phpFlickr-2.0.0/phpFlickr.php");
  
$f = new phpFlickr("<Your FlickrAPI key here>");
+
$f = new phpFlickr("<your Flickr API 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><$
+
$output="<table><tr><td colspan='$limit'>The $limit most interesting photos from Flickr for the tag <b>'$tag'</b></td></tr><tr>";
 +
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><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></td>";
+
$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.="</tr></table>";
 
$output.="</tr></table>";
 
+
} else {
 +
$output="<i>Flickr Extension: no images found for tag <b>$input</b></i>";
 +
}
 
return $output;
 
return $output;
 
         }
 
         }
 +
 
?>
 
?>
</pre>
+
</highlightSyntax>  
  
As always, this is just a quick example, and can be heavily extended. Feel free to do so.
 
  
 
[[Category:Mediawiki Extensions]]
 
[[Category:Mediawiki Extensions]]

Latest revision as of 22:54, 21 December 2008

This is a little Mediawiki Extension to include 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.


What you type:

<flickr limit=5>Fnord</flickr>


What you get:

<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 <flickr>-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.

This is possible due to using a) the Flickr API, b) phpFlickr, c) the Debian PHP-Pear packages and d) a nice article in the latest iX (german) magazine, issue July 2006, p. 62 called "Bildergeflimmer". We could call this a Flickr->Mediawiki Mashup (->same iX issue, p. 55). mutante 20:56, 18 June 2006 (CEST)

Source[edit]

<highlightSyntax> <?php

  1. Flickr > Mediawiki MashUp Test (Web 2.3)
  2. mutante from http://s23.org/wiki
  3. inspired by "iX" magazine issue July 2006, p.62 article "Bildergeflimmer"
  4. greets: cosmea,took,DrOwl,Kunda,Finn,hundfred,kdoz... and all of S23

$wgExtensionFunctions[] = "wfFlickrExtension";

  1. extension hook callback function from mediawiki

function wfFlickrExtension() { global $wgParser; $wgParser->setHook( "flickr", "renderFlickr" );

  }

$wgExtensionCredits['parserhook'][] = array(

       'name' => 'Flicker extension',
       'author' => '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 ) { global $wgOutputEncoding;


  1. How many pictures to show , upper limit 10, if not good,set default to 3
  2. Make really sure the input is integer

if (is_numeric($argv["limit"]) && is_int(intval($argv["limit"])) && $argv["limit"]>0 && $argv["limit"] <11) { $limit=intval($argv["limit"]); } else { $limit=3; }

  1. What is the tag

$input = mysql_real_escape_string($input);

  1. If not too long, set Input Text as Tag

if (!is_string($input) || strlen($input)>255) { $input="error"; } else { $tag=$input; }

require_once("./extensions/phpFlickr-2.0.0/phpFlickr.php");

$f = new phpFlickr("<your Flickr API key here>"); $f->enableCache("fs","./flickr_cache");


  1. get the X most interesting pictures for tag "flower"

$photos_interesting = $f->photos_search(array("tags"=>"$tag", "sort"=>"interestingness-desc","per_page"=>$limit));

  1. output a table with the pictures

$output="

";

if (is_array ($photos_interesting['photo']) && count($photos_interesting['photo'])>0) { foreach ($photos_interesting['photo'] as $photo) {

$output.="";

}

$output.="
The $limit most interesting photos from Flickr for the tag '$tag'
<a href=http://www.flickr.com/photos/$photo[owner]/$photo[id]><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></a>

";

} else { $output="Flickr Extension: no images found for tag $input"; } return $output;

       }

?> </highlightSyntax>