/**
  * Show the search result if available
  */
 protected function showResult()
 {
     global $wgRequest, $wgUser, $wgOut;
     $page = $wgRequest->getInt('p', 1);
     $q = $wgRequest->getVal('q');
     if (!$q) {
         return;
     }
     $ifi = new ImportFreeImages();
     // TODO: get the right licenses
     $photos = $ifi->searchPhotos($q, $page);
     if (!$photos) {
         $wgOut->addHTML(wfMsg('importfreeimages_nophotosfound', htmlspecialchars($q)));
         return;
     }
     $sk = $wgUser->getSkin();
     $wgOut->addHTML('<table cellpadding="4" id="mw-ifi-result">');
     $specialUploadTitle = SpecialPage::getTitleFor('Upload');
     $ownermsg = wfMsg('importfreeimages_owner');
     $importmsg = wfMsg('importfreeimages_importthis');
     $i = 0;
     foreach ($photos['photo'] as $photo) {
         $owner = $ifi->getOwnerInfo($photo['owner']);
         $owner_esc = htmlspecialchars($photo['owner'], ENT_QUOTES);
         $id_esc = htmlspecialchars($photo['id'], ENT_QUOTES);
         $title_esc = htmlspecialchars($photo['title'], ENT_QUOTES);
         $username_esc = htmlspecialchars($owner['username'], ENT_QUOTES);
         $thumb_esc = htmlspecialchars("http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}_{$ifi->thumbType}.jpg", ENT_QUOTES);
         $format = isset($photo['originalformat']) ? $photo['originalformat'] : '.jpg';
         $link = $specialUploadTitle->escapeLocalURL(array('wpSourceType' => 'IFI', 'wpFlickrId' => $photo['id'], 'wpDestFile' => $photo['title'] . '.' . $format));
         if ($i % $ifi->resultsPerRow == 0) {
             $wgOut->addHTML('<tr>');
         }
         # TODO: Fix nasty HTML generation
         $wgOut->addHTML("\n\t\t\t\t\t<td align='center' style='padding-top: 15px; border-bottom: 1px solid #ccc;'>\n\t\t\t\t\t\t<font size=-2><a href='http://www.flickr.com/photos/{$owner_esc}/{$id_esc}/'>{$title_esc}</a>\n\t\t\t\t\t\t<br />{$ownermsg}: <a href='http://www.flickr.com/people/{$owner_esc}/'>{$username_esc}</a>\n\t\t\t\t\t\t<br /><img src='{$thumb_esc}' />\n\t\t\t\t\t\t<br />(<a href='{$link}'>{$importmsg}</a>)</font>\n\t\t\t\t\t</td>\n\t\t\t");
         if ($i % $ifi->resultsPerRow == $ifi->resultsPerRow - 1) {
             $wgOut->addHTML('</tr>');
         }
         $i++;
     }
     $wgOut->addHTML('</table>');
     if ($ifi->resultsPerPage * $page < $photos['total']) {
         $page++;
         $wgOut->addHTML('<br />' . $sk->makeLinkObj($this->getTitle(), wfMsgHtml('importfreeimages_next', $ifi->resultsPerPage), "p={$page}&q=" . urlencode($q)));
     }
 }
Example #2
0
 public static function onUploadFormInitDescriptor(&$descriptor)
 {
     global $wgRequest;
     if ($wgRequest->getVal('wpSourceType') != 'IFI' || !$wgRequest->getCheck('wpFlickrId')) {
         return true;
     }
     $ifi = new ImportFreeImages();
     $id = $wgRequest->getVal('wpFlickrId', 0);
     $info = $ifi->getPhotoInfo($id);
     $name_wiki = wfEscapeWikiText($info['owner']['username']);
     if ($ifi->creditsTemplate) {
         $owner_wiki = wfEscapeWikiText($info['owner']['realname']);
         $id_wiki = wfEscapeWikiText($id);
         $caption = "{{" . $ifi->creditsTemplate . intval($info['license']) . "|1={$id_wiki}|2={$owner_wiki}|3={$name_wiki}}}";
     } else {
         // TODO: this is totally wrong: The whole message should be configurable, we shouldn't include arbitrary templates
         // additionally, the license information is not correct (we are not guaranteed to get "CC by 2.0" images only)
         $caption = wfMsgForContent('importfreeimages_filefromflickr', $info['title'], 'http://www.flickr.com/people/' . urlencode($info['owner']['username']) . ' ' . $name_wiki) . ' {{CC by 2.0}} ';
         $caption = trim($caption);
     }
     $descriptor['UploadDescription']['default'] = $caption;
     return true;
 }