Index: trunk/extensions/ImportFreeImages/ImportFreeImages.php |
— | — | @@ -17,20 +17,18 @@ |
18 | 18 | $wgExtensionFunctions[] = 'wfImportFreeImages'; |
19 | 19 | $wgIFI_FlickrAPIKey = ''; |
20 | 20 | $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 |
23 | 23 | |
24 | 24 | $wgIFI_ResultsPerPage = 20; |
25 | | -$wgIFI_ResultsPerRow = 4; |
| 25 | +$wgIFI_ResultsPerRow = 5; |
26 | 26 | // see the flickr api page for more information on these params |
27 | 27 | // for licnese info http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html |
28 | 28 | // default 4 is CC Attribution License |
29 | 29 | $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 |
32 | 32 | $wgIFI_AppendRandomNumber = true; /// append random # to destination filename |
33 | | -$wgIFI_ThumbType = "t"; // s for square t for thumbnail |
34 | | - |
35 | 33 | require_once("SpecialPage.php"); |
36 | 34 | |
37 | 35 | |
— | — | @@ -61,6 +59,7 @@ |
62 | 60 | 'importfreeimages_filefromflickr' => '$1 by user <b>[$2]</b> from flickr. Original URL', |
63 | 61 | 'importfreeimages_promptuserforfilename' => 'Please enter a destination filename:', |
64 | 62 | 'importfreeimages_returntoform' => 'Or, click <a href=\'$1\'>here</a> to return to return to your search results', |
| 63 | + 'importfreeimages_invalidurl' => 'Invalid URL', |
65 | 64 | ) |
66 | 65 | ); |
67 | 66 | |
— | — | @@ -126,20 +125,20 @@ |
127 | 126 | { |
128 | 127 | global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgIFI_FlickrAPIKey, $wgTmpDirectory; |
129 | 128 | 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; |
131 | 130 | require_once("phpFlickr-2.0.0/phpFlickr.php"); |
132 | 131 | |
133 | 132 | $fname = "wfSpecialImportFreeImages"; |
134 | 133 | $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages"); |
135 | 134 | |
136 | 135 | if( $wgUser->isAnon() ) { |
137 | | - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
| 136 | + $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); |
138 | 137 | return; |
139 | 138 | } |
140 | 139 | |
141 | 140 | if (empty($wgIFI_FlickrAPIKey)) { |
142 | 141 | // error - need to set $wgIFI_FlickrAPIKey to use this extension |
143 | | - $wgOut->showErrorPage('error', 'importfreeimages_noapikey'); |
| 142 | + $wgOut->errorpage('error', 'importfreeimages_noapikey'); |
144 | 143 | return; |
145 | 144 | } |
146 | 145 | $q = ''; |
— | — | @@ -151,10 +150,9 @@ |
152 | 151 | $import = ''; |
153 | 152 | if ($wgRequest->wasPosted() && isset($_POST['url'])) { |
154 | 153 | $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; |
159 | 157 | } |
160 | 158 | |
161 | 159 | $f = new phpFlickr($wgIFI_FlickrAPIKey); |
— | — | @@ -185,6 +183,7 @@ |
186 | 184 | fclose($r); |
187 | 185 | chmod( $name, 0777 ); |
188 | 186 | $info = $f->photos_getInfo($_POST['id']); |
| 187 | + |
189 | 188 | |
190 | 189 | if (!empty($wgIFI_CreditsTemplate)) { |
191 | 190 | $caption = "{{" . $wgIFI_CreditsTemplate . $info['license'] . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']). "}}"; |
— | — | @@ -192,7 +191,7 @@ |
193 | 192 | $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>$import</nowiki>. {{CC by 2.0}} "; |
194 | 193 | } |
195 | 194 | $caption = trim($caption); |
196 | | - $t = $_POST['ititle']; |
| 195 | + $t = $_POST['title']; |
197 | 196 | |
198 | 197 | // handle duplicate filenames |
199 | 198 | $i = strrpos($import, "/"); |
— | — | @@ -216,7 +215,7 @@ |
217 | 216 | "caption" => $caption, |
218 | 217 | "url" => $import, "title" => $_POST['t'] ); |
219 | 218 | */ |
220 | | - $filename = urldecode($_POST['ititle']) . ($wgIFI_AppendRandomNumber ? "-" . rand(0, 9999) : "") . ".jpg"; |
| 219 | + $filename = urldecode($_POST['title']) . ($wgIFI_AppendRandomNumber ? "-" . rand(0, 9999) : "") . ".jpg"; |
221 | 220 | $filename = str_replace("?", "", $filename); |
222 | 221 | $filename = str_replace(":", "", $filename); |
223 | 222 | $filename = preg_replace('/ [ ]*/', ' ', $filename); |
— | — | @@ -276,21 +275,21 @@ |
277 | 276 | <input type=hidden name='action' value='submit'> |
278 | 277 | <input type=hidden name='owner' value=''> |
279 | 278 | <input type=hidden name='name' value=''> |
280 | | - <input type=hidden name='ititle' value=''> |
| 279 | + <input type=hidden name='title' value=''> |
281 | 280 | |
282 | 281 | <script type=\"text/javascript\"> |
283 | 282 | |
284 | | - function s2 (url, id, owner, name, ititle) { |
| 283 | + function s2 (url, id, owner, name, title) { |
285 | 284 | document.uploadphotoform.url.value = url; |
286 | 285 | document.uploadphotoform.id.value = id; |
287 | 286 | document.uploadphotoform.owner.value = owner; |
288 | 287 | document.uploadphotoform.name.value = name; |
289 | | - document.uploadphotoform.ititle.value = ititle; |
| 288 | + document.uploadphotoform.title.value = title; |
290 | 289 | 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; |
295 | 294 | } |
296 | 295 | } |
297 | 296 | document.uploadphotoform.submit(); |
— | — | @@ -299,6 +298,8 @@ |
300 | 299 | </script> |
301 | 300 | |
302 | 301 | "); |
| 302 | +//print_r($photos); |
| 303 | +//exit; |
303 | 304 | foreach ($photos['photo'] as $photo) { |
304 | 305 | if ($i % $wgIFI_ResultsPerRow == 0) $wgOut->addHTML("<tr>"); |
305 | 306 | $owner = $f->people_getInfo($photo['owner']); |
— | — | @@ -308,9 +309,8 @@ |
309 | 310 | $wgOut->addHTML( "<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>") ; |
310 | 311 | $wgOut->addHTML( $owner['username'] ); |
311 | 312 | $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\">" ); |
315 | 315 | |
316 | 316 | $wgOut->addHTML( "<br/>(<a href='#' onclick=\"s2('$url', '{$photo['id']}','{$photo['owner']}', '" |
317 | 317 | . urlencode($owner['username'] ) . "', '" . urlencode($photo['title']) . "');\">" . |