implemented javascript-driven revision comparison (with the little radio buttons)
This commit is contained in:
parent
187ae59d7b
commit
132bf9cb35
@ -82,8 +82,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
return ViewMetaData::generate()->addMeta('revised', date('c', $revised))
|
||||
$data = ViewMetaData::generate()->addMeta('revised', date('c', $revised))
|
||||
->addCss($this->cssPath . '/global.css');
|
||||
|
||||
return parent::getMetaData()->merge($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,14 +47,18 @@
|
||||
public function __construct(Collection $revisions, $pageName, $priority = 0) {
|
||||
parent::__construct($priority);
|
||||
|
||||
if ($revisions->type !== 'WikiHistory') {
|
||||
throw new InvalidTypeException(1, 'Collection with type "WikiHistory"', $revisions);
|
||||
if ($revisions->type !== 'Registry') {
|
||||
throw new InvalidTypeException(1, 'Collection with type "Registry"', $revisions);
|
||||
}
|
||||
|
||||
$this->revisions = $revisions;
|
||||
$this->pageName = $pageName;
|
||||
}
|
||||
|
||||
public function getMetaData() {
|
||||
return ViewMetaData::generate()->addJavaScript($this->jsPath . '/wiki.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the view
|
||||
*
|
||||
@ -69,31 +73,37 @@
|
||||
<th>Date</th>
|
||||
<th>Message</th>
|
||||
<th>Author</th>
|
||||
<th>Diff</th>
|
||||
<th colspan="3">Diff</th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
$previous = null;
|
||||
foreach ($this->revisions as $revision => $history) {
|
||||
foreach ($this->revisions as $revision => $revisionData) {
|
||||
$affectedBytes = 'n/a';
|
||||
if ($previous !== null) {
|
||||
$link = $this->wikiPath . '/' . $this->pageName;
|
||||
$link .= '?diff[' . $previous->revision . ',' . $revision .']';
|
||||
$affectedBytes = strlen($history->wikitext) - strlen($previous->wikitext);
|
||||
$affectedBytes = (($affectedBytes >= 0) ? '+' : '') . $affectedBytes;
|
||||
$affectedBytes = '<a href="' . $link .'">' . $affectedBytes . ' bytes</a>';
|
||||
$affectedBytes = strlen($revisionData->wikitext) - strlen($previous->wikitext);
|
||||
$percentage = round(100 * $affectedBytes / strlen($revisionData->wikitext), 2);
|
||||
$prefix = ($affectedBytes === 0) ? '±' : (($affectedBytes > 0) ? '+' : '');
|
||||
$suffix = (abs($affectedBytes) === 1) ? ' byte' : ' bytes';
|
||||
$affectedBytes = $prefix . $affectedBytes . $suffix . ' (' . $prefix . $percentage . '%)';
|
||||
|
||||
$affectedBytes = '<a href="' . $link .'">' . $affectedBytes . '</a>';
|
||||
}
|
||||
|
||||
$previous = $history;
|
||||
$previous = $revisionData;
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><?php echo $history->revision; ?></td>
|
||||
<td><?php echo $history->created; ?></td>
|
||||
<td><?php echo $history->message; ?></td>
|
||||
<td><?php echo $history->created_user_id; ?></td>
|
||||
<td><?php echo $revisionData->revision; ?></td>
|
||||
<td><?php echo $revisionData->created; ?></td>
|
||||
<td><?php echo $revisionData->message; ?></td>
|
||||
<td><a href="<?php echo $this->wikiPath; ?>/Users?<?php echo $revisionData->user_name; ?>"><?php echo $revisionData->user_name; ?></a></td>
|
||||
<td><?php echo $affectedBytes; ?></td>
|
||||
<td><input type="radio" name="oldrev" value="<?php echo $revisionData->revision; ?>"/></td>
|
||||
<td><input type="radio" name="newrev" value="<?php echo $revisionData->revision; ?>"/></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
@ -102,6 +112,10 @@
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td colspan="7"><input type="button" value="Compare Revisions" onclick="Wiki.compareRevisions('<?php echo $this->wikiPath . '/' . $this->pageName;?>?diff')"/>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<?php
|
||||
|
36
src/media/js/wiki.js
Normal file
36
src/media/js/wiki.js
Normal file
@ -0,0 +1,36 @@
|
||||
var Wiki = {
|
||||
|
||||
compareRevisions: function(path) {
|
||||
var oldDiff = Wiki.getRevision("oldrev");
|
||||
if (oldDiff === null) {
|
||||
alert("No old revision is selected");
|
||||
return false;
|
||||
}
|
||||
|
||||
var newDiff = Wiki.getRevision("newrev");
|
||||
if (newDiff === null) {
|
||||
alert("No new revision is selected");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oldDiff === newDiff) {
|
||||
alert("Cannot compare the same revision");
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = path + "[" + oldDiff + "," + newDiff + "]";
|
||||
document.location = url;
|
||||
},
|
||||
|
||||
getRevision: function(name) {
|
||||
var revs = document.getElementsByName(name);
|
||||
for (var i = 0, len = revs.length; i < len; ++i) {
|
||||
if (revs[i].checked) {
|
||||
return revs[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user