예제 #1
0
 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");
     }
 }
 function toHTML()
 {
     wfProfileIn(__METHOD__);
     $res = "";
     foreach ($this->images as $imageData) {
         $title = Title::newFromText($imageData['name'], NS_FILE);
         if (empty($title) || !$title->exists()) {
             continue;
         }
         $file = $this->getImage($title);
         $res .= ImageServingHelper::getPlaceholder($file);
     }
     wfProfileOut(__METHOD__);
     return $res;
 }
예제 #3
0
 /**
  * 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');
 }
예제 #4
0
        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']));
    }
    echo "Indexing more then one count pages\n";
    $res = $db->select(array('imagelinks'), array('il_from,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"));
    $total_num = $res->numRows();
    $out = array();
    $count = 0;
    $total_count = 0;
    $startTime = Time();
    Wikia::log(__METHOD__, 'imageServingIndexer', 'starting for:' . $wgCityId . " total number:" . $total_num);
    while ($row = $db->fetchRow($res)) {
        $total_count++;
        $count++;
        $out[] = $row['il_from'];
        if ($count == package_size) {
            runIndexer($out, $total_count, $total_num);
 private static function hookSwitch($onOff = true)
 {
     self::$hookOnOff = $onOff;
 }