Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions asset/js/common/recent-changes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function() {

// Handle a time period selection.
$('#time-period').on('change', function() {
var thisSelect = $(this);
var params = {'hours': thisSelect.val()};
window.location.href = thisSelect.data('url') + '?' + $.param(params);
});

});
14 changes: 14 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'Scripto\Controller\PublicApp\Item' => Scripto\Controller\PublicApp\ItemController::class,
'Scripto\Controller\PublicApp\Media' => Scripto\Controller\PublicApp\MediaController::class,
'Scripto\Controller\PublicApp\Revision' => Scripto\Controller\PublicApp\RevisionController::class,
'Scripto\Controller\PublicApp\RecentChanges' => Scripto\Controller\PublicApp\RecentChangesController::class,
'Scripto\Controller\Admin\User' => Scripto\Controller\Admin\UserController::class,
'Scripto\Controller\Admin\Item' => Scripto\Controller\Admin\ItemController::class,
'Scripto\Controller\Admin\Media' => Scripto\Controller\Admin\MediaController::class,
Expand Down Expand Up @@ -301,6 +302,19 @@
],
],
],
'scripto-recent-changes' => [
'type' => 'Segment',
'options' => [
'route' => '/scripto/recent-changes',
'constraints' => [
],
'defaults' => [
'__NAMESPACE__' => 'Scripto\Controller\PublicApp',
'controller' => 'recent-changes',
'action' => 'browse',
],
],
],
'scripto-talk-media-id' => [
'type' => 'Segment',
'options' => [
Expand Down
26 changes: 26 additions & 0 deletions src/Controller/PublicApp/RecentChangesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Scripto\Controller\PublicApp;

use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;

class RecentChangesController extends AbstractActionController
{
public function browseAction()
{
$hours = $this->params()->fromQuery('hours', 720); // 30 days
$continue = $this->params()->fromQuery('continue');

$response = $this->scripto()->apiClient()->queryRecentChanges($hours, 10, $continue);

$recentChanges = $this->scripto()->prepareMediawikiList($response['query']['recentchanges']);

$continue = isset($response['continue']) ? $response['continue']['rccontinue'] : null;

$view = new ViewModel;
$view->setVariable('recentChanges', $recentChanges);
$view->setVariable('hours', $hours);
$view->setVariable('continue', $continue);
return $view;
}
}
44 changes: 44 additions & 0 deletions src/Mediawiki/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,50 @@ public function queryRevision($title, $revisionId)
return $this->revisionCache[$title][$revisionId];
}

/**
* Query recent changes.
*
* @link https://www.mediawiki.org/wiki/API:RecentChanges
* @param int $hours How many hours ago to end listing
* @param int $limit
* @param string $continue
* @return array
*/
public function queryRecentChanges($hours, $limit, $continue = null)
{
if (!is_numeric($limit)) {
throw new Exception\InvalidArgumentException('A limit must be numeric');
}
if (isset($continue) && !is_string($continue)) {
throw new Exception\InvalidArgumentException('A continue must be a string');
}

$request = [
'action' => 'query',
'list' => 'recentchanges',
'rclimit' => $limit,
'rcend' => strtotime(sprintf('-%s hour', $hours)),
'rcprop' => 'user|comment|timestamp|title|ids|sizes|parsedcomment|loginfo|flags',
];
if ($continue) {
$request['rccontinue'] = $continue;
}

$query = $this->request($request);

if (isset($query['error'])) {
throw new Exception\QueryException($query['error']['info']);
}
// Set timestamps to DateTime objects adjusted to Omeka's time zone.
foreach ($query['query']['recentchanges'] as $index => $recentChange) {
$dateTime = new DateTime($recentChange['timestamp']);
$dateTime->setTimezone(new DateTimeZone($this->timeZone));
$query['query']['recentchanges'][$index]['timestamp'] = $dateTime;
}

return $query;
}

/**
* Parse revision wikitext into HTML.
*
Expand Down
10 changes: 10 additions & 0 deletions src/ViewHelper/Scripto.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ public function watchlistTimePeriodSelect()
);
}

/**
* Render the recentchanges time period select.
*
* @return string
*/
public function recentChangesTimePeriodSelect()
{
return $this->watchlistTimePeriodSelect();
}

/**
* Render an admin search box for filtering items and media.
*
Expand Down
107 changes: 107 additions & 0 deletions view/scripto/public-app/recent-changes/browse.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
$this->headScript()->appendFile($this->assetUrl('js/common/recent-changes.js', 'Scripto'));
$this->scripto()->postTitle($this->translate('Recent changes'));
?>
<div class="resource-content">
<div class="browse-controls">
<?php echo $this->scripto()->recentChangesTimePeriodSelect(); ?>
<?php echo $this->scripto()->mediawikiPagination(); ?>
</div>
<table class="tablesaw" data-tablesaw-mode="stack">
<thead>
<tr>
<th><?php echo $this->translate('Media #'); ?></th>
<th><?php echo $this->translate('Type'); ?></th>
<th><?php echo $this->translate('Item'); ?></th>
<th><?php echo $this->translate('Project'); ?></th>
<th><?php echo $this->translate('Revision'); ?></th>
<th></th>
<th><?php echo $this->translate('Size'); ?></th>
<th><?php echo $this->translate('User'); ?></th>
<th class="comment"><?php echo $this->translate('Comment'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($recentChanges as $page): ?>
<?php
$date = $page['timestamp']->format('G:i, j F Y');
$sizeDiff = $page['newlen'] - $page['oldlen'];
$sMedia = isset($page['scripto_media']) ? $page['scripto_media'] : null;
$sItem = $sMedia ? $sMedia->scriptoItem() : null;
$project = $sItem ? $sItem->scriptoProject() : null;
$isTalk = (1 === $page['ns']);
?>
<tr>
<td>
<?php echo $sMedia
? $isTalk
? $this->hyperlink(sprintf($this->scripto()->translate($project->mediaType(), 'Media #%s notes'), $sMedia->position()), $sMedia->url('talk'))
: $this->hyperlink(sprintf($this->scripto()->translate($project->mediaType(), 'Media #%s'), $sMedia->position()), $sMedia->url())
: $this->translate('n/a'); ?>
</td>
<td><?php echo $project ? $this->scripto()->translate($project->itemType(), 'Item') : $this->translate('n/a'); ?></td>
<td><?php echo $sItem ? $sItem->link($sItem->item()->displayTitle()) : $page['title']; ?></td>
<td><?php echo $project ? $project->link($project->title()) : $this->translate('n/a'); ?></td>
<td>
<?php echo $sMedia
? $this->hyperlink($date, $this->url(
$isTalk ? 'scripto-talk-revision-id' : 'scripto-revision-id',
[
'action' => 'show',
'project-id' => $project->id(),
'item-id' => $sItem->item()->id(),
'media-id' => $sMedia->media()->id(),
'revision-id' => $page['revid'],
],
true
))
: $date; ?>
</td>
<td>
<?php echo $sMedia
? sprintf(
'(%s | %s)',
$page['old_revid']
? $this->hyperlink($this->translate('diff'), $this->url(
$isTalk ? 'scripto-talk-revision-compare' : 'scripto-revision-compare',
[
'action' => 'compare',
'project-id' => $project->id(),
'item-id' => $sItem->item()->id(),
'media-id' => $sMedia->media()->id(),
'from-revision-id' => $page['old_revid'],
'to-revision-id' => $page['revid'],
],
true
))
: $this->translate('diff'),
$this->hyperlink($this->translate('hist'), $this->url(
$isTalk ? 'scripto-talk-revision' : 'scripto-revision',
[
'action' => 'browse',
'project-id' => $project->id(),
'item-id' => $sItem->item()->id(),
'media-id' => $sMedia->media()->id(),
],
true
))
)
: ''; ?>
</td>
<td><?php echo sprintf(
$this->translate('%s bytes (%s)'),
number_format($page['newlen']),
sprintf(
'<span style="color: %s;">%s%s</span>',
0 < $sizeDiff ? 'green' : (0 > $sizeDiff ? 'red' : 'inherit'),
0 < $sizeDiff ? '+' : '',
number_format($sizeDiff)
)
); ?></td>
<td><?php echo $this->hyperlink($page['user'], $this->url('scripto-user-contributions', ['action' => 'contributions', 'user-id' => $page['user']], true)); ?></td>
<td><i><?php echo strip_tags($page['parsedcomment']); ?></i></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>