Index: trunk/extensions/ImportFreeImages/ImportFreeImages.php |
— | — | @@ -16,16 +16,16 @@ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | $wgExtensionFunctions[] = 'wfImportFreeImages'; |
20 | | -$wgFlickrAPIKey = ''; |
21 | | -$wgTemplateName = 'flickr'; // use this to format the image content with some key parameters |
| 20 | +$wgIFI_FlickrAPIKey = ''; |
| 21 | +$wgIFI_CreditsTemplate = 'flickr'; // use this to format the image content with some key parameters |
22 | 22 | |
23 | | -$wgResultsPerPage = 20; |
24 | | -$wgResultsPerRow = 5; |
| 23 | +$wgIFI_ResultsPerPage = 20; |
| 24 | +$wgIFI_ResultsPerRow = 5; |
25 | 25 | // see the flickr api page for more information on these params |
26 | 26 | // for licnese info http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html |
27 | 27 | // default 4 is CC Attribution License |
28 | | -$wgFlickrLicense = 4; |
29 | | -$wgFlickrSort = "interestingness-desc"; |
| 28 | +$wgIFI_FlickrLicense = 4; |
| 29 | +$wgIFI_FlickrSort = "interestingness-desc"; |
30 | 30 | require_once("SpecialPage.php"); |
31 | 31 | |
32 | 32 | |
— | — | @@ -63,13 +63,19 @@ |
64 | 64 | |
65 | 65 | function wfSpecialImportFreeImages( $par ) |
66 | 66 | { |
67 | | - global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgFlickrAPIKey, $wgTmpDirectory; |
68 | | - global $wgResultsPerPage, $wgFlickrSort, $wgFlickrLicense, $wgResultsPerRow, $wgTemplateName; |
| 67 | + global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgIFI_FlickrAPIKey, $wgTmpDirectory; |
| 68 | + global $wgIFI_ResultsPerPage, $wgIFI_FlickrSort, $wgIFI_FlickrLicense, $wgIFI_ResultsPerRow, $wgIFI_CreditsTemplate; |
69 | 69 | |
70 | 70 | $fname = "wfSpecialImportFreeImages"; |
| 71 | + $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages"); |
71 | 72 | |
72 | | - if (empty($wgFlickrAPIKey)) { |
73 | | - // error - need to set $wgFlickrAPIKey to use this extension |
| 73 | + if( $wgUser->isAnon() ) { |
| 74 | + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + if (empty($wgIFI_FlickrAPIKey)) { |
| 79 | + // error - need to set $wgIFI_FlickrAPIKey to use this extension |
74 | 80 | $wgOut->showErrorPage('error', 'importfreeimages_noapikey'); |
75 | 81 | return; |
76 | 82 | } |
— | — | @@ -78,7 +84,8 @@ |
79 | 85 | $q = $_GET['q']; |
80 | 86 | } |
81 | 87 | |
82 | | - $wgOut->addHTML(wfMsg ('importfreeimages_description') . "<br/><br/><form method=GET>".wfMsg('search'). |
| 88 | + $wgOut->addHTML(wfMsg ('importfreeimages_description') . "<br/><br/> |
| 89 | + <form method=GET action='" . $importPage->getFullURL() . "'>".wfMsg('search'). |
83 | 90 | ": <input type=text name=q value='" . htmlspecialchars($q) . "'><input type=submit value=".wfMsg('search')."></form>"); |
84 | 91 | |
85 | 92 | $import = ''; |
— | — | @@ -95,8 +102,8 @@ |
96 | 103 | $size = fwrite ( $r, $pageContents); |
97 | 104 | fclose($r); |
98 | 105 | chmod( $name, 0777 ); |
99 | | - if (!empty($wgTemplateName)) { |
100 | | - $caption = "{{" . $wgTemplateName . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']). "}}"; |
| 106 | + if (!empty($wgIFI_CreditsTemplate)) { |
| 107 | + $caption = "{{" . $wgIFI_CreditsTemplate . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']). "}}"; |
101 | 108 | } else { |
102 | 109 | $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>$import</nowiki>. {{CC by 2.0}} "; |
103 | 110 | } |
— | — | @@ -139,21 +146,20 @@ |
140 | 147 | $page = $_GET['p']; |
141 | 148 | if ($page == '') $page = 1; |
142 | 149 | require_once("phpFlickr-2.0.0/phpFlickr.php"); |
143 | | - $f = new phpFlickr($wgFlickrAPIKey); |
| 150 | + $f = new phpFlickr($wgIFI_FlickrAPIKey); |
144 | 151 | $q = $_GET['q']; |
145 | 152 | // TODO: get the right licenses |
146 | 153 | $photos = $f->photos_search(array( |
147 | 154 | "tags"=>"$q", "tag_mode"=>"any", |
148 | 155 | "page" => $page, |
149 | | - "per_page" => $wgResultsPerPage, "license" => $wgFlickrLicense, |
150 | | - "sort" => $wgFlickrSort )); |
| 156 | + "per_page" => $wgIFI_ResultsPerPage, "license" => $wgIFI_FlickrLicense, |
| 157 | + "sort" => $wgIFI_FlickrSort )); |
151 | 158 | |
152 | 159 | $i = 0; |
153 | 160 | if ($photos == null || !is_array($photos) || sizeof($photos) == 0 || !isset($photos['photo']) ) { |
154 | 161 | $wgOut->addHTML(wfMsg("importfreeimages_nophotosfound",$q)); |
155 | 162 | return; |
156 | 163 | } |
157 | | - $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages"); |
158 | 164 | $sk = $wgUser->getSkin(); |
159 | 165 | |
160 | 166 | $wgOut->addHTML("<table cellpadding=4> |
— | — | @@ -180,7 +186,7 @@ |
181 | 187 | |
182 | 188 | "); |
183 | 189 | foreach ($photos['photo'] as $photo) { |
184 | | - if ($i % $wgResultsPerRow == 0) $wgOut->addHTML("<tr>"); |
| 190 | + if ($i % $wgIFI_ResultsPerRow == 0) $wgOut->addHTML("<tr>"); |
185 | 191 | $owner = $f->people_getInfo($photo['owner']); |
186 | 192 | $wgOut->addHTML( "<td align=center style='padding-top: 15px; border-bottom: 1px solid #ccc;'><font size=-2><a href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>" ); |
187 | 193 | $wgOut->addHTML( $photo['title'] ); |
— | — | @@ -195,13 +201,13 @@ |
196 | 202 | . urlencode($owner['username'] ) . "', '" . urlencode($photo['title']) . "');\">" . |
197 | 203 | wfMsg('importfreeimages_importthis') . "</a>)\n" ); |
198 | 204 | $wgOut->addHTML("</td>"); |
199 | | - if ($i % $wgResultsPerRow == ($wgResultsPerRow - 1) ) $wgOut->addHTML("</tr>"); |
| 205 | + if ($i % $wgIFI_ResultsPerRow == ($wgIFI_ResultsPerRow - 1) ) $wgOut->addHTML("</tr>"); |
200 | 206 | $i++; |
201 | 207 | } |
202 | 208 | $wgOut->addHTML("</form></table>"); |
203 | 209 | $page = $page + 1; |
204 | 210 | |
205 | | - $wgOut->addHTML("<br/>" . $sk->makeLinkObj($importPage, wfMsg('importfreeimages_next', $wgResultsPerPage), "p=$page&q=" . urlencode($q) ) ); |
| 211 | + $wgOut->addHTML("<br/>" . $sk->makeLinkObj($importPage, wfMsg('importfreeimages_next', $wgIFI_ResultsPerPage), "p=$page&q=" . urlencode($q) ) ); |
206 | 212 | //print_r($photo); |
207 | 213 | } |
208 | 214 | } |