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 publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | 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 |
+ | # 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 , |
+ | # How many pictures to show , limit < 10 |
+ | |||
− | # Make really sure the input is integer |
||
− | if (is_numeric($argv["limit"] |
+ | if (is_numeric($argv["limit"]) && $argv["limit"]>=0 && $argv["limit"] <=11) { |
− | $limit= |
+ | $limit=$argv["limit"]; |
} else { |
} else { |
||
$limit=3; |
$limit=3; |
||
} |
} |
||
− | # |
+ | # just in case |
− | $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(" |
+ | require_once("phpFlickr.php"); |
− | $f = new phpFlickr("< |
+ | $f = new phpFlickr("<Your FlickrAPI key here>"); |
$f->enableCache("fs","./flickr_cache"); |
$f->enableCache("fs","./flickr_cache"); |
||
⚫ | |||
− | |||
⚫ | |||
$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><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 |
+ | $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; |
||
} |
} |
||
+ | ?> |
||
?> |
?> |
||
+ | </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]] |