1<?php 2/** 3 * DokuWiki Plugin pagestats (Admin Component) 4 * Administration interface for PageStats plugin 5 */ 6 7if (!defined('DOKU_INC')) die(); 8 9class admin_plugin_pagestats extends DokuWiki_Admin_Plugin { 10 11 /** 12 * Access for managers 13 */ 14 public function forAdminOnly() { 15 return false; 16 } 17 18 /** 19 * Return sort order for position in admin menu 20 */ 21 public function getMenuSort() { 22 return 200; 23 } 24 25 /** 26 * Display name in admin menu 27 */ 28 public function getMenuText($language) { 29 return 'Page Stats'; 30 } 31 32 /** 33 * Handle user request 34 */ 35 public function handle() { 36 global $INPUT; 37 38 if ($INPUT->str('action') === 'clearCache' && checkSecurityToken()) { 39 /** @var helper_plugin_pagestats $helper */ 40 $helper = plugin_load('helper', 'pagestats'); 41 if ($helper) { 42 $helper->clearCache(); 43 msg($this->getLang('admin_cache_cleared'), 1); 44 } 45 } 46 } 47 48 /** 49 * Output HTML for the admin page 50 */ 51 public function html() { 52 global $ID; 53 54 /** @var helper_plugin_pagestats $helper */ 55 $helper = plugin_load('helper', 'pagestats'); 56 if (!$helper) { 57 echo '<div class="error">Failed to load PageStats helper</div>'; 58 return; 59 } 60 61 $stats = $helper->getStats(); 62 63 echo '<h1>' . $this->getLang('admin_title') . '</h1>'; 64 65 echo '<div class="level1">'; 66 echo '<p>' . $this->getLang('admin_intro') . '</p>'; 67 echo '</div>'; 68 69 echo '<h2>' . $this->getLang('admin_current_stats') . '</h2>'; 70 echo '<div class="table">'; 71 echo '<table class="inline">'; 72 echo '<tr><th>Statistic</th><th>Value</th></tr>'; 73 echo '<tr><td>' . $this->getLang('admin_total_pages') . '</td><td>' . hsc($stats['PAGESTATSPAGE']) . '</td></tr>'; 74 echo '<tr><td>' . $this->getLang('admin_pages_size') . '</td><td>' . hsc($stats['PAGESTATSMB']) . ' ' . $this->getLang('unit_mb') . '</td></tr>'; 75 echo '<tr><td>' . $this->getLang('admin_total_media') . '</td><td>' . hsc($stats['MEDIASTATSPAGE']) . '</td></tr>'; 76 echo '<tr><td>' . $this->getLang('admin_media_size') . '</td><td>' . hsc($stats['MEDIASTATSMB']) . ' ' . $this->getLang('unit_mb') . '</td></tr>'; 77 echo '</table>'; 78 echo '</div>'; 79 80 echo '<h2>' . $this->getLang('admin_usage_title') . '</h2>'; 81 echo '<div class="level2">'; 82 echo '<p>' . $this->getLang('admin_usage_text') . '</p>'; 83 echo '<ul>'; 84 echo '<li><code>~~PAGESTATSPAGE~~</code> - ' . $this->getLang('page_stats_count') . '</li>'; 85 echo '<li><code>~~PAGESTATSMB~~</code> - ' . $this->getLang('page_stats_size') . '</li>'; 86 echo '<li><code>~~MEDIASTATSPAGE~~</code> - ' . $this->getLang('media_stats_count') . '</li>'; 87 echo '<li><code>~~MEDIASTATSMB~~</code> - ' . $this->getLang('media_stats_size') . '</li>'; 88 echo '</ul>'; 89 echo '<p><strong>' . $this->getLang('admin_nocache_note') . '</strong></p>'; 90 echo '</div>'; 91 92 echo '<h2>' . $this->getLang('admin_cache_title') . '</h2>'; 93 echo '<div class="level2">'; 94 echo '<p>' . $this->getLang('admin_cache_text') . '</p>'; 95 96 // Cache-Informationen anzeigen 97 $cacheTime = $this->getConf('cacheTime'); 98 echo '<p>'; 99 if ($cacheTime > 0) { 100 echo $this->getLang('admin_cache_time') . ' ' . $cacheTime . ' ' . 101 $this->getLang('admin_cache_time_seconds') . ' (' . 102 number_format($cacheTime / 3600, 1) . ' ' . 103 $this->getLang('admin_cache_time_hours') . ')'; 104 echo '<br/><small>' . $this->getLang('admin_cache_time_config_hint') . '</small>'; 105 } else { 106 echo $this->getLang('admin_cache_disabled'); 107 echo '<br/><small>' . $this->getLang('admin_cache_enable_hint') . '</small>'; 108 } 109 echo '</p>'; 110 111 // Cache leeren Formular 112 $form = new Doku_Form(array('method' => 'post', 'id' => 'pagestats_form')); 113 $form->addHidden('id', $ID); 114 $form->addHidden('action', 'clearCache'); 115 $form->addHidden('sectok', getSecurityToken()); 116 $form->addElement(form_makeButton('submit', '', $this->getLang('admin_clear_cache'))); 117 echo $form->getForm(); 118 119 echo '</div>'; 120 } 121}