Esempio n. 1
0
 /**
  * @param string $prop See self::$siprops
  * @return array
  * @throws Exception If property is not supported
  * @throws Exception If fetching failed
  */
 public function getSiteInfo($prop)
 {
     global $kgCache;
     $key = kfCacheKey('base', 'mwapi', $this->dbname, 'siteinfo', $prop);
     $value = $kgCache->get($key);
     if ($value === false) {
         if (!in_array($prop, self::$siprops)) {
             throw new Exception('Unsupported property "' . $prop . '"');
         }
         $values = $this->fetchSiteInfo();
         if ($values !== false) {
             foreach (self::$siprops as $siprop) {
                 $kgCache->set(kfCacheKey('base', 'mwapi', $this->dbname, 'siteinfo', $siprop), $values->{$siprop}, 3600);
             }
             $value = $values->{$prop};
         } else {
             // Don't try again within this request nor for the next few
             $value = null;
             $kgCache->set($key, $value, 60 * 5);
         }
     }
     if ($value === null) {
         throw new Exception('Fetch siteinfo failed');
     }
     return $value;
 }
Esempio n. 2
0
 /**
  * Get information for all (replicated) databases.
  *
  * See https://wikitech.wikimedia.org/wiki/Nova_Resource:Tools/Help#Metadata_database
  *
  * @return array
  */
 public static function getAllDbInfos()
 {
     if (!isset(self::$dbInfos)) {
         global $kgCache;
         $key = kfCacheKey('base', 'labsdb', 'meta', 'dbinfos');
         $value = $kgCache->get($key);
         if ($value === false) {
             $value = self::fetchAllDbInfos();
             $kgCache->set($key, $value, 3600 * 24);
         }
         self::$dbInfos = $value;
     }
     return self::$dbInfos;
 }
<?php

/**
 * Tool configuration (example for localhost development)
 */
$kgConf->remoteBase = '//localhost/mw-tool-example/public_html/base';
$tool->setSettings(array('foo' => 'example'));
$kgCache->set(kfCacheKey('base', 'labsdb', 'meta', 'dbinfos'), array('krinklewiki' => array('dbname' => 'krinklewiki', 'family' => 'wikipedia', 'url' => 'http://alpha.wikipedia.krinkle.dev', 'slice' => 's0.local'), 'metawiki' => array('dbname' => 'metawiki', 'family' => 'special', 'url' => 'https://meta.wikimedia.org', 'slice' => 's0.local')));
Esempio n. 4
0
 /**
  * @return stdClass
  * @throws Exception If fetch failed
  */
 protected function getSiteMatrix()
 {
     global $kgCache;
     $key = kfCacheKey('sitematrix', 2);
     $value = $kgCache->get($key);
     if ($value === false) {
         $value = $this->fetchSiteMatrix();
         if ($value !== false) {
             $kgCache->set($key, $value, 3600);
         } else {
             $value = null;
             // Don't try again for another minute
             $kgCache->set($key, $value, 60);
         }
     }
     if ($value === null) {
         throw new Exception('Fetch sitematrix failed');
     }
     return $value;
 }