r20366 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20365‎ | r20366 | r20367 >
Date:13:26, 12 March 2007
Author:travis
Status:old
Tags:
Comment:
use farm[0-9].static.flickr.com
Modified paths:
  • /trunk/extensions/ImportFreeImages/ImportFreeImages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ImportFreeImages/ImportFreeImages.php
@@ -17,20 +17,18 @@
1818 $wgExtensionFunctions[] = 'wfImportFreeImages';
1919 $wgIFI_FlickrAPIKey = '';
2020 $wgIFI_CreditsTemplate = 'flickr'; // use this to format the image content with some key parameters
21 -$wgIFI_GetOriginal = true; // import the original version of the photo
22 -$wgIFI_PromptForFilename = true; // prompt the user through javascript for the destination filename
 21+$wgIFI_GetOriginal = false; // import the original version of the photo
 22+$wgIFI_PromptForFilename = false; // prompt the user through javascript for the destination filename
2323
2424 $wgIFI_ResultsPerPage = 20;
25 -$wgIFI_ResultsPerRow = 4;
 25+$wgIFI_ResultsPerRow = 5;
2626 // see the flickr api page for more information on these params
2727 // for licnese info http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
2828 // default 4 is CC Attribution License
2929 $wgIFI_FlickrLicense = "4,5";
30 -$wgIFI_FlickrSort = "interestingness-desc";
31 -$wgIFI_FlickrSearchBy = "tags"; // Can be tags or text. See http://www.flickr.com/services/api/flickr.photos.search.html
 30+$wgIFI_FlickrSort = "relevance";
 31+$wgIFI_FlickrSearchBy = "text"; // Can be tags or text. See http://www.flickr.com/services/api/flickr.photos.search.html
3232 $wgIFI_AppendRandomNumber = true; /// append random # to destination filename
33 -$wgIFI_ThumbType = "t"; // s for square t for thumbnail
34 -
3533 require_once("SpecialPage.php");
3634
3735
@@ -61,6 +59,7 @@
6260 'importfreeimages_filefromflickr' => '$1 by user <b>[$2]</b> from flickr. Original URL',
6361 'importfreeimages_promptuserforfilename' => 'Please enter a destination filename:',
6462 'importfreeimages_returntoform' => 'Or, click <a href=\'$1\'>here</a> to return to return to your search results',
 63+ 'importfreeimages_invalidurl' => 'Invalid URL',
6564 )
6665 );
6766
@@ -126,20 +125,20 @@
127126 {
128127 global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgIFI_FlickrAPIKey, $wgTmpDirectory;
129128 global $wgIFI_ResultsPerPage, $wgIFI_FlickrSort, $wgIFI_FlickrLicense, $wgIFI_ResultsPerRow, $wgIFI_CreditsTemplate;
130 - global $wgIFI_GetOriginal, $wgIFI_PromptForFilename, $wgIFI_AppendRandomNumber, $wgIFI_FlickrSearchBy, $wgIFI_ThumbType;
 129+ global $wgIFI_GetOriginal, $wgIFI_PromptForFilename, $wgIFI_AppendRandomNumber, $wgIFI_FlickrSearchBy;
131130 require_once("phpFlickr-2.0.0/phpFlickr.php");
132131
133132 $fname = "wfSpecialImportFreeImages";
134133 $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages");
135134
136135 if( $wgUser->isAnon() ) {
137 - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
 136+ $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
138137 return;
139138 }
140139
141140 if (empty($wgIFI_FlickrAPIKey)) {
142141 // error - need to set $wgIFI_FlickrAPIKey to use this extension
143 - $wgOut->showErrorPage('error', 'importfreeimages_noapikey');
 142+ $wgOut->errorpage('error', 'importfreeimages_noapikey');
144143 return;
145144 }
146145 $q = '';
@@ -151,10 +150,9 @@
152151 $import = '';
153152 if ($wgRequest->wasPosted() && isset($_POST['url'])) {
154153 $import = $_POST['url'];
155 - if (strpos($import, "http://static.flickr.com/") !== 0) {
156 - // avoid hack attempts
157 - echo "not supported.";
158 - exit;
 154+ if (!preg_match('/^http:\/\/farm[0-9]+.static.flickr.com/', $import)) {
 155+ $wgOut->errorpage('error', 'importfreeimages_invalidurl');
 156+ return;
159157 }
160158
161159 $f = new phpFlickr($wgIFI_FlickrAPIKey);
@@ -185,6 +183,7 @@
186184 fclose($r);
187185 chmod( $name, 0777 );
188186 $info = $f->photos_getInfo($_POST['id']);
 187+
189188
190189 if (!empty($wgIFI_CreditsTemplate)) {
191190 $caption = "{{" . $wgIFI_CreditsTemplate . $info['license'] . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']). "}}";
@@ -192,7 +191,7 @@
193192 $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>$import</nowiki>. {{CC by 2.0}} ";
194193 }
195194 $caption = trim($caption);
196 - $t = $_POST['ititle'];
 195+ $t = $_POST['title'];
197196
198197 // handle duplicate filenames
199198 $i = strrpos($import, "/");
@@ -216,7 +215,7 @@
217216 "caption" => $caption,
218217 "url" => $import, "title" => $_POST['t'] );
219218 */
220 - $filename = urldecode($_POST['ititle']) . ($wgIFI_AppendRandomNumber ? "-" . rand(0, 9999) : "") . ".jpg";
 219+ $filename = urldecode($_POST['title']) . ($wgIFI_AppendRandomNumber ? "-" . rand(0, 9999) : "") . ".jpg";
221220 $filename = str_replace("?", "", $filename);
222221 $filename = str_replace(":", "", $filename);
223222 $filename = preg_replace('/ [ ]*/', ' ', $filename);
@@ -276,21 +275,21 @@
277276 <input type=hidden name='action' value='submit'>
278277 <input type=hidden name='owner' value=''>
279278 <input type=hidden name='name' value=''>
280 - <input type=hidden name='ititle' value=''>
 279+ <input type=hidden name='title' value=''>
281280
282281 <script type=\"text/javascript\">
283282
284 - function s2 (url, id, owner, name, ititle) {
 283+ function s2 (url, id, owner, name, title) {
285284 document.uploadphotoform.url.value = url;
286285 document.uploadphotoform.id.value = id;
287286 document.uploadphotoform.owner.value = owner;
288287 document.uploadphotoform.name.value = name;
289 - document.uploadphotoform.ititle.value = ititle;
 288+ document.uploadphotoform.title.value = title;
290289 if (" . ($wgIFI_PromptForFilename ? "true" : "false") . ") {
291 - ititle = ititle.replace(/\+/g, ' ');
292 - document.uploadphotoform.ititle.value = prompt('" . wfMsg('importfreeimages_promptuserforfilename') . "', unescape(ititle));
293 - if (document.uploadphotoform.ititle.value == '') {
294 - document.uploadphotoform.ititle.value = ititle;
 290+ title = title.replace(/\+/g, ' ');
 291+ document.uploadphotoform.title.value = prompt('" . wfMsg('importfreeimages_promptuserforfilename') . "', unescape(title));
 292+ if (document.uploadphotoform.title.value == '') {
 293+ document.uploadphotoform.title.value = title;
295294 }
296295 }
297296 document.uploadphotoform.submit();
@@ -299,6 +298,8 @@
300299 </script>
301300
302301 ");
 302+//print_r($photos);
 303+//exit;
303304 foreach ($photos['photo'] as $photo) {
304305 if ($i % $wgIFI_ResultsPerRow == 0) $wgOut->addHTML("<tr>");
305306 $owner = $f->people_getInfo($photo['owner']);
@@ -308,9 +309,8 @@
309310 $wgOut->addHTML( "<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>") ;
310311 $wgOut->addHTML( $owner['username'] );
311312 $wgOut->addHTML( "</a><br/>" );
312 - //$wgOut->addHTML( "<img src=http://static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "." . "jpg>" );
313 - $url="http://static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "." . "jpg";
314 - $wgOut->addHTML( "<img src=http://static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "_$wgIFI_ThumbType.jpg>" );
 313+ $url="http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}.jpg";
 314+ $wgOut->addHTML( "<img src=\"http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}_s.jpg\">" );
315315
316316 $wgOut->addHTML( "<br/>(<a href='#' onclick=\"s2('$url', '{$photo['id']}','{$photo['owner']}', '"
317317 . urlencode($owner['username'] ) . "', '" . urlencode($photo['title']) . "');\">" .