/** * 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))); } }