*/
class admin_plugin_acknowledge_stats extends AdminPlugin
{
/** @inheritdoc */
public function forAdminOnly()
{
return false;
}
/** @inheritDoc */
public function getMenuText($language)
{
return $this->getLang('menu_stats');
}
/** @inheritdoc */
public function handle()
{
}
/** @inheritdoc */
public function html()
{
global $INPUT;
/** @var helper_plugin_acknowledge $helper */
$helper = plugin_load('helper', 'acknowledge');
$ns = trim($INPUT->str('ns'), ':');
echo '
';
echo '
' . $this->getLang('menu_stats') . '
';
$stats = $helper->getStatistics($ns);
// whole-wiki summary
$this->htmlSummary($stats['total']);
// back-link to root
if ($ns !== '') {
echo '
' . $this->nsLink('', $this->getLang('statsTotalLink')) . '
';
echo '
' . $this->getLang('statsNamespace') . ' ' . $ns . '
';
}
if (empty($stats['namespaces'])) {
echo '
' . $this->getLang('nothingfound') . '
';
echo '
';
return;
}
echo '';
echo '';
echo '| ' . $this->getLang('statsSubnamespace') . ' | ';
echo '' . $this->getLang('statsAcked') . ' | ';
echo '' . $this->getLang('statsRequired') . ' | ';
echo '' . $this->getLang('statsPages') . ' | ';
echo '' . $this->getLang('statsRatio') . ' | ';
echo '
';
foreach ($stats['namespaces'] as $key => $data) {
$this->htmlRow($this->nsLabel($key, $ns, $data['haschildren']), $data);
}
echo '
';
echo '';
}
/**
* Whole-wiki summary
*
* @param array $total {required:int, acked:int, pages:int}
* @return void
*/
protected function htmlSummary(array $total): void
{
$ratio = $total['required'] ? round($total['acked'] * 100 / $total['required']) : 0;
echo '';
echo '
' . $this->getLang('statsTotal') . '
';
echo '
';
echo '- ' . $this->getLang('statsAcked') . ': ' . $total['acked'] . '
';
echo '- ' . $this->getLang('statsRequired') . ': ' . $total['required'] . '
';
echo '- ' . $this->getLang('statsPages') . ': ' . $total['pages'] . '
';
echo '- ' . $this->getLang('statsRatio') . ': ' . $ratio . '%' . '
';
echo '
';
echo '
';
}
/**
* Namespace label, linked if it has children
*
* @param string $key Sub-namespace key (relative to the current namespace)
* @param string $ns Currently explored namespace
* @param bool $haschildren
* @return string HTML
*/
protected function nsLabel(string $key, string $ns, bool $haschildren): string
{
if ($key === '') {
return $this->getLang('statsRoot');
}
if ($key === $ns) {
return $this->getLang('statsHere');
}
// show the part relative to the current namespace
$relative = $ns === '' ? $key : substr($key, strlen($ns) + 1);
$label = $relative . ':';
return $haschildren ? $this->nsLink($key, $label) : $label;
}
/**
* Link to a namespace drill-down view
*
* @param string $ns
* @param string $label
* @return string
*/
protected function nsLink(string $ns, string $label): string
{
global $ID;
$params = ['do' => 'admin', 'page' => 'acknowledge_stats'];
if ($ns !== '') $params['ns'] = $ns;
return '' . $label . '';
}
/**
* Render a single statistics row
*
* @param string $label
* @param array $data {required:int, acked:int, pages:int}
* @return void
*/
protected function htmlRow(string $label, array $data): void
{
$ratio = $data['required'] ? round($data['acked'] * 100 / $data['required']) : 0;
echo '';
echo '| ' . $label . ' | ';
echo '' . $data['acked'] . ' | ';
echo '' . $data['required'] . ' | ';
echo '' . $data['pages'] . ' | ';
echo '' . $ratio . '% | ';
echo '
';
}
/** @inheritDoc */
public function getTOC()
{
return (new admin_plugin_acknowledge_report())->getTOC();
}
}