public function testHasNoStats()
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('wb_changes', '*');
     $dbw->delete('wb_changes_dispatch', '*');
     $stats = new DispatchStats();
     $stats->load(time());
     $this->assertFalse($stats->hasStats());
     // Still no stats as the table is empty
 }
 /**
  * Adds DispatchStats info to the API
  * @param array $data
  * @return bool
  */
 public static function onAPIQuerySiteInfoStatisticsInfo(array &$data)
 {
     $stats = new DispatchStats();
     $stats->load();
     if ($stats->hasStats()) {
         $data['dispatch'] = array('oldest' => array('id' => $stats->getMinChangeId(), 'timestamp' => $stats->getMinChangeTimestamp()), 'newest' => array('id' => $stats->getMaxChangeId(), 'timestamp' => $stats->getMaxChangeTimestamp()), 'freshest' => self::formatDispatchRow($stats->getFreshest()), 'median' => self::formatDispatchRow($stats->getMedian()), 'stalest' => self::formatDispatchRow($stats->getStalest()), 'average' => self::formatDispatchRow($stats->getAverage()));
     }
     return true;
 }
 /**
  * @see SpecialWikibasePage::execute
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     $lang = $this->getContext()->getLanguage();
     $stats = new DispatchStats();
     $stats->load();
     $this->getOutput()->addHTML(Html::rawElement('p', array(), $this->msg('wikibase-dispatchstats-intro')->parse()));
     if (!$stats->hasStats()) {
         $this->getOutput()->addHTML(Html::rawElement('p', array(), $this->msg('wikibase-dispatchstats-no-stats')->parse()));
         return;
     }
     // changes ------
     $this->getOutput()->addHTML(Html::rawElement('h2', array(), $this->msg('wikibase-dispatchstats-changes')->parse()));
     $this->getOutput()->addHTML(Html::openElement('table', array('class' => 'wikitable')));
     $this->outputRow(array('', $this->msg('wikibase-dispatchstats-change-id')->text(), $this->msg('wikibase-dispatchstats-change-timestamp')->text()), 'th');
     $this->outputRow(array($this->msg('wikibase-dispatchstats-oldest-change')->text(), $stats->getMinChangeId(), $lang->timeanddate($stats->getMinChangeTimestamp(), true)));
     $this->outputRow(array($this->msg('wikibase-dispatchstats-newest-change')->text(), $stats->getMaxChangeId(), $lang->timeanddate($stats->getMaxChangeTimestamp(), true)));
     $this->getOutput()->addHTML(Html::closeElement('table'));
     // dispatch stats ------
     $this->getOutput()->addHTML(Html::rawElement('h2', array(), $this->msg('wikibase-dispatchstats-stats')->parse()));
     $this->getOutput()->addHTML(Html::openElement('table', array('class' => 'wikitable')));
     $this->outputRow(array('', $this->msg('wikibase-dispatchstats-site-id')->text(), $this->msg('wikibase-dispatchstats-pos')->text(), $this->msg('wikibase-dispatchstats-lag-num')->text(), $this->msg('wikibase-dispatchstats-lag-time')->text(), $this->msg('wikibase-dispatchstats-touched')->text()), 'th');
     $this->outputStateRow($this->msg('wikibase-dispatchstats-freshest')->text(), $stats->getFreshest());
     $this->outputStateRow($this->msg('wikibase-dispatchstats-median')->text(), $stats->getMedian());
     $this->outputStateRow($this->msg('wikibase-dispatchstats-stalest')->text(), $stats->getStalest());
     $this->outputStateRow($this->msg('wikibase-dispatchstats-average')->text(), $stats->getAverage());
     $this->getOutput()->addHTML(Html::closeElement('table'));
 }