/** * @brief Returns an array containing result from Image Serving * * @requestParam Array $ids an array of Article IDs from which to retrieve images * @requestParam int $width the desired thumbnail width in pixels * @requestParam mixed $height the desired thumbnail height in pixels or an array of proportions (@see ImageServing::getImages) * @requestParam int $count the maximum number of images to retrieve for each Article ID * * @responseParam Array $result a multi-dimensional array whith the Article ID as the key and an array of image URL's as the values */ public function getImages() { $this->response->setFormat('json'); if (!$this->wg->User->isAllowed('read')) { $this->setVal('status', 'error'); $this->setVal('result', 'User is not allowed to read'); return true; } $ids = $this->getVal('ids'); if (!is_array($ids)) { $this->setVal('status', 'error'); $this->setVal('result', 'ids list needs to be an array'); return true; } foreach ($ids as $key => $val) { $ids[$key] = (int) $ids[$key]; } $height = $this->getVal('height'); if (!is_array($height)) { $height = (int) $height; } $width = (int) $this->getVal('width'); $count = (int) $this->getVal('count'); if (!is_array($height) && $height < 1 || $count < 1 || $width < 1 || count($ids) < 1) { $this->setVal('status', 'error'); $this->setVal('result', 'height, width, count and the total of passed in ID\'s need to be bigger than 0'); return true; } $is = new ImageServing($ids, $width, $height); $this->setVal('status', 'ok'); $this->setVal('result', $is->getImages($count)); }
public function getForMap() { $pageName = $this->request->getVal('title'); $oTitle = Title::newFromText($pageName); if (empty($oTitle) || !$oTitle->exists()) { return array(); } $pageId = $oTitle->getArticleId(); // TODO: getImages() are not cached $imageServing = new ImageServing(array($pageId), 100, array('w' => 1, 'h' => 1)); $images = $imageServing->getImages(1); if (!empty($images[$pageId][0]['url'])) { $imageUrl = $images[$pageId][0]['url']; } else { $imageUrl = ''; } $oArticleService = F::Build('ArticleService'); $oArticleService->setArticleById($pageId); $textSnippet = $oArticleService->getTextSnippet(120); $strPos = mb_strrpos($textSnippet, ' '); $textSnippet = mb_substr($textSnippet, 0, $strPos); $textSnippet .= ' ...'; $this->setVal('title', $oTitle->getText()); $this->setVal('imgUrl', $imageUrl); $this->setVal('articleUrl', $oTitle->getLocalUrl()); $this->setVal('textSnippet', $textSnippet); }
public function execute() { global $wgRequest; wfProfileIn(__METHOD__); extract($this->extractRequestParams()); $imageServing = new ImageServing(array($Id), $Size, array("w" => $Size, "h" => $Height)); foreach ($imageServing->getImages(1) as $key => $value) { $tmpTitle = Title::newFromText($value[0]['name'], NS_FILE); $image = wfFindFile($tmpTitle); // BugId:31460 ForeignAPIFile does not support loading metadata from the file itself. // Note, that ForeignAPIFile::getPath() is a dommy method and always returns false, so // the 'File not found' dieUsage() call in the next if block is inevitable for ForeignAPIFile objects. if ($FailOnFileNotFound && false == $image instanceof ForeignAPIFile) { $image->loadFromFile(); // side effect forces isMissing() check to fail if file really does not exist } if (!($image instanceof File && $image->exists()) || $image->isMissing() || $image->mime == 'unknown/unknown') { $this->dieUsage('File not found', 'filenotfound'); } $width = $image->getWidth(); $height = $image->getHeight(); $imageUrl = $imageServing->getUrl($image->getName(), $width, $height); } $result = $this->getResult(); $result->addValue('image', $this->getModuleName(), $imageUrl); $result->addValue('imagepage', $this->getModuleName(), $tmpTitle->getFullUrl()); wfProfileOut(__METHOD__); }
/** * Returns information to summarize an article with a snippet of text and a picture if applicable. */ public function blurb() { wfProfileIn(__METHOD__); $idStr = $this->request->getVal('ids'); $ids = explode(',', $idStr); $summary = array(); # Iterate through each title per wiki ID foreach ($ids as $id) { $title = Title::newFromID($id); if (empty($title)) { $summary[$this->wg->CityId]['error'][] = "Unable to find title for ID {$id}"; break; } $service = new ArticleService($id); $snippet = $service->getTextSnippet(); $imageServing = new ImageServing(array($id), 200, array('w' => 2, 'h' => 1)); $images = $imageServing->getImages(1); // get just one image per article $imageURL = ''; if (isset($images[$id])) { $imageURL = $images[$id][0]['url']; } $summary[$id] = array('wiki' => $this->wg->Sitename, 'wikiUrl' => $this->wg->Server, 'titleDBkey' => $title->getPrefixedDBkey(), 'titleText' => $title->getFullText(), 'articleId' => $title->getArticleID(), 'imageUrl' => $imageURL, 'url' => $title->getFullURL(), 'snippet' => $snippet); } wfProfileOut(__METHOD__); $this->summary = $summary; }
public function execute() { $title = $this->getOption('title'); $dryRun = true; # don't store results in database $this->output("Parsing '" . $title . "'..."); $time = microtime(true); $title = Title::newFromText($title); if (!$title->exists()) { $this->error('Given title does not exist', 1); } $article = new Article($title); $images = ImageServingHelper::buildAndGetIndex($article, false, $dryRun); $time = microtime(true) - $time; $this->output(" done in " . round($time, 4) . " sec\n"); $this->output("\nImages found: " . count($images) . "\n\n"); $this->output(implode("\n", $images) . "\n"); // get filtered list of images global $wgAllowMemcacheReads; $wgAllowMemcacheReads = false; $im = new ImageServing(array($title->getArticleID()), 32, 32); $ret = $im->getImages(20); $images = reset($ret); $this->output("\nImages list as returned by ImageServing (min size: 32x32 px):\n"); foreach ($images as $image) { $this->output("* {$image['name']}\n"); } }
/** * Return first image from an article, matched criteria * @param $title * @param $width * @return null|Title */ protected static function getFirstArticleImageLargerThan($title, $width, $height) { $imageServing = new ImageServing([$title->getArticleID()], $width, $height); $out = $imageServing->getImages(1); if (!empty($out)) { ///used reset instead direct call because we can get hashmap from ImageServing driver. $first = reset($out); $name = $first[0]['name']; return Title::newFromText($name, NS_FILE); } return null; }
function execute($article_id = null, $limit = "", $offset = "", $show = true) { global $wgRequest, $wgOut, $wgTitle, $wgUser; if (!$wgUser->isAllowed('imageservingtest')) { throw new PermissionsError('imageservingtest'); } $this->size = 200; $this->prop = array("w" => 2, "h" => 1); switch ($wgRequest->getVal("option", 1)) { case "2": $this->size = 270; $this->prop = array("w" => 3, "h" => 1); break; case "3": $this->size = 100; $this->prop = array("w" => 1, "h" => 1); break; } if ($wgRequest->getVal("article", "") != "") { $title = Title::newFromText($wgRequest->getVal("article"), NS_MAIN); $test = new ImageServing(array($title->getArticleId()), $this->size, $this->prop); foreach ($test->getImages(20) as $value) { $wgOut->addHTML("<b>" . $title->getText() . "</b><br><br>"); foreach ($value as $value2) { $wgOut->addHTML("<img src='{$value2['url']}' /> <br>"); $wgOut->addHTML($value2['name'] . "<br>"); } } return; } $wgOut->addHTML(Xml::element("a", array("href" => $wgTitle->getLocalURL("option=1")), wfMsg('imageserving-option1')) . "<br>"); $wgOut->addHTML(Xml::element("a", array("href" => $wgTitle->getLocalURL("option=2")), wfMsg('imageserving-option2')) . "<br>"); $wgOut->addHTML(Xml::element("a", array("href" => $wgTitle->getLocalURL("option=3")), wfMsg('imageserving-option3')) . "<br>"); if (empty($limit) && empty($offset)) { list($limit, $offset) = wfCheckLimits(); } /** removed reference to deprecated mechanism of Mostvisitedpages * right now operation of ImageServing Test is not very clear * TODO: provide clearer way of using ImageServingTest (BugId:97236) */ }
/** * See functions below for expected URL params */ public function execute() { global $wgRequest, $wgCacheBuster; wfProfileIn(__METHOD__); extract($this->extractRequestParams()); // Allow optionally using a prefixed-title instead of the page_id. if (empty($Id)) { $title = Title::newFromText($Title); if (is_object($title)) { $Id = $title->getArticleID(); } } $article = Article::newFromID($Id); if (is_object($article)) { // Automatically follow redirects. if ($article->isRedirect()) { $title = $article->followRedirect(); if (is_object($title)) { // if this is not an object, then we're pretty unlikely to get any good image matches, but more likely to get them for the original ID. $Id = $title->getArticleID(); } } $imageUrl = null; $imageServing = new ImageServing(array($Id)); foreach ($imageServing->getImages(1) as $key => $value) { $imgTitle = Title::newFromText($value[0]['name'], NS_FILE); $imgFile = wfFindFile($imgTitle); if (!empty($imgFile)) { $imageUrl = wfReplaceImageServer($imgFile->getFullUrl(), $wgCacheBuster); } } $result = $this->getResult(); if (empty($imageUrl)) { $result->addValue('image', "error", "No good, representiative image was found for this page."); // TODO: i18n } else { $result->addValue('image', $this->getModuleName(), $imageUrl); } } wfProfileOut(__METHOD__); }
/** * Proxy function for fetching thumbnails from ImageServing. * * @param $articles array List of article ids * @return array */ protected function findImages($articles) { wfProfileIn(__METHOD__); $articleIds = array_keys($articles); $result = array(); foreach ($articleIds as $articleId) { $imageServing = new ImageServing(array($articleId), $this->confThumbWidth, $this->confThumbProportion); $images = $imageServing->getImages(1); if (!empty($images) && !empty($images[$articleId]) && is_array($images[$articleId])) { $result[$articleId] = array_shift($images); } } wfProfileOut(__METHOD__); return $result; }
/** * @static * @return AjaxResponse */ public static function getImageData() { global $wgRequest; $ret = array('result' => false); $titleText = $wgRequest->getText('title'); if (!empty($titleText)) { $title = Title::newFromText($titleText); if (!empty($title) && $title->exists()) { $articleId = $title->getArticleId(); $source = new ImageServing(array($articleId), 120, array("w" => 3, "h" => 2)); $result = $source->getImages(1); if (!empty($result[$articleId][0])) { $ret = array_merge(array('result' => true), $result[$articleId][0]); } } } $json = json_encode($ret); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); return $response; }
/** * Returns data needed to render marker for a given place on a map with multiple places * * This method returns article's URL, text snippet and an image for current place * * TODO: add caching */ public function getForMap() { if ($this->isEmpty()) { return false; } wfProfileIn(__METHOD__); $pageId = $this->getPageId(); $oTitle = F::build('Title', array($pageId), 'newFromID'); if (empty($oTitle) || !$oTitle->exists()) { wfProfileOut(__METHOD__); return array(); } // TODO: getImages() are not cached $imageServing = new ImageServing(array($pageId), 100, array('w' => 1, 'h' => 1)); $images = $imageServing->getImages(1); if (!empty($images[$pageId][0]['url'])) { $imageUrl = $images[$pageId][0]['url']; } else { $imageUrl = ''; } $oArticleService = F::Build('ArticleService'); $oArticleService->setArticleById($pageId); $textSnippet = $oArticleService->getTextSnippet(120); $strPos = mb_strrpos($textSnippet, ' '); $textSnippet = mb_substr($textSnippet, 0, $strPos); $textSnippet .= ' ...'; $ret = array('lat' => $this->getLat(), 'lan' => $this->getLon(), 'label' => $oTitle->getText(), 'imageUrl' => $imageUrl, 'articleUrl' => $oTitle->getLocalUrl(), 'textSnippet' => $textSnippet); wfProfileOut(__METHOD__); return $ret; }
/** * Accesses top wiki articles for right rail, see PLA-466 */ public function topWikiArticles() { global $wgLang; $pages = []; try { $pageData = $this->app->sendRequest('ArticlesApiController', 'getTop', ['namespaces' => 0])->getData(); $ids = []; $counter = 0; foreach ($pageData['items'] as $pageDatum) { $ids[] = $pageDatum['id']; if ($counter++ >= 12) { break; } } if (!empty($ids)) { $params = ['ids' => implode(',', $ids), 'height' => 80, 'width' => 80, 'abstract' => 120]; $detailResponse = $this->app->sendRequest('ArticlesApiController', 'getDetails', $params)->getData(); $dimensions = $this->getHotArticleImageDimensions(); foreach ($detailResponse['items'] as $id => $item) { if (!empty($item['thumbnail'])) { $item['thumbnailSize'] = "small"; //get the first one image from imageServing as it needs other size if (empty($pages)) { $is = new ImageServing([$id], $dimensions['width'], $dimensions['height']); $result = $is->getImages(1); if (!empty($result[$id][0]['url'])) { $item['thumbnail'] = $result[$id][0]['url']; $item['thumbnailSize'] = "large"; } } //render date $item['date'] = $wgLang->date($item['revision']['timestamp']); $item = $this->processArticleItem($item, 100); $pages[] = $item; } } } } catch (Exception $e) { } // ignoring API exceptions for gracefulness $this->setVal('pages', $pages); }
function formatResult($skin, $result) { global $wgRequest, $wgTitle; $res = false; if (empty($this->show)) { $this->data[$result->title] = array('value' => $result->value, 'namespace' => $result->namespace); } else { $title = Title::newFromText($result->title, $result->namespace); $article_name = $title->getText(); if ($title) { $result->title = Xml::element("a", array("href" => $title->getLocalURL()), $title->getFullText() . "(" . $title->getArticleId() . ")"); $is = new ImageServing(array($title->getArticleId()), $this->size, $this->prop); $result->title .= "<div>"; foreach ($is->getImages(1) as $key => $value) { foreach ($value as $value2) { $result->title .= "<img src='{$value2['url']}' /> <br>"; $result->title .= $value2['name'] . "<br>"; } } $result->title .= Xml::element("a", array("href" => $wgTitle->getLocalURL("option=" . $wgRequest->getVal("option", 1) . "&article=" . $article_name)), wfMsg("imageserving-showall")) . "<br>"; $result->title .= "</div>"; } $res = wfSpecialList($result->title, $result->value); } return $res; }
/** * Injects some important CSS and Javascript into the <head> of the page. * * @param $out OutputPage * @param $sk Skin */ public static function BeforePageDisplay(&$out, &$sk) { global $wgVersion, $fbLogo, $fbScript, $fbExtensionScript, $fbIncludeJquery, $fbScriptEnableLocales, $wgJsMimeType, $wgStyleVersion, $wgTitle, $wgNoExternals; $pageId = $wgTitle->getArticleId(); if ($pageId > 0) { $images = new ImageServing(array($pageId), 100, array('w' => 1, 'h' => 1)); $image = $images->getImages(1); if (!empty($image[$pageId])) { $out->addLink(array('rel' => 'image_src', 'href' => $image[$pageId][0]['url'])); } } if (!F::app()->checkSkin(array('wikiamobile', 'wikiaapp'), $sk)) { // If the user's language is different from the default language, use the correctly localized facebook code. // NOTE: Can't use wgLanguageCode here because the same FBConnect config can run for many wgLanguageCode's on one site (such as Wikia). if ($fbScriptEnableLocales) { global $fbScriptLangCode, $wgLang; wfProfileIn(__METHOD__ . "::fb-locale-by-mediawiki-lang"); if ($wgLang->getCode() !== $fbScriptLangCode) { // Attempt to find a matching facebook locale. $defaultLocale = FBConnectLanguage::getFbLocaleForLangCode($fbScriptLangCode); $locale = FBConnectLanguage::getFbLocaleForLangCode($wgLang->getCode()); if ($defaultLocale != $locale) { global $fbScriptByLocale; $fbScript = str_replace(FBCONNECT_LOCALE, $locale, $fbScriptByLocale); } } wfProfileOut(__METHOD__ . "::fb-locale-by-mediawiki-lang"); } // Asynchronously load the Facebook Connect JavaScript SDK before the page's content // macbre: moved to SkinAfterBottomScripts method (RT #140425) // Inserts list of global JavaScript variables if necessary if (self::MGVS_hack($mgvs_script)) { $out->addInlineScript($mgvs_script); } // macbre: lazy load JavaScript Facebook API if (empty($wgNoExternals)) { $out->addHTML(F::build('JSSnippets')->addToStack(array(), array('$.loadFacebookAPI'), 'window.onFBloaded')); } // Add a Facebook logo to the class .mw-fblink $style = empty($fbLogo) ? '' : <<<STYLE \t\t\t/* Add a pretty logo to Facebook links */ \t\t\t.mw-fblink { \t\t\t\tbackground: url({$fbLogo}) top left no-repeat !important; \t\t\t\tpadding-left: 17px !important; \t\t\t} STYLE; // Things get a little simpler in 1.16... if (version_compare($wgVersion, '1.16', '>=')) { // Add a pretty Facebook logo if $fbLogo is set if ($fbLogo) { $out->addInlineStyle($style); } // Don't include jQuery if it's already in use on the site $out->includeJQuery(); // Add the script file specified by $url if (!empty($fbExtensionScript)) { $out->addScriptFile($fbExtensionScript); } } else { // Add a pretty Facebook logo if $fbLogo is set if ($fbLogo) { $out->addScript('<style type="text/css">' . $style . '</style>'); } // Don't include jQuery if it's already in use on the site if (!empty($fbIncludeJquery)) { $out->addScriptFile("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"); } // Add the script file specified by $url if (!empty($fbExtensionScript)) { $out->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$fbExtensionScript}?{$wgStyleVersion}\"></script>\n"); } } } return true; }
/** * @param $outputModel * @return mixed */ protected function getImage($wikiId, $articleId) { $dbName = ''; try { $row = \WikiFactory::getWikiByID($wikiId); if ($row) { $dbName = $row->city_dbname; if (!empty($dbName)) { $db = wfGetDB(DB_SLAVE, [], $dbName); // throws if database does not exits. $imageServing = new \ImageServing([$articleId], self::IMAGE_SIZE, self::IMAGE_SIZE, $db); $isResult = $imageServing->getImages(1); $images = isset($isResult[$articleId]) ? $isResult[$articleId] : false; if ($images && sizeof($images) > 0) { $imageName = $images[0]['name']; $file = \GlobalFile::newFromText($imageName, $wikiId); if ($file->exists()) { return $imageServing->getUrl($file, $file->getWidth(), $file->getHeight()); } } } } } catch (\DBConnectionError $ex) { // Swallow this exception. there is no simple way of telling if database does not exist other than catching exception. // Or am I wrong ? \Wikia::log(__METHOD__, false, "Cannot get database connection to " . $dbName); } return null; }
/** * Returns image from page. * @param $mPageId int page id * @return string - image url */ protected function getImageFromPageId($mPageId) { if (!is_array($mPageId)) { $mPageId = array($mPageId); } $imageServing = new ImageServing($mPageId, $this->thumbWidth, array("w" => $this->thumbWidth, "h" => $this->thumbHeight)); $imageUrl = ''; foreach ($imageServing->getImages(1) as $value) { if (!empty($value[0]['name'])) { $tmpTitle = Title::newFromText($value[0]['name'], NS_FILE); $image = wfFindFile($tmpTitle); if (empty($image)) { return ''; } $imageUrl = wfReplaceImageServer($image->getThumbUrl($imageServing->getCut($image->getWidth(), $image->getHeight()) . "-" . $image->getName())); } } return $imageUrl; }
/** * Returns an URL for an image from article with given title * * @param String $titleText * @param Integer $width * @param Integer $height * * @return string */ public function getArticleImage($titleText, $width, $height) { $title = Title::newFromText($titleText); if (!is_null($title)) { $articleId = $title->getArticleId(); $is = new ImageServing([$articleId], $width, $height); $images = $is->getImages(1); if (!empty($images[$articleId])) { $image = array_pop($images[$articleId]); return $image['url']; } } return ''; }
public static function findFirstImageTitleFromArticle($articleId) { $imageTitle = null; if (!empty($articleId)) { $is = new ImageServing([$articleId]); $image = $is->getImages(1); if (!empty($image)) { $image_title_name = $image[$articleId][0]['name']; if (!empty($image_title_name)) { $imageTitle = Title::newFromText($image_title_name, NS_FILE); } } } return $imageTitle; }
/** * This is called by ImageServing if no representative image is found for a page. * If this is a song page, will first check the album page, then the artist page for a good image. * If this is an album page, will check the artist page for a good image. * If this is an artist page, there is no good fallback, so 'out' will be returned unmodified. */ function lw_ImageServingFallback(ImageServing $imageServing, $n, &$out) { wfProfileIn(__METHOD__); // For Gracenote pages (since they don't have their own images), fall back to the NS_MAIN pages with the same titles. $articleTitlesToTry = array(); if (isset($imageServing->articlesByNS[NS_GRACENOTE])) { $gnArticles = $imageServing->articlesByNS[NS_GRACENOTE]; foreach ($gnArticles as $gnArticleData) { $title = $gnArticleData['title']; // Just pass the page title in directly. By not passing the Gracenote namespace in, we'll get the main-namespace equivalent. $articleTitlesToTry[] = $title; } } // For main namespace pages, fall back from song to album to artist. if (isset($imageServing->articlesByNS[NS_MAIN])) { $articles = $imageServing->articlesByNS[NS_MAIN]; foreach ($articles as $articleData) { $title = $articleData['title']; // If the title is an album, fall back to the artist... if the title is a song, fall back to the album. $matches = array(); if (0 < preg_match("/^(.*?):.*[ _]\\([0-9]{4}\\)\$/", $title, $matches)) { $articleTitlesToTry[] = $matches[1]; } else { // TODO: Fall back to the album if there is one in the wikiText (which would automatically fall back to the artist if the album doesn't have a pic). // NOTE: At the moment, I actually think artist pics might be better than album pics. // TODO: Fall back to the album if there is one in the wikiText (which would automatically fall back to the artist if the album doesn't have a pic). // Fall back to the artist if no album could be found in the wikiText. // TODO: if we have the wikitext already & the artist can be found in there, use that instead of a regex on the title (it is more likely to be accurate since the artist name may have colons in it). // TODO: if we have the wikitext already & the artist can be found in there, use that instead of a regex on the title (it is more likely to be accurate since the artist name may have colons in it). if (0 < preg_match("/^(.*?):/", $title, $matches)) { $articleTitlesToTry[] = $matches[1]; } } } } // If we found some reasonable fallback-pages above, pass those into ImageServing. if (count($articleTitlesToTry) > 0) { $articleIds = array(); foreach ($articleTitlesToTry as $titleStr) { $title = Title::newFromText($titleStr); // Titles with & break image serving, causing an endless loop here -- owen hack fix if (strpos($titleStr, "&") == false && is_object($title)) { $articleId = $title->getArticleID(); $article = Article::newFromID($articleId); if (is_object($article)) { /* @var $article WikiPage */ // Automatically follow redirects. if ($article->isRedirect()) { $title = $article->followRedirect(); $articleId = $title->getArticleID(); } // The title str could be converted into an article-id, so add it to the array to be processed. $articleIds[] = $articleId; } } } // Some of the titles were real pages, use ImageServing to get the results and store them (by reference) in '$out'. if (count($articleIds) > 0) { $imageServing = new ImageServing($articleIds); $out = $imageServing->getImages($n); } } wfProfileOut(__METHOD__); return true; // because this is a hook }
protected function afterGet($pages, $limit) { wfProfileIn(__METHOD__); $imageServing = new ImageServing(array_keys($pages), 200, array('w' => 2, 'h' => 1)); $images = $imageServing->getImages(1); // get just one image per article foreach ($pages as $pageId => $data) { $data['imgUrl'] = isset($images[$pageId]) ? $images[$pageId][0]['url'] : null; $data['imgOriginalDimensions'] = isset($images[$pageId]) ? $images[$pageId][0]['original_dimensions'] : null; $data['text'] = $this->getArticleSnippet($pageId); $this->pushData($data); if (count($this->getData()) >= $limit) { break; } } wfProfileOut(__METHOD__); }
public function getThumbnails($articleIds = null, $width = null) { wfProfileIn(__METHOD__); $articleIds = !empty($articleIds) ? $articleIds : $this->getVal('articleIds'); $width = !empty($width) ? $width : $this->getVal('width'); $source = new ImageServing($articleIds, $width, array("w" => 3, "h" => 2)); $result = $source->getImages(1); $this->setVal('thumbnails', $result); wfProfileOut(__METHOD__); return $result; }
protected function afterGet($pages, $limit) { global $wgContentNamespaces, $wgEnableRelatedPagesUnionSelectQueries, $wgUser; wfProfileIn(__METHOD__); // ImageServing extension enabled, get images $imageServing = new ImageServing(array_keys($pages), 200, array('w' => 2, 'h' => 1)); $images = $imageServing->getImages(1); // get just one image per article // TMP: always remove last article to get a text snippeting working example // macbre: removed as requested by Angie //$images = array_slice($images, 0, $limit-1, true); foreach ($pages as $pageId => $data) { if (isset($images[$pageId])) { $image = $images[$pageId][0]; $data['imgUrl'] = $image['url']; $this->pushData($data); } else { // no images, get a text snippet $data['text'] = $this->getArticleSnippet($pageId); if ($data['text'] != '') { $this->pushData($data); } } if (count($this->getData()) >= $limit) { break; } } wfProfileOut(__METHOD__); }