From f9528c0c7accd2da60f16864555b4982b940a1a0 Mon Sep 17 00:00:00 2001
From: Klap-in
Date: Sun, 27 Jan 2013 22:02:47 +0100
Subject: Added diff navigation Navigation links to move to previous edit
before revision in left column or next/last edit after revision in right
column.
---
inc/changelog.php | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++
inc/html.php | 47 +++++++++++-
inc/lang/en/lang.php | 4 +
inc/lang/nl/lang.php | 4 +
4 files changed, 267 insertions(+), 1 deletion(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index 9768fea51..e25c3144e 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -543,4 +543,217 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
return $revs;
}
+/**
+ * Get the nth revision left or right handside for a specific page id
+ * and revision (timestamp). For large changelog files, only the chunk containing the
+ * reference revision $rev is read and sometimes a next chunck.
+ *
+ * Adjacent changelog lines are optimistically parsed and cached to speed up
+ * consecutive calls to getRevisionInfo.
+ *
+ * @author Gerrit Uitslag
+ *
+ * based on getRevisionInfo by
+ * @author Ben Coburn
+ * @author Kate Arzamastseva
+ *
+ * @param string $id pageid
+ * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
+ * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
+ * @param int $chunk_size maximum block size
+ * @param bool $media
+ * @return bool|string
+ */
+function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media = false) {
+ global $cache_revinfo;
+ global $INFO;
+ $cache =& $cache_revinfo;
+ if(!isset($cache[$id])) {
+ $cache[$id] = array();
+ }
+ $rev = max($rev, 0);
+
+ //no direction given or last rev, so no follow-up
+ if(!$direction || ($direction > 0 && $rev == $INFO['meta']['last_change']['date'])) {
+ return false;
+ }
+
+ if($media) {
+ $file = mediaMetaFN($id, '.changes');
+ } else {
+ $file = metaFN($id, '.changes');
+ }
+ if(!@file_exists($file)) {
+ return false;
+ }
+
+ //get $lines from changelog
+ $lines = array();
+ $fp = null;
+ $tail = 0;
+ $head = 0;
+ $eof = 0;
+ if(filesize($file) < $chunk_size || $chunk_size == 0) {
+ // read whole file
+ $uses_chuncks = false;
+ $lines = file($file);
+ if($lines === false) {
+ return false;
+ }
+ } else {
+ // read by chunk
+ $uses_chuncks = true;
+ $fp = fopen($file, 'rb'); // "file pointer"
+ if($fp === false) {
+ return false;
+ } //error
+ $head = 0;
+ fseek($fp, 0, SEEK_END); //set file position indicator 0 byte from end.
+ $tail = ftell($fp); //return current position of pointer as integer
+ $eof = $tail;
+ $finger = 0;
+ $finger_rev = 0;
+
+ // find chunk
+ while($tail - $head > $chunk_size) {
+ $finger = $head + floor(($tail - $head) / 2.0);
+ $finger = getNewlinepointer($fp, $finger);
+ $tmp = fgets($fp); // then read at that location
+ $tmp = parseChangelogLine($tmp);
+ $finger_rev = $tmp['date'];
+ if($finger == $head || $finger == $tail) {
+ break;
+ }
+ if($finger_rev > $rev) {
+ $tail = $finger;
+ } else {
+ $head = $finger;
+ }
+ }
+
+ if($tail - $head < 1) {
+ // cound not find chunk, assume requested rev is missing
+ fclose($fp);
+ return false;
+ }
+
+ $lines = readChunk($fp, $head, $tail);
+ }
+
+ // look for revisions later then $rev, when founded count till the wanted revision is reached
+ // also parse and cache changelog lines that pass
+ $revcounter = 0;
+ $relrev = false;
+ $tmp = array();
+ $checkotherchunck = true; //always runs once
+ while(!$relrev && $checkotherchunck) {
+
+ if($direction > 0) {
+ foreach($lines as $value) {
+ $tmp = parseChangelogLine($value);
+ if($tmp !== false) {
+ $cache[$id][$tmp['date']] = $tmp;
+ //look for revs older then reference $rev and select $direction-th one
+ if($tmp['date'] > $rev) {
+ $revcounter++;
+ if($revcounter == $direction) {
+ $relrev = $tmp['date'];
+ }
+ }
+ }
+ }
+ } else {
+ //parse in reverse order
+ for($i = count($lines) - 1; $i >= 0; $i--) {
+ $tmp = parseChangelogLine($lines[$i]);
+ if($tmp !== false) {
+ $cache[$id][$tmp['date']] = $tmp;
+ //look for revs older then reference $rev and select $direction-th one
+ if($tmp['date'] < $rev) {
+ $revcounter++;
+ if($revcounter == abs($direction)) {
+ $relrev = $tmp['date'];
+ }
+ }
+ }
+ }
+ }
+
+ //true when $rev is found, but not the wanted follow-up.
+ $checkotherchunck = $uses_chuncks
+ && ($tmp['date'] == $rev || ($revcounter > 0 && !$relrev))
+ && !feof($fp);
+
+ if($checkotherchunck) {
+ if($direction > 0) {
+ //get interval of next chunck, smaller than $chunck_size
+ $head = $tail;
+ $lookpointer = true;
+ $tail = $head + floor($chunk_size * (2 / 3));
+ while($lookpointer) {
+ $tail = min($tail, $eof);
+ $tail = getNewlinepointer($fp, $tail);
+ $lookpointer = $tail - $head > $chunk_size;
+ if($lookpointer) {
+ $tail = $head + floor(($tail - $head) / 2);
+ }
+ }
+ } else {
+ $tail = $head;
+ $head = max($tail - $chunk_size, 0);
+ $head = getNewlinepointer($fp, $head);
+ }
+
+ //load next chunck
+ $lines = readChunk($fp, $head, $tail);
+ }
+ }
+ if($uses_chuncks) {
+ fclose($fp);
+ }
+ if($relrev == $INFO['meta']['last_change']['date']) {
+ return 'current';
+ }
+ return $relrev;
+}
+
+/**
+ * Read chunk and return array with lines of given chunck.
+ * Has no check if $head and $tail are really at a new line
+ *
+ * @param $fp resource filepointer
+ * @param $head int start point chunck
+ * @param $tail int end point chunck
+ * @return array lines read from chunck
+ */
+function readChunk($fp, $head, $tail) {
+ $chunk = '';
+ $chunk_size = max($tail - $head, 0); // found chunk size
+ $got = 0;
+ fseek($fp, $head);
+ while($got < $chunk_size && !feof($fp)) {
+ $tmp = @fread($fp, max($chunk_size - $got, 0));
+ if($tmp === false) {
+ break;
+ } //error state
+ $got += strlen($tmp);
+ $chunk .= $tmp;
+ }
+ $lines = explode("\n", $chunk);
+ array_pop($lines); // remove trailing newline
+ return $lines;
+}
+
+/**
+ * Set pointer to first new line after $finger and return its position
+ *
+ * @param $fp resource filepointer
+ * @param $finger int a pointer
+ * @return int pointer
+ */
+function getNewlinepointer($fp, $finger) {
+ fseek($fp, $finger);
+ fgets($fp); // slip the finger forward to a new line
+ return ftell($fp);
+}
diff --git a/inc/html.php b/inc/html.php
index 5c1c75cf6..9d344a05f 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1151,6 +1151,18 @@ function html_diff($text='',$intro=true,$type=null){
}
$r_text = rawWiki($ID,$r_rev);
+ //look for previous/next revision
+ if($r_rev) {
+ $next_rev = getRelativeRevision($ID, $r_rev, 1);
+ } else {
+ $next_rev = false;
+ }
+ if($l_rev) {
+ $prev_rev = getRelativeRevision($ID, $l_rev, -1);
+ } else {
+ $prev_rev = false;
+ }
+
list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev);
}
@@ -1191,7 +1203,40 @@ function html_diff($text='',$intro=true,$type=null){
'rev2[1]' => $r_rev,
'difftype' => $type,
));
- ptln(''.$lang['difflink'].'
');
+ ptln(''.$lang['difflink'].'
');
+ if($prev_rev){
+ $diffurlprev = wl($ID, array(
+ 'do' => 'diff',
+ 'rev2[0]' => $prev_rev,
+ 'rev2[1]' => $l_rev,
+ 'difftype' => $type,
+ ));
+ ptln('← '.$lang['diffpreviousedit'].' - ');
+ }
+ $recenturl = wl($ID, array(
+ 'do' => 'revisions'
+ ));
+ ptln(''.$lang['overviewrevs'].'');
+ if($next_rev){
+ if($next_rev=='current') {
+ $diffurlnextparam = array(
+ 'do' => 'diff',
+ 'rev' => $r_rev,
+ 'difftype' => $type,
+ );
+ $navnexttitle = $lang['difflastedit'];
+ } else {
+ $diffurlnextparam = array(
+ 'do' => 'diff',
+ 'rev2[0]' => $r_rev,
+ 'rev2[1]' => $next_rev,
+ 'difftype' => $type,
+ );
+ $navnexttitle = $lang['diffnextedit'];
+ }
+ ptln(' - '.$navnexttitle.' →');
+ }
+ ptln('
');
ptln('');
}
?>
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 144faf4e1..92d352097 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -184,6 +184,10 @@ $lang['difflink'] = 'Link to this comparison view';
$lang['diff_type'] = 'View differences:';
$lang['diff_inline'] = 'Inline';
$lang['diff_side'] = 'Side by Side';
+$lang['diffpreviousedit'] = 'Previous edit';
+$lang['diffnextedit'] = 'Next edit';
+$lang['difflastedit'] = 'Last edit';
+$lang['overviewrevs'] = 'Overview of revisions';
$lang['line'] = 'Line';
$lang['breadcrumb'] = 'Trace';
$lang['youarehere'] = 'You are here';
diff --git a/inc/lang/nl/lang.php b/inc/lang/nl/lang.php
index 0241eab2f..2fe536f31 100644
--- a/inc/lang/nl/lang.php
+++ b/inc/lang/nl/lang.php
@@ -185,6 +185,10 @@ $lang['difflink'] = 'Link naar deze vergelijking';
$lang['diff_type'] = 'Bekijk verschillen:';
$lang['diff_inline'] = 'Inline';
$lang['diff_side'] = 'Zij aan zij';
+$lang['diffpreviousedit'] = 'Vorige bewerking';
+$lang['diffnextedit'] = 'Volgende bewerking';
+$lang['difflastedit'] = 'Laatste bewerking';
+$lang['overviewrevs'] = 'Overzicht van revisies';
$lang['line'] = 'Regel';
$lang['breadcrumb'] = 'Spoor';
$lang['youarehere'] = 'Je bent hier';
--
cgit v1.2.3
From ce2f604739dc66e32e05f7078ada1711fe387979 Mon Sep 17 00:00:00 2001
From: Klap-in
Date: Mon, 28 Jan 2013 01:17:40 +0100
Subject: Add working EoF and BoF checks when chunck reading. Also isset on
meta-last_change-date entry.
---
inc/changelog.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index e25c3144e..d2be5b2db 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -574,7 +574,7 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
$rev = max($rev, 0);
//no direction given or last rev, so no follow-up
- if(!$direction || ($direction > 0 && $rev == $INFO['meta']['last_change']['date'])) {
+ if(!$direction || ($direction > 0 && isset($INFO['meta']['last_change']['date']) && $rev == $INFO['meta']['last_change']['date'])) {
return false;
}
@@ -682,7 +682,7 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
//true when $rev is found, but not the wanted follow-up.
$checkotherchunck = $uses_chuncks
&& ($tmp['date'] == $rev || ($revcounter > 0 && !$relrev))
- && !feof($fp);
+ && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
if($checkotherchunck) {
if($direction > 0) {
@@ -712,7 +712,7 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
fclose($fp);
}
- if($relrev == $INFO['meta']['last_change']['date']) {
+ if(isset($INFO['meta']['last_change']) && $relrev == $INFO['meta']['last_change']['date']) {
return 'current';
}
return $relrev;
--
cgit v1.2.3
From 9a01fb1de9ece0c4d37cb331e51e3b0b7dcf75a8 Mon Sep 17 00:00:00 2001
From: Klap-in
Date: Mon, 28 Jan 2013 01:39:57 +0100
Subject: Add some breaks to while loops.
---
inc/changelog.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/inc/changelog.php b/inc/changelog.php
index d2be5b2db..c5c1c8246 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -697,6 +697,7 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
if($lookpointer) {
$tail = $head + floor(($tail - $head) / 2);
}
+ if($tail == $head) break;
}
} else {
$tail = $head;
@@ -706,6 +707,7 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
//load next chunck
$lines = readChunk($fp, $head, $tail);
+ if(empty($lines)) break;
}
}
if($uses_chuncks) {
--
cgit v1.2.3
From 040f0e135c37c5b544f16277ff69205369df5f1f Mon Sep 17 00:00:00 2001
From: Klap-in
Date: Mon, 4 Feb 2013 15:45:59 +0100
Subject: some refactoring
---
inc/changelog.php | 265 ++++++++++++++++++++++++------------------------------
1 file changed, 117 insertions(+), 148 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index c5c1c8246..fc9dc9fd1 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -360,59 +360,13 @@ function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
} else {
$file = metaFN($id, '.changes');
}
- if (!@file_exists($file)) { return false; }
- if (filesize($file)<$chunk_size || $chunk_size==0) {
- // read whole file
- $lines = file($file);
- if ($lines===false) { return false; }
- } else {
- // read by chunk
- $fp = fopen($file, 'rb'); // "file pointer"
- if ($fp===false) { return false; }
- $head = 0;
- fseek($fp, 0, SEEK_END);
- $tail = ftell($fp);
- $finger = 0;
- $finger_rev = 0;
- // find chunk
- while ($tail-$head>$chunk_size) {
- $finger = $head+floor(($tail-$head)/2.0);
- fseek($fp, $finger);
- fgets($fp); // slip the finger forward to a new line
- $finger = ftell($fp);
- $tmp = fgets($fp); // then read at that location
- $tmp = parseChangelogLine($tmp);
- $finger_rev = $tmp['date'];
- if ($finger==$head || $finger==$tail) { break; }
- if ($finger_rev>$rev) {
- $tail = $finger;
- } else {
- $head = $finger;
- }
- }
-
- if ($tail-$head<1) {
- // cound not find chunk, assume requested rev is missing
- fclose($fp);
- return false;
- }
-
- // read chunk
- $chunk = '';
- $chunk_size = max($tail-$head, 0); // found chunk size
- $got = 0;
- fseek($fp, $head);
- while ($got<$chunk_size && !feof($fp)) {
- $tmp = @fread($fp, max($chunk_size-$got, 0));
- if ($tmp===false) { break; } //error state
- $got += strlen($tmp);
- $chunk .= $tmp;
- }
- $lines = explode("\n", $chunk);
- array_pop($lines); // remove trailing newline
+ //read lines from changelog
+ list($fp, $lines) = _readloglines($file, $rev, $chunk_size);
+ if($fp) {
fclose($fp);
}
+ if(empty($lines)) return false;
// parse and cache changelog lines
foreach ($lines as $value) {
@@ -572,9 +526,13 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
$cache[$id] = array();
}
$rev = max($rev, 0);
+ $direction = (int) $direction;
//no direction given or last rev, so no follow-up
- if(!$direction || ($direction > 0 && isset($INFO['meta']['last_change']['date']) && $rev == $INFO['meta']['last_change']['date'])) {
+ if(!$direction ||
+ ($direction > 0
+ && isset($INFO['meta']['last_change']['date'])
+ && $rev == $INFO['meta']['last_change']['date'])) {
return false;
}
@@ -583,42 +541,125 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
} else {
$file = metaFN($id, '.changes');
}
+
+ //get lines from changelog
+ list($fp, $lines, $head, $tail, $eof) = _readloglines($file, $rev, $chunk_size);
+ if(empty($lines)) return false;
+
+ // look for revisions later/earlier then $rev, when founded count till the wanted revision is reached
+ // also parse and cache changelog lines for getRevisionInfo().
+ $revcounter = 0;
+ $relativerev = false;
+ $checkotherchunck = true; //always runs once
+ while(!$relativerev && $checkotherchunck) {
+ $tmp = array();
+ //parse in normal or reverse order
+ $count = count($lines);
+ if($direction > 0) {
+ $start = 0;
+ $step = 1;
+ } else {
+ $start = $count - 1;
+ $step = -1;
+ }
+ for($i = $start; $i >= 0 && $i < $count; $i = $i + $step) {
+ $tmp = parseChangelogLine($lines[$i]);
+ if($tmp !== false) {
+ $cache[$id][$tmp['date']] = $tmp;
+ //look for revs older/earlier then reference $rev and select $direction-th one
+ if(($direction > 0 && $tmp['date'] > $rev) || ($direction < 0 && $tmp['date'] < $rev)) {
+ $revcounter++;
+ if($revcounter == abs($direction)) {
+ $relativerev = $tmp['date'];
+ }
+ }
+ }
+ }
+
+ //true when $rev is found, but not the wanted follow-up.
+ $checkotherchunck = $fp
+ && ($tmp['date'] == $rev || ($revcounter > 0 && !$relativerev))
+ && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
+
+ if($checkotherchunck) {
+ //search bounds of chunck, rounded on new line, but smaller than $chunck_size
+ if($direction > 0) {
+ $head = $tail;
+ $lookpointer = true;
+ $tail = $head + floor($chunk_size * (2 / 3));
+ while($lookpointer) {
+ $tail = min($tail, $eof);
+ $tail = _getNewlinepointer($fp, $tail);
+ $lookpointer = $tail - $head > $chunk_size;
+ if($lookpointer) {
+ $tail = $head + floor(($tail - $head) / 2);
+ }
+ if($tail == $head) break;
+ }
+ } else {
+ $tail = $head;
+ $head = max($tail - $chunk_size, 0);
+ $head = _getNewlinepointer($fp, $head);
+ }
+
+ //load next chunck
+ $lines = _readChunk($fp, $head, $tail);
+ if(empty($lines)) break;
+ }
+ }
+ if($fp) {
+ fclose($fp);
+ }
+
+ if(isset($INFO['meta']['last_change']) && $relativerev == $INFO['meta']['last_change']['date']) {
+ return 'current';
+ }
+ return $relativerev;
+}
+
+/**
+ * get lines from changelog.
+ * If file larger than $chuncksize, only chunck is read that could contain $rev.
+ *
+ * @param int $file path to changelog file
+ * @param int $rev revision timestamp
+ * @param int $chunk_size maximum block size read from file
+ * @return array(fp, array(changeloglines), $head, $tail, $eof)|bool
+ * returns false when not succeed. fp only defined for chuck reading, needs closing.
+ */
+function _readloglines($file, $rev, $chunk_size) {
if(!@file_exists($file)) {
return false;
}
- //get $lines from changelog
- $lines = array();
$fp = null;
- $tail = 0;
$head = 0;
+ $tail = 0;
$eof = 0;
if(filesize($file) < $chunk_size || $chunk_size == 0) {
// read whole file
- $uses_chuncks = false;
- $lines = file($file);
+ $lines = file($file);
if($lines === false) {
return false;
}
} else {
// read by chunk
- $uses_chuncks = true;
- $fp = fopen($file, 'rb'); // "file pointer"
+ $fp = fopen($file, 'rb'); // "file pointer"
if($fp === false) {
return false;
- } //error
+ }
$head = 0;
- fseek($fp, 0, SEEK_END); //set file position indicator 0 byte from end.
- $tail = ftell($fp); //return current position of pointer as integer
- $eof = $tail;
+ fseek($fp, 0, SEEK_END);
+ $eof = ftell($fp);
+ $tail = $eof;
$finger = 0;
$finger_rev = 0;
// find chunk
while($tail - $head > $chunk_size) {
$finger = $head + floor(($tail - $head) / 2.0);
- $finger = getNewlinepointer($fp, $finger);
- $tmp = fgets($fp); // then read at that location
+ $finger = _getNewlinepointer($fp, $finger);
+ $tmp = fgets($fp);
$tmp = parseChangelogLine($tmp);
$finger_rev = $tmp['date'];
if($finger == $head || $finger == $tail) {
@@ -637,87 +678,15 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
return false;
}
- $lines = readChunk($fp, $head, $tail);
- }
-
- // look for revisions later then $rev, when founded count till the wanted revision is reached
- // also parse and cache changelog lines that pass
- $revcounter = 0;
- $relrev = false;
- $tmp = array();
- $checkotherchunck = true; //always runs once
- while(!$relrev && $checkotherchunck) {
-
- if($direction > 0) {
- foreach($lines as $value) {
- $tmp = parseChangelogLine($value);
- if($tmp !== false) {
- $cache[$id][$tmp['date']] = $tmp;
- //look for revs older then reference $rev and select $direction-th one
- if($tmp['date'] > $rev) {
- $revcounter++;
- if($revcounter == $direction) {
- $relrev = $tmp['date'];
- }
- }
- }
- }
- } else {
- //parse in reverse order
- for($i = count($lines) - 1; $i >= 0; $i--) {
- $tmp = parseChangelogLine($lines[$i]);
- if($tmp !== false) {
- $cache[$id][$tmp['date']] = $tmp;
- //look for revs older then reference $rev and select $direction-th one
- if($tmp['date'] < $rev) {
- $revcounter++;
- if($revcounter == abs($direction)) {
- $relrev = $tmp['date'];
- }
- }
- }
- }
- }
-
- //true when $rev is found, but not the wanted follow-up.
- $checkotherchunck = $uses_chuncks
- && ($tmp['date'] == $rev || ($revcounter > 0 && !$relrev))
- && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
-
- if($checkotherchunck) {
- if($direction > 0) {
- //get interval of next chunck, smaller than $chunck_size
- $head = $tail;
- $lookpointer = true;
- $tail = $head + floor($chunk_size * (2 / 3));
- while($lookpointer) {
- $tail = min($tail, $eof);
- $tail = getNewlinepointer($fp, $tail);
- $lookpointer = $tail - $head > $chunk_size;
- if($lookpointer) {
- $tail = $head + floor(($tail - $head) / 2);
- }
- if($tail == $head) break;
- }
- } else {
- $tail = $head;
- $head = max($tail - $chunk_size, 0);
- $head = getNewlinepointer($fp, $head);
- }
-
- //load next chunck
- $lines = readChunk($fp, $head, $tail);
- if(empty($lines)) break;
- }
- }
- if($uses_chuncks) {
- fclose($fp);
+ $lines = _readChunk($fp, $head, $tail);
}
-
- if(isset($INFO['meta']['last_change']) && $relrev == $INFO['meta']['last_change']['date']) {
- return 'current';
- }
- return $relrev;
+ return array(
+ $fp,
+ $lines,
+ $head,
+ $tail,
+ $eof
+ );
}
/**
@@ -729,16 +698,16 @@ function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media =
* @param $tail int end point chunck
* @return array lines read from chunck
*/
-function readChunk($fp, $head, $tail) {
+function _readChunk($fp, $head, $tail) {
$chunk = '';
$chunk_size = max($tail - $head, 0); // found chunk size
$got = 0;
fseek($fp, $head);
while($got < $chunk_size && !feof($fp)) {
$tmp = @fread($fp, max($chunk_size - $got, 0));
- if($tmp === false) {
+ if($tmp === false) { //error state
break;
- } //error state
+ }
$got += strlen($tmp);
$chunk .= $tmp;
}
@@ -754,7 +723,7 @@ function readChunk($fp, $head, $tail) {
* @param $finger int a pointer
* @return int pointer
*/
-function getNewlinepointer($fp, $finger) {
+function _getNewlinepointer($fp, $finger) {
fseek($fp, $finger);
fgets($fp); // slip the finger forward to a new line
return ftell($fp);
--
cgit v1.2.3
From 8eccf945d3e3d5f072979c015b21624810f7d0a8 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 20 Nov 2013 13:18:44 +0100
Subject: page related changelog reading refactored to class
---
inc/changelog.php | 771 ++++++++++++++++++++++++++++++------------------------
1 file changed, 430 insertions(+), 341 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index f7b07ae57..36be9dc79 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -334,399 +334,488 @@ function _handleRecent($line,$ns,$flags,&$seen){
}
/**
- * Get the changelog information for a specific page id
- * and revision (timestamp). Adjacent changelog lines
- * are optimistically parsed and cached to speed up
- * consecutive calls to getRevisionInfo. For large
- * changelog files, only the chunk containing the
- * requested changelog line is read.
- *
- * @author Ben Coburn
- * @author Kate Arzamastseva
+ * Class PageRevisionLog
*/
-function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
- global $cache_revinfo;
- $cache =& $cache_revinfo;
- if (!isset($cache[$id])) { $cache[$id] = array(); }
- $rev = max($rev, 0);
-
- // check if it's already in the memory cache
- if (isset($cache[$id]) && isset($cache[$id][$rev])) {
- return $cache[$id][$rev];
- }
-
- if ($media) {
- $file = mediaMetaFN($id, '.changes');
- } else {
- $file = metaFN($id, '.changes');
- }
+class PageRevisionLog {
+
+ /** @var string */
+ private $id;
+ /** @var int */
+ private $chunk_size;
+ /** @var array */
+ private $cache;
+
+ /**
+ * Constructor
+ *
+ * @param string $id page id
+ * @param int $chunk_size maximum block size read from file
+ */
+ public function __construct($id, $chunk_size = 8192) {
+ global $cache_revinfo;
+
+ $this->cache =& $cache_revinfo;
+ if(!isset($this->cache[$id])) {
+ $this->cache[$id] = array();
+ }
- //read lines from changelog
- list($fp, $lines) = _readloglines($file, $rev, $chunk_size);
- if($fp) {
- fclose($fp);
- }
- if(empty($lines)) return false;
+ $this->id = $id;
+ $this->setChunkSize($chunk_size);
- // parse and cache changelog lines
- foreach ($lines as $value) {
- $tmp = parseChangelogLine($value);
- if ($tmp!==false) {
- $cache[$id][$tmp['date']] = $tmp;
- }
}
- if (!isset($cache[$id][$rev])) { return false; }
- return $cache[$id][$rev];
-}
-/**
- * Return a list of page revisions numbers
- * Does not guarantee that the revision exists in the attic,
- * only that a line with the date exists in the changelog.
- * By default the current revision is skipped.
- *
- * id: the page of interest
- * first: skip the first n changelog lines
- * num: number of revisions to return
- *
- * The current revision is automatically skipped when the page exists.
- * See $INFO['meta']['last_change'] for the current revision.
- *
- * For efficiency, the log lines are parsed and cached for later
- * calls to getRevisionInfo. Large changelog files are read
- * backwards in chunks until the requested number of changelog
- * lines are recieved.
- *
- * @author Ben Coburn
- * @author Kate Arzamastseva
- */
-function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
- global $cache_revinfo;
- $cache =& $cache_revinfo;
- if (!isset($cache[$id])) { $cache[$id] = array(); }
+ /**
+ * Set chunk size for file reading
+ *
+ * @param int $chunk_size maximum block size read from file
+ */
+ public function setChunkSize($chunk_size) {
+ if(!is_numeric($chunk_size)) $chunk_size = 0;
- $revs = array();
- $lines = array();
- $count = 0;
- if ($media) {
- $file = mediaMetaFN($id, '.changes');
- } else {
- $file = metaFN($id, '.changes');
- }
- $num = max($num, 0);
- if ($num == 0) { return $revs; }
-
- $chunk_size = max($chunk_size, 0);
- if ($first<0) {
- $first = 0;
- } else if (!$media && @file_exists(wikiFN($id)) || $media && @file_exists(mediaFN($id))) {
- // skip current revision if the page exists
- $first = max($first+1, 0);
+ $this->chunk_size = (int) max($chunk_size, 0);
}
- if (!@file_exists($file)) { return $revs; }
- if (filesize($file)<$chunk_size || $chunk_size==0) {
- // read whole file
- $lines = file($file);
- if ($lines===false) { return $revs; }
- } else {
- // read chunks backwards
- $fp = fopen($file, 'rb'); // "file pointer"
- if ($fp===false) { return $revs; }
- fseek($fp, 0, SEEK_END);
- $tail = ftell($fp);
-
- // chunk backwards
- $finger = max($tail-$chunk_size, 0);
- while ($count<$num+$first) {
- fseek($fp, $finger);
- $nl = $finger;
- if ($finger>0) {
- fgets($fp); // slip the finger forward to a new line
- $nl = ftell($fp);
- }
+ /**
+ * Get the changelog information for a specific page id and revision (timestamp)
+ *
+ * Adjacent changelog lines are optimistically parsed and cached to speed up
+ * consecutive calls to getRevisionInfo. For large changelog files, only the chunk
+ * containing the requested changelog line is read.
+ *
+ * @param int $rev revision timestamp
+ * @param bool $media look into media log?
+ * @return bool|array false or array with entries:
+ * - date: unix timestamp
+ * - ip: IPv4 address (127.0.0.1)
+ * - type: log line type
+ * - id: page id
+ * - user: user name
+ * - sum: edit summary (or action reason)
+ * - extra: extra data (varies by line type)
+ *
+ * @author Ben Coburn
+ * @author Kate Arzamastseva
+ */
+ public function getRevisionInfo($rev, $media = false) {
+ $rev = max($rev, 0);
+
+ // check if it's already in the memory cache
+ if(isset($this->cache[$this->id]) && isset($this->cache[$this->id][$rev])) {
+ return $this->cache[$this->id][$rev];
+ }
- // was the chunk big enough? if not, take another bite
- if($nl > 0 && $tail <= $nl){
- $finger = max($finger-$chunk_size, 0);
- continue;
- }else{
- $finger = $nl;
- }
+ //read lines from changelog
+ list($fp, $lines) = $this->readloglines($media, $rev);
+ if($fp) {
+ fclose($fp);
+ }
+ if(empty($lines)) return false;
- // read chunk
- $chunk = '';
- $read_size = max($tail-$finger, 0); // found chunk size
- $got = 0;
- while ($got<$read_size && !feof($fp)) {
- $tmp = @fread($fp, max($read_size-$got, 0));
- if ($tmp===false) { break; } //error state
- $got += strlen($tmp);
- $chunk .= $tmp;
- }
- $tmp = explode("\n", $chunk);
- array_pop($tmp); // remove trailing newline
-
- // combine with previous chunk
- $count += count($tmp);
- $lines = array_merge($tmp, $lines);
-
- // next chunk
- if ($finger==0) { break; } // already read all the lines
- else {
- $tail = $finger;
- $finger = max($tail-$chunk_size, 0);
+ // parse and cache changelog lines
+ foreach($lines as $value) {
+ $tmp = parseChangelogLine($value);
+ if($tmp !== false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
}
}
- fclose($fp);
- }
-
- // skip parsing extra lines
- $num = max(min(count($lines)-$first, $num), 0);
- if ($first>0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$first-$num, 0), $num); }
- else if ($first>0 && $num==0) { $lines = array_slice($lines, 0, max(count($lines)-$first, 0)); }
- else if ($first==0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$num, 0)); }
-
- // handle lines in reverse order
- for ($i = count($lines)-1; $i >= 0; $i--) {
- $tmp = parseChangelogLine($lines[$i]);
- if ($tmp!==false) {
- $cache[$id][$tmp['date']] = $tmp;
- $revs[] = $tmp['date'];
+ if(!isset($this->cache[$this->id][$rev])) {
+ return false;
}
+ return $this->cache[$this->id][$rev];
}
- return $revs;
-}
+ /**
+ * Return a list of page revisions numbers
+ *
+ * Does not guarantee that the revision exists in the attic,
+ * only that a line with the date exists in the changelog.
+ * By default the current revision is skipped.
+ *
+ * The current revision is automatically skipped when the page exists.
+ * See $INFO['meta']['last_change'] for the current revision.
+ * A negative $first let read the current revision too.
+ *
+ * For efficiency, the log lines are parsed and cached for later
+ * calls to getRevisionInfo. Large changelog files are read
+ * backwards in chunks until the requested number of changelog
+ * lines are recieved.
+ *
+ * @param int $first skip the first n changelog lines
+ * @param int $num number of revisions to return
+ * @param bool $media look into media log?
+ * @return array with the revision timestamps
+ *
+ * @author Ben Coburn
+ * @author Kate Arzamastseva
+ */
+ public function getRevisions($first, $num, $media = false) {
+ $revs = array();
+ $lines = array();
+ $count = 0;
+ if ($media) {
+ $file = mediaMetaFN($this->id, '.changes');
+ } else {
+ $file = metaFN($this->id, '.changes');
+ }
+ $num = max($num, 0);
+ if ($num == 0) { return $revs; }
+
+ $this->chunk_size = max($this->chunk_size, 0);
+ if ($first<0) {
+ $first = 0;
+ } else if (!$media && @file_exists(wikiFN($this->id)) || $media && @file_exists(mediaFN($this->id))) {
+ // skip current revision if the page exists
+ $first = max($first+1, 0);
+ }
-/**
- * Get the nth revision left or right handside for a specific page id
- * and revision (timestamp). For large changelog files, only the chunk containing the
- * reference revision $rev is read and sometimes a next chunck.
- *
- * Adjacent changelog lines are optimistically parsed and cached to speed up
- * consecutive calls to getRevisionInfo.
- *
- * @author Gerrit Uitslag
- *
- * based on getRevisionInfo by
- * @author Ben Coburn
- * @author Kate Arzamastseva
- *
- * @param string $id pageid
- * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
- * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
- * @param int $chunk_size maximum block size
- * @param bool $media
- * @return bool|string
- */
-function getRelativeRevision($id, $rev, $direction, $chunk_size = 8192, $media = false) {
- global $cache_revinfo;
- global $INFO;
- $cache =& $cache_revinfo;
- if(!isset($cache[$id])) {
- $cache[$id] = array();
- }
- $rev = max($rev, 0);
- $direction = (int) $direction;
-
- //no direction given or last rev, so no follow-up
- if(!$direction ||
- ($direction > 0
- && isset($INFO['meta']['last_change']['date'])
- && $rev == $INFO['meta']['last_change']['date'])) {
- return false;
- }
+ if (!@file_exists($file)) { return $revs; }
+ if (filesize($file)<$this->chunk_size || $this->chunk_size==0) {
+ // read whole file
+ $lines = file($file);
+ if ($lines===false) { return $revs; }
+ } else {
+ // read chunks backwards
+ $fp = fopen($file, 'rb'); // "file pointer"
+ if ($fp===false) { return $revs; }
+ fseek($fp, 0, SEEK_END);
+ $tail = ftell($fp);
+
+ // chunk backwards
+ $finger = max($tail-$this->chunk_size, 0);
+ while ($count<$num+$first) {
+ fseek($fp, $finger);
+ $nl = $finger;
+ if ($finger>0) {
+ fgets($fp); // slip the finger forward to a new line
+ $nl = ftell($fp);
+ }
- if($media) {
- $file = mediaMetaFN($id, '.changes');
- } else {
- $file = metaFN($id, '.changes');
- }
+ // was the chunk big enough? if not, take another bite
+ if($nl > 0 && $tail <= $nl){
+ $finger = max($finger-$this->chunk_size, 0);
+ continue;
+ }else{
+ $finger = $nl;
+ }
- //get lines from changelog
- list($fp, $lines, $head, $tail, $eof) = _readloglines($file, $rev, $chunk_size);
- if(empty($lines)) return false;
-
- // look for revisions later/earlier then $rev, when founded count till the wanted revision is reached
- // also parse and cache changelog lines for getRevisionInfo().
- $revcounter = 0;
- $relativerev = false;
- $checkotherchunck = true; //always runs once
- while(!$relativerev && $checkotherchunck) {
- $tmp = array();
- //parse in normal or reverse order
- $count = count($lines);
- if($direction > 0) {
- $start = 0;
- $step = 1;
- } else {
- $start = $count - 1;
- $step = -1;
+ // read chunk
+ $chunk = '';
+ $read_size = max($tail-$finger, 0); // found chunk size
+ $got = 0;
+ while ($got<$read_size && !feof($fp)) {
+ $tmp = @fread($fp, max($read_size-$got, 0));
+ if ($tmp===false) { break; } //error state
+ $got += strlen($tmp);
+ $chunk .= $tmp;
+ }
+ $tmp = explode("\n", $chunk);
+ array_pop($tmp); // remove trailing newline
+
+ // combine with previous chunk
+ $count += count($tmp);
+ $lines = array_merge($tmp, $lines);
+
+ // next chunk
+ if ($finger==0) { break; } // already read all the lines
+ else {
+ $tail = $finger;
+ $finger = max($tail-$this->chunk_size, 0);
+ }
+ }
+ fclose($fp);
}
- for($i = $start; $i >= 0 && $i < $count; $i = $i + $step) {
+
+ // skip parsing extra lines
+ $num = max(min(count($lines)-$first, $num), 0);
+ if ($first>0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$first-$num, 0), $num); }
+ else if ($first>0 && $num==0) { $lines = array_slice($lines, 0, max(count($lines)-$first, 0)); }
+ else if ($first==0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$num, 0)); }
+
+ // handle lines in reverse order
+ for ($i = count($lines)-1; $i >= 0; $i--) {
$tmp = parseChangelogLine($lines[$i]);
- if($tmp !== false) {
- $cache[$id][$tmp['date']] = $tmp;
- //look for revs older/earlier then reference $rev and select $direction-th one
- if(($direction > 0 && $tmp['date'] > $rev) || ($direction < 0 && $tmp['date'] < $rev)) {
- $revcounter++;
- if($revcounter == abs($direction)) {
- $relativerev = $tmp['date'];
- }
- }
+ if ($tmp!==false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
+ $revs[] = $tmp['date'];
}
}
- //true when $rev is found, but not the wanted follow-up.
- $checkotherchunck = $fp
- && ($tmp['date'] == $rev || ($revcounter > 0 && !$relativerev))
- && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
+ return $revs;
+ }
+
+ /**
+ * Get the nth revision left or right handside for a specific page id and revision (timestamp)
+ *
+ * For large changelog files, only the chunk containing the
+ * reference revision $rev is read and sometimes a next chunck.
+ *
+ * Adjacent changelog lines are optimistically parsed and cached to speed up
+ * consecutive calls to getRevisionInfo.
+ *
+ * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
+ * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
+ * @param bool $media look into media log?
+ * @return bool|int
+ * timestamp of the requested revision
+ * otherwise false
+ */
+ public function getRelativeRevision($rev, $direction, $media = false) {
+ global $INFO;
+
+ $rev = max($rev, 0);
+ $direction = (int) $direction;
+
+ //no direction given or last rev, so no follow-up
+ if(!$direction ||
+ ($direction > 0
+ && isset($INFO['meta']['last_change']['date'])
+ && $rev == $INFO['meta']['last_change']['date'])) {
+ return false;
+ }
- if($checkotherchunck) {
- //search bounds of chunck, rounded on new line, but smaller than $chunck_size
+ //get lines from changelog
+ list($fp, $lines, $head, $tail, $eof) = $this->readloglines($media, $rev);
+ if(empty($lines)) return false;
+
+ // look for revisions later/earlier then $rev, when founded count till the wanted revision is reached
+ // also parse and cache changelog lines for getRevisionInfo().
+ $revcounter = 0;
+ $relativerev = false;
+ $checkotherchunck = true; //always runs once
+ while(!$relativerev && $checkotherchunck) {
+ $tmp = array();
+ //parse in normal or reverse order
+ $count = count($lines);
if($direction > 0) {
- $head = $tail;
- $lookpointer = true;
- $tail = $head + floor($chunk_size * (2 / 3));
- while($lookpointer) {
- $tail = min($tail, $eof);
- $tail = _getNewlinepointer($fp, $tail);
- $lookpointer = $tail - $head > $chunk_size;
- if($lookpointer) {
- $tail = $head + floor(($tail - $head) / 2);
+ $start = 0;
+ $step = 1;
+ } else {
+ $start = $count - 1;
+ $step = -1;
+ }
+ for($i = $start; $i >= 0 && $i < $count; $i = $i + $step) {
+ $tmp = parseChangelogLine($lines[$i]);
+ if($tmp !== false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
+ //look for revs older/earlier then reference $rev and select $direction-th one
+ if(($direction > 0 && $tmp['date'] > $rev) || ($direction < 0 && $tmp['date'] < $rev)) {
+ $revcounter++;
+ if($revcounter == abs($direction)) {
+ $relativerev = $tmp['date'];
+ }
}
- if($tail == $head) break;
}
- } else {
- $tail = $head;
- $head = max($tail - $chunk_size, 0);
- $head = _getNewlinepointer($fp, $head);
}
- //load next chunck
- $lines = _readChunk($fp, $head, $tail);
- if(empty($lines)) break;
+ //true when $rev is found, but not the wanted follow-up.
+ $checkotherchunck = $fp
+ && ($tmp['date'] == $rev || ($revcounter > 0 && !$relativerev))
+ && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
+
+ if($checkotherchunck) {
+ //search bounds of chunck, rounded on new line, but smaller than $chunck_size
+ if($direction > 0) {
+ $head = $tail;
+ $lookpointer = true;
+ $tail = $head + floor($this->chunk_size * (2 / 3));
+ while($lookpointer) {
+ $tail = min($tail, $eof);
+ $tail = $this->getNewlinepointer($fp, $tail);
+ $lookpointer = $tail - $head > $this->chunk_size;
+ if($lookpointer) {
+ $tail = $head + floor(($tail - $head) / 2);
+ }
+ if($tail == $head) break;
+ }
+ } else {
+ $tail = $head;
+ $head = max($tail - $this->chunk_size, 0);
+ $head = $this->getNewlinepointer($fp, $head);
+ }
+
+ //load next chunck
+ $lines = $this->readChunk($fp, $head, $tail);
+ if(empty($lines)) break;
+ }
+ }
+ if($fp) {
+ fclose($fp);
}
- }
- if($fp) {
- fclose($fp);
- }
- if(isset($INFO['meta']['last_change']) && $relativerev == $INFO['meta']['last_change']['date']) {
- return 'current';
+ return $relativerev;
}
- return $relativerev;
-}
-/**
- * get lines from changelog.
- * If file larger than $chuncksize, only chunck is read that could contain $rev.
- *
- * @param int $file path to changelog file
- * @param int $rev revision timestamp
- * @param int $chunk_size maximum block size read from file
- * @return array(fp, array(changeloglines), $head, $tail, $eof)|bool
- * returns false when not succeed. fp only defined for chuck reading, needs closing.
- */
-function _readloglines($file, $rev, $chunk_size) {
- if(!@file_exists($file)) {
- return false;
- }
- $fp = null;
- $head = 0;
- $tail = 0;
- $eof = 0;
- if(filesize($file) < $chunk_size || $chunk_size == 0) {
- // read whole file
- $lines = file($file);
- if($lines === false) {
- return false;
+ /**
+ * Returns lines from changelog.
+ * If file larger than $chuncksize, only chunck is read that could contain $rev.
+ *
+ * @param bool $media look into media log?
+ * @param int $rev revision timestamp
+ * @return array(fp, array(changeloglines), $head, $tail, $eof)|bool
+ * returns false when not succeed. fp only defined for chuck reading, needs closing.
+ */
+ protected function readloglines($media, $rev) {
+ if($media) {
+ $file = mediaMetaFN($this->id, '.changes');
+ } else {
+ $file = metaFN($this->id, '.changes');
}
- } else {
- // read by chunk
- $fp = fopen($file, 'rb'); // "file pointer"
- if($fp === false) {
+
+ if(!@file_exists($file)) {
return false;
}
- $head = 0;
- fseek($fp, 0, SEEK_END);
- $eof = ftell($fp);
- $tail = $eof;
- $finger = 0;
- $finger_rev = 0;
-
- // find chunk
- while($tail - $head > $chunk_size) {
- $finger = $head + floor(($tail - $head) / 2.0);
- $finger = _getNewlinepointer($fp, $finger);
- $tmp = fgets($fp);
- $tmp = parseChangelogLine($tmp);
- $finger_rev = $tmp['date'];
- if($finger == $head || $finger == $tail) {
- break;
+
+ $fp = null;
+ $head = 0;
+ $tail = 0;
+ $eof = 0;
+
+ if(filesize($file) < $this->chunk_size || $this->chunk_size == 0) {
+ // read whole file
+ $lines = file($file);
+ if($lines === false) {
+ return false;
}
- if($finger_rev > $rev) {
- $tail = $finger;
- } else {
- $head = $finger;
+ } else {
+ // read by chunk
+ $fp = fopen($file, 'rb'); // "file pointer"
+ if($fp === false) {
+ return false;
+ }
+ $head = 0;
+ fseek($fp, 0, SEEK_END);
+ $eof = ftell($fp);
+ $tail = $eof;
+
+ // find chunk
+ while($tail - $head > $this->chunk_size) {
+ $finger = $head + floor(($tail - $head) / 2.0);
+ $finger = $this->getNewlinepointer($fp, $finger);
+ $tmp = fgets($fp);
+ $tmp = parseChangelogLine($tmp);
+ $finger_rev = $tmp['date'];
+ if($finger == $head || $finger == $tail) {
+ break;
+ }
+ if($finger_rev > $rev) {
+ $tail = $finger;
+ } else {
+ $head = $finger;
+ }
+ }
+
+ if($tail - $head < 1) {
+ // cound not find chunk, assume requested rev is missing
+ fclose($fp);
+ return false;
}
+
+ $lines = $this->readChunk($fp, $head, $tail);
}
+ return array(
+ $fp,
+ $lines,
+ $head,
+ $tail,
+ $eof
+ );
+ }
- if($tail - $head < 1) {
- // cound not find chunk, assume requested rev is missing
- fclose($fp);
- return false;
+ /**
+ * Read chunk and return array with lines of given chunck.
+ * Has no check if $head and $tail are really at a new line
+ *
+ * @param $fp resource filepointer
+ * @param $head int start point chunck
+ * @param $tail int end point chunck
+ * @return array lines read from chunck
+ */
+ protected function readChunk($fp, $head, $tail) {
+ $chunk = '';
+ $chunk_size = max($tail - $head, 0); // found chunk size
+ $got = 0;
+ fseek($fp, $head);
+ while($got < $chunk_size && !feof($fp)) {
+ $tmp = @fread($fp, max($chunk_size - $got, 0));
+ if($tmp === false) { //error state
+ break;
+ }
+ $got += strlen($tmp);
+ $chunk .= $tmp;
}
+ $lines = explode("\n", $chunk);
+ array_pop($lines); // remove trailing newline
+ return $lines;
+ }
- $lines = _readChunk($fp, $head, $tail);
+ /**
+ * Set pointer to first new line after $finger and return its position
+ *
+ * @param $fp resource filepointer
+ * @param $finger int a pointer
+ * @return int pointer
+ */
+ protected function getNewlinepointer($fp, $finger) {
+ fseek($fp, $finger);
+ fgets($fp); // slip the finger forward to a new line
+ return ftell($fp);
+ }
+
+ /**
+ * Check whether given revision is the current page
+ *
+ * @param int $rev timestamp of current page
+ * @return bool true if $rev is current revision, otherwise false
+ */
+ static public function isCurrentRevision($rev){
+ return isset($INFO['meta']['last_change']) && $rev == $INFO['meta']['last_change']['date'];
}
- return array(
- $fp,
- $lines,
- $head,
- $tail,
- $eof
- );
}
/**
- * Read chunk and return array with lines of given chunck.
- * Has no check if $head and $tail are really at a new line
+ * Get the changelog information for a specific page id
+ * and revision (timestamp). Adjacent changelog lines
+ * are optimistically parsed and cached to speed up
+ * consecutive calls to getRevisionInfo. For large
+ * changelog files, only the chunk containing the
+ * requested changelog line is read.
*
- * @param $fp resource filepointer
- * @param $head int start point chunck
- * @param $tail int end point chunck
- * @return array lines read from chunck
+ * @deprecated 20-11-2013
+ *
+ * @author Ben Coburn
+ * @author Kate Arzamastseva
*/
-function _readChunk($fp, $head, $tail) {
- $chunk = '';
- $chunk_size = max($tail - $head, 0); // found chunk size
- $got = 0;
- fseek($fp, $head);
- while($got < $chunk_size && !feof($fp)) {
- $tmp = @fread($fp, max($chunk_size - $got, 0));
- if($tmp === false) { //error state
- break;
- }
- $got += strlen($tmp);
- $chunk .= $tmp;
- }
- $lines = explode("\n", $chunk);
- array_pop($lines); // remove trailing newline
- return $lines;
+function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
+
+ $log = new PageRevisionLog($id, $chunk_size);
+ return $log->getRevisionInfo($rev, $media);
}
/**
- * Set pointer to first new line after $finger and return its position
+ * Return a list of page revisions numbers
+ * Does not guarantee that the revision exists in the attic,
+ * only that a line with the date exists in the changelog.
+ * By default the current revision is skipped.
+ *
+ * id: the page of interest
+ * first: skip the first n changelog lines
+ * num: number of revisions to return
+ *
+ * The current revision is automatically skipped when the page exists.
+ * See $INFO['meta']['last_change'] for the current revision.
+ *
+ * For efficiency, the log lines are parsed and cached for later
+ * calls to getRevisionInfo. Large changelog files are read
+ * backwards in chunks until the requested number of changelog
+ * lines are recieved.
+ *
+ * @deprecated 20-11-2013
*
- * @param $fp resource filepointer
- * @param $finger int a pointer
- * @return int pointer
+ * @author Ben Coburn
+ * @author Kate Arzamastseva
*/
-function _getNewlinepointer($fp, $finger) {
- fseek($fp, $finger);
- fgets($fp); // slip the finger forward to a new line
- return ftell($fp);
+function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
+ $log = new PageRevisionLog($id, $chunk_size);
+ return $log->getRevisions($first, $num, $media);
}
--
cgit v1.2.3
From 6556cf69fed60e750c3d32c106427cdfbbfdf384 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 20 Nov 2013 13:20:54 +0100
Subject: Update changelog unit tests
---
_test/tests/inc/changelog_getrevisioninfo.test.php | 30 +++++++-----
_test/tests/inc/changelog_getrevisions.test.php | 56 ++++++++++++++--------
2 files changed, 56 insertions(+), 30 deletions(-)
diff --git a/_test/tests/inc/changelog_getrevisioninfo.test.php b/_test/tests/inc/changelog_getrevisioninfo.test.php
index 9637d21c8..a2f0d808f 100644
--- a/_test/tests/inc/changelog_getrevisioninfo.test.php
+++ b/_test/tests/inc/changelog_getrevisioninfo.test.php
@@ -21,7 +21,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
unset($cache['nonexist']);
}
if(isset($cache['mailinglist'])) {
- unset($cache['nonexist']);
+ unset($cache['mailinglist']);
}
}
@@ -33,7 +33,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$id = 'nonexist';
$revsexpected = false;
- $revs = getRevisionInfo($id, $rev, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($id, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -44,10 +45,11 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
//returns cached value
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
}
@@ -58,7 +60,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
}
@@ -69,10 +72,11 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
//returns cached value
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
}
@@ -83,7 +87,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals($infoexpected, $info);
}
@@ -93,7 +98,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
function test_negativerev() {
$rev = -10;
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals(false, $info);
}
@@ -103,7 +109,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
function test_notexistingrev() {
$rev = 1362525890;
- $info = getRevisionInfo($this->pageid, $rev, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev, $media = false);
$this->assertEquals(false, $info);
}
@@ -114,7 +121,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $info = getRevisionInfo($this->pageid, $rev, true);
+ $pagelog = new PageRevisionLog($this->pageid, true);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
}
\ No newline at end of file
diff --git a/_test/tests/inc/changelog_getrevisions.test.php b/_test/tests/inc/changelog_getrevisions.test.php
index a9be26dae..e2b9d115e 100644
--- a/_test/tests/inc/changelog_getrevisions.test.php
+++ b/_test/tests/inc/changelog_getrevisions.test.php
@@ -36,7 +36,7 @@ class changelog_getrevisions_test extends DokuWikiTest {
unset($cache['nonexist']);
}
if(isset($cache['mailinglist'])) {
- unset($cache['nonexist']);
+ unset($cache['mailinglist']);
}
}
@@ -48,7 +48,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$id = 'nonexist';
- $revs = getRevisions($id, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($id, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$revsexpected = array();
$this->assertEquals($revsexpected, $revs);
}
@@ -62,10 +63,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[1]);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -78,10 +81,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[2]);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -94,10 +99,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 5;
$revsexpected = array_slice($this->revsexpected, $first + 1, $num);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -109,10 +116,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[0]);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -124,7 +133,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1000;
$revsexpected = array_slice($this->revsexpected, 1);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 0, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 0);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -136,10 +146,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = -10;
$revsexpected = array();
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -151,10 +163,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = -10;
$revsexpected = array();
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -166,10 +180,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 0;
$revsexpected = array();
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -181,7 +197,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 50;
$revsexpected = array_slice($this->revsexpected, $first + 1);
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
@@ -193,7 +210,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 50;
$revsexpected = array();
- $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num, $media = false);
$this->assertEquals($revsexpected, $revs);
}
--
cgit v1.2.3
From 55545bcc9b8532818cc1fc8b920deb07cc3f2c61 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 20 Nov 2013 13:21:44 +0100
Subject: Add unit tests for getRelativerevision
---
.../inc/changelog_getrelativerevision.test.php | 273 +++++++++++++++++++++
1 file changed, 273 insertions(+)
create mode 100644 _test/tests/inc/changelog_getrelativerevision.test.php
diff --git a/_test/tests/inc/changelog_getrelativerevision.test.php b/_test/tests/inc/changelog_getrelativerevision.test.php
new file mode 100644
index 000000000..7cd081eab
--- /dev/null
+++ b/_test/tests/inc/changelog_getrelativerevision.test.php
@@ -0,0 +1,273 @@
+getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * no nonexist.changes meta file available
+ */
+ function test_nodirection() {
+ $rev = 1362525899;
+ $dir = 0;
+ $revsexpected = false;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * start at exact current revision of mailinglist page
+ *
+ */
+ function test_startatexactcurrentrev() {
+ $rev = 1374261194;
+ $dir = 1;
+ $revsexpected = false;
+
+// global $INFO;
+// $INFO = pageinfo();
+// var_dump($INFO);
+// var_dump($INFO['meta']);
+// var_dump($INFO['meta']['last_change']);
+// var_dump($INFO['meta']['last_change']['date']);
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * request existing rev
+ */
+ function test_requestrev() {
+ $rev = 1362525359;
+ $dir = 1;
+ $revexpected = 1362525899;
+ $infoexpected = parseChangelogLine($this->logline);
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ //checked info returned from cache
+ $info = $pagelog->getRevisionInfo($revfound, $media = false);
+ $this->assertEquals($infoexpected, $info);
+ }
+
+ /**
+ * request existing rev with chucked reading
+ */
+ function test_requestnextrev_chuncked() {
+ $rev = 1362525899;
+ $dir = 1;
+ $revexpected = 1362525926;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * request existing rev
+ */
+ function test_requestnextfifthrev() {
+ $rev = 1362525899;
+ $dir = 5;
+ $revexpected = 1362526767;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * request existing rev with chucked reading
+ */
+ function test_requestnextfifthrev_chuncked() {
+ $rev = 1362525899;
+ $dir = 5;
+ $revexpected = 1362526767;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * request existing rev
+ */
+ function test_requestprevrev() {
+ $rev = 1362525899;
+ $dir1 = -1;
+ $dir5 = -5;
+ $revexpected1 = 1362525359;
+ $revexpected5 = 1360110636;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound1 = $pagelog->getRelativeRevision($rev, $dir1, $media = false);
+ $this->assertEquals($revexpected1, $revfound1);
+
+ $revfound5 = $pagelog->getRelativeRevision($rev, $dir5, $media = false);
+ $this->assertEquals($revexpected5, $revfound5);
+ }
+
+ /**
+ * request existing rev with chucked reading
+ */
+ function test_requestprevrev_chuncked() {
+ $rev = 1362525899;
+ $dir1 = -1;
+ $dir5 = -5;
+ $revexpected1 = 1362525359;
+ $revexpected5 = 1360110636;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revfound1 = $pagelog->getRelativeRevision($rev, $dir1, $media = false);
+ $this->assertEquals($revexpected1, $revfound1);
+
+ $revfound5 = $pagelog->getRelativeRevision($rev, $dir5, $media = false);
+ $this->assertEquals($revexpected5, $revfound5);
+ }
+
+ /**
+ * request after recentest version in changelog
+ */
+ function test_requestrecentestlogline_next() {
+ $rev = 1374261194;
+ $dir = 1;
+ $revexpected = false;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * request after recentest version in changelog, with chuncked reading
+ */
+ function test_requestrecentestlogline_next_chuncked() {
+ $rev = 1374261194;
+ $dir = 1;
+ $revexpected = false;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+
+ /**
+ * request before current version
+ */
+ function test_requestrecentestlogline_prev() {
+ $rev = 1374261194;
+ $dir = -1;
+ $revexpected = 1371579614;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * request before current version, with chuncked reading
+ */
+ function test_requestrecentestlogline_prev_chuncked() {
+ $rev = 1374261194;
+ $dir = -1;
+ $revexpected = 1371579614;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * Request negative revision
+ * looks in positive direction, so it catches the oldest revision
+ */
+ function test_negativerev_posdir() {
+ $rev = -10;
+ $dir = 1;
+ $revexpected = 1360110636;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * Request negative revision
+ * looks in negative direction, but there is nothing
+ */
+ function test_negativerev_negdir() {
+ $rev = -10;
+ $dir = -1;
+ $revexpected = false;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * Start at non existing revision somewhere between existing revisions
+ */
+ function test_startatnotexistingrev_next() {
+ $rev = 1362525890;
+ $dir = 1;
+ $revexpected = 1362525899;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+ /**
+ * Start at non existing revision somewhere between existing revisions
+ */
+ function test_startatnotexistingrev_prev() {
+ $rev = 1362525890;
+ $dir = -1;
+ $revexpected = 1362525359;
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $this->assertEquals($revexpected, $revfound);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3
From f523c9718baf12a5bc99e2285bc0666796ab2a97 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 20 Nov 2013 13:36:22 +0100
Subject: update function calls to changelog functions
---
feed.php | 5 +++--
inc/RemoteAPICore.php | 11 +++++++----
inc/common.php | 8 +++++---
inc/html.php | 39 +++++++++++++++++++++------------------
inc/media.php | 6 ++++--
inc/subscription.php | 6 ++++--
lib/plugins/revert/admin.php | 3 ++-
7 files changed, 46 insertions(+), 32 deletions(-)
diff --git a/feed.php b/feed.php
index 77c8b28df..80a533717 100644
--- a/feed.php
+++ b/feed.php
@@ -292,8 +292,9 @@ function rss_buildItems(&$rss, &$data, $opt) {
switch($opt['item_content']) {
case 'diff':
case 'htmldiff':
+ $pagelog = new PageRevisionLog($id);
if($ditem['media']) {
- $revs = getRevisions($id, 0, 1, 8192, true);
+ $revs = $pagelog->getRevisions(0, 1, true);
$rev = $revs[0];
$src_r = '';
$src_l = '';
@@ -318,7 +319,7 @@ function rss_buildItems(&$rss, &$data, $opt) {
} else {
require_once(DOKU_INC.'inc/DifferenceEngine.php');
- $revs = getRevisions($id, 0, 1);
+ $revs = $pagelog->getRevisions(0, 1);
$rev = $revs[0];
if($rev) {
diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php
index 2eb8ea403..311ff8c8c 100644
--- a/inc/RemoteAPICore.php
+++ b/inc/RemoteAPICore.php
@@ -374,7 +374,8 @@ class RemoteAPICore {
throw new RemoteException('The requested page does not exist', 121);
}
- $info = getRevisionInfo($id, $time, 1024);
+ $pagelog = new PageRevisionLog($id, 1024);
+ $info = $pagelog->getRevisionInfo($time);
$data = array(
'name' => $id,
@@ -646,11 +647,12 @@ class RemoteAPICore {
throw new RemoteException('Empty page ID', 131);
}
- $revisions = getRevisions($id, $first, $conf['recent']+1);
+ $pagelog = new PageRevisionLog($id);
+ $revisions = $pagelog->getRevisions($first, $conf['recent']+1);
if(count($revisions)==0 && $first!=0) {
$first=0;
- $revisions = getRevisions($id, $first, $conf['recent']+1);
+ $revisions = $pagelog->getRevisions($first, $conf['recent']+1);
}
if(count($revisions)>0 && $first==0) {
@@ -672,7 +674,8 @@ class RemoteAPICore {
// case this can lead to less pages being returned than
// specified via $conf['recent']
if($time){
- $info = getRevisionInfo($id, $time, 1024);
+ $pagelog->setChunkSize(1024);
+ $info = $pagelog->getRevisionInfo($time);
if(!empty($info)) {
$data['user'] = $info['user'];
$data['ip'] = $info['ip'];
diff --git a/inc/common.php b/inc/common.php
index 32771285b..dd30b53ab 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -187,13 +187,14 @@ function pageinfo() {
$info['meta'] = p_get_metadata($ID);
//who's the editor
+ $pagelog = new PageRevisionLog($ID, 1024);
if($REV) {
- $revinfo = getRevisionInfo($ID, $REV, 1024);
+ $revinfo = $pagelog->getRevisionInfo($REV);
} else {
if(is_array($info['meta']['last_change'])) {
$revinfo = $info['meta']['last_change'];
} else {
- $revinfo = getRevisionInfo($ID, $info['lastmod'], 1024);
+ $revinfo = $pagelog->getRevisionInfo($info['lastmod']);
// cache most recent changelog line in metadata if missing and still valid
if($revinfo !== false) {
$info['meta']['last_change'] = $revinfo;
@@ -1059,8 +1060,9 @@ function saveWikiText($id, $text, $summary, $minor = false) {
$wasRemoved = (trim($text) == ''); // check for empty or whitespace only
$wasCreated = !@file_exists($file);
$wasReverted = ($REV == true);
+ $pagelog = new PageRevisionLog($id, 1024);
$newRev = false;
- $oldRev = getRevisions($id, -1, 1, 1024); // from changelog
+ $oldRev = $pagelog->getRevisions(-1, 1); // from changelog
$oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]);
if(!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) {
// add old revision to the attic if missing
diff --git a/inc/html.php b/inc/html.php
index 91d8c1833..e1c69a043 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -414,20 +414,18 @@ function html_revisions($first=0, $media_id = false){
global $conf;
global $lang;
$id = $ID;
+ if ($media_id) $id = $media_id;
+
/* we need to get one additional log entry to be able to
* decide if this is the last page or is there another one.
* see html_recent()
*/
- if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
- else {
- $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
- $id = $media_id;
- }
+ $pagelog = new PageRevisionLog($id);
+ $revisions = $pagelog->getRevisions($first, $conf['recent']+1, (boolean)$media_id);
if(count($revisions)==0 && $first!=0){
$first=0;
- if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
- else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
+ $revisions = $pagelog->getRevisions($first, $conf['recent']+1, (boolean)$media_id);
}
$hasNext = false;
if (count($revisions)>$conf['recent']) {
@@ -486,10 +484,12 @@ function html_revisions($first=0, $media_id = false){
$form->addElement(form_makeCloseTag('span'));
}
+ $pagelog->setChunkSize(1024);
+
$form->addElement(form_makeOpenTag('span', array('class' => 'user')));
if (!$media_id) $editor = $INFO['editor'];
else {
- $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true);
+ $revinfo = $pagelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))), true);
if($revinfo['user']){
$editor = $revinfo['user'];
}else{
@@ -510,10 +510,10 @@ function html_revisions($first=0, $media_id = false){
foreach($revisions as $rev){
$date = dformat($rev);
if (!$media_id) {
- $info = getRevisionInfo($id,$rev,true);
+ $info = $pagelog->getRevisionInfo($rev);
$exists = page_exists($id,$rev);
} else {
- $info = getRevisionInfo($id,$rev,true,true);
+ $info = $pagelog->getRevisionInfo($rev,true);
$exists = @file_exists(mediaFN($id,$rev));
}
@@ -706,7 +706,8 @@ function html_recent($first=0, $show_changes='both'){
$href = '';
if ($recent['media']) {
- $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
+ $pagelog = new PageRevisionLog($recent['id']);
+ $diff = (count($pagelog->getRevisions(0, 1, true)) && @file_exists(mediaFN($recent['id'])));
if ($diff) {
$href = media_managerURL(array('tab_details' => 'history',
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
@@ -1008,10 +1009,11 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$ml_or_wl = $media ? 'ml' : 'wl';
$l_minor = $r_minor = '';
+ $pagelog = new PageRevisionLog($id);
if(!$l_rev){
$l_head = '—';
}else{
- $l_info = getRevisionInfo($id,$l_rev,true, $media);
+ $l_info = $pagelog->getRevisionInfo($l_rev, $media);
if($l_info['user']){
$l_user = ''.editorinfo($l_info['user']).'';
if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
@@ -1029,7 +1031,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
}
if($r_rev){
- $r_info = getRevisionInfo($id,$r_rev,true, $media);
+ $r_info = $pagelog->getRevisionInfo($r_rev, $media);
if($r_info['user']){
$r_user = ''.editorinfo($r_info['user']).'';
if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
@@ -1045,7 +1047,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$r_head_title.''.
$head_separator.$r_user.' '.$r_sum;
}elseif($_rev = @filemtime($media_or_wikiFN($id))){
- $_info = getRevisionInfo($id,$_rev,true, $media);
+ $_info = $pagelog->getRevisionInfo($_rev, $media);
if($_info['user']){
$_user = ''.editorinfo($_info['user']).'';
if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
@@ -1082,6 +1084,7 @@ function html_diff($text='',$intro=true,$type=null){
global $lang;
global $INPUT;
global $INFO;
+ $pagelog = new PageRevisionLog($ID);
if(!$type) {
$type = $INPUT->str('difftype');
@@ -1140,7 +1143,7 @@ function html_diff($text='',$intro=true,$type=null){
$l_rev = $rev1;
}else{ // no revision was given, compare previous to current
$r_rev = '';
- $revs = getRevisions($ID, 0, 1);
+ $revs = $pagelog->getRevisions(0, 1);
$l_rev = $revs[0];
$REV = $l_rev; // store revision back in $REV
}
@@ -1155,12 +1158,12 @@ function html_diff($text='',$intro=true,$type=null){
//look for previous/next revision
if($r_rev) {
- $next_rev = getRelativeRevision($ID, $r_rev, 1);
+ $next_rev = $pagelog->getRelativeRevision($r_rev, 1);
} else {
$next_rev = false;
}
if($l_rev) {
- $prev_rev = getRelativeRevision($ID, $l_rev, -1);
+ $prev_rev = $pagelog->getRelativeRevision($l_rev, -1);
} else {
$prev_rev = false;
}
@@ -1219,7 +1222,7 @@ function html_diff($text='',$intro=true,$type=null){
));
ptln(''.$lang['overviewrevs'].'');
if($next_rev){
- if($next_rev=='current') {
+ if(PageRevisionLog::isCurrentRevision($next_rev)) {
$diffurlnextparam = array(
'do' => 'diff',
'rev' => $r_rev,
diff --git a/inc/media.php b/inc/media.php
index d69426414..9f0c2cb8c 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -492,7 +492,8 @@ function media_saveOldRevision($id){
$date = filemtime($oldf);
if (!$conf['mediarevisions']) return $date;
- if (!getRevisionInfo($id, $date, 8192, true)) {
+ $pagelog = new PageRevisionLog($id);
+ if (!$pagelog->getRevisionInfo($date, true)) {
// there was an external edit,
// there is no log entry for current version of file
if (!@file_exists(mediaMetaFN($id,'.changes'))) {
@@ -1071,7 +1072,8 @@ function media_diff($image, $ns, $auth, $fromajax = false) {
$l_rev = $rev1;
}else{ // no revision was given, compare previous to current
$r_rev = '';
- $revs = getRevisions($image, 0, 1, 8192, true);
+ $pagelog = new PageRevisionLog($image);
+ $revs = $pagelog->getRevisions(0, 1, true);
if (file_exists(mediaFN($image, $revs[0]))) {
$l_rev = $revs[0];
} else {
diff --git a/inc/subscription.php b/inc/subscription.php
index ddf2f39e6..87db3c621 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -336,7 +336,8 @@ class Subscription {
while(!is_null($rev) && $rev['date'] >= $lastupdate &&
($_SERVER['REMOTE_USER'] === $rev['user'] ||
$rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) {
- $rev = getRevisions($rev['id'], $n++, 1);
+ $pagelog = new PageRevisionLog($rev['id']);
+ $rev = $pagelog->getRevisions($n++, 1);
$rev = (count($rev) > 0) ? $rev[0] : null;
}
@@ -515,9 +516,10 @@ class Subscription {
* @return bool
*/
protected function send_digest($subscriber_mail, $id, $lastupdate) {
+ $pagelog = new PageRevisionLog($id);
$n = 0;
do {
- $rev = getRevisions($id, $n++, 1);
+ $rev = $pagelog->getRevisions($n++, 1);
$rev = (count($rev) > 0) ? $rev[0] : null;
} while(!is_null($rev) && $rev > $lastupdate);
diff --git a/lib/plugins/revert/admin.php b/lib/plugins/revert/admin.php
index 423d67449..ffb6fbc47 100644
--- a/lib/plugins/revert/admin.php
+++ b/lib/plugins/revert/admin.php
@@ -83,7 +83,8 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin {
// find the last non-spammy revision
$data = '';
- $old = getRevisions($id, 0, $this->max_revs);
+ $pagelog = new PageRevisionLog($id);
+ $old = $pagelog->getRevisions(0, $this->max_revs);
if(count($old)){
foreach($old as $REV){
$data = rawWiki($id,$REV);
--
cgit v1.2.3
From ee33e0c5628d9cab52676a5aa2f55356c563c209 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 20 Nov 2013 13:47:13 +0100
Subject: isCurrentPage is page dependent
---
inc/changelog.php | 9 ++-------
inc/html.php | 2 +-
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index 36be9dc79..de26fdf6a 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -560,16 +560,11 @@ class PageRevisionLog {
* otherwise false
*/
public function getRelativeRevision($rev, $direction, $media = false) {
- global $INFO;
-
$rev = max($rev, 0);
$direction = (int) $direction;
//no direction given or last rev, so no follow-up
- if(!$direction ||
- ($direction > 0
- && isset($INFO['meta']['last_change']['date'])
- && $rev == $INFO['meta']['last_change']['date'])) {
+ if(!$direction || ($direction > 0 && $this->isCurrentRevision($rev)) ) {
return false;
}
@@ -768,7 +763,7 @@ class PageRevisionLog {
* @param int $rev timestamp of current page
* @return bool true if $rev is current revision, otherwise false
*/
- static public function isCurrentRevision($rev){
+ public function isCurrentRevision($rev){
return isset($INFO['meta']['last_change']) && $rev == $INFO['meta']['last_change']['date'];
}
}
diff --git a/inc/html.php b/inc/html.php
index e1c69a043..b48a17fc5 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1222,7 +1222,7 @@ function html_diff($text='',$intro=true,$type=null){
));
ptln(''.$lang['overviewrevs'].'');
if($next_rev){
- if(PageRevisionLog::isCurrentRevision($next_rev)) {
+ if($pagelog->isCurrentRevision($next_rev)) {
$diffurlnextparam = array(
'do' => 'diff',
'rev' => $r_rev,
--
cgit v1.2.3
From 0f13c836f0ee71a3188a775b9ea64025e10d38f5 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Thu, 21 Nov 2013 18:02:12 +0100
Subject: Improved isCurrentRevision(), tests included
---
.../inc/changelog_getrelativerevision.test.php | 35 ++++++++++++++++++++++
inc/changelog.php | 7 +++--
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/_test/tests/inc/changelog_getrelativerevision.test.php b/_test/tests/inc/changelog_getrelativerevision.test.php
index 7cd081eab..588c424b1 100644
--- a/_test/tests/inc/changelog_getrelativerevision.test.php
+++ b/_test/tests/inc/changelog_getrelativerevision.test.php
@@ -270,4 +270,39 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
$this->assertEquals($revexpected, $revfound);
}
+
+ function test_iscurrentpagerevision() {
+ $rev = 1385051947;
+ $currentexpected = true;
+
+ //set a known timestamp
+ touch(wikiFN($this->pageid), $rev);
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+
+ $current = $pagelog->isCurrentRevision($rev, $media = false);
+ $this->assertEquals($currentexpected, $current);
+ }
+
+ function test_isnotcurrentpagerevision() {
+ $rev = 1385051947;
+ $not_current_rev = $rev - 1;
+ $currentexpected = false;
+
+ //set a known timestamp
+ touch(wikiFN($this->pageid), $rev);
+
+ $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
+ $current = $pagelog->isCurrentRevision($not_current_rev, $media = false);
+ $this->assertEquals($currentexpected, $current);
+ }
+
+ function test_notexistingcurrentpage() {
+ $rev = 1385051947;
+ $currentexpected = false;
+
+ $pagelog = new PageRevisionLog('nonexistingpage', $chunk_size = 8192);
+ $current = $pagelog->isCurrentRevision($rev, $media = false);
+ $this->assertEquals($currentexpected, $current);
+ }
}
\ No newline at end of file
diff --git a/inc/changelog.php b/inc/changelog.php
index de26fdf6a..722365853 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -760,11 +760,12 @@ class PageRevisionLog {
/**
* Check whether given revision is the current page
*
- * @param int $rev timestamp of current page
+ * @param int $rev timestamp of current page
+ * @param bool $media look for media?
* @return bool true if $rev is current revision, otherwise false
*/
- public function isCurrentRevision($rev){
- return isset($INFO['meta']['last_change']) && $rev == $INFO['meta']['last_change']['date'];
+ public function isCurrentRevision($rev, $media = false) {
+ return $rev == @filemtime($media ? mediaFN($this->id) : wikiFN($this->id));
}
}
--
cgit v1.2.3
From 047bad06fab8157452aa0dd04379a7c507b1f39f Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Thu, 21 Nov 2013 21:07:08 +0100
Subject: refactor PageRevisionLog into Media- and PageChangelog extending
Changelog
---
.../inc/changelog_getrelativerevision.test.php | 87 +++++++--------
_test/tests/inc/changelog_getrevisioninfo.test.php | 34 +++---
_test/tests/inc/changelog_getrevisions.test.php | 72 ++++++------
feed.php | 5 +-
inc/RemoteAPICore.php | 4 +-
inc/changelog.php | 124 +++++++++++++++------
inc/common.php | 4 +-
inc/html.php | 55 +++++----
inc/media.php | 8 +-
inc/subscription.php | 6 +-
lib/plugins/revert/admin.php | 2 +-
11 files changed, 232 insertions(+), 169 deletions(-)
diff --git a/_test/tests/inc/changelog_getrelativerevision.test.php b/_test/tests/inc/changelog_getrelativerevision.test.php
index 588c424b1..fa4c68897 100644
--- a/_test/tests/inc/changelog_getrelativerevision.test.php
+++ b/_test/tests/inc/changelog_getrelativerevision.test.php
@@ -33,8 +33,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$id = 'nonexist';
$revsexpected = false;
- $pagelog = new PageRevisionLog($id, $chunk_size = 8192);
- $revs = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($id, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revsexpected, $revs);
}
@@ -46,8 +46,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 0;
$revsexpected = false;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revsexpected, $revs);
}
@@ -67,8 +67,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
// var_dump($INFO['meta']['last_change']);
// var_dump($INFO['meta']['last_change']['date']);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revsexpected, $revs);
}
@@ -81,11 +81,11 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$revexpected = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
//checked info returned from cache
- $info = $pagelog->getRevisionInfo($revfound, $media = false);
+ $info = $pagelog->getRevisionInfo($revfound);
$this->assertEquals($infoexpected, $info);
}
@@ -97,8 +97,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 1;
$revexpected = 1362525926;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -110,8 +110,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 5;
$revexpected = 1362526767;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -123,8 +123,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 5;
$revexpected = 1362526767;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -138,11 +138,11 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$revexpected1 = 1362525359;
$revexpected5 = 1360110636;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound1 = $pagelog->getRelativeRevision($rev, $dir1, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
$this->assertEquals($revexpected1, $revfound1);
- $revfound5 = $pagelog->getRelativeRevision($rev, $dir5, $media = false);
+ $revfound5 = $pagelog->getRelativeRevision($rev, $dir5);
$this->assertEquals($revexpected5, $revfound5);
}
@@ -156,11 +156,11 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$revexpected1 = 1362525359;
$revexpected5 = 1360110636;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revfound1 = $pagelog->getRelativeRevision($rev, $dir1, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
$this->assertEquals($revexpected1, $revfound1);
- $revfound5 = $pagelog->getRelativeRevision($rev, $dir5, $media = false);
+ $revfound5 = $pagelog->getRelativeRevision($rev, $dir5);
$this->assertEquals($revexpected5, $revfound5);
}
@@ -172,8 +172,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 1;
$revexpected = false;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -185,8 +185,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 1;
$revexpected = false;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -199,8 +199,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = -1;
$revexpected = 1371579614;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -212,8 +212,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = -1;
$revexpected = 1371579614;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -226,8 +226,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 1;
$revexpected = 1360110636;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -240,8 +240,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = -1;
$revexpected = false;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -253,8 +253,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = 1;
$revexpected = 1362525899;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -266,8 +266,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$dir = -1;
$revexpected = 1362525359;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revfound = $pagelog->getRelativeRevision($rev, $dir, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
@@ -278,9 +278,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
//set a known timestamp
touch(wikiFN($this->pageid), $rev);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
-
- $current = $pagelog->isCurrentRevision($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $current = $pagelog->isCurrentRevision($rev);
$this->assertEquals($currentexpected, $current);
}
@@ -292,8 +291,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
//set a known timestamp
touch(wikiFN($this->pageid), $rev);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $current = $pagelog->isCurrentRevision($not_current_rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $current = $pagelog->isCurrentRevision($not_current_rev);
$this->assertEquals($currentexpected, $current);
}
@@ -301,8 +300,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$rev = 1385051947;
$currentexpected = false;
- $pagelog = new PageRevisionLog('nonexistingpage', $chunk_size = 8192);
- $current = $pagelog->isCurrentRevision($rev, $media = false);
+ $pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192);
+ $current = $pagelog->isCurrentRevision($rev);
$this->assertEquals($currentexpected, $current);
}
}
\ No newline at end of file
diff --git a/_test/tests/inc/changelog_getrevisioninfo.test.php b/_test/tests/inc/changelog_getrevisioninfo.test.php
index a2f0d808f..c073bac79 100644
--- a/_test/tests/inc/changelog_getrevisioninfo.test.php
+++ b/_test/tests/inc/changelog_getrevisioninfo.test.php
@@ -33,8 +33,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$id = 'nonexist';
$revsexpected = false;
- $pagelog = new PageRevisionLog($id, $chunk_size = 8192);
- $revs = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($id, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionInfo($rev);
$this->assertEquals($revsexpected, $revs);
}
@@ -45,11 +45,11 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
//returns cached value
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
@@ -60,8 +60,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
@@ -72,11 +72,11 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
//returns cached value
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
@@ -87,8 +87,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
@@ -98,8 +98,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
function test_negativerev() {
$rev = -10;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals(false, $info);
}
@@ -109,8 +109,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
function test_notexistingrev() {
$rev = 1362525890;
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $info = $pagelog->getRevisionInfo($rev, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $info = $pagelog->getRevisionInfo($rev);
$this->assertEquals(false, $info);
}
@@ -121,7 +121,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
- $pagelog = new PageRevisionLog($this->pageid, true);
+ $pagelog = new PageChangeLog($this->pageid, true);
$info = $pagelog->getRevisionInfo($rev);
$this->assertEquals($infoexpected, $info);
}
diff --git a/_test/tests/inc/changelog_getrevisions.test.php b/_test/tests/inc/changelog_getrevisions.test.php
index e2b9d115e..aa2198981 100644
--- a/_test/tests/inc/changelog_getrevisions.test.php
+++ b/_test/tests/inc/changelog_getrevisions.test.php
@@ -48,8 +48,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$id = 'nonexist';
- $pagelog = new PageRevisionLog($id, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($id, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$revsexpected = array();
$this->assertEquals($revsexpected, $revs);
}
@@ -63,12 +63,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[1]);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -81,12 +81,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[2]);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -99,12 +99,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 5;
$revsexpected = array_slice($this->revsexpected, $first + 1, $num);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -116,12 +116,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1;
$revsexpected = array($this->revsexpected[0]);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -133,8 +133,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 1000;
$revsexpected = array_slice($this->revsexpected, 1);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 0);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 0);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -146,12 +146,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = -10;
$revsexpected = array();
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -163,12 +163,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = -10;
$revsexpected = array();
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($this->pageid, $first, $num, $chunk_size = 8192);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -180,12 +180,12 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 0;
$revsexpected = array();
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -197,8 +197,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 50;
$revsexpected = array_slice($this->revsexpected, $first + 1);
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
@@ -210,8 +210,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
$num = 50;
$revsexpected = array();
- $pagelog = new PageRevisionLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num, $media = false);
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
}
diff --git a/feed.php b/feed.php
index 80a533717..b0699b1a2 100644
--- a/feed.php
+++ b/feed.php
@@ -292,9 +292,9 @@ function rss_buildItems(&$rss, &$data, $opt) {
switch($opt['item_content']) {
case 'diff':
case 'htmldiff':
- $pagelog = new PageRevisionLog($id);
if($ditem['media']) {
- $revs = $pagelog->getRevisions(0, 1, true);
+ $medialog = new MediaChangeLog($id);
+ $revs = $medialog->getRevisions(0, 1);
$rev = $revs[0];
$src_r = '';
$src_l = '';
@@ -319,6 +319,7 @@ function rss_buildItems(&$rss, &$data, $opt) {
} else {
require_once(DOKU_INC.'inc/DifferenceEngine.php');
+ $pagelog = new PageChangeLog($id);
$revs = $pagelog->getRevisions(0, 1);
$rev = $revs[0];
diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php
index 311ff8c8c..aa1e06f57 100644
--- a/inc/RemoteAPICore.php
+++ b/inc/RemoteAPICore.php
@@ -374,7 +374,7 @@ class RemoteAPICore {
throw new RemoteException('The requested page does not exist', 121);
}
- $pagelog = new PageRevisionLog($id, 1024);
+ $pagelog = new PageChangeLog($id, 1024);
$info = $pagelog->getRevisionInfo($time);
$data = array(
@@ -647,7 +647,7 @@ class RemoteAPICore {
throw new RemoteException('Empty page ID', 131);
}
- $pagelog = new PageRevisionLog($id);
+ $pagelog = new PageChangeLog($id);
$revisions = $pagelog->getRevisions($first, $conf['recent']+1);
if(count($revisions)==0 && $first!=0) {
diff --git a/inc/changelog.php b/inc/changelog.php
index 722365853..f70f20ff9 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -334,16 +334,17 @@ function _handleRecent($line,$ns,$flags,&$seen){
}
/**
- * Class PageRevisionLog
+ * Class ChangeLog
+ * methods for handling of changelog of pages or media files
*/
-class PageRevisionLog {
+abstract class ChangeLog {
/** @var string */
- private $id;
+ protected $id;
/** @var int */
- private $chunk_size;
+ protected $chunk_size;
/** @var array */
- private $cache;
+ protected $cache;
/**
* Constructor
@@ -366,6 +367,7 @@ class PageRevisionLog {
/**
* Set chunk size for file reading
+ * Chunk size zero let read whole file at once
*
* @param int $chunk_size maximum block size read from file
*/
@@ -375,6 +377,20 @@ class PageRevisionLog {
$this->chunk_size = (int) max($chunk_size, 0);
}
+ /**
+ * Returns path to changelog
+ *
+ * @return string path to file
+ */
+ abstract protected function getChangelogFilename();
+
+ /**
+ * Returns path to current page/media
+ *
+ * @return string path to file
+ */
+ abstract protected function getFilename();
+
/**
* Get the changelog information for a specific page id and revision (timestamp)
*
@@ -383,7 +399,6 @@ class PageRevisionLog {
* containing the requested changelog line is read.
*
* @param int $rev revision timestamp
- * @param bool $media look into media log?
* @return bool|array false or array with entries:
* - date: unix timestamp
* - ip: IPv4 address (127.0.0.1)
@@ -396,7 +411,7 @@ class PageRevisionLog {
* @author Ben Coburn
* @author Kate Arzamastseva
*/
- public function getRevisionInfo($rev, $media = false) {
+ public function getRevisionInfo($rev) {
$rev = max($rev, 0);
// check if it's already in the memory cache
@@ -405,7 +420,7 @@ class PageRevisionLog {
}
//read lines from changelog
- list($fp, $lines) = $this->readloglines($media, $rev);
+ list($fp, $lines) = $this->readloglines($rev);
if($fp) {
fclose($fp);
}
@@ -442,32 +457,28 @@ class PageRevisionLog {
*
* @param int $first skip the first n changelog lines
* @param int $num number of revisions to return
- * @param bool $media look into media log?
* @return array with the revision timestamps
*
* @author Ben Coburn
* @author Kate Arzamastseva
*/
- public function getRevisions($first, $num, $media = false) {
+ public function getRevisions($first, $num) {
$revs = array();
$lines = array();
$count = 0;
- if ($media) {
- $file = mediaMetaFN($this->id, '.changes');
- } else {
- $file = metaFN($this->id, '.changes');
- }
+
$num = max($num, 0);
if ($num == 0) { return $revs; }
- $this->chunk_size = max($this->chunk_size, 0);
if ($first<0) {
$first = 0;
- } else if (!$media && @file_exists(wikiFN($this->id)) || $media && @file_exists(mediaFN($this->id))) {
+ } else if (@file_exists($this->getFilename())) {
// skip current revision if the page exists
$first = max($first+1, 0);
}
+ $file = $this->getChangelogFilename();
+
if (!@file_exists($file)) { return $revs; }
if (filesize($file)<$this->chunk_size || $this->chunk_size==0) {
// read whole file
@@ -554,12 +565,11 @@ class PageRevisionLog {
*
* @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
* @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
- * @param bool $media look into media log?
* @return bool|int
* timestamp of the requested revision
* otherwise false
*/
- public function getRelativeRevision($rev, $direction, $media = false) {
+ public function getRelativeRevision($rev, $direction) {
$rev = max($rev, 0);
$direction = (int) $direction;
@@ -569,7 +579,7 @@ class PageRevisionLog {
}
//get lines from changelog
- list($fp, $lines, $head, $tail, $eof) = $this->readloglines($media, $rev);
+ list($fp, $lines, $head, $tail, $eof) = $this->readloglines($rev);
if(empty($lines)) return false;
// look for revisions later/earlier then $rev, when founded count till the wanted revision is reached
@@ -645,17 +655,12 @@ class PageRevisionLog {
* Returns lines from changelog.
* If file larger than $chuncksize, only chunck is read that could contain $rev.
*
- * @param bool $media look into media log?
* @param int $rev revision timestamp
* @return array(fp, array(changeloglines), $head, $tail, $eof)|bool
* returns false when not succeed. fp only defined for chuck reading, needs closing.
*/
- protected function readloglines($media, $rev) {
- if($media) {
- $file = mediaMetaFN($this->id, '.changes');
- } else {
- $file = metaFN($this->id, '.changes');
- }
+ protected function readloglines($rev) {
+ $file = $this->getChangelogFilename();
if(!@file_exists($file)) {
return false;
@@ -761,14 +766,56 @@ class PageRevisionLog {
* Check whether given revision is the current page
*
* @param int $rev timestamp of current page
- * @param bool $media look for media?
* @return bool true if $rev is current revision, otherwise false
*/
- public function isCurrentRevision($rev, $media = false) {
- return $rev == @filemtime($media ? mediaFN($this->id) : wikiFN($this->id));
+ public function isCurrentRevision($rev) {
+ return $rev == @filemtime($this->getFilename());
+ }
+}
+
+class PageChangelog extends ChangeLog {
+
+ /**
+ * Returns path to changelog
+ *
+ * @return string path to file
+ */
+ protected function getChangelogFilename() {
+ return metaFN($this->id, '.changes');
+ }
+
+ /**
+ * Returns path to current page/media
+ *
+ * @return string path to file
+ */
+ protected function getFilename() {
+ return wikiFN($this->id);
+ }
+}
+
+class MediaChangelog extends ChangeLog {
+
+ /**
+ * Returns path to changelog
+ *
+ * @return string path to file
+ */
+ protected function getChangelogFilename() {
+ return mediaMetaFN($this->id, '.changes');
+ }
+
+ /**
+ * Returns path to current page/media
+ *
+ * @return string path to file
+ */
+ protected function getFilename() {
+ return mediaFN($this->id);
}
}
+
/**
* Get the changelog information for a specific page id
* and revision (timestamp). Adjacent changelog lines
@@ -783,9 +830,12 @@ class PageRevisionLog {
* @author Kate Arzamastseva
*/
function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
-
- $log = new PageRevisionLog($id, $chunk_size);
- return $log->getRevisionInfo($rev, $media);
+ if($media) {
+ $changelog = new MediaChangeLog($id, $chunk_size);
+ } else {
+ $changelog = new PageChangeLog($id, $chunk_size);
+ }
+ return $changelog->getRevisionInfo($rev);
}
/**
@@ -812,6 +862,10 @@ function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
* @author Kate Arzamastseva
*/
function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
- $log = new PageRevisionLog($id, $chunk_size);
- return $log->getRevisions($first, $num, $media);
+ if($media) {
+ $changelog = new MediaChangeLog($id, $chunk_size);
+ } else {
+ $changelog = new PageChangeLog($id, $chunk_size);
+ }
+ return $changelog->getRevisions($first, $num);
}
diff --git a/inc/common.php b/inc/common.php
index dd30b53ab..7821cb3de 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -187,7 +187,7 @@ function pageinfo() {
$info['meta'] = p_get_metadata($ID);
//who's the editor
- $pagelog = new PageRevisionLog($ID, 1024);
+ $pagelog = new PageChangeLog($ID, 1024);
if($REV) {
$revinfo = $pagelog->getRevisionInfo($REV);
} else {
@@ -1060,7 +1060,7 @@ function saveWikiText($id, $text, $summary, $minor = false) {
$wasRemoved = (trim($text) == ''); // check for empty or whitespace only
$wasCreated = !@file_exists($file);
$wasReverted = ($REV == true);
- $pagelog = new PageRevisionLog($id, 1024);
+ $pagelog = new PageChangeLog($id, 1024);
$newRev = false;
$oldRev = $pagelog->getRevisions(-1, 1); // from changelog
$oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]);
diff --git a/inc/html.php b/inc/html.php
index b48a17fc5..442126f71 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -414,18 +414,23 @@ function html_revisions($first=0, $media_id = false){
global $conf;
global $lang;
$id = $ID;
- if ($media_id) $id = $media_id;
+ if ($media_id) {
+ $id = $media_id;
+ $changelog = new MediaChangeLog($id);
+ } else {
+ $changelog = new PageChangeLog($id);
+ }
/* we need to get one additional log entry to be able to
* decide if this is the last page or is there another one.
* see html_recent()
*/
- $pagelog = new PageRevisionLog($id);
- $revisions = $pagelog->getRevisions($first, $conf['recent']+1, (boolean)$media_id);
+
+ $revisions = $changelog->getRevisions($first, $conf['recent']+1);
if(count($revisions)==0 && $first!=0){
$first=0;
- $revisions = $pagelog->getRevisions($first, $conf['recent']+1, (boolean)$media_id);
+ $revisions = $changelog->getRevisions($first, $conf['recent']+1);
}
$hasNext = false;
if (count($revisions)>$conf['recent']) {
@@ -484,17 +489,18 @@ function html_revisions($first=0, $media_id = false){
$form->addElement(form_makeCloseTag('span'));
}
- $pagelog->setChunkSize(1024);
+ $changelog->setChunkSize(1024);
$form->addElement(form_makeOpenTag('span', array('class' => 'user')));
- if (!$media_id) $editor = $INFO['editor'];
- else {
- $revinfo = $pagelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))), true);
- if($revinfo['user']){
+ if($media_id) {
+ $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
+ if($revinfo['user']) {
$editor = $revinfo['user'];
- }else{
+ } else {
$editor = $revinfo['ip'];
}
+ } else {
+ $editor = $INFO['editor'];
}
$form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
$form->addElement(form_makeCloseTag('span'));
@@ -509,12 +515,11 @@ function html_revisions($first=0, $media_id = false){
foreach($revisions as $rev){
$date = dformat($rev);
- if (!$media_id) {
- $info = $pagelog->getRevisionInfo($rev);
- $exists = page_exists($id,$rev);
- } else {
- $info = $pagelog->getRevisionInfo($rev,true);
- $exists = @file_exists(mediaFN($id,$rev));
+ $info = $changelog->getRevisionInfo($rev);
+ if($media_id) {
+ $exists = @file_exists(mediaFN($id, $rev));
+ } else {
+ $exists = page_exists($id, $rev);
}
if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
@@ -706,8 +711,8 @@ function html_recent($first=0, $show_changes='both'){
$href = '';
if ($recent['media']) {
- $pagelog = new PageRevisionLog($recent['id']);
- $diff = (count($pagelog->getRevisions(0, 1, true)) && @file_exists(mediaFN($recent['id'])));
+ $medialog = new MediaChangeLog($recent['id']);
+ $diff = (count($medialog->getRevisions(0, 1)) && @file_exists(mediaFN($recent['id'])));
if ($diff) {
$href = media_managerURL(array('tab_details' => 'history',
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
@@ -1009,11 +1014,15 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$ml_or_wl = $media ? 'ml' : 'wl';
$l_minor = $r_minor = '';
- $pagelog = new PageRevisionLog($id);
+ if($media) {
+ $log = new MediaChangeLog($id);
+ } else {
+ $log = new PageChangeLog($id);
+ }
if(!$l_rev){
$l_head = '—';
}else{
- $l_info = $pagelog->getRevisionInfo($l_rev, $media);
+ $l_info = $log->getRevisionInfo($l_rev);
if($l_info['user']){
$l_user = ''.editorinfo($l_info['user']).'';
if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
@@ -1031,7 +1040,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
}
if($r_rev){
- $r_info = $pagelog->getRevisionInfo($r_rev, $media);
+ $r_info = $log->getRevisionInfo($r_rev);
if($r_info['user']){
$r_user = ''.editorinfo($r_info['user']).'';
if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
@@ -1047,7 +1056,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$r_head_title.''.
$head_separator.$r_user.' '.$r_sum;
}elseif($_rev = @filemtime($media_or_wikiFN($id))){
- $_info = $pagelog->getRevisionInfo($_rev, $media);
+ $_info = $log->getRevisionInfo($_rev);
if($_info['user']){
$_user = ''.editorinfo($_info['user']).'';
if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
@@ -1084,7 +1093,7 @@ function html_diff($text='',$intro=true,$type=null){
global $lang;
global $INPUT;
global $INFO;
- $pagelog = new PageRevisionLog($ID);
+ $pagelog = new PageChangeLog($ID);
if(!$type) {
$type = $INPUT->str('difftype');
diff --git a/inc/media.php b/inc/media.php
index 9f0c2cb8c..3bdaa8ef7 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -492,8 +492,8 @@ function media_saveOldRevision($id){
$date = filemtime($oldf);
if (!$conf['mediarevisions']) return $date;
- $pagelog = new PageRevisionLog($id);
- if (!$pagelog->getRevisionInfo($date, true)) {
+ $medialog = new MediaChangeLog($id);
+ if (!$medialog->getRevisionInfo($date)) {
// there was an external edit,
// there is no log entry for current version of file
if (!@file_exists(mediaMetaFN($id,'.changes'))) {
@@ -1072,8 +1072,8 @@ function media_diff($image, $ns, $auth, $fromajax = false) {
$l_rev = $rev1;
}else{ // no revision was given, compare previous to current
$r_rev = '';
- $pagelog = new PageRevisionLog($image);
- $revs = $pagelog->getRevisions(0, 1, true);
+ $medialog = new MediaChangeLog($image);
+ $revs = $medialog->getRevisions(0, 1);
if (file_exists(mediaFN($image, $revs[0]))) {
$l_rev = $revs[0];
} else {
diff --git a/inc/subscription.php b/inc/subscription.php
index 87db3c621..e6fb23f63 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -288,7 +288,7 @@ class Subscription {
public function send_bulk($page) {
if(!$this->isenabled()) return 0;
- /** @var auth_basic $auth */
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
global $conf;
global $USERINFO;
@@ -336,7 +336,7 @@ class Subscription {
while(!is_null($rev) && $rev['date'] >= $lastupdate &&
($_SERVER['REMOTE_USER'] === $rev['user'] ||
$rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) {
- $pagelog = new PageRevisionLog($rev['id']);
+ $pagelog = new PageChangeLog($rev['id']);
$rev = $pagelog->getRevisions($n++, 1);
$rev = (count($rev) > 0) ? $rev[0] : null;
}
@@ -516,7 +516,7 @@ class Subscription {
* @return bool
*/
protected function send_digest($subscriber_mail, $id, $lastupdate) {
- $pagelog = new PageRevisionLog($id);
+ $pagelog = new PageChangeLog($id);
$n = 0;
do {
$rev = $pagelog->getRevisions($n++, 1);
diff --git a/lib/plugins/revert/admin.php b/lib/plugins/revert/admin.php
index ffb6fbc47..88d8cd93d 100644
--- a/lib/plugins/revert/admin.php
+++ b/lib/plugins/revert/admin.php
@@ -83,7 +83,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin {
// find the last non-spammy revision
$data = '';
- $pagelog = new PageRevisionLog($id);
+ $pagelog = new PageChangeLog($id);
$old = $pagelog->getRevisions(0, $this->max_revs);
if(count($old)){
foreach($old as $REV){
--
cgit v1.2.3
From 4f6e20c71de298e046e451fd51919a51779b7e17 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Thu, 21 Nov 2013 21:13:02 +0100
Subject: fix not updated call, renaming
---
_test/tests/inc/changelog_getrevisions.test.php | 2 +-
inc/html.php | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/_test/tests/inc/changelog_getrevisions.test.php b/_test/tests/inc/changelog_getrevisions.test.php
index aa2198981..675754faf 100644
--- a/_test/tests/inc/changelog_getrevisions.test.php
+++ b/_test/tests/inc/changelog_getrevisions.test.php
@@ -164,7 +164,7 @@ class changelog_getrevisions_test extends DokuWikiTest {
$revsexpected = array();
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($this->pageid, $first, $num, $chunk_size = 8192);
+ $revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
diff --git a/inc/html.php b/inc/html.php
index 442126f71..03a760035 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1015,14 +1015,14 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$l_minor = $r_minor = '';
if($media) {
- $log = new MediaChangeLog($id);
+ $changelog = new MediaChangeLog($id);
} else {
- $log = new PageChangeLog($id);
+ $changelog = new PageChangeLog($id);
}
if(!$l_rev){
$l_head = '—';
}else{
- $l_info = $log->getRevisionInfo($l_rev);
+ $l_info = $changelog->getRevisionInfo($l_rev);
if($l_info['user']){
$l_user = ''.editorinfo($l_info['user']).'';
if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
@@ -1040,7 +1040,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
}
if($r_rev){
- $r_info = $log->getRevisionInfo($r_rev);
+ $r_info = $changelog->getRevisionInfo($r_rev);
if($r_info['user']){
$r_user = ''.editorinfo($r_info['user']).'';
if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
@@ -1056,7 +1056,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
$r_head_title.''.
$head_separator.$r_user.' '.$r_sum;
}elseif($_rev = @filemtime($media_or_wikiFN($id))){
- $_info = $log->getRevisionInfo($_rev);
+ $_info = $changelog->getRevisionInfo($_rev);
if($_info['user']){
$_user = ''.editorinfo($_info['user']).'';
if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
--
cgit v1.2.3
From 332817fccb0577125da59b71f437e72ae823a7c8 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Thu, 21 Nov 2013 22:48:08 +0100
Subject: improve unittests getrelativerevision. Bit code reformatting unit
tests
---
.../inc/changelog_getrelativerevision.test.php | 131 +++++++++++++--------
_test/tests/inc/changelog_getrevisioninfo.test.php | 14 +--
_test/tests/inc/changelog_getrevisions.test.php | 46 ++++----
3 files changed, 113 insertions(+), 78 deletions(-)
diff --git a/_test/tests/inc/changelog_getrelativerevision.test.php b/_test/tests/inc/changelog_getrelativerevision.test.php
index fa4c68897..c636b3c04 100644
--- a/_test/tests/inc/changelog_getrelativerevision.test.php
+++ b/_test/tests/inc/changelog_getrelativerevision.test.php
@@ -28,9 +28,9 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* no nonexist.changes meta file available
*/
function test_changemetadatanotexists() {
- $rev = 1362525899;
- $dir = 1;
- $id = 'nonexist';
+ $rev = 1362525899;
+ $dir = 1;
+ $id = 'nonexist';
$revsexpected = false;
$pagelog = new PageChangeLog($id, $chunk_size = 8192);
@@ -42,8 +42,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* no nonexist.changes meta file available
*/
function test_nodirection() {
- $rev = 1362525899;
- $dir = 0;
+ $rev = 1362525899;
+ $dir = 0;
$revsexpected = false;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -56,29 +56,65 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
*
*/
function test_startatexactcurrentrev() {
- $rev = 1374261194;
- $dir = 1;
- $revsexpected = false;
+ $rev = 1385051947;
+ $dir = 1;
+ $revsexpectedpos = false;
+ $revsexpectedneg = 1374261194;
-// global $INFO;
-// $INFO = pageinfo();
-// var_dump($INFO);
-// var_dump($INFO['meta']);
-// var_dump($INFO['meta']['last_change']);
-// var_dump($INFO['meta']['last_change']['date']);
+ //set a known timestamp
+ touch(wikiFN($this->pageid), $rev);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revs = $pagelog->getRelativeRevision($rev, $dir);
- $this->assertEquals($revsexpected, $revs);
+ $this->assertEquals($revsexpectedpos, $revs);
+
+ $revs = $pagelog->getRelativeRevision($rev, -$dir);
+ $this->assertEquals($revsexpectedneg, $revs);
+ }
+
+ /**
+ * start at exact last revision of mailinglist page
+ *
+ */
+ function test_startatexactlastrev() {
+ $rev = 1360110636;
+ $dir = 1;
+ $revsexpectedpos = 1361901536;
+ $revsexpectedneg = false;
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revsexpectedpos, $revs);
+
+ $revs = $pagelog->getRelativeRevision($rev, -$dir);
+ $this->assertEquals($revsexpectedneg, $revs);
+ }
+
+ /**
+ * start at exact one before last revision of mailinglist page
+ *
+ */
+ function test_requestlastrevisions() {
+ $rev = 1361901536;
+ $dir = -1;
+ $revsexpectedlast = 1360110636;
+ $revsexpectedbeforelast = false;
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revsexpectedlast, $revs);
+
+ $revs = $pagelog->getRelativeRevision($rev, 2 * $dir);
+ $this->assertEquals($revsexpectedbeforelast, $revs);
}
/**
* request existing rev
*/
function test_requestrev() {
- $rev = 1362525359;
- $dir = 1;
- $revexpected = 1362525899;
+ $rev = 1362525359;
+ $dir = 1;
+ $revexpected = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -93,8 +129,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request existing rev with chucked reading
*/
function test_requestnextrev_chuncked() {
- $rev = 1362525899;
- $dir = 1;
+ $rev = 1362525899;
+ $dir = 1;
$revexpected = 1362525926;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
@@ -106,9 +142,9 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request existing rev
*/
function test_requestnextfifthrev() {
- $rev = 1362525899;
- $dir = 5;
- $revexpected = 1362526767;
+ $rev = 1362525899;
+ $dir = 5;
+ $revexpected = 1362526767;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
@@ -119,8 +155,8 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request existing rev with chucked reading
*/
function test_requestnextfifthrev_chuncked() {
- $rev = 1362525899;
- $dir = 5;
+ $rev = 1362525899;
+ $dir = 5;
$revexpected = 1362526767;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
@@ -132,11 +168,11 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request existing rev
*/
function test_requestprevrev() {
- $rev = 1362525899;
- $dir1 = -1;
- $dir5 = -5;
- $revexpected1 = 1362525359;
- $revexpected5 = 1360110636;
+ $rev = 1362525899;
+ $dir1 = -1;
+ $dir5 = -5;
+ $revexpected1 = 1362525359;
+ $revexpected5 = 1360110636;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
@@ -150,11 +186,11 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request existing rev with chucked reading
*/
function test_requestprevrev_chuncked() {
- $rev = 1362525899;
- $dir1 = -1;
- $dir5 = -5;
- $revexpected1 = 1362525359;
- $revexpected5 = 1360110636;
+ $rev = 1362525899;
+ $dir1 = -1;
+ $dir5 = -5;
+ $revexpected1 = 1362525359;
+ $revexpected5 = 1360110636;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
@@ -168,9 +204,9 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request after recentest version in changelog
*/
function test_requestrecentestlogline_next() {
- $rev = 1374261194;
- $dir = 1;
- $revexpected = false;
+ $rev = 1374261194;
+ $dir = 1;
+ $revexpected = false;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
@@ -181,23 +217,22 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request after recentest version in changelog, with chuncked reading
*/
function test_requestrecentestlogline_next_chuncked() {
- $rev = 1374261194;
- $dir = 1;
- $revexpected = false;
+ $rev = 1374261194;
+ $dir = 1;
+ $revexpected = false;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
-
/**
* request before current version
*/
function test_requestrecentestlogline_prev() {
- $rev = 1374261194;
- $dir = -1;
- $revexpected = 1371579614;
+ $rev = 1374261194;
+ $dir = -1;
+ $revexpected = 1371579614;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
@@ -208,9 +243,9 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
* request before current version, with chuncked reading
*/
function test_requestrecentestlogline_prev_chuncked() {
- $rev = 1374261194;
- $dir = -1;
- $revexpected = 1371579614;
+ $rev = 1374261194;
+ $dir = -1;
+ $revexpected = 1371579614;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
diff --git a/_test/tests/inc/changelog_getrevisioninfo.test.php b/_test/tests/inc/changelog_getrevisioninfo.test.php
index c073bac79..07e229824 100644
--- a/_test/tests/inc/changelog_getrevisioninfo.test.php
+++ b/_test/tests/inc/changelog_getrevisioninfo.test.php
@@ -29,8 +29,8 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* no nonexist.changes meta file available
*/
function test_changemetadatanotexists() {
- $rev = 1362525899;
- $id = 'nonexist';
+ $rev = 1362525899;
+ $id = 'nonexist';
$revsexpected = false;
$pagelog = new PageChangeLog($id, $chunk_size = 8192);
@@ -42,7 +42,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* request existing rev
*/
function test_requestrev() {
- $rev = 1362525899;
+ $rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -57,7 +57,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* request existing rev with chucked reading
*/
function test_requestrev_chuncked() {
- $rev = 1362525899;
+ $rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
@@ -69,7 +69,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* request current version
*/
function test_requestrecentestlogline() {
- $rev = 1374261194;
+ $rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -84,7 +84,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* request current version, with chuncked reading
*/
function test_requestrecentestlogline_chuncked() {
- $rev = 1374261194;
+ $rev = 1374261194;
$infoexpected = parseChangelogLine($this->firstlogline);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
@@ -118,7 +118,7 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
* sometimes chuncksize is set to true
*/
function test_chuncksizetrue() {
- $rev = 1362525899;
+ $rev = 1362525899;
$infoexpected = parseChangelogLine($this->logline);
$pagelog = new PageChangeLog($this->pageid, true);
diff --git a/_test/tests/inc/changelog_getrevisions.test.php b/_test/tests/inc/changelog_getrevisions.test.php
index 675754faf..69315638f 100644
--- a/_test/tests/inc/changelog_getrevisions.test.php
+++ b/_test/tests/inc/changelog_getrevisions.test.php
@@ -45,11 +45,11 @@ class changelog_getrevisions_test extends DokuWikiTest {
*/
function test_changemetadatanotexists() {
$first = 0;
- $num = 1;
- $id = 'nonexist';
+ $num = 1;
+ $id = 'nonexist';
$pagelog = new PageChangeLog($id, $chunk_size = 8192);
- $revs = $pagelog->getRevisions($first, $num);
+ $revs = $pagelog->getRevisions($first, $num);
$revsexpected = array();
$this->assertEquals($revsexpected, $revs);
}
@@ -59,8 +59,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* (so skips first line which belongs to the current existing page)
*/
function test_requestlastrev() {
- $first = 0;
- $num = 1;
+ $first = 0;
+ $num = 1;
$revsexpected = array($this->revsexpected[1]);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -77,8 +77,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* (so skips first line which belongs to the current existing page)
*/
function test_requestonebutlastrev() {
- $first = 1;
- $num = 1;
+ $first = 1;
+ $num = 1;
$revsexpected = array($this->revsexpected[2]);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -95,8 +95,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* (so skips first line of current existing page)
*/
function test_requestrevswithoffset() {
- $first = 10;
- $num = 5;
+ $first = 10;
+ $num = 5;
$revsexpected = array_slice($this->revsexpected, $first + 1, $num);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -112,8 +112,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* first = -1 requests recentest logline, without skipping
*/
function test_requestrecentestlogline() {
- $first = -1;
- $num = 1;
+ $first = -1;
+ $num = 1;
$revsexpected = array($this->revsexpected[0]);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -129,8 +129,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* chunck size = 0 skips chuncked loading
*/
function test_wholefile() {
- $first = 0;
- $num = 1000;
+ $first = 0;
+ $num = 1000;
$revsexpected = array_slice($this->revsexpected, 1);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 0);
@@ -142,8 +142,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* Negative range returns no result
*/
function test_negativenum() {
- $first = 0;
- $num = -10;
+ $first = 0;
+ $num = -10;
$revsexpected = array();
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -159,8 +159,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* Negative range returns no result
*/
function test_negativennumoffset() {
- $first = 2;
- $num = -10;
+ $first = 2;
+ $num = -10;
$revsexpected = array();
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -176,8 +176,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* zero range returns no result
*/
function test_zeronum() {
- $first = 5;
- $num = 0;
+ $first = 5;
+ $num = 0;
$revsexpected = array();
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -193,8 +193,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* get oldest revisions
*/
function test_requestlargeoffset() {
- $first = 22;
- $num = 50;
+ $first = 22;
+ $num = 50;
$revsexpected = array_slice($this->revsexpected, $first + 1);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
@@ -206,8 +206,8 @@ class changelog_getrevisions_test extends DokuWikiTest {
* request with too large offset and range
*/
function test_requesttoolargenumberrevs() {
- $first = 50;
- $num = 50;
+ $first = 50;
+ $num = 50;
$revsexpected = array();
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
--
cgit v1.2.3
From 59cce2d943ee9a18fafc9a0594ede031f7bf7190 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Fri, 22 Nov 2013 15:30:48 +0100
Subject: Improve changelog reading. Inclusive unittests for chunks smaller
than changelog lines.
---
.../inc/changelog_getrelativerevision.test.php | 82 +++++++++++++++++++++-
_test/tests/inc/changelog_getrevisioninfo.test.php | 12 ++++
inc/changelog.php | 50 ++++++-------
3 files changed, 116 insertions(+), 28 deletions(-)
diff --git a/_test/tests/inc/changelog_getrelativerevision.test.php b/_test/tests/inc/changelog_getrelativerevision.test.php
index c636b3c04..f9962066a 100644
--- a/_test/tests/inc/changelog_getrelativerevision.test.php
+++ b/_test/tests/inc/changelog_getrelativerevision.test.php
@@ -109,9 +109,9 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
}
/**
- * request existing rev
+ * request existing rev and check cache
*/
- function test_requestrev() {
+ function test_requestrev_checkcache() {
$rev = 1362525359;
$dir = 1;
$revexpected = 1362525899;
@@ -120,20 +120,96 @@ class changelog_getrelativerevision_test extends DokuWikiTest {
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
+
//checked info returned from cache
$info = $pagelog->getRevisionInfo($revfound);
$this->assertEquals($infoexpected, $info);
}
+ /**
+ * request existing rev
+ */
+ function test_requestnextrev() {
+ $rev = 1362525899;
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+
+ $dir = 1;
+ $revexpected = 1362525926;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = 2;
+ $revexpected = 1362526039;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -1;
+ $revexpected = 1362525359;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -2;
+ $revexpected = 1362525145;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
/**
* request existing rev with chucked reading
*/
function test_requestnextrev_chuncked() {
$rev = 1362525899;
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+
$dir = 1;
$revexpected = 1362525926;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $dir = 2;
+ $revexpected = 1362526039;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -1;
+ $revexpected = 1362525359;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -2;
+ $revexpected = 1362525145;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+ }
+
+
+ /**
+ * request existing rev with chucked reading, chunk size smaller than line length
+ */
+ function test_requestnextrev_chunkshorterthanlines() {
+ $rev = 1362525899;
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+
+ $dir = 1;
+ $revexpected = 1362525926;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = 2;
+ $revexpected = 1362526039;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -1;
+ $revexpected = 1362525359;
+ $revfound = $pagelog->getRelativeRevision($rev, $dir);
+ $this->assertEquals($revexpected, $revfound);
+
+ $dir = -2;
+ $revexpected = 1362525145;
$revfound = $pagelog->getRelativeRevision($rev, $dir);
$this->assertEquals($revexpected, $revfound);
}
diff --git a/_test/tests/inc/changelog_getrevisioninfo.test.php b/_test/tests/inc/changelog_getrevisioninfo.test.php
index 07e229824..79b31d68e 100644
--- a/_test/tests/inc/changelog_getrevisioninfo.test.php
+++ b/_test/tests/inc/changelog_getrevisioninfo.test.php
@@ -65,6 +65,18 @@ class changelog_getrevisionsinfo_test extends DokuWikiTest {
$this->assertEquals($infoexpected, $info);
}
+ /**
+ * request existing rev with chucked reading
+ */
+ function test_requestrev_chunckedsmallerthanlinelength() {
+ $rev = 1362525899;
+ $infoexpected = parseChangelogLine($this->logline);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $info = $pagelog->getRevisionInfo($rev);
+ $this->assertEquals($infoexpected, $info);
+ }
+
/**
* request current version
*/
diff --git a/inc/changelog.php b/inc/changelog.php
index f70f20ff9..f47042066 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -494,12 +494,7 @@ abstract class ChangeLog {
// chunk backwards
$finger = max($tail-$this->chunk_size, 0);
while ($count<$num+$first) {
- fseek($fp, $finger);
- $nl = $finger;
- if ($finger>0) {
- fgets($fp); // slip the finger forward to a new line
- $nl = ftell($fp);
- }
+ $nl = getNewlinepointer($fp, $finger);
// was the chunk big enough? if not, take another bite
if($nl > 0 && $tail <= $nl){
@@ -514,7 +509,7 @@ abstract class ChangeLog {
$read_size = max($tail-$finger, 0); // found chunk size
$got = 0;
while ($got<$read_size && !feof($fp)) {
- $tmp = @fread($fp, max($read_size-$got, 0));
+ $tmp = @fread($fp, max($read_size-$got, 0)); //todo why not use chunk_size?
if ($tmp===false) { break; } //error state
$got += strlen($tmp);
$chunk .= $tmp;
@@ -620,22 +615,22 @@ abstract class ChangeLog {
if($checkotherchunck) {
//search bounds of chunck, rounded on new line, but smaller than $chunck_size
if($direction > 0) {
- $head = $tail;
- $lookpointer = true;
- $tail = $head + floor($this->chunk_size * (2 / 3));
- while($lookpointer) {
- $tail = min($tail, $eof);
- $tail = $this->getNewlinepointer($fp, $tail);
- $lookpointer = $tail - $head > $this->chunk_size;
- if($lookpointer) {
- $tail = $head + floor(($tail - $head) / 2);
- }
- if($tail == $head) break;
- }
+ $head = $tail;
+ $tail = $head + floor($this->chunk_size * (2 / 3));
+ $tail = $this->getNewlinepointer($fp, $tail);
} else {
$tail = $head;
$head = max($tail - $this->chunk_size, 0);
- $head = $this->getNewlinepointer($fp, $head);
+ while(true) {
+ $nl = $this->getNewlinepointer($fp, $head);
+ // was the chunk big enough? if not, take another bite
+ if($nl > 0 && $tail <= $nl) {
+ $head = max($head - $this->chunk_size, 0);
+ } else {
+ $head = $nl;
+ break;
+ }
+ }
}
//load next chunck
@@ -693,11 +688,12 @@ abstract class ChangeLog {
$finger = $head + floor(($tail - $head) / 2.0);
$finger = $this->getNewlinepointer($fp, $finger);
$tmp = fgets($fp);
- $tmp = parseChangelogLine($tmp);
- $finger_rev = $tmp['date'];
if($finger == $head || $finger == $tail) {
break;
}
+ $tmp = parseChangelogLine($tmp);
+ $finger_rev = $tmp['date'];
+
if($finger_rev > $rev) {
$tail = $finger;
} else {
@@ -737,7 +733,7 @@ abstract class ChangeLog {
$got = 0;
fseek($fp, $head);
while($got < $chunk_size && !feof($fp)) {
- $tmp = @fread($fp, max($chunk_size - $got, 0));
+ $tmp = @fread($fp, max(min($this->chunk_size, $chunk_size - $got), 0));
if($tmp === false) { //error state
break;
}
@@ -758,8 +754,12 @@ abstract class ChangeLog {
*/
protected function getNewlinepointer($fp, $finger) {
fseek($fp, $finger);
- fgets($fp); // slip the finger forward to a new line
- return ftell($fp);
+ $nl = $finger;
+ if($finger > 0) {
+ fgets($fp); // slip the finger forward to a new line
+ $nl = ftell($fp);
+ }
+ return $nl;
}
/**
--
cgit v1.2.3
From 7d1e323e214bc52984e7df38732878be392adc5f Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Fri, 22 Nov 2013 15:50:04 +0100
Subject: bugfix and reformatting changelog. small chunck unittests
---
_test/tests/inc/changelog_getrevisions.test.php | 14 ++-
inc/changelog.php | 122 +++++++++++++-----------
2 files changed, 79 insertions(+), 57 deletions(-)
diff --git a/_test/tests/inc/changelog_getrevisions.test.php b/_test/tests/inc/changelog_getrevisions.test.php
index 69315638f..b247ce3d6 100644
--- a/_test/tests/inc/changelog_getrevisions.test.php
+++ b/_test/tests/inc/changelog_getrevisions.test.php
@@ -47,10 +47,10 @@ class changelog_getrevisions_test extends DokuWikiTest {
$first = 0;
$num = 1;
$id = 'nonexist';
+ $revsexpected = array();
$pagelog = new PageChangeLog($id, $chunk_size = 8192);
$revs = $pagelog->getRevisions($first, $num);
- $revsexpected = array();
$this->assertEquals($revsexpected, $revs);
}
@@ -70,6 +70,10 @@ class changelog_getrevisions_test extends DokuWikiTest {
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisions($first, $num);
+ $this->assertEquals($revsexpected, $revs);
}
/**
@@ -88,6 +92,10 @@ class changelog_getrevisions_test extends DokuWikiTest {
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisions($first, $num);
+ $this->assertEquals($revsexpected, $revs);
}
/**
@@ -106,6 +114,10 @@ class changelog_getrevisions_test extends DokuWikiTest {
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
$revs = $pagelog->getRevisions($first, $num);
$this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisions($first, $num);
+ $this->assertEquals($revsexpected, $revs);
}
/**
diff --git a/inc/changelog.php b/inc/changelog.php
index f47042066..26480ad23 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -350,7 +350,7 @@ abstract class ChangeLog {
* Constructor
*
* @param string $id page id
- * @param int $chunk_size maximum block size read from file
+ * @param int $chunk_size maximum block size read from file
*/
public function __construct($id, $chunk_size = 8192) {
global $cache_revinfo;
@@ -398,7 +398,7 @@ abstract class ChangeLog {
* consecutive calls to getRevisionInfo. For large changelog files, only the chunk
* containing the requested changelog line is read.
*
- * @param int $rev revision timestamp
+ * @param int $rev revision timestamp
* @return bool|array false or array with entries:
* - date: unix timestamp
* - ip: IPv4 address (127.0.0.1)
@@ -455,8 +455,8 @@ abstract class ChangeLog {
* backwards in chunks until the requested number of changelog
* lines are recieved.
*
- * @param int $first skip the first n changelog lines
- * @param int $num number of revisions to return
+ * @param int $first skip the first n changelog lines
+ * @param int $num number of revisions to return
* @return array with the revision timestamps
*
* @author Ben Coburn
@@ -465,52 +465,62 @@ abstract class ChangeLog {
public function getRevisions($first, $num) {
$revs = array();
$lines = array();
- $count = 0;
+ $count = 0;
$num = max($num, 0);
- if ($num == 0) { return $revs; }
+ if($num == 0) {
+ return $revs;
+ }
- if ($first<0) {
+ if($first < 0) {
$first = 0;
- } else if (@file_exists($this->getFilename())) {
+ } else if(@file_exists($this->getFilename())) {
// skip current revision if the page exists
- $first = max($first+1, 0);
+ $first = max($first + 1, 0);
}
$file = $this->getChangelogFilename();
- if (!@file_exists($file)) { return $revs; }
- if (filesize($file)<$this->chunk_size || $this->chunk_size==0) {
+ if(!@file_exists($file)) {
+ return $revs;
+ }
+ if(filesize($file) < $this->chunk_size || $this->chunk_size == 0) {
// read whole file
$lines = file($file);
- if ($lines===false) { return $revs; }
+ if($lines === false) {
+ return $revs;
+ }
} else {
// read chunks backwards
$fp = fopen($file, 'rb'); // "file pointer"
- if ($fp===false) { return $revs; }
+ if($fp === false) {
+ return $revs;
+ }
fseek($fp, 0, SEEK_END);
$tail = ftell($fp);
// chunk backwards
- $finger = max($tail-$this->chunk_size, 0);
- while ($count<$num+$first) {
- $nl = getNewlinepointer($fp, $finger);
+ $finger = max($tail - $this->chunk_size, 0);
+ while($count < $num + $first) {
+ $nl = $this->getNewlinepointer($fp, $finger);
// was the chunk big enough? if not, take another bite
- if($nl > 0 && $tail <= $nl){
- $finger = max($finger-$this->chunk_size, 0);
+ if($nl > 0 && $tail <= $nl) {
+ $finger = max($finger - $this->chunk_size, 0);
continue;
- }else{
+ } else {
$finger = $nl;
}
// read chunk
$chunk = '';
- $read_size = max($tail-$finger, 0); // found chunk size
+ $read_size = max($tail - $finger, 0); // found chunk size
$got = 0;
- while ($got<$read_size && !feof($fp)) {
- $tmp = @fread($fp, max($read_size-$got, 0)); //todo why not use chunk_size?
- if ($tmp===false) { break; } //error state
+ while($got < $read_size && !feof($fp)) {
+ $tmp = @fread($fp, max($read_size - $got, 0)); //todo why not use chunk_size?
+ if($tmp === false) {
+ break;
+ } //error state
$got += strlen($tmp);
$chunk .= $tmp;
}
@@ -522,25 +532,27 @@ abstract class ChangeLog {
$lines = array_merge($tmp, $lines);
// next chunk
- if ($finger==0) { break; } // already read all the lines
+ if($finger == 0) {
+ break;
+ } // already read all the lines
else {
$tail = $finger;
- $finger = max($tail-$this->chunk_size, 0);
+ $finger = max($tail - $this->chunk_size, 0);
}
}
fclose($fp);
}
// skip parsing extra lines
- $num = max(min(count($lines)-$first, $num), 0);
- if ($first>0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$first-$num, 0), $num); }
- else if ($first>0 && $num==0) { $lines = array_slice($lines, 0, max(count($lines)-$first, 0)); }
- else if ($first==0 && $num>0) { $lines = array_slice($lines, max(count($lines)-$num, 0)); }
+ $num = max(min(count($lines) - $first, $num), 0);
+ if ($first > 0 && $num > 0) { $lines = array_slice($lines, max(count($lines) - $first - $num, 0), $num); }
+ else if($first > 0 && $num == 0) { $lines = array_slice($lines, 0, max(count($lines) - $first, 0)); }
+ else if($first == 0 && $num > 0) { $lines = array_slice($lines, max(count($lines) - $num, 0)); }
// handle lines in reverse order
- for ($i = count($lines)-1; $i >= 0; $i--) {
+ for($i = count($lines) - 1; $i >= 0; $i--) {
$tmp = parseChangelogLine($lines[$i]);
- if ($tmp!==false) {
+ if($tmp !== false) {
$this->cache[$this->id][$tmp['date']] = $tmp;
$revs[] = $tmp['date'];
}
@@ -558,8 +570,8 @@ abstract class ChangeLog {
* Adjacent changelog lines are optimistically parsed and cached to speed up
* consecutive calls to getRevisionInfo.
*
- * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
- * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
+ * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber)
+ * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev
* @return bool|int
* timestamp of the requested revision
* otherwise false
@@ -569,7 +581,7 @@ abstract class ChangeLog {
$direction = (int) $direction;
//no direction given or last rev, so no follow-up
- if(!$direction || ($direction > 0 && $this->isCurrentRevision($rev)) ) {
+ if(!$direction || ($direction > 0 && $this->isCurrentRevision($rev))) {
return false;
}
@@ -579,8 +591,8 @@ abstract class ChangeLog {
// look for revisions later/earlier then $rev, when founded count till the wanted revision is reached
// also parse and cache changelog lines for getRevisionInfo().
- $revcounter = 0;
- $relativerev = false;
+ $revcounter = 0;
+ $relativerev = false;
$checkotherchunck = true; //always runs once
while(!$relativerev && $checkotherchunck) {
$tmp = array();
@@ -588,10 +600,10 @@ abstract class ChangeLog {
$count = count($lines);
if($direction > 0) {
$start = 0;
- $step = 1;
+ $step = 1;
} else {
$start = $count - 1;
- $step = -1;
+ $step = -1;
}
for($i = $start; $i >= 0 && $i < $count; $i = $i + $step) {
$tmp = parseChangelogLine($lines[$i]);
@@ -645,12 +657,11 @@ abstract class ChangeLog {
return $relativerev;
}
-
/**
* Returns lines from changelog.
* If file larger than $chuncksize, only chunck is read that could contain $rev.
*
- * @param int $rev revision timestamp
+ * @param int $rev revision timestamp
* @return array(fp, array(changeloglines), $head, $tail, $eof)|bool
* returns false when not succeed. fp only defined for chuck reading, needs closing.
*/
@@ -661,10 +672,10 @@ abstract class ChangeLog {
return false;
}
- $fp = null;
- $head = 0;
- $tail = 0;
- $eof = 0;
+ $fp = null;
+ $head = 0;
+ $tail = 0;
+ $eof = 0;
if(filesize($file) < $this->chunk_size || $this->chunk_size == 0) {
// read whole file
@@ -680,18 +691,18 @@ abstract class ChangeLog {
}
$head = 0;
fseek($fp, 0, SEEK_END);
- $eof = ftell($fp);
- $tail = $eof;
+ $eof = ftell($fp);
+ $tail = $eof;
// find chunk
while($tail - $head > $this->chunk_size) {
- $finger = $head + floor(($tail - $head) / 2.0);
- $finger = $this->getNewlinepointer($fp, $finger);
- $tmp = fgets($fp);
+ $finger = $head + floor(($tail - $head) / 2.0);
+ $finger = $this->getNewlinepointer($fp, $finger);
+ $tmp = fgets($fp);
if($finger == $head || $finger == $tail) {
break;
}
- $tmp = parseChangelogLine($tmp);
+ $tmp = parseChangelogLine($tmp);
$finger_rev = $tmp['date'];
if($finger_rev > $rev) {
@@ -728,9 +739,9 @@ abstract class ChangeLog {
* @return array lines read from chunck
*/
protected function readChunk($fp, $head, $tail) {
- $chunk = '';
+ $chunk = '';
$chunk_size = max($tail - $head, 0); // found chunk size
- $got = 0;
+ $got = 0;
fseek($fp, $head);
while($got < $chunk_size && !feof($fp)) {
$tmp = @fread($fp, max(min($this->chunk_size, $chunk_size - $got), 0));
@@ -765,7 +776,7 @@ abstract class ChangeLog {
/**
* Check whether given revision is the current page
*
- * @param int $rev timestamp of current page
+ * @param int $rev timestamp of current page
* @return bool true if $rev is current revision, otherwise false
*/
public function isCurrentRevision($rev) {
@@ -815,7 +826,6 @@ class MediaChangelog extends ChangeLog {
}
}
-
/**
* Get the changelog information for a specific page id
* and revision (timestamp). Adjacent changelog lines
@@ -829,7 +839,7 @@ class MediaChangelog extends ChangeLog {
* @author Ben Coburn
* @author Kate Arzamastseva
*/
-function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
+function getRevisionInfo($id, $rev, $chunk_size = 8192, $media = false) {
if($media) {
$changelog = new MediaChangeLog($id, $chunk_size);
} else {
@@ -861,7 +871,7 @@ function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) {
* @author Ben Coburn
* @author Kate Arzamastseva
*/
-function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) {
+function getRevisions($id, $first, $num, $chunk_size = 8192, $media = false) {
if($media) {
$changelog = new MediaChangeLog($id, $chunk_size);
} else {
--
cgit v1.2.3
From 80e97297edd90144da2bafba9158bd9295bdda6e Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 27 Nov 2013 00:39:35 +0100
Subject: read changelog with chunks of chunksize size in getRevisions()
---
inc/changelog.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index 26480ad23..33cdaf533 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -517,7 +517,7 @@ abstract class ChangeLog {
$read_size = max($tail - $finger, 0); // found chunk size
$got = 0;
while($got < $read_size && !feof($fp)) {
- $tmp = @fread($fp, max($read_size - $got, 0)); //todo why not use chunk_size?
+ $tmp = @fread($fp, max(min($this->chunk_size, $read_size - $got), 0));
if($tmp === false) {
break;
} //error state
--
cgit v1.2.3
From 1da8dc976a4e9184fe550789a77d8e5cb866926f Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 27 Nov 2013 00:56:02 +0100
Subject: retrieve revisions around some given revisions
With unit tests
One case is not yet fixed:
when rev1 is first rev from changelog, only $max/2 revisions are
retrieved, but it should retrieve $max revisions.
---
_test/tests/inc/changelog_getRevisionsAround.php | 183 ++++++++++++++++++++
inc/changelog.php | 204 ++++++++++++++++++++---
2 files changed, 365 insertions(+), 22 deletions(-)
create mode 100644 _test/tests/inc/changelog_getRevisionsAround.php
diff --git a/_test/tests/inc/changelog_getRevisionsAround.php b/_test/tests/inc/changelog_getRevisionsAround.php
new file mode 100644
index 000000000..d4d6b8496
--- /dev/null
+++ b/_test/tests/inc/changelog_getRevisionsAround.php
@@ -0,0 +1,183 @@
+getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * Surrounding revisions of rev1 and rev2 overlaps
+ */
+ function test_request_overlapping() {
+ $rev1 = 1362526767;
+ $rev2 = 1362527164;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 5, 11),
+ array_slice($this->revsexpected, 8, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * Surrounding revisions of rev1 and rev2 don't overlap.
+ */
+ function test_request_non_overlapping() {
+ $rev1 = 1362525899;
+ $rev2 = 1368612599;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 0, 11),
+ array_slice($this->revsexpected, 13, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * rev1 and rev2 are at start and end of the changelog.
+ * Should return still a number of revisions equal to max
+ */
+ function test_request_first_last() {
+ $rev1 = 1360110636;
+ $rev2 = 1374261194;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 0, 11),
+ array_slice($this->revsexpected, 13, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+
+ /**
+ * Number of requested revisions is larger than available revisions,
+ * so returns whole log
+ */
+ function test_request_wholelog() {
+ $rev1 = 1362525899;
+ $rev2 = 1368612599;
+ $max = 50;
+ $revsexpected = array($this->revsexpected, $this->revsexpected);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * When rev1 > rev2, their order is changed
+ */
+ function test_request_wrong_order_revs() {
+ $rev1 = 1362527164;
+ $rev2 = 1362526767;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 5, 11),
+ array_slice($this->revsexpected, 8, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+}
\ No newline at end of file
diff --git a/inc/changelog.php b/inc/changelog.php
index 33cdaf533..dfcd1f241 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -625,28 +625,8 @@ abstract class ChangeLog {
&& !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0));
if($checkotherchunck) {
- //search bounds of chunck, rounded on new line, but smaller than $chunck_size
- if($direction > 0) {
- $head = $tail;
- $tail = $head + floor($this->chunk_size * (2 / 3));
- $tail = $this->getNewlinepointer($fp, $tail);
- } else {
- $tail = $head;
- $head = max($tail - $this->chunk_size, 0);
- while(true) {
- $nl = $this->getNewlinepointer($fp, $head);
- // was the chunk big enough? if not, take another bite
- if($nl > 0 && $tail <= $nl) {
- $head = max($head - $this->chunk_size, 0);
- } else {
- $head = $nl;
- break;
- }
- }
- }
+ list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, $direction);
- //load next chunck
- $lines = $this->readChunk($fp, $head, $tail);
if(empty($lines)) break;
}
}
@@ -657,6 +637,61 @@ abstract class ChangeLog {
return $relativerev;
}
+ /**
+ * Returns revisions around rev1 and rev2
+ * When available it returns $max entries for each revision
+ *
+ * @param int $rev1 oldest revision timestamp
+ * @param int $rev2 newest revision timestamp
+ * @param int $max maximum number of revisions returned
+ * @return array with two arrays with revisions surrounding rev1 respectively rev2
+ */
+ public function getRevisionsAround($rev1, $rev2, $max = 50) {
+ $max = floor(abs($max) / 2)*2 + 1;
+ $rev1 = max($rev1, 0);
+ $rev2 = max($rev2, 0);
+
+ if($rev2 < $rev1) {
+ $rev = $rev2;
+ $rev2 = $rev1;
+ $rev1 = $rev;
+ }
+ //collect revisions around rev2
+ list($revs2, $allrevs, $fp, $lines, $head, $tail) = $this->retrieveRevisionsAround($rev2, $max);
+
+ if(empty($revs2)) return array(array(), array());
+
+ //collect revisions around rev1
+ $index = array_search($rev1, $allrevs);
+ if($index === false) {
+ //no overlapping revisions
+ list($revs1,,,,,) = $this->retrieveRevisionsAround($rev1, $max);
+ if(empty($revs1)) $revs1 = array();
+ } else {
+ //revisions overlaps, reuse revisions around rev2
+ $revs1 = $allrevs;
+ while($head > 0) {
+ for($i = count($lines) - 1; $i >= 0; $i--) {
+ $tmp = parseChangelogLine($lines[$i]);
+ if($tmp !== false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
+ $revs1[] = $tmp['date'];
+ $index++;
+
+ if($index > floor($max / 2)) break 2;
+ }
+ }
+
+ list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, -1);
+ }
+ sort($revs1);
+ //return wanted selection
+ $revs1 = array_slice($revs1, max($index - floor($max/2), 0), $max);
+ }
+
+ return array($revs1, $revs2);
+ }
+
/**
* Returns lines from changelog.
* If file larger than $chuncksize, only chunck is read that could contain $rev.
@@ -759,7 +794,7 @@ abstract class ChangeLog {
/**
* Set pointer to first new line after $finger and return its position
*
- * @param $fp resource filepointer
+ * @param resource $fp filepointer
* @param $finger int a pointer
* @return int pointer
*/
@@ -782,8 +817,130 @@ abstract class ChangeLog {
public function isCurrentRevision($rev) {
return $rev == @filemtime($this->getFilename());
}
+
+ /**
+ * Returns the next lines of the changelog of the chunck before head or after tail
+ *
+ * @param resource $fp filepointer
+ * @param int $head position head of last chunk
+ * @param int $tail position tail of last chunk
+ * @param int $direction positive forward, negative backward
+ * @return array with entries:
+ * - $lines: changelog lines of readed chunk
+ * - $head: head of chunk
+ * - $tail: tail of chunk
+ */
+ protected function readAdjacentChunk($fp, $head, $tail, $direction) {
+ if(!$fp) return array(array(), $head, $tail);
+
+ if($direction > 0) {
+ //read forward
+ $head = $tail;
+ $tail = $head + floor($this->chunk_size * (2 / 3));
+ $tail = $this->getNewlinepointer($fp, $tail);
+ } else {
+ //read backward
+ $tail = $head;
+ $head = max($tail - $this->chunk_size, 0);
+ while(true) {
+ $nl = $this->getNewlinepointer($fp, $head);
+ // was the chunk big enough? if not, take another bite
+ if($nl > 0 && $tail <= $nl) {
+ $head = max($head - $this->chunk_size, 0);
+ } else {
+ $head = $nl;
+ break;
+ }
+ }
+ }
+
+ //load next chunck
+ $lines = $this->readChunk($fp, $head, $tail);
+ return array($lines, $head, $tail);
+ }
+
+ /**
+ * Collect the $max revisions near to the timestamp $rev
+ *
+ * @param int $rev revision timestamp
+ * @param int $max maximum number of revisions to be returned
+ * @return bool|array
+ * return array with entries:
+ * - $requestedrevs: array of with $max revision timestamps
+ * - $revs: all parsed revision timestamps
+ * - $fp: filepointer only defined for chuck reading, needs closing.
+ * - $lines: non-parsed changelog lines before the parsed revisions
+ * - $head: position of first readed changelogline
+ * - $lasttail: position of end of last readed changelogline
+ * otherwise false
+ */
+ protected function retrieveRevisionsAround($rev, $max) {
+ //get lines from changelog
+ list($fp, $lines, $starthead, $starttail, $eof) = $this->readloglines($rev);
+ if(empty($lines)) return false;
+
+ //parse chunk containing $rev, and read forward more chunks until $max/2 is reached
+ $head = $starthead;
+ $tail = $starttail;
+ $revs = array();
+ $aftercount = $beforecount = 0;
+ while(count($lines) > 0) {
+ foreach($lines as $line) {
+ $tmp = parseChangelogLine($line);
+ if($tmp !== false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
+ $revs[] = $tmp['date'];
+ if($tmp['date'] >= $rev) {
+ //count revs after reference $rev
+ $aftercount++;
+ if($aftercount == 1) $beforecount = count($revs);
+ }
+ //enough revs after reference $rev?
+ if($aftercount > floor($max / 2)) break 2;
+ }
+ }
+ //retrieve next chunk
+ list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, 1);
+ }
+ if($aftercount == 0) return false;
+
+ $lasttail = $tail;
+
+ //read additional chuncks backward until $max/2 is reached and total number of revs is equal to $max
+ $lines = array();
+ $i = 0;
+ if($aftercount > 0) {
+ $head = $starthead;
+ $tail = $starttail;
+ while($head > 0) {
+ list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, -1);
+
+ for($i = count($lines) - 1; $i >= 0; $i--) {
+ $tmp = parseChangelogLine($lines[$i]);
+ if($tmp !== false) {
+ $this->cache[$this->id][$tmp['date']] = $tmp;
+ $revs[] = $tmp['date'];
+ $beforecount++;
+ //enough revs before reference $rev?
+ if($beforecount > max(floor($max / 2), $max - $aftercount)) break 2;
+ }
+ }
+ }
+ }
+ sort($revs);
+
+ //keep only non-parsed lines
+ $lines = array_slice($lines, 0, $i);
+ //trunk desired selection
+ $requestedrevs = array_slice($revs, -$max, $max);
+
+ return array($requestedrevs, $revs, $fp, $lines, $head, $lasttail);
+ }
}
+/**
+ * Class PageChangelog handles changelog of a wiki page
+ */
class PageChangelog extends ChangeLog {
/**
@@ -805,6 +962,9 @@ class PageChangelog extends ChangeLog {
}
}
+/**
+ * Class MediaChangelog handles changelog of a media file
+ */
class MediaChangelog extends ChangeLog {
/**
--
cgit v1.2.3
From f1f2f711ea957b8fa3c9b4982e63b1476208c4e2 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Sat, 15 Feb 2014 16:49:20 +0100
Subject: Merge remote-tracking branch 'origin/master' into diff_navigation
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
* include upstream change
* added dropdowns
---
inc/html.php | 90 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 65 insertions(+), 25 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 9951e4b57..b698d2e3d 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1193,6 +1193,7 @@ function html_diff($text='',$intro=true,$type=null){
if (!$text) {
ptln('');
+ //display type
$form = new Doku_Form(array('action'=>wl()));
$form->addHidden('id',$ID);
$form->addHidden('rev2[0]',$l_rev);
@@ -1211,44 +1212,83 @@ function html_diff($text='',$intro=true,$type=null){
$form->printForm();
$diffurl = wl($ID, array(
- 'do' => 'diff',
- 'rev2[0]' => $l_rev,
- 'rev2[1]' => $r_rev ? $r_rev : $INFO['lastmod'], // link to exactly this view FS#2835
- 'difftype' => $type,
- ));
+ 'do' => 'diff',
+ 'rev2[0]' => $l_rev,
+ 'rev2[1]' => $r_rev ? $r_rev : $INFO['lastmod'], // link to exactly this view FS#2835
+ 'difftype' => $type,
+ ));
ptln('
'.$lang['difflink'].'
');
+
+ //revisions navigation
+ list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
+ foreach($l_revs as $rev) {
+ $info = $pagelog->getRevisionInfo($rev);
+ $l_revisions[$rev] = array($rev, dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum']);
+ }
+ foreach($r_revs as $rev) {
+ $info = $pagelog->getRevisionInfo($rev);
+ $r_revisions[$rev] = array($rev, dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum']);
+ }
+
+
if($prev_rev){
$diffurlprev = wl($ID, array(
- 'do' => 'diff',
- 'rev2[0]' => $prev_rev,
- 'rev2[1]' => $l_rev,
- 'difftype' => $type,
- ));
- ptln('← '.$lang['diffpreviousedit'].' - ');
+ 'do' => 'diff',
+ 'rev2[0]' => $prev_rev,
+ 'rev2[1]' => $l_rev,
+ 'difftype' => $type,
+ ));
+ ptln('← '.$lang['diffpreviousedit'].'');
}
- $recenturl = wl($ID, array(
- 'do' => 'revisions'
- ));
- ptln(''.$lang['overviewrevs'].'');
+ var_dump($l_revisions);
+ $form = new Doku_Form(array('action'=>wl()));
+ $form->addHidden('id',$ID);
+ $form->addHidden('difftype',$type);
+ $form->addHidden('rev2[1]',$r_rev);
+ $form->addHidden('do','diff');
+ $form->addElement(form_makeListboxField(
+ 'rev2[0]',
+ $l_revisions,
+ $l_rev,
+ '','','',
+ array('class'=>'quickselect')));
+ $form->addElement(form_makeButton('submit', 'diff','Go'));
+ $form->printForm();
+
+ $form = new Doku_Form(array('action'=>wl()));
+ $form->addHidden('id',$ID);
+ $form->addHidden('rev2[0]',$l_rev);
+ $form->addHidden('difftype',$type);
+ $form->addHidden('do','diff');
+ $form->addElement(form_makeListboxField(
+ 'rev2[1]',
+ $r_revisions,
+ $r_rev ? $r_rev : $INFO['meta']['last_change']['date'],
+ '','','',
+ array('class'=>'quickselect')));
+ $form->addElement(form_makeButton('submit', 'diff','Go'));
+ $form->printForm();
+
if($next_rev){
if($pagelog->isCurrentRevision($next_rev)) {
$diffurlnextparam = array(
- 'do' => 'diff',
- 'rev' => $r_rev,
- 'difftype' => $type,
- );
+ 'do' => 'diff',
+ 'rev' => $r_rev,
+ 'difftype' => $type,
+ );
$navnexttitle = $lang['difflastedit'];
} else {
$diffurlnextparam = array(
- 'do' => 'diff',
- 'rev2[0]' => $r_rev,
- 'rev2[1]' => $next_rev,
- 'difftype' => $type,
- );
+ 'do' => 'diff',
+ 'rev2[0]' => $r_rev,
+ 'rev2[1]' => $next_rev,
+ 'difftype' => $type,
+ );
$navnexttitle = $lang['diffnextedit'];
}
- ptln(' - '.$navnexttitle.' →');
+ ptln(''.$navnexttitle.' →');
}
+
ptln('
');
ptln('
');
}
--
cgit v1.2.3
From eeb8f429f3a505770c8dcf81998b009ba9d884fd Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Sat, 15 Feb 2014 17:23:27 +0100
Subject: add disable options to form_makeListboxField. Disable out of range
revisions
---
inc/form.php | 18 +++++++++++-------
inc/html.php | 17 +++++++++++++----
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/inc/form.php b/inc/form.php
index 312c42b60..25c65bd55 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -565,10 +565,11 @@ function form_makeListboxField($name, $values, $selected='', $label=null, $id=''
if (is_null($label)) $label = $name;
$options = array();
reset($values);
- if (is_null($selected) || $selected == '')
+ if (is_null($selected) || $selected == '') {
$selected = array();
- elseif (!is_array($selected))
+ } elseif (!is_array($selected)) {
$selected = array($selected);
+ }
// FIXME: php doesn't know the difference between a string and an integer
if (is_string(key($values))) {
foreach ($values as $val=>$text) {
@@ -576,11 +577,13 @@ function form_makeListboxField($name, $values, $selected='', $label=null, $id=''
}
} else {
foreach ($values as $val) {
- if (is_array($val))
- @list($val,$text) = $val;
- else
+ $disabled = false;
+ if (is_array($val)) {
+ @list($val,$text,$disabled) = $val;
+ } else {
$text = null;
- $options[] = array($val,$text,in_array($val,$selected));
+ }
+ $options[] = array($val,$text,in_array($val,$selected),$disabled);
}
}
$elem = array('_elem'=>'listboxfield', '_options'=>$options, '_text'=>$label, '_class'=>$class,
@@ -934,11 +937,12 @@ function form_listboxfield($attrs) {
$s .= '
'); //todo paragraphs are a mess..
ptln('');
}
?>
@@ -1331,6 +1313,34 @@ function html_diff($text='',$intro=true,$type=null){
'diff',
+ 'rev' => $lrev,
+ 'difftype' => $type,
+ );
+ } else {
+ $urlparam = array(
+ 'do' => 'diff',
+ 'rev2[0]' => $lrev,
+ 'rev2[1]' => $rrev,
+ 'difftype' => $type,
+ );
+ }
+ ptln('' . $name . '');
+}
+
function html_insert_softbreaks($diffhtml) {
// search the diff html string for both:
// - html tags, so these can be ignored
--
cgit v1.2.3
From 7f92538e7173852561b0396626dd35783550ed92 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Sat, 15 Feb 2014 20:12:01 +0100
Subject: remove close p tag in diffview
---
inc/html.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/inc/html.php b/inc/html.php
index 5ea8ece4c..ce5da488b 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1280,7 +1280,6 @@ function html_diff($text='',$intro=true,$type=null){
html_diff_navigationlink($type, ' →→', $l_next, $r_next);
}
- ptln(''); //todo paragraphs are a mess..
ptln('');
}
?>
--
cgit v1.2.3
From 2e608c527514d5fb03eb88c8da1c101f231d5736 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Sat, 15 Feb 2014 20:41:09 +0100
Subject: reverse revisions display order
---
inc/changelog.php | 2 +-
inc/html.php | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index dfcd1f241..d2ad23c08 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -689,7 +689,7 @@ abstract class ChangeLog {
$revs1 = array_slice($revs1, max($index - floor($max/2), 0), $max);
}
- return array($revs1, $revs2);
+ return array(array_reverse($revs1), array_reverse($revs2));
}
/**
diff --git a/inc/html.php b/inc/html.php
index ce5da488b..3cce6ceab 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1225,11 +1225,11 @@ function html_diff($text='',$intro=true,$type=null){
}
$l_index = array_search($l_rev, $l_revs);
- $l_prev = $l_revs[$l_index - 1];
- $l_next = $l_revs[$l_index + 1];
+ $l_prev = $l_revs[$l_index + 1];
+ $l_next = $l_revs[$l_index - 1];
$r_index = array_search($r_rev, $r_revs);
- $r_prev = $r_revs[$r_index - 1];
- $r_next = $r_revs[$r_index + 1];
+ $r_prev = $r_revs[$r_index + 1];
+ $r_next = $r_revs[$r_index - 1];
if($l_prev) {
html_diff_navigationlink($type, '←← ', $l_prev, $r_prev);
--
cgit v1.2.3
From c931f569620802229ca2b48a0aafff77d5072979 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Sat, 15 Feb 2014 21:19:55 +0100
Subject: rename unit tests for getRevisionAround. Fix revs order as well.
---
_test/tests/inc/changelog_getRevisionsAround.php | 183 --------------------
.../inc/changelog_getRevisionsAround.test.php | 188 +++++++++++++++++++++
2 files changed, 188 insertions(+), 183 deletions(-)
delete mode 100644 _test/tests/inc/changelog_getRevisionsAround.php
create mode 100644 _test/tests/inc/changelog_getRevisionsAround.test.php
diff --git a/_test/tests/inc/changelog_getRevisionsAround.php b/_test/tests/inc/changelog_getRevisionsAround.php
deleted file mode 100644
index d4d6b8496..000000000
--- a/_test/tests/inc/changelog_getRevisionsAround.php
+++ /dev/null
@@ -1,183 +0,0 @@
-getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
- /**
- * Surrounding revisions of rev1 and rev2 overlaps
- */
- function test_request_overlapping() {
- $rev1 = 1362526767;
- $rev2 = 1362527164;
- $max = 10;
- $revsexpected = array(
- array_slice($this->revsexpected, 5, 11),
- array_slice($this->revsexpected, 8, 11)
- );
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
- /**
- * Surrounding revisions of rev1 and rev2 don't overlap.
- */
- function test_request_non_overlapping() {
- $rev1 = 1362525899;
- $rev2 = 1368612599;
- $max = 10;
- $revsexpected = array(
- array_slice($this->revsexpected, 0, 11),
- array_slice($this->revsexpected, 13, 11)
- );
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
- /**
- * rev1 and rev2 are at start and end of the changelog.
- * Should return still a number of revisions equal to max
- */
- function test_request_first_last() {
- $rev1 = 1360110636;
- $rev2 = 1374261194;
- $max = 10;
- $revsexpected = array(
- array_slice($this->revsexpected, 0, 11),
- array_slice($this->revsexpected, 13, 11)
- );
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
-
- /**
- * Number of requested revisions is larger than available revisions,
- * so returns whole log
- */
- function test_request_wholelog() {
- $rev1 = 1362525899;
- $rev2 = 1368612599;
- $max = 50;
- $revsexpected = array($this->revsexpected, $this->revsexpected);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
- /**
- * When rev1 > rev2, their order is changed
- */
- function test_request_wrong_order_revs() {
- $rev1 = 1362527164;
- $rev2 = 1362526767;
- $max = 10;
- $revsexpected = array(
- array_slice($this->revsexpected, 5, 11),
- array_slice($this->revsexpected, 8, 11)
- );
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
-
- $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
- $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
- $this->assertEquals($revsexpected, $revs);
- }
-
-}
\ No newline at end of file
diff --git a/_test/tests/inc/changelog_getRevisionsAround.test.php b/_test/tests/inc/changelog_getRevisionsAround.test.php
new file mode 100644
index 000000000..2a5cb849e
--- /dev/null
+++ b/_test/tests/inc/changelog_getRevisionsAround.test.php
@@ -0,0 +1,188 @@
+getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * Surrounding revisions of rev1 and rev2 overlaps
+ */
+ function test_request_overlapping() {
+ $rev1 = 1362526767;
+ $rev2 = 1362527164;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 8, 11),
+ array_slice($this->revsexpected, 5, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * Surrounding revisions of rev1 and rev2 don't overlap.
+ */
+ function test_request_non_overlapping() {
+ $rev1 = 1362525899;
+ $rev2 = 1368612599;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 13, 11),
+ array_slice($this->revsexpected, 0, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * rev1 and rev2 are at start and end of the changelog.
+ * Should return still a number of revisions equal to max
+ */
+ function test_request_first_last() {
+ $rev1 = 1360110636;
+ $rev2 = 1374261194;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 13, 11),
+ array_slice($this->revsexpected, 0, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ //todo: number of revisions on the left side is not (yet) completed until max number
+ $revsexpected = array(
+ array_slice($this->revsexpected, 18, 6),
+ array_slice($this->revsexpected, 0, 11)
+ );
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+
+ /**
+ * Number of requested revisions is larger than available revisions,
+ * so returns whole log
+ */
+ function test_request_wholelog() {
+ $rev1 = 1362525899;
+ $rev2 = 1368612599;
+ $max = 50;
+ $revsexpected = array($this->revsexpected, $this->revsexpected);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+ /**
+ * When rev1 > rev2, their order is changed
+ */
+ function test_request_wrong_order_revs() {
+ $rev1 = 1362527164;
+ $rev2 = 1362526767;
+ $max = 10;
+ $revsexpected = array(
+ array_slice($this->revsexpected, 8, 11),
+ array_slice($this->revsexpected, 5, 11)
+ );
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+
+ $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
+ $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
+ $this->assertEquals($revsexpected, $revs);
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3
From 723eeeaec752d354de90bba38d758de312da1732 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Mon, 17 Feb 2014 00:20:02 +0100
Subject: replace arrows in names of diff links by texts
---
inc/html.php | 16 +++++++++-------
inc/lang/en/lang.php | 8 +++++---
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 3cce6ceab..8f3f43fde 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1207,6 +1207,7 @@ function html_diff($text='',$intro=true,$type=null){
//revisions navigation
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date'];
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
+ $l_revisions = array();
foreach($l_revs as $rev) {
$info = $pagelog->getRevisionInfo($rev);
$l_revisions[$rev] = array(
@@ -1215,6 +1216,7 @@ function html_diff($text='',$intro=true,$type=null){
$rev >= $r_rev
);
}
+ $r_revisions = array();
foreach($r_revs as $rev) {
$info = $pagelog->getRevisionInfo($rev);
$r_revisions[$rev] = array(
@@ -1232,8 +1234,8 @@ function html_diff($text='',$intro=true,$type=null){
$r_next = $r_revs[$r_index - 1];
if($l_prev) {
- html_diff_navigationlink($type, '←← ', $l_prev, $r_prev);
- html_diff_navigationlink($type, '← ', $l_prev, $r_rev);
+ html_diff_navigationlink($type, $lang['diffbothprevrev'], $l_prev, $r_prev);
+ html_diff_navigationlink($type, $lang['diffprevrev'], $l_prev, $r_rev);
}
$form = new Doku_Form(array('action'=>wl()));
@@ -1251,10 +1253,10 @@ function html_diff($text='',$intro=true,$type=null){
$form->printForm();
if($l_next < $r_rev) {
- html_diff_navigationlink($type, ' →', $l_next, $r_rev);
+ html_diff_navigationlink($type, $lang['diffnextrev'], $l_next, $r_rev);
}
if($l_rev < $r_prev) {
- html_diff_navigationlink($type, '← ', $l_rev, $r_prev);
+ html_diff_navigationlink($type, $lang['diffprevrev'], $l_rev, $r_prev);
}
$form = new Doku_Form(array('action'=>wl()));
@@ -1273,11 +1275,11 @@ function html_diff($text='',$intro=true,$type=null){
if($r_next) {
if($pagelog->isCurrentRevision($r_next)) {
- html_diff_navigationlink($type, ' →', $l_rev); //last
+ html_diff_navigationlink($type, $lang['difflastrev'], $l_rev);
} else {
- html_diff_navigationlink($type, ' →', $l_rev, $r_next); //next
+ html_diff_navigationlink($type, $lang['diffnextrev'], $l_rev, $r_next);
}
- html_diff_navigationlink($type, ' →→', $l_next, $r_next);
+ html_diff_navigationlink($type, $lang['diffbothnextrev'], $l_next, $r_next);
}
ptln('');
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 6c531f425..131af82a1 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -191,9 +191,11 @@ $lang['difflink'] = 'Link to this comparison view';
$lang['diff_type'] = 'View differences:';
$lang['diff_inline'] = 'Inline';
$lang['diff_side'] = 'Side by Side';
-$lang['diffpreviousedit'] = 'Previous edit';
-$lang['diffnextedit'] = 'Next edit';
-$lang['difflastedit'] = 'Last edit';
+$lang['diffprevrev'] = 'Previous revision';
+$lang['diffnextrev'] = 'Next revision';
+$lang['difflastrev'] = 'Last revision';
+$lang['diffbothprevrev'] = 'Both sides previous revision';
+$lang['diffbothnextrev'] = 'Both sides next revision';
$lang['overviewrevs'] = 'Overview of revisions';
$lang['line'] = 'Line';
$lang['breadcrumb'] = 'Trace';
--
cgit v1.2.3
From 51684808ed7a3b426f3fdb92186448b3d68d0464 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Mon, 17 Feb 2014 00:46:50 +0100
Subject: add comments to html_diff
---
inc/html.php | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 8f3f43fde..3accaa038 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1181,7 +1181,9 @@ function html_diff($text='',$intro=true,$type=null){
if (!$text) {
ptln('');
- //display type
+ /*
+ * display type and exact reference
+ */
$form = new Doku_Form(array('action'=>wl()));
$form->addHidden('id',$ID);
$form->addHidden('rev2[0]',$l_rev);
@@ -1204,8 +1206,10 @@ function html_diff($text='',$intro=true,$type=null){
html_diff_navigationlink($type, $lang['difflink'], $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
ptln('
');
- //revisions navigation
- $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date'];
+ /*
+ * Revisions navigation
+ */
+ $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
$l_revisions = array();
foreach($l_revs as $rev) {
@@ -1213,7 +1217,7 @@ function html_diff($text='',$intro=true,$type=null){
$l_revisions[$rev] = array(
$rev,
dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum'],
- $rev >= $r_rev
+ $rev >= $r_rev //disable?
);
}
$r_revisions = array();
@@ -1222,10 +1226,10 @@ function html_diff($text='',$intro=true,$type=null){
$r_revisions[$rev] = array(
$rev,
dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum'],
- $rev <= $l_rev
+ $rev <= $l_rev //disable?
);
}
-
+ //determine previous/next revisions
$l_index = array_search($l_rev, $l_revs);
$l_prev = $l_revs[$l_index + 1];
$l_next = $l_revs[$l_index - 1];
@@ -1233,11 +1237,12 @@ function html_diff($text='',$intro=true,$type=null){
$r_prev = $r_revs[$r_index + 1];
$r_next = $r_revs[$r_index - 1];
+ //move back
if($l_prev) {
html_diff_navigationlink($type, $lang['diffbothprevrev'], $l_prev, $r_prev);
html_diff_navigationlink($type, $lang['diffprevrev'], $l_prev, $r_rev);
}
-
+ //left dropdown
$form = new Doku_Form(array('action'=>wl()));
$form->addHidden('id',$ID);
$form->addHidden('difftype',$type);
@@ -1252,13 +1257,14 @@ function html_diff($text='',$intro=true,$type=null){
$form->addElement(form_makeButton('submit', 'diff','Go'));
$form->printForm();
+ //move forward/back
if($l_next < $r_rev) {
html_diff_navigationlink($type, $lang['diffnextrev'], $l_next, $r_rev);
}
if($l_rev < $r_prev) {
html_diff_navigationlink($type, $lang['diffprevrev'], $l_rev, $r_prev);
}
-
+ //rigth dropdown
$form = new Doku_Form(array('action'=>wl()));
$form->addHidden('id',$ID);
$form->addHidden('rev2[0]',$l_rev);
@@ -1272,10 +1278,10 @@ function html_diff($text='',$intro=true,$type=null){
array('class'=>'quickselect')));
$form->addElement(form_makeButton('submit', 'diff','Go'));
$form->printForm();
-
+ //move forward
if($r_next) {
if($pagelog->isCurrentRevision($r_next)) {
- html_diff_navigationlink($type, $lang['difflastrev'], $l_rev);
+ html_diff_navigationlink($type, $lang['difflastrev'], $l_rev); //last revision is diff with current page
} else {
html_diff_navigationlink($type, $lang['diffnextrev'], $l_rev, $r_next);
}
@@ -1284,6 +1290,9 @@ function html_diff($text='',$intro=true,$type=null){
ptln('
');
}
+ /*
+ * Diff view
+ */
?>
--
cgit v1.2.3
From ad9453f4c77a19d4a6537a37a742c2ebe588c5b3 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Mon, 17 Feb 2014 00:56:30 +0100
Subject: remove unnecessary strings and Dutch diff strings (better later once)
---
inc/lang/en/lang.php | 1 -
inc/lang/nl/lang.php | 4 ----
2 files changed, 5 deletions(-)
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 131af82a1..f76ce09ec 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -196,7 +196,6 @@ $lang['diffnextrev'] = 'Next revision';
$lang['difflastrev'] = 'Last revision';
$lang['diffbothprevrev'] = 'Both sides previous revision';
$lang['diffbothnextrev'] = 'Both sides next revision';
-$lang['overviewrevs'] = 'Overview of revisions';
$lang['line'] = 'Line';
$lang['breadcrumb'] = 'Trace';
$lang['youarehere'] = 'You are here';
diff --git a/inc/lang/nl/lang.php b/inc/lang/nl/lang.php
index 4a0a49306..e5e3e3c76 100644
--- a/inc/lang/nl/lang.php
+++ b/inc/lang/nl/lang.php
@@ -197,10 +197,6 @@ $lang['difflink'] = 'Link naar deze vergelijking';
$lang['diff_type'] = 'Bekijk verschillen:';
$lang['diff_inline'] = 'Inline';
$lang['diff_side'] = 'Zij aan zij';
-$lang['diffpreviousedit'] = 'Vorige bewerking';
-$lang['diffnextedit'] = 'Volgende bewerking';
-$lang['difflastedit'] = 'Laatste bewerking';
-$lang['overviewrevs'] = 'Overzicht van revisies';
$lang['line'] = 'Regel';
$lang['breadcrumb'] = 'Spoor';
$lang['youarehere'] = 'Je bent hier';
--
cgit v1.2.3
From 98a6b21422744d0a705ef5afe6983e2797135d99 Mon Sep 17 00:00:00 2001
From: Anika Henke
Date: Mon, 17 Feb 2014 01:46:56 +0000
Subject: roughly styled diff nav row
---
inc/html.php | 37 ++++++++++++++++++++-----------------
lib/tpl/dokuwiki/css/_diff.css | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 3accaa038..ad72b78a6 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1203,12 +1203,14 @@ function html_diff($text='',$intro=true,$type=null){
ptln('');
// link to exactly this view FS#2835
- html_diff_navigationlink($type, $lang['difflink'], $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
- ptln('
');
+ html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
+ ptln('');
/*
* Revisions navigation
*/
+ ptln('');
+
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
$l_revisions = array();
@@ -1239,8 +1241,8 @@ function html_diff($text='',$intro=true,$type=null){
//move back
if($l_prev) {
- html_diff_navigationlink($type, $lang['diffbothprevrev'], $l_prev, $r_prev);
- html_diff_navigationlink($type, $lang['diffprevrev'], $l_prev, $r_rev);
+ html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
+ html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
}
//left dropdown
$form = new Doku_Form(array('action'=>wl()));
@@ -1259,10 +1261,10 @@ function html_diff($text='',$intro=true,$type=null){
//move forward/back
if($l_next < $r_rev) {
- html_diff_navigationlink($type, $lang['diffnextrev'], $l_next, $r_rev);
+ html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
}
if($l_rev < $r_prev) {
- html_diff_navigationlink($type, $lang['diffprevrev'], $l_rev, $r_prev);
+ html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
}
//rigth dropdown
$form = new Doku_Form(array('action'=>wl()));
@@ -1281,14 +1283,15 @@ function html_diff($text='',$intro=true,$type=null){
//move forward
if($r_next) {
if($pagelog->isCurrentRevision($r_next)) {
- html_diff_navigationlink($type, $lang['difflastrev'], $l_rev); //last revision is diff with current page
+ html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
} else {
- html_diff_navigationlink($type, $lang['diffnextrev'], $l_rev, $r_next);
+ html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
}
- html_diff_navigationlink($type, $lang['diffbothnextrev'], $l_next, $r_next);
+ html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
}
- ptln('
');
+ ptln(''); // .diffnav
+ ptln(''); // .diffoptions
}
/*
* Diff view
@@ -1326,29 +1329,29 @@ function html_diff($text='',$intro=true,$type=null){
/**
* Create html link to a diff defined by two revisions
*
- * @param string $type display type
+ * @param string $difftype display type
+ * @param string $linktype
* @param int $lrev oldest revision
* @param int $rrev newest revision or null for diff with current revision
- * @param string $name
* @return string html of link to a diff
*/
-function html_diff_navigationlink($type, $name, $lrev, $rrev = null) {
- global $ID;
+function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
+ global $ID, $lang;
if($rrev === null) {
$urlparam = array(
'do' => 'diff',
'rev' => $lrev,
- 'difftype' => $type,
+ 'difftype' => $difftype,
);
} else {
$urlparam = array(
'do' => 'diff',
'rev2[0]' => $lrev,
'rev2[1]' => $rrev,
- 'difftype' => $type,
+ 'difftype' => $difftype,
);
}
- ptln('' . $name . '');
+ ptln('' . $lang[$linktype] . '');
}
function html_insert_softbreaks($diffhtml) {
diff --git a/lib/tpl/dokuwiki/css/_diff.css b/lib/tpl/dokuwiki/css/_diff.css
index b7c82d829..28cde7786 100644
--- a/lib/tpl/dokuwiki/css/_diff.css
+++ b/lib/tpl/dokuwiki/css/_diff.css
@@ -73,3 +73,41 @@
background-color: inherit;
font-weight: bold;
}
+
+/* diff nav */
+
+.dokuwiki .diffnav a {
+ display: inline-block;
+ vertical-align: middle;
+}
+.dokuwiki .diffnav a span {
+ display: none;
+}
+
+.dokuwiki .diffnav a:before {
+ font-size: 1.2em;
+ display: inline-block;
+ line-height: 1;
+ padding: .1em .2em;
+ border: 1px solid @ini_border;
+ border-radius: 2px;
+ color: @ini_text;
+}
+
+.dokuwiki .diffnav a.diffprevrev:before {
+ content: '\25C0'; /* left triangle */
+}
+.dokuwiki .diffnav a.diffnextrev:before,
+.dokuwiki .diffnav a.difflastrev:before {
+ content: '\25B6'; /* right triangle */
+}
+.dokuwiki .diffnav a.diffbothprevrev:before {
+ content: '\25C0\25C0';
+}
+.dokuwiki .diffnav a.diffbothnextrev:before {
+ content: '\25B6\25B6';
+}
+
+.dokuwiki .diffnav select {
+ width: 15em;
+}
--
cgit v1.2.3
From 04e99fe1c566aa96e5a6ccf95e51bde362c67b44 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Mon, 17 Feb 2014 14:31:35 +0100
Subject: Code reformatting html_diff
---
inc/html.php | 208 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 112 insertions(+), 96 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index ad72b78a6..0d2c21638 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1080,14 +1080,14 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
}
/**
- * show diff
+ * Show diff
*
* @author Andreas Gohr
- * @param string $text - compare with this text with most current version
- * @param bool $intro - display the intro text
- * @param string $type type of the diff (inline or sidebyside)
+ * @param string $text compare with this text with most current version
+ * @param bool $intro display the intro text
+ * @param string $type type of the diff (inline or sidebyside)
*/
-function html_diff($text='',$intro=true,$type=null){
+function html_diff($text = '', $intro = true, $type = null) {
global $ID;
global $REV;
global $lang;
@@ -1097,9 +1097,9 @@ function html_diff($text='',$intro=true,$type=null){
if(!$type) {
$type = $INPUT->str('difftype');
- if (empty($type)) {
+ if(empty($type)) {
$type = get_doku_pref('difftype', $type);
- if (empty($type) && $INFO['ismobile']) {
+ if(empty($type) && $INFO['ismobile']) {
$type = 'inline';
}
}
@@ -1112,45 +1112,45 @@ function html_diff($text='',$intro=true,$type=null){
$rev1 = $REV;
$rev2 = $INPUT->ref('rev2');
- if(is_array($rev2)){
+ if(is_array($rev2)) {
$rev1 = (int) $rev2[0];
$rev2 = (int) $rev2[1];
- if(!$rev1){
+ if(!$rev1) {
$rev1 = $rev2;
unset($rev2);
}
- }else{
+ } else {
$rev2 = $INPUT->int('rev2');
}
$r_minor = '';
$l_minor = '';
- if($text){ // compare text to the most current revision
- $l_rev = '';
- $l_text = rawWiki($ID,'');
- $l_head = ''.
- $ID.' '.dformat((int) @filemtime(wikiFN($ID))).' '.
+ if($text) { // compare text to the most current revision
+ $l_rev = '';
+ $l_text = rawWiki($ID, '');
+ $l_head = '' .
+ $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . ' ' .
$lang['current'];
- $r_rev = '';
- $r_text = cleanText($text);
- $r_head = $lang['yours'];
- }else{
- if($rev1 && isset($rev2) && $rev2){ // two specific revisions wanted
+ $r_rev = '';
+ $r_text = cleanText($text);
+ $r_head = $lang['yours'];
+ } else {
+ if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
// make sure order is correct (older on the left)
- if($rev1 < $rev2){
+ if($rev1 < $rev2) {
$l_rev = $rev1;
$r_rev = $rev2;
- }else{
+ } else {
$l_rev = $rev2;
$r_rev = $rev1;
}
- }elseif($rev1){ // single revision given, compare to current
+ } elseif($rev1) { // single revision given, compare to current
$r_rev = '';
$l_rev = $rev1;
- }else{ // no revision was given, compare previous to current
+ } else { // no revision was given, compare previous to current
$r_rev = '';
$revs = $pagelog->getRevisions(0, 1);
$l_rev = $revs[0];
@@ -1158,54 +1158,60 @@ function html_diff($text='',$intro=true,$type=null){
}
// when both revisions are empty then the page was created just now
- if(!$l_rev && !$r_rev){
+ if(!$l_rev && !$r_rev) {
$l_text = '';
- }else{
- $l_text = rawWiki($ID,$l_rev);
+ } else {
+ $l_text = rawWiki($ID, $l_rev);
}
- $r_text = rawWiki($ID,$r_rev);
+ $r_text = rawWiki($ID, $r_rev);
list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
}
- $df = new Diff(explode("\n",$l_text),explode("\n",$r_text));
+ $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
- if($type == 'inline'){
- $tdf = new InlineDiffFormatter();
+ if($type == 'inline') {
+ $diffformatter = new InlineDiffFormatter();
} else {
- $tdf = new TableDiffFormatter();
+ $diffformatter = new TableDiffFormatter();
}
if($intro) print p_locale_xhtml('diff');
- if (!$text) {
+ if(!$text) {
ptln('');
/*
* display type and exact reference
*/
- $form = new Doku_Form(array('action'=>wl()));
- $form->addHidden('id',$ID);
- $form->addHidden('rev2[0]',$l_rev);
- $form->addHidden('rev2[1]',$r_rev);
- $form->addHidden('do','diff');
- $form->addElement(form_makeListboxField(
- 'difftype',
- array(
- 'sidebyside' => $lang['diff_side'],
- 'inline' => $lang['diff_inline']),
- $type,
- $lang['diff_type'],
- '','',
- array('class'=>'quickselect')));
- $form->addElement(form_makeButton('submit', 'diff','Go'));
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('rev2[0]', $l_rev);
+ $form->addHidden('rev2[1]', $r_rev);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'difftype',
+ array(
+ 'sidebyside' => $lang['diff_side'],
+ 'inline' => $lang['diff_inline']
+ ),
+ $type,
+ $lang['diff_type'],
+ '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
$form->printForm();
ptln('
');
// link to exactly this view FS#2835
html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
ptln('
');
+ }
+ if(!$text) {
/*
* Revisions navigation
*/
@@ -1218,7 +1224,7 @@ function html_diff($text='',$intro=true,$type=null){
$info = $pagelog->getRevisionInfo($rev);
$l_revisions[$rev] = array(
$rev,
- dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum'],
+ dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
$rev >= $r_rev //disable?
);
}
@@ -1227,7 +1233,7 @@ function html_diff($text='',$intro=true,$type=null){
$info = $pagelog->getRevisionInfo($rev);
$r_revisions[$rev] = array(
$rev,
- dformat($info['date']).' '.editorinfo($info['user']).' '.$info['sum'],
+ dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
$rev <= $l_rev //disable?
);
}
@@ -1245,18 +1251,21 @@ function html_diff($text='',$intro=true,$type=null){
html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
}
//left dropdown
- $form = new Doku_Form(array('action'=>wl()));
- $form->addHidden('id',$ID);
- $form->addHidden('difftype',$type);
- $form->addHidden('rev2[1]',$r_rev);
- $form->addHidden('do','diff');
- $form->addElement(form_makeListboxField(
- 'rev2[0]',
- $l_revisions,
- $l_rev,
- '','','',
- array('class'=>'quickselect')));
- $form->addElement(form_makeButton('submit', 'diff','Go'));
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('difftype', $type);
+ $form->addHidden('rev2[1]', $r_rev);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'rev2[0]',
+ $l_revisions,
+ $l_rev,
+ '', '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
$form->printForm();
//move forward/back
@@ -1267,18 +1276,21 @@ function html_diff($text='',$intro=true,$type=null){
html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
}
//rigth dropdown
- $form = new Doku_Form(array('action'=>wl()));
- $form->addHidden('id',$ID);
- $form->addHidden('rev2[0]',$l_rev);
- $form->addHidden('difftype',$type);
- $form->addHidden('do','diff');
- $form->addElement(form_makeListboxField(
- 'rev2[1]',
- $r_revisions,
- $r_rev,
- '','','',
- array('class'=>'quickselect')));
- $form->addElement(form_makeButton('submit', 'diff','Go'));
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('rev2[0]', $l_rev);
+ $form->addHidden('difftype', $type);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'rev2[1]',
+ $r_revisions,
+ $r_rev,
+ '', '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
$form->printForm();
//move forward
if($r_next) {
@@ -1293,37 +1305,41 @@ function html_diff($text='',$intro=true,$type=null){
ptln('
'); // .diffnav
ptln(''); // .diffoptions
}
+
/*
* Diff view
*/
?>
-
-
-
- >
-
- |
-
-
- >
-
- |
-
+
+
+
+
+ >
+
+ |
+
+
+
+ >
+
+ |
+
-
- >
-
- |
- >
-
- |
-
+
+ >
+
+ |
+ >
+
+ |
+
format($df)); ?>
+ echo html_insert_softbreaks($diffformatter->format($diff)); ?>
-
Date: Mon, 17 Feb 2014 15:52:54 +0100
Subject: Put diff navigation in diff view table
---
inc/html.php | 65 +++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 42 insertions(+), 23 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 0d2c21638..fb44cd655 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1209,14 +1209,16 @@ function html_diff($text = '', $intro = true, $type = null) {
// link to exactly this view FS#2835
html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
ptln('');
+
+ ptln(''); // .diffoptions
}
+ $l_nav = '';
+ $r_nav = '';
if(!$text) {
/*
* Revisions navigation
*/
- ptln('');
-
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
$l_revisions = array();
@@ -1245,10 +1247,11 @@ function html_diff($text = '', $intro = true, $type = null) {
$r_prev = $r_revs[$r_index + 1];
$r_next = $r_revs[$r_index - 1];
+
//move back
if($l_prev) {
- html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
- html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
+ $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
+ $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
}
//left dropdown
$form = new Doku_Form(array('action' => wl()));
@@ -1266,14 +1269,15 @@ function html_diff($text = '', $intro = true, $type = null) {
)
);
$form->addElement(form_makeButton('submit', 'diff', 'Go'));
- $form->printForm();
-
- //move forward/back
+ $l_nav .= $form->getForm();
+ //move forward
if($l_next < $r_rev) {
- html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
+ $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
}
+
+ //move back
if($l_rev < $r_prev) {
- html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
+ $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
}
//rigth dropdown
$form = new Doku_Form(array('action' => wl()));
@@ -1291,19 +1295,16 @@ function html_diff($text = '', $intro = true, $type = null) {
)
);
$form->addElement(form_makeButton('submit', 'diff', 'Go'));
- $form->printForm();
+ $r_nav .= $form->getForm();
//move forward
if($r_next) {
if($pagelog->isCurrentRevision($r_next)) {
- html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
+ $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
} else {
- html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
+ $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
}
- html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
+ $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
}
-
- ptln('
'); // .diffnav
- ptln(''); // .diffoptions
}
/*
@@ -1313,12 +1314,22 @@ function html_diff($text = '', $intro = true, $type = null) {
+ if($type == 'inline') {
+ if(!$text) { ?>
+
+
+ |
+
+
+
+ >
+
+ |
+
+
-
- >
-
- |
+
+ |
@@ -1326,7 +1337,13 @@ function html_diff($text = '', $intro = true, $type = null) {
-
+
+
+ |
+ |
+
+
>
@@ -1367,7 +1384,9 @@ function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
'difftype' => $difftype,
);
}
- ptln('' . $lang[$linktype] . '');
+ return '' .
+ '' . $lang[$linktype] . '' .
+ '' . "\n";
}
function html_insert_softbreaks($diffhtml) {
--
cgit v1.2.3
From c7686ac1482eea421fa245b2a448d55ad2b483b7 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Mon, 17 Feb 2014 16:56:32 +0100
Subject: Reorganise generation and displaying of html. Added comments
---
inc/html.php | 193 +++++++++++++++++++++++++++++++++--------------------------
1 file changed, 107 insertions(+), 86 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index fb44cd655..cda971f3d 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1095,6 +1095,9 @@ function html_diff($text = '', $intro = true, $type = null) {
global $INFO;
$pagelog = new PageChangeLog($ID);
+ /*
+ * Determine diff type
+ */
if(!$type) {
$type = $INPUT->str('difftype');
if(empty($type)) {
@@ -1106,6 +1109,9 @@ function html_diff($text = '', $intro = true, $type = null) {
}
if($type != 'inline') $type = 'sidebyside';
+ /*
+ * Determine requested revision(s)
+ */
// we're trying to be clever here, revisions to compare can be either
// given as rev and rev2 parameters, with rev2 being optional. Or in an
// array in rev2.
@@ -1124,6 +1130,9 @@ function html_diff($text = '', $intro = true, $type = null) {
$rev2 = $INPUT->int('rev2');
}
+ /*
+ * Determine left and right revision, its texts and the header
+ */
$r_minor = '';
$l_minor = '';
@@ -1168,58 +1177,14 @@ function html_diff($text = '', $intro = true, $type = null) {
list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
}
- $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
-
- if($type == 'inline') {
- $diffformatter = new InlineDiffFormatter();
- } else {
- $diffformatter = new TableDiffFormatter();
- }
-
- if($intro) print p_locale_xhtml('diff');
-
- if(!$text) {
- ptln('');
-
- /*
- * display type and exact reference
- */
- $form = new Doku_Form(array('action' => wl()));
- $form->addHidden('id', $ID);
- $form->addHidden('rev2[0]', $l_rev);
- $form->addHidden('rev2[1]', $r_rev);
- $form->addHidden('do', 'diff');
- $form->addElement(
- form_makeListboxField(
- 'difftype',
- array(
- 'sidebyside' => $lang['diff_side'],
- 'inline' => $lang['diff_inline']
- ),
- $type,
- $lang['diff_type'],
- '', '',
- array('class' => 'quickselect')
- )
- );
- $form->addElement(form_makeButton('submit', 'diff', 'Go'));
- $form->printForm();
-
- ptln(' ');
- // link to exactly this view FS#2835
- html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
- ptln(' ');
-
- ptln(' '); // .diffoptions
- }
-
+ /*
+ * Build navigation
+ */
$l_nav = '';
$r_nav = '';
if(!$text) {
- /*
- * Revisions navigation
- */
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog
+ //retrieve revisions with additional info
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
$l_revisions = array();
foreach($l_revs as $rev) {
@@ -1247,13 +1212,13 @@ function html_diff($text = '', $intro = true, $type = null) {
$r_prev = $r_revs[$r_index + 1];
$r_next = $r_revs[$r_index - 1];
-
+ //Left side:
//move back
if($l_prev) {
$l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
$l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
}
- //left dropdown
+ //dropdown
$form = new Doku_Form(array('action' => wl()));
$form->addHidden('id', $ID);
$form->addHidden('difftype', $type);
@@ -1275,11 +1240,12 @@ function html_diff($text = '', $intro = true, $type = null) {
$l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
}
+ //Right side:
//move back
if($l_rev < $r_prev) {
$r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
}
- //rigth dropdown
+ //dropdown
$form = new Doku_Form(array('action' => wl()));
$form->addHidden('id', $ID);
$form->addHidden('rev2[0]', $l_rev);
@@ -1306,54 +1272,109 @@ function html_diff($text = '', $intro = true, $type = null) {
$r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
}
}
+ /*
+ * Create diff object and the formatter
+ */
+ $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
+
+ if($type == 'inline') {
+ $diffformatter = new InlineDiffFormatter();
+ } else {
+ $diffformatter = new TableDiffFormatter();
+ }
+ /*
+ * Display intro
+ */
+ if($intro) print p_locale_xhtml('diff');
/*
- * Diff view
+ * Display type and exact reference
+ */
+ if(!$text) {
+ ptln('');
+
+
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('rev2[0]', $l_rev);
+ $form->addHidden('rev2[1]', $r_rev);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'difftype',
+ array(
+ 'sidebyside' => $lang['diff_side'],
+ 'inline' => $lang['diff_inline']
+ ),
+ $type,
+ $lang['diff_type'],
+ '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
+ $form->printForm();
+
+ ptln(' ');
+ // link to exactly this view FS#2835
+ html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
+ ptln(' ');
+
+ ptln(' '); // .diffoptions
+ }
+
+ /*
+ * Display diff view table
*/
?>
-
+
+
+
+
+ |
+
+
+
+ >
+
+ |
+
+
-
- |
+
+ |
-
- >
-
+ |
+ >
+
|
-
-
-
- |
-
-
-
- >
-
- |
-
-
+
+
+ |
+ |
+
+
- |
- |
+ >
+
+ |
+ >
+
+ |
-
-
- >
-
- |
- >
-
- |
-
- format($diff)); ?>
+ format($diff)); ?>
+
Date: Mon, 17 Feb 2014 17:27:54 +0100
Subject: Improve PHPDocs html.php
---
inc/html.php | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index cda971f3d..05688e0aa 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -19,6 +19,7 @@ if(!defined('NL')) define('NL',"\n");
* @return string the HTML code of the link
*/
function html_wikilink($id,$name=null,$search=''){
+ /** @var Doku_Renderer_xhtml $xhtml_renderer */
static $xhtml_renderer = null;
if(is_null($xhtml_renderer)){
$xhtml_renderer = p_get_renderer('xhtml');
@@ -1410,6 +1411,12 @@ function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
'' . "\n";
}
+/**
+ * Insert soft breaks in diff html
+ *
+ * @param $diffhtml
+ * @return string
+ */
function html_insert_softbreaks($diffhtml) {
// search the diff html string for both:
// - html tags, so these can be ignored
@@ -1417,6 +1424,12 @@ function html_insert_softbreaks($diffhtml) {
return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
}
+/**
+ * callback which adds softbreaks
+ *
+ * @param array $match array with first the complete match
+ * @return string the replacement
+ */
function html_softbreak_callback($match){
// if match is an html tag, return it intact
if ($match[0]{0} == '<') return $match[0];
@@ -1528,7 +1541,7 @@ function html_updateprofile(){
global $conf;
global $INPUT;
global $INFO;
- /** @var auth_basic $auth */
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
print p_locale_xhtml('updateprofile');
@@ -1744,7 +1757,7 @@ function html_minoredit(){
function html_debug(){
global $conf;
global $lang;
- /** @var auth_basic $auth */
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
global $INFO;
--
cgit v1.2.3
From baf0c3e506eee97c63d130af88fe3547c31579cc Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Tue, 18 Feb 2014 21:59:16 +0100
Subject: extract navigation html to separated method
---
inc/html.php | 208 +++++++++++++++++++++++++++++++++--------------------------
1 file changed, 118 insertions(+), 90 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 05688e0aa..7d533282e 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1082,9 +1082,11 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa
/**
* Show diff
+ * between current page version and provided $text
+ * or between the revisions provided via GET or POST
*
* @author Andreas Gohr
- * @param string $text compare with this text with most current version
+ * @param string $text when non-empty: compare with this text with most current version
* @param bool $intro display the intro text
* @param string $type type of the diff (inline or sidebyside)
*/
@@ -1184,94 +1186,7 @@ function html_diff($text = '', $intro = true, $type = null) {
$l_nav = '';
$r_nav = '';
if(!$text) {
- $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog
- //retrieve revisions with additional info
- list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
- $l_revisions = array();
- foreach($l_revs as $rev) {
- $info = $pagelog->getRevisionInfo($rev);
- $l_revisions[$rev] = array(
- $rev,
- dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
- $rev >= $r_rev //disable?
- );
- }
- $r_revisions = array();
- foreach($r_revs as $rev) {
- $info = $pagelog->getRevisionInfo($rev);
- $r_revisions[$rev] = array(
- $rev,
- dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
- $rev <= $l_rev //disable?
- );
- }
- //determine previous/next revisions
- $l_index = array_search($l_rev, $l_revs);
- $l_prev = $l_revs[$l_index + 1];
- $l_next = $l_revs[$l_index - 1];
- $r_index = array_search($r_rev, $r_revs);
- $r_prev = $r_revs[$r_index + 1];
- $r_next = $r_revs[$r_index - 1];
-
- //Left side:
- //move back
- if($l_prev) {
- $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
- $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
- }
- //dropdown
- $form = new Doku_Form(array('action' => wl()));
- $form->addHidden('id', $ID);
- $form->addHidden('difftype', $type);
- $form->addHidden('rev2[1]', $r_rev);
- $form->addHidden('do', 'diff');
- $form->addElement(
- form_makeListboxField(
- 'rev2[0]',
- $l_revisions,
- $l_rev,
- '', '', '',
- array('class' => 'quickselect')
- )
- );
- $form->addElement(form_makeButton('submit', 'diff', 'Go'));
- $l_nav .= $form->getForm();
- //move forward
- if($l_next < $r_rev) {
- $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
- }
-
- //Right side:
- //move back
- if($l_rev < $r_prev) {
- $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
- }
- //dropdown
- $form = new Doku_Form(array('action' => wl()));
- $form->addHidden('id', $ID);
- $form->addHidden('rev2[0]', $l_rev);
- $form->addHidden('difftype', $type);
- $form->addHidden('do', 'diff');
- $form->addElement(
- form_makeListboxField(
- 'rev2[1]',
- $r_revisions,
- $r_rev,
- '', '', '',
- array('class' => 'quickselect')
- )
- );
- $form->addElement(form_makeButton('submit', 'diff', 'Go'));
- $r_nav .= $form->getForm();
- //move forward
- if($r_next) {
- if($pagelog->isCurrentRevision($r_next)) {
- $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
- } else {
- $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
- }
- $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
- }
+ list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
}
/*
* Create diff object and the formatter
@@ -1318,7 +1233,7 @@ function html_diff($text = '', $intro = true, $type = null) {
ptln('');
// link to exactly this view FS#2835
- html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
+ echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']);
ptln(' ');
ptln(''); // .diffoptions
@@ -1381,6 +1296,118 @@ function html_diff($text = '', $intro = true, $type = null) {
getRevisionsAround($l_rev, $r_rev);
+ $l_revisions = array();
+ foreach($l_revs as $rev) {
+ $info = $pagelog->getRevisionInfo($rev);
+ $l_revisions[$rev] = array(
+ $rev,
+ dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
+ $rev >= $r_rev //disable?
+ );
+ }
+ $r_revisions = array();
+ foreach($r_revs as $rev) {
+ $info = $pagelog->getRevisionInfo($rev);
+ $r_revisions[$rev] = array(
+ $rev,
+ dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
+ $rev <= $l_rev //disable?
+ );
+ }
+ //determine previous/next revisions
+ $l_index = array_search($l_rev, $l_revs);
+ $l_prev = $l_revs[$l_index + 1];
+ $l_next = $l_revs[$l_index - 1];
+ $r_index = array_search($r_rev, $r_revs);
+ $r_prev = $r_revs[$r_index + 1];
+ $r_next = $r_revs[$r_index - 1];
+
+
+ /*
+ * Left side:
+ */
+ $l_nav = '';
+ //move back
+ if($l_prev) {
+ $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
+ $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
+ }
+ //dropdown
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('difftype', $type);
+ $form->addHidden('rev2[1]', $r_rev);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'rev2[0]',
+ $l_revisions,
+ $l_rev,
+ '', '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
+ $l_nav .= $form->getForm();
+ //move forward
+ if($l_next < $r_rev) {
+ $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
+ }
+
+ /*
+ * Right side:
+ */
+ $r_nav = '';
+ //move back
+ if($l_rev < $r_prev) {
+ $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
+ }
+ //dropdown
+ $form = new Doku_Form(array('action' => wl()));
+ $form->addHidden('id', $ID);
+ $form->addHidden('rev2[0]', $l_rev);
+ $form->addHidden('difftype', $type);
+ $form->addHidden('do', 'diff');
+ $form->addElement(
+ form_makeListboxField(
+ 'rev2[1]',
+ $r_revisions,
+ $r_rev,
+ '', '', '',
+ array('class' => 'quickselect')
+ )
+ );
+ $form->addElement(form_makeButton('submit', 'diff', 'Go'));
+ $r_nav .= $form->getForm();
+ //move forward
+ if($r_next) {
+ if($pagelog->isCurrentRevision($r_next)) {
+ $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
+ } else {
+ $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
+ }
+ $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
+ }
+ return array($l_nav, $r_nav);
+}
+
/**
* Create html link to a diff defined by two revisions
*
@@ -1715,6 +1742,7 @@ function html_edit(){
* Display the default edit form
*
* Is the default action for HTML_EDIT_FORMSELECTION.
+ * @param mixed[] $param
*/
function html_edit_form($param) {
global $TEXT;
--
cgit v1.2.3
From af59854ba94dae9584db04d5688dddb581503d33 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Tue, 18 Feb 2014 22:25:53 +0100
Subject: Check if revision is defined at all before comparing
---
inc/html.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/inc/html.php b/inc/html.php
index 7d533282e..e7d401594 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1339,7 +1339,6 @@ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
$r_prev = $r_revs[$r_index + 1];
$r_next = $r_revs[$r_index - 1];
-
/*
* Left side:
*/
@@ -1367,7 +1366,7 @@ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
$form->addElement(form_makeButton('submit', 'diff', 'Go'));
$l_nav .= $form->getForm();
//move forward
- if($l_next < $r_rev) {
+ if($l_next && $l_next < $r_rev) {
$l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
}
--
cgit v1.2.3
From 8f3927df350b53ee1287d66b36e9b29452c864f4 Mon Sep 17 00:00:00 2001
From: Anika Henke
Date: Wed, 19 Feb 2014 01:21:07 +0000
Subject: improved styling of diff nav row
---
lib/tpl/dokuwiki/css/_diff.css | 18 +++++++++--
lib/tpl/dokuwiki/css/basic.less | 1 +
lib/tpl/dokuwiki/css/mobile.less | 6 ++--
lib/tpl/dokuwiki/css/sites/abcwiki.css | 39 +++++++++++++++++++++++
lib/tpl/dokuwiki/css/sites/paralis.css | 58 ++++++++++++++++++++++++++++++++++
5 files changed, 118 insertions(+), 4 deletions(-)
create mode 100644 lib/tpl/dokuwiki/css/sites/abcwiki.css
create mode 100644 lib/tpl/dokuwiki/css/sites/paralis.css
diff --git a/lib/tpl/dokuwiki/css/_diff.css b/lib/tpl/dokuwiki/css/_diff.css
index 28cde7786..13c3012d9 100644
--- a/lib/tpl/dokuwiki/css/_diff.css
+++ b/lib/tpl/dokuwiki/css/_diff.css
@@ -76,6 +76,9 @@
/* diff nav */
+.dokuwiki table.diff_sidebyside td.diffnav {
+ padding-bottom: .7em;
+}
.dokuwiki .diffnav a {
display: inline-block;
vertical-align: middle;
@@ -84,11 +87,17 @@
display: none;
}
+.dokuwiki .diffnav a:hover,
+.dokuwiki .diffnav a:active,
+.dokuwiki .diffnav a:focus {
+ background-color: @ini_background_alt;
+ text-decoration: none;
+}
+
.dokuwiki .diffnav a:before {
- font-size: 1.2em;
display: inline-block;
line-height: 1;
- padding: .1em .2em;
+ padding: .2em .4em;
border: 1px solid @ini_border;
border-radius: 2px;
color: @ini_text;
@@ -110,4 +119,9 @@
.dokuwiki .diffnav select {
width: 15em;
+ height: 1.5em; /* height is necessary for longer options in Webkit */
+}
+
+.dokuwiki .diffnav select option[selected] {
+ font-weight: bold;
}
diff --git a/lib/tpl/dokuwiki/css/basic.less b/lib/tpl/dokuwiki/css/basic.less
index c296185e9..ac9f6803a 100644
--- a/lib/tpl/dokuwiki/css/basic.less
+++ b/lib/tpl/dokuwiki/css/basic.less
@@ -455,6 +455,7 @@ input[disabled],
button[disabled],
select[disabled],
textarea[disabled],
+option[disabled],
input[readonly],
button[readonly],
select[readonly],
diff --git a/lib/tpl/dokuwiki/css/mobile.less b/lib/tpl/dokuwiki/css/mobile.less
index 0fbd0e8fe..6d552876d 100644
--- a/lib/tpl/dokuwiki/css/mobile.less
+++ b/lib/tpl/dokuwiki/css/mobile.less
@@ -266,11 +266,13 @@ body {
#config__manager td .input,
.dokuwiki fieldset,
.dokuwiki input.edit,
-.dokuwiki textarea,
-.dokuwiki select {
+.dokuwiki textarea {
width: auto !important;
max-width: 100% !important;
}
+.dokuwiki select {
+ max-width: 100% !important;
+}
#config__manager fieldset {
margin-left: 0;
margin-right: 0;
diff --git a/lib/tpl/dokuwiki/css/sites/abcwiki.css b/lib/tpl/dokuwiki/css/sites/abcwiki.css
new file mode 100644
index 000000000..9f436516b
--- /dev/null
+++ b/lib/tpl/dokuwiki/css/sites/abcwiki.css
@@ -0,0 +1,39 @@
+
+html,
+body {
+ background-color: #369;
+}
+
+#dokuwiki__header,
+#dokuwiki__aside,
+.docInfo,
+#dokuwiki__footer {
+ color: #fff;
+}
+
+#dokuwiki__header a,
+#dokuwiki__aside a,
+.docInfo a,
+#dokuwiki__footer a {
+ color: #ff9 !important;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+ color: #036;
+}
+
+.dokuwiki div.breadcrumbs {
+ border-top-color: #999;
+ border-bottom-color: #666;
+}
+.dokuwiki div.breadcrumbs div:first-child {
+ border-bottom-color: #999;
+}
+.dokuwiki div.breadcrumbs div:last-child {
+ border-top-color: #666;
+}
diff --git a/lib/tpl/dokuwiki/css/sites/paralis.css b/lib/tpl/dokuwiki/css/sites/paralis.css
new file mode 100644
index 000000000..201bca936
--- /dev/null
+++ b/lib/tpl/dokuwiki/css/sites/paralis.css
@@ -0,0 +1,58 @@
+
+@media screen {
+
+body {
+ font: normal 100%/1.4 Frutiger, Calibri, "Myriad Pro", Myriad, "Nimbus Sans L", Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5,
+h6 {
+ font-family: Constantia, Utopia, Lucidabright, Lucida, Georgia, "Nimbus Roman No9 L", serif;
+ color: @ini_text_neu;
+}
+
+q {
+ font-style: italic;
+}
+
+#dokuwiki__header h1 a {
+ color: @ini_link;
+ font-weight: bold;
+}
+
+div.dokuwiki p.plugin__pagenav {
+ margin: 0 0 1.4em;
+}
+
+
+} /* /@media */
+
+
+#dokuwiki__header h1 {
+ position: relative;
+}
+#dokuwiki__header h1 img {
+ position: absolute;
+ top: -27px;
+ left: -33px;
+ max-width: none;
+}
+#dokuwiki__header h1 {
+ padding-left: 110px;
+}
+#dokuwiki__header p.claim {
+ padding-left: 110px;
+}
+
+
+@media print {
+
+.dokuwiki p.plugin__pagenav {
+ display: none;
+}
+
+} /* /@media */
--
cgit v1.2.3
From c130b0f8ec18ec66ac40422cf354a23268108866 Mon Sep 17 00:00:00 2001
From: Anika Henke
Date: Wed, 19 Feb 2014 01:34:14 +0000
Subject: improved positioning of diff options
---
inc/html.php | 2 +-
lib/tpl/dokuwiki/css/_diff.css | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/inc/html.php b/inc/html.php
index e7d401594..1a549824e 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1207,7 +1207,7 @@ function html_diff($text = '', $intro = true, $type = null) {
* Display type and exact reference
*/
if(!$text) {
- ptln('');
+ ptln(' ');
$form = new Doku_Form(array('action' => wl()));
diff --git a/lib/tpl/dokuwiki/css/_diff.css b/lib/tpl/dokuwiki/css/_diff.css
index 13c3012d9..09e95d9f6 100644
--- a/lib/tpl/dokuwiki/css/_diff.css
+++ b/lib/tpl/dokuwiki/css/_diff.css
@@ -74,6 +74,15 @@
font-weight: bold;
}
+/* diff options */
+
+.dokuwiki .diffoptions form {
+ float: left;
+}
+.dokuwiki .diffoptions p {
+ float: right;
+}
+
/* diff nav */
.dokuwiki table.diff_sidebyside td.diffnav {
--
cgit v1.2.3
From 621bbd2a24f6ceac0310c04b27e11a2c7c325294 Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Wed, 19 Feb 2014 17:58:36 +0100
Subject: diff of removed page, require handling right rev=0
When page is removed, and diff can be requested between a revision and
current situation. This results in right revision is 0.
Similar case just after creating a page. A diff between the first
version and nothing before, result in left revision is 0.
In these cases a empty dummy revision is placed as selected value in
dropdown. Otherwise user got distracted by the revisions details shown
in select field, which are not related to the diff below.
---
inc/changelog.php | 16 +++++++++++-----
inc/html.php | 31 ++++++++++++++++++++++++-------
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/inc/changelog.php b/inc/changelog.php
index d2ad23c08..28e53e77a 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -642,7 +642,7 @@ abstract class ChangeLog {
* When available it returns $max entries for each revision
*
* @param int $rev1 oldest revision timestamp
- * @param int $rev2 newest revision timestamp
+ * @param int $rev2 newest revision timestamp (0 looks up last revision)
* @param int $max maximum number of revisions returned
* @return array with two arrays with revisions surrounding rev1 respectively rev2
*/
@@ -651,10 +651,16 @@ abstract class ChangeLog {
$rev1 = max($rev1, 0);
$rev2 = max($rev2, 0);
- if($rev2 < $rev1) {
- $rev = $rev2;
- $rev2 = $rev1;
- $rev1 = $rev;
+ if($rev2) {
+ if($rev2 < $rev1) {
+ $rev = $rev2;
+ $rev2 = $rev1;
+ $rev1 = $rev;
+ }
+ } else {
+ //empty right side means a removed page. Look up last revision.
+ $revs = $this->getRevisions(-1, 1);
+ $rev2 = $revs[0];
}
//collect revisions around rev2
list($revs2, $allrevs, $fp, $lines, $head, $tail) = $this->retrieveRevisionsAround($rev2, $max);
diff --git a/inc/html.php b/inc/html.php
index 1a549824e..39d0eeada 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1308,21 +1308,27 @@ function html_diff($text = '', $intro = true, $type = null) {
function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
global $INFO, $ID;
- //last timestamp is not in changelog
+ //last timestamp is not in changelog (note: when page is removed, the metadata timestamp is zero as well)
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date'];
//retrieve revisions with additional info
list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
$l_revisions = array();
+ if(!$l_rev) {
+ $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
+ }
foreach($l_revs as $rev) {
$info = $pagelog->getRevisionInfo($rev);
$l_revisions[$rev] = array(
$rev,
dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'],
- $rev >= $r_rev //disable?
+ $r_rev ? $rev >= $r_rev : false //disable?
);
}
$r_revisions = array();
+ if(!$r_rev) {
+ $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
+ }
foreach($r_revs as $rev) {
$info = $pagelog->getRevisionInfo($rev);
$r_revisions[$rev] = array(
@@ -1331,13 +1337,24 @@ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
$rev <= $l_rev //disable?
);
}
+
//determine previous/next revisions
$l_index = array_search($l_rev, $l_revs);
$l_prev = $l_revs[$l_index + 1];
$l_next = $l_revs[$l_index - 1];
- $r_index = array_search($r_rev, $r_revs);
- $r_prev = $r_revs[$r_index + 1];
- $r_next = $r_revs[$r_index - 1];
+ if($r_rev) {
+ $r_index = array_search($r_rev, $r_revs);
+ $r_prev = $r_revs[$r_index + 1];
+ $r_next = $r_revs[$r_index - 1];
+ } else {
+ //removed page
+ if($l_next) {
+ $r_prev = $r_revs[0];
+ } else {
+ $r_prev = null;
+ }
+ $r_next = null;
+ }
/*
* Left side:
@@ -1366,7 +1383,7 @@ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
$form->addElement(form_makeButton('submit', 'diff', 'Go'));
$l_nav .= $form->getForm();
//move forward
- if($l_next && $l_next < $r_rev) {
+ if($l_next && ($l_next < $r_rev || !$r_rev)) {
$l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
}
@@ -1418,7 +1435,7 @@ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
*/
function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
global $ID, $lang;
- if($rrev === null) {
+ if(!$rrev) {
$urlparam = array(
'do' => 'diff',
'rev' => $lrev,
--
cgit v1.2.3
From 4d5954c8d1f8bcc5450f8cf70d8139cf5a1e697d Mon Sep 17 00:00:00 2001
From: Gerrit Uitslag
Date: Thu, 20 Feb 2014 14:03:29 +0100
Subject: improve comment in html_diff_navigation
---
inc/html.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/inc/html.php b/inc/html.php
index 39d0eeada..2c7e8b1a6 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1308,7 +1308,8 @@ function html_diff($text = '', $intro = true, $type = null) {
function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
global $INFO, $ID;
- //last timestamp is not in changelog (note: when page is removed, the metadata timestamp is zero as well)
+ // last timestamp is not in changelog, retrieve timestamp from metadata
+ // note: when page is removed, the metadata timestamp is zero
$r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date'];
//retrieve revisions with additional info
--
cgit v1.2.3
From 01486f869816b6358d14a710f3d89b190e9391b4 Mon Sep 17 00:00:00 2001
From: Anika Henke
Date: Sun, 16 Mar 2014 19:08:14 +0000
Subject: tiny improvement on diffnav select width
---
lib/tpl/dokuwiki/css/_diff.css | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/tpl/dokuwiki/css/_diff.css b/lib/tpl/dokuwiki/css/_diff.css
index 09e95d9f6..bc56a37c4 100644
--- a/lib/tpl/dokuwiki/css/_diff.css
+++ b/lib/tpl/dokuwiki/css/_diff.css
@@ -127,7 +127,8 @@
}
.dokuwiki .diffnav select {
- width: 15em;
+ width: 60%;
+ min-width: 9em;
height: 1.5em; /* height is necessary for longer options in Webkit */
}
--
cgit v1.2.3
|