/** * Format a size in bytes for output, using an appropriate * unit (KB or MB or GB) according to the magnitude in question * * @param mixed $size Size in kB to format, as string or int, <b<NO FLOAT</b> * @return string Plain text (not HTML) * @todo handle properly float $size, the problem is how to handle them with 32 bits system (substr?) */ function wfFormatSizekB($size) { global $wgLang; if (PHP_INT_SIZE == 8) { // check if system is 32 or 64 bits // 64 bits if ($size > 1024) { return wfFormatSizeMB($size / 1024); } } elseif (PHP_INT_SIZE == 4) { // 32 bits if (strlen($size) > 3) { // not very precise, but work even with big big size return wfFormatSizeMB(substr($size, 0, -3)); } } else { // ??? return wfMessage('size-kilobytes', $wgLang->formatNum($size))->text(); } // if we arrive here, we know that size is less than 1024 or 1000 if ($size < 1) { return '< ' . wfMessage('size-kilobytes', $wgLang->formatNum(1))->text(); } else { return wfMessage('size-kilobytes', $wgLang->formatNum($size))->text(); } }
/** * Format a table cell. The return value should be HTML, but use an empty * string not   for empty cells. Do not include the <td> and </td>. * * The current result row is available as $this->mCurrentRow, in case you * need more context. * * @param $name String: the database field name * @param $value String: the value retrieved from the database */ function formatValue($name, $value) { global $wgLang; switch ($name) { case 'wps_start_date': case 'wps_end_date': return $value === null ? '-' : $wgLang->date($value, true); case 'wpp_name': return wfMessage('wpp-' . $value)->text(); case 'wps_tmr_status': $msg = wfMessage("status-{$value}")->text(); if ($value == 'PE' && $this->mCurrentRow->wps_active == 0) { $msg .= ' (' . SpecialSubscriptions::getLinkCancel($this->mCurrentRow->wps_id) . ')'; } return $msg; case 'wpp_nb_wikiplaces': case 'wpp_nb_wikiplace_pages': return wfFormatNumber($value); case 'wpp_monthly_bandwidth': case 'wpp_diskspace': return wfFormatSizeMB($value); default: return htmlspecialchars($value); } }
function formatMonthlyQuotas() { $html = Xml::openElement('ul'); $html .= Html::rawElement('li', array(), '<b>' . wfFormatNumber($this->mCurrentRow->wpp_monthly_page_hits) . '</b> ' . wfMessage('wp-Hits')->text()); $html .= Html::rawElement('li', array(), '<b>' . wfFormatSizeMB($this->mCurrentRow->wpp_monthly_bandwidth) . '</b> ' . wfMessage('wp-bandwidth')->text()); $html .= Xml::closeElement('ul'); return $html; }
private function displayList() { $user = $this->getUser(); if ($user->isAllowed(WP_ADMIN_RIGHT) && $this->name != null) { $user_id = User::newFromName($this->name)->getId(); if ($user_id == 0) { $this->action = self::ACTION_NOACTION; $this->msgKey = 'wp-invalid-name'; $this->msgType = 'error'; $this->display(); return; } } else { $user_id = $user->getId(); } $output = $this->getOutput(); $tp = new WpWikiplacesTablePager(); $tp->setSelectConds(array('wpw_owner_user_id' => $user_id)); $tp->setHeader(wfMessage('wp-list-header')->parse()); $diskspace = wfFormatSizeMB(WpPage::countDiskspaceUsageByUser($user_id)); $pages = wfFormatNumber(WpPage::countPagesOwnedByUser($user_id)); $tp->setFooter(wfMessage('wp-list-footer', $diskspace, $pages)->parse()); /** @TODO Add Total Hits, Total Bandwidth & Report Updated, ie. Make pretty getters and factories in WpWikiplace that can take the result/row from the pager as argument */ $output->addHTML($tp->getWholeHtml()); }