r18256 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r18255‎ | r18256 | r18257 >
Date:14:33, 11 December 2006
Author:travis
Status:old
Tags:
Comment:
change global variable names, add error for anon users
Modified paths:
  • /trunk/extensions/ImportFreeImages/ImportFreeImages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ImportFreeImages/ImportFreeImages.php
@@ -16,16 +16,16 @@
1717 */
1818
1919 $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
2222
23 -$wgResultsPerPage = 20;
24 -$wgResultsPerRow = 5;
 23+$wgIFI_ResultsPerPage = 20;
 24+$wgIFI_ResultsPerRow = 5;
2525 // see the flickr api page for more information on these params
2626 // for licnese info http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
2727 // default 4 is CC Attribution License
28 -$wgFlickrLicense = 4;
29 -$wgFlickrSort = "interestingness-desc";
 28+$wgIFI_FlickrLicense = 4;
 29+$wgIFI_FlickrSort = "interestingness-desc";
3030 require_once("SpecialPage.php");
3131
3232
@@ -63,13 +63,19 @@
6464
6565 function wfSpecialImportFreeImages( $par )
6666 {
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;
6969
7070 $fname = "wfSpecialImportFreeImages";
 71+ $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages");
7172
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
7480 $wgOut->showErrorPage('error', 'importfreeimages_noapikey');
7581 return;
7682 }
@@ -78,7 +84,8 @@
7985 $q = $_GET['q'];
8086 }
8187
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').
8390 ": <input type=text name=q value='" . htmlspecialchars($q) . "'><input type=submit value=".wfMsg('search')."></form>");
8491
8592 $import = '';
@@ -95,8 +102,8 @@
96103 $size = fwrite ( $r, $pageContents);
97104 fclose($r);
98105 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']). "}}";
101108 } else {
102109 $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>$import</nowiki>. {{CC by 2.0}} ";
103110 }
@@ -139,21 +146,20 @@
140147 $page = $_GET['p'];
141148 if ($page == '') $page = 1;
142149 require_once("phpFlickr-2.0.0/phpFlickr.php");
143 - $f = new phpFlickr($wgFlickrAPIKey);
 150+ $f = new phpFlickr($wgIFI_FlickrAPIKey);
144151 $q = $_GET['q'];
145152 // TODO: get the right licenses
146153 $photos = $f->photos_search(array(
147154 "tags"=>"$q", "tag_mode"=>"any",
148155 "page" => $page,
149 - "per_page" => $wgResultsPerPage, "license" => $wgFlickrLicense,
150 - "sort" => $wgFlickrSort ));
 156+ "per_page" => $wgIFI_ResultsPerPage, "license" => $wgIFI_FlickrLicense,
 157+ "sort" => $wgIFI_FlickrSort ));
151158
152159 $i = 0;
153160 if ($photos == null || !is_array($photos) || sizeof($photos) == 0 || !isset($photos['photo']) ) {
154161 $wgOut->addHTML(wfMsg("importfreeimages_nophotosfound",$q));
155162 return;
156163 }
157 - $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages");
158164 $sk = $wgUser->getSkin();
159165
160166 $wgOut->addHTML("<table cellpadding=4>
@@ -180,7 +186,7 @@
181187
182188 ");
183189 foreach ($photos['photo'] as $photo) {
184 - if ($i % $wgResultsPerRow == 0) $wgOut->addHTML("<tr>");
 190+ if ($i % $wgIFI_ResultsPerRow == 0) $wgOut->addHTML("<tr>");
185191 $owner = $f->people_getInfo($photo['owner']);
186192 $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'] . "/'>" );
187193 $wgOut->addHTML( $photo['title'] );
@@ -195,13 +201,13 @@
196202 . urlencode($owner['username'] ) . "', '" . urlencode($photo['title']) . "');\">" .
197203 wfMsg('importfreeimages_importthis') . "</a>)\n" );
198204 $wgOut->addHTML("</td>");
199 - if ($i % $wgResultsPerRow == ($wgResultsPerRow - 1) ) $wgOut->addHTML("</tr>");
 205+ if ($i % $wgIFI_ResultsPerRow == ($wgIFI_ResultsPerRow - 1) ) $wgOut->addHTML("</tr>");
200206 $i++;
201207 }
202208 $wgOut->addHTML("</form></table>");
203209 $page = $page + 1;
204210
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) ) );
206212 //print_r($photo);
207213 }
208214 }