ChangeLog::getRevisionsAround PHP Method

getRevisionsAround() public method

Returns revisions around rev1 and rev2 When available it returns $max entries for each revision
public getRevisionsAround ( integer $rev1, integer $rev2, integer $max = 50 ) : array
$rev1 integer oldest revision timestamp
$rev2 integer newest revision timestamp (0 looks up last revision)
$max integer 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) {
            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);
        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(array_reverse($revs1), array_reverse($revs2));
    }