2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
//Diff function by Leto of StC.
|
|
|
|
function diff($OldText, $NewText) {
|
|
|
|
$LineArrayOld = explode("\n",$OldText);
|
|
|
|
$LineArrayNew = explode("\n",$NewText);
|
|
|
|
$LineOffset = 0;
|
|
|
|
$Result = array();
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
foreach ($LineArrayOld as $OldLine => $OldString) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Key = $OldLine + $LineOffset;
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Key < 0) {
|
|
|
|
$Key = 0;
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
$Found = -1;
|
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
while ($Key<count($LineArrayNew)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
if ($OldString != $LineArrayNew[$Key]) {
|
|
|
|
$Key++;
|
|
|
|
} elseif ($OldString == $LineArrayNew[$Key]) {
|
|
|
|
$Found = $Key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Found == '-1') { //we never found the old line in the new array
|
2011-03-28 14:21:28 +00:00
|
|
|
$Result[] = '<span class="line_deleted">← '.$OldString.'</span><br />';
|
|
|
|
$LineOffset = $LineOffset - 1;
|
2013-04-20 08:01:01 +00:00
|
|
|
} elseif ($Found == $OldLine + $LineOffset) {
|
2012-09-26 07:15:36 +00:00
|
|
|
$Result[] = '<span class="line_unchanged">↕ '.$OldString.'</span><br />';
|
2013-04-20 08:01:01 +00:00
|
|
|
} elseif ($Found != $OldLine + $LineOffset) {
|
|
|
|
if ($Found < $OldLine + $LineOffset) {
|
2013-02-22 08:00:24 +00:00
|
|
|
$Result[] = '<span class="line_moved">⇤ '.$OldString.'</span><br />';
|
|
|
|
} else {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Result[] = '<span class="line_moved">← '.$OldString.'</span><br />';
|
|
|
|
$Key = $OldLine + $LineOffset;
|
2013-04-20 08:01:01 +00:00
|
|
|
while ($Key < $Found) {
|
2012-09-26 07:15:36 +00:00
|
|
|
$Result[] = '<span class="line_new">→ '.$LineArrayNew[$Key].'</span><br />';
|
2011-03-28 14:21:28 +00:00
|
|
|
$Key++;
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
$Result[] = '<span class="line_moved">→ '.$OldString.'</span><br />';
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
$LineOffset = $Found-$OldLine;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-20 08:01:01 +00:00
|
|
|
if (count($LineArrayNew) > count($LineArrayOld) + $LineOffset) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Key = count($LineArrayOld) + $LineOffset;
|
2013-04-20 08:01:01 +00:00
|
|
|
while ($Key < count($LineArrayNew)) {
|
2012-09-26 07:15:36 +00:00
|
|
|
$Result[] = '<span class="line_new">→ '.$LineArrayNew[$Key].'</span><br />';
|
2011-03-28 14:21:28 +00:00
|
|
|
$Key++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $Result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_body($ID, $Rev) {
|
|
|
|
global $DB, $Revision, $Body;
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Rev == $Revision) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Str = $Body;
|
|
|
|
} else {
|
2013-06-06 08:01:03 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT Body
|
|
|
|
FROM wiki_revisions
|
|
|
|
WHERE ID='$ID'
|
|
|
|
AND Revision='$Rev'");
|
2013-04-20 08:01:01 +00:00
|
|
|
if (!$DB->record_count()) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
list($Str) = $DB->next_record();
|
|
|
|
}
|
|
|
|
return $Str;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2013-02-22 08:00:24 +00:00
|
|
|
!isset($_GET['old']) ||
|
|
|
|
!isset($_GET['new']) ||
|
|
|
|
!isset($_GET['id']) ||
|
|
|
|
!is_number($_GET['old']) ||
|
|
|
|
!is_number($_GET['new']) ||
|
|
|
|
!is_number($_GET['id']) ||
|
2011-03-28 14:21:28 +00:00
|
|
|
$_GET['old'] > $_GET['new']
|
|
|
|
) { error(0); }
|
|
|
|
|
|
|
|
$ArticleID = $_GET['id'];
|
|
|
|
|
|
|
|
$Article = $Alias->article($ArticleID);
|
|
|
|
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Article);
|
2013-04-20 08:01:01 +00:00
|
|
|
if ($Read > $LoggedUser['EffectiveClass']) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
View::show_header('Compare Article Revisions');
|
2011-03-28 14:21:28 +00:00
|
|
|
$Diff2 = get_body($ArticleID, $_GET['new']);
|
|
|
|
$Diff1 = get_body($ArticleID, $_GET['old']);
|
|
|
|
?>
|
|
|
|
<div class="thin">
|
2012-08-19 08:00:19 +00:00
|
|
|
<div class="header">
|
2012-09-09 08:00:26 +00:00
|
|
|
<h2>Compare <a href="wiki.php?action=article&id=<?=$ArticleID?>"><?=$Title?></a> Revisions</h2>
|
2012-08-19 08:00:19 +00:00
|
|
|
</div>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="box center_revision" id="center">
|
2013-04-20 08:01:01 +00:00
|
|
|
<div class="body"><? foreach (diff($Diff1, $Diff2) AS $Line) { echo $Line; } ?></div>
|
2011-03-28 14:21:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?
|
2012-10-11 08:00:15 +00:00
|
|
|
View::show_footer();
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|