예제 #1
0
 /**
  * Construct a Wikimedia instance.
  * @param Database $db The database with which to connect to the database.
  * @param Cacher $cache The cache with which to read and write cached data.
  */
 public function __construct($db, $cache)
 {
     $this->wikis = $cache->Get('wikimedia-wikis');
     if (!$this->wikis) {
         // build wiki list
         $this->wikis = array();
         $db->Connect('metawiki.labsdb', 'metawiki_p');
         foreach ($db->Query('SELECT dbname, lang, family, url, size, is_closed, slice FROM meta_p.wiki WHERE url IS NOT NULL')->fetchAllAssoc() as $row) {
             if ($row['dbname'] == 'votewiki') {
                 continue;
             }
             // DB schema is broken
             $this->wikis[$row['dbname']] = new Wiki($row['dbname'], $row['lang'], $row['family'], $row['url'], $row['size'], $row['is_closed'], $row['slice']);
         }
         // cache result
         if (count($this->wikis)) {
             // if the fetch failed, we *don't* want to cache the result for a full day
             $cache->Save('wikimedia-wikis', $this->wikis);
         }
         $db->ConnectPrevious();
     }
 }