created wiki stats page

This commit is contained in:
tmont 2008-10-27 05:41:06 +00:00
parent 5d2801b67d
commit a5d3a08c14
6 changed files with 142 additions and 17 deletions

View File

@ -54,6 +54,7 @@
case 'WikiPageNewView':
case 'WikiPageEditView':
case 'WikiPageHistoryView':
case 'WikiPageStatsView':
case 'WikiPageMenuView':
case 'WikiPageContentView':
case 'PanaceaWikiView':

View File

@ -1,7 +1,7 @@
<?php
/**
* WikiPageContentView
* PanaceaWikiView
*
* @package Panacea
* @subpackage Views
@ -13,7 +13,7 @@
require_once 'NowhereConcave/bootstrap.php';
/**
* View for wiki content
* View for wiki-related things
*
* @package Panacea
* @subpackage Views
@ -53,6 +53,14 @@
$this->action = $action;
}
public function makeWikiUserLink($user) {
if (!is_string($user)) {
throw new InvalidTypeException(1, 'string', $user);
}
return '<a href="' . $this->wikiPath . '/Users?' . $user .'">' . $user . '</a>';
}
/**
* Gets meta data for this view
*

View File

@ -22,6 +22,13 @@
*/
class WikiPageEditView extends PanaceaWikiView {
/**
* Renders the view
*
* @author Tommy Montgomery
* @since 2008-10-18
* @uses WikiPageObject::getRevision()
*/
public function send() { ?>
<div class="wikicontent">

View File

@ -0,0 +1,110 @@
<?php
/**
* WikiPageStatsView
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-26
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* View for a wiki page's statistics
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-26
*/
class WikiPageStatsView extends PanaceaWikiView {
/**
* @var WikiStats
*/
protected $stats;
/**
* Creates a new {@link WikiRevisionDiffView}
*
* @author Tommy Montgomery
* @since 2008-10-21
*
* @param WikiPageObject $page The wiki page to display
* @param WikiDiff $diff The diff between the two revisions
* @param string $action The action to take
* @param int $priority The priority of the view
*/
public function __construct(WikiPageObject $page, WikiStats $stats, $action = null, $priority = 0) {
parent::__construct($page, $action, $priority);
$this->stats = $stats;
}
/**
* Renders the view
*
* @author Tommy Montgomery
* @since 2008-10-26
*/
public function send() {
$age = time() - strtotime($this->stats->created);
$ageInDays = $age / 86400;
$mostActiveAuthors = '';
foreach ($this->stats->mostActiveAuthor as $author => $numRevisions) {
$mostActiveAuthors .= $this->makeWikiUserLink($author) . ' (' . $numRevisions . ' revisions)<br />';
}
$mostActiveAuthors = substr($mostActiveAuthors, 0, -6);
?>
<h1><?php echo $this->page->page->page_name; ?>: Statistics</h1>
<div class="wikicontent">
<table>
<tr>
<th>Created</th>
<td><?php echo $this->stats->created; ?> by <?php echo $this->makeWikiUserLink($this->stats->creator); ?></td>
</tr>
<tr>
<th>Last change</th>
<td><?php echo $this->stats->lastUpdated; ?> by <?php echo $this->makeWikiUserLink($this->stats->lastAuthor); ?></td>
</tr>
<tr>
<th>Age</th>
<td><?php echo $ageInDays; ?> days</td>
</tr>
<tr>
<th>Unparsed size</th>
<td><?php echo $this->stats->size; ?> bytes</td>
</tr>
<tr>
<th>Revisions</th>
<td><?php echo $this->stats->numRevisions; ?></td>
</tr>
<tr>
<th>Revisions/day</th>
<td><?php echo $this->stats->numRevisions / $ageInDays; ?></td>
</tr>
<tr>
<th>Unique authors</th>
<td><?php echo $this->stats->numAuthors; ?></td>
</tr>
<tr>
<th>Most active author(s)</th>
<td><?php echo $mostActiveAuthors; ?></td>
</tr>
</table>
</div>
<?php
}
}
?>

View File

@ -54,7 +54,8 @@
$this->addView(new WikiPageHistoryView($this->page, $revisions, $this->action, 2));
break;
case 'stats':
$this->addView(new WikiPageStatsView($this->page, $this->action, 2));
$stats = new WikiStats($this->page);
$this->addView(new WikiPageStatsView($this->page, $stats, $this->action, 2));
break;
default:
//check for diffs: WikiPage?diff[oldRev,newRev]
@ -63,8 +64,6 @@
$newRevision = (int)$matches[2];
$diff = $this->page->compareRevisions($oldRevision, $newRevision, $vendor);
//echo '<pre>'; var_dump($diff); echo '</pre>'; exit;
$this->addView(new WikiRevisionDiffView($this->page, $diff, $this->action, 2));
}
else {

View File

@ -1,36 +1,37 @@
<?php
/**
* WikiPageHistoryView
* WikiRevisionDiffView
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-18
* @since 2008-10-21
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* View for a wiki page's history
* View for a wiki page's diff between revisions
*
* @package Panacea
* @subpackage Views
* @author Tommy Montgomery
* @since 2008-10-18
* @since 2008-10-21
*/
class WikiRevisionDiffView extends PanaceaWikiView {
/**
* @var WikiDiff
*/
protected $diff;
/**
* Creates a new {@link WikiPageHistoryView}
* Creates a new {@link WikiRevisionDiffView}
*
* @author Tommy Montgomery
* @since 2008-10-21
* @uses addView()
* @uses WikiRevisionHistoryView
*
* @param WikiPageObject $page The wiki page to display
* @param WikiDiff $diff The diff between the two revisions
@ -39,7 +40,6 @@
*/
public function __construct(WikiPageObject $page, WikiDiff $diff, $action = null, $priority = 0) {
parent::__construct($page, $action, $priority);
$this->diff = $diff;
}