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"); } }
/** * test function ImageServingHelper::buildIndex * * This test assumes that: * - "Main Page" article * - "Wiki-wordmark.png" image * - "FireflyLogo-NoBackground.png" image * exist on a wiki this test is run for * * @see ImageServingHelper::buildIndex * @dataProvider buildIndexProvider */ public function testBuildIndex($wikitext, $expectedImages) { $title = Title::newFromText('Main Page'); $article = new Article($title); // mock article's content $article->mContent = $wikitext; $article->mContentLoaded = true; // disable access to the database $this->getMethodMock('DatabaseMysql', 'replace'); $this->getMethodMock('Database', 'delete'); // mock wgTitle needed by RedirectsService $this->mockGlobalVariable('wgTitle', $title); $images = ImageServingHelper::buildAndGetIndex($article); $this->assertEquals($expectedImages, $images, 'List of images matches expected ones'); }
require "commandLine.inc"; if (isset($options['help'])) { die("indexer for blog listing pages"); } $db = wfGetDB(DB_SLAVE, array()); /* * first time it run only count on pages and then it run this script with param -do and list * it is hack for problem with memory leak from parser */ if (!empty($options['do']) && $options['do'] == 1) { $pages = explode(",", $options['list']); foreach ($pages as $value) { $qArticle = Article::newFromID(trim($value)); $wgTitle = $qArticle->getTitle(); //title for parser ImageServingHelper::buildAndGetIndex($qArticle, true); unset($qArticle); } exit; } if (!isset($options['force'])) { if (WikiFactory::getVarValueByName("wgImagesIndexed", $wgCityId)) { echo "This wiki is already indexed change wgImagesIndexed to false to reindex\n"; exit; } } if (empty($options['do']) || $options['do'] != 1) { $res = $db->select(array('imagelinks'), array('il_from,il_to,count(*) as cnt'), array("il_from in (select il_from from image inner join imagelinks where img_media_type != 'VIDEO' and il_to = img_name and il_from not in (select page_id from page_wikia_props))"), __METHOD__, array("GROUP BY" => "il_from", "HAVING" => "cnt = 1")); echo "Indexing one count pages\n"; while ($row = $db->fetchRow($res)) { ImageServingHelper::buildIndex($row['il_from'], array($row['il_to']));