PHP Class ChangeLog, dokuwiki

Inheritance: extends DataObject
Show file Open project: splitbrain/dokuwiki Class Usage Examples

Protected Properties

Property Type Description
$cache array
$chunk_size integer
$id string

Public Methods

Method Description
__construct ( string $id, integer $chunk_size = 8192 ) Constructor
getLastRevisionAt ( number $date_at ) : string Return an existing revision for a specific date which is the current one or younger or equal then the date
getRelativeRevision ( integer $rev, integer $direction ) : boolean | integer Get the nth revision left or right handside for a specific page id and revision (timestamp)
getRevisionInfo ( integer $rev ) : boolean | array Get the changelog information for a specific page id and revision (timestamp)
getRevisions ( integer $first, integer $num ) : array Return a list of page revisions numbers
getRevisionsAround ( integer $rev1, integer $rev2, integer $max = 50 ) : array Returns revisions around rev1 and rev2 When available it returns $max entries for each revision
isCurrentRevision ( integer $rev ) : boolean Check whether given revision is the current page
setChunkSize ( integer $chunk_size ) Set chunk size for file reading Chunk size zero let read whole file at once

Protected Methods

Method Description
getChangelogFilename ( ) : string Returns path to changelog
getFilename ( ) : string Returns path to current page/media
getNewlinepointer ( resource $fp, integer $finger ) : integer Set pointer to first new line after $finger and return its position
readAdjacentChunk ( resource $fp, integer $head, integer $tail, integer $direction ) : array Returns the next lines of the changelog of the chunck before head or after tail
readChunk ( resource $fp, integer $head, integer $tail ) : array Read chunk and return array with lines of given chunck.
readloglines ( integer $rev ) : array | false Returns lines from changelog.
retrieveRevisionsAround ( integer $rev, integer $max ) : boolean | array Collect the $max revisions near to the timestamp $rev

Method Details

__construct() public method

Constructor
public __construct ( string $id, integer $chunk_size = 8192 )
$id string page id
$chunk_size integer maximum block size read from file

getChangelogFilename() abstract protected method

Returns path to changelog
abstract protected getChangelogFilename ( ) : string
return string path to file

getFilename() abstract protected method

Returns path to current page/media
abstract protected getFilename ( ) : string
return string path to file

getLastRevisionAt() public method

Return an existing revision for a specific date which is the current one or younger or equal then the date
public getLastRevisionAt ( number $date_at ) : string
$date_at number timestamp
return string revision ('' for current)

getNewlinepointer() protected method

Set pointer to first new line after $finger and return its position
protected getNewlinepointer ( resource $fp, integer $finger ) : integer
$fp resource filepointer
$finger integer a pointer
return integer pointer

getRelativeRevision() public method

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.
public getRelativeRevision ( integer $rev, integer $direction ) : boolean | integer
$rev integer revision timestamp used as startdate (doesn't need to be revisionnumber)
$direction integer give position of returned revision with respect to $rev; positive=next, negative=prev
return boolean | integer timestamp of the requested revision otherwise false

getRevisionInfo() public method

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 ([email protected])
Author: Kate Arzamastseva ([email protected])
public getRevisionInfo ( integer $rev ) : boolean | array
$rev integer revision timestamp
return boolean | 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)

getRevisions() public method

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.
Author: Ben Coburn ([email protected])
Author: Kate Arzamastseva ([email protected])
public getRevisions ( integer $first, integer $num ) : array
$first integer skip the first n changelog lines
$num integer number of revisions to return
return array with the revision timestamps

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

isCurrentRevision() public method

Check whether given revision is the current page
public isCurrentRevision ( integer $rev ) : boolean
$rev integer timestamp of current page
return boolean true if $rev is current revision, otherwise false

readAdjacentChunk() protected method

Returns the next lines of the changelog of the chunck before head or after tail
protected readAdjacentChunk ( resource $fp, integer $head, integer $tail, integer $direction ) : array
$fp resource filepointer
$head integer position head of last chunk
$tail integer position tail of last chunk
$direction integer positive forward, negative backward
return array with entries: - $lines: changelog lines of readed chunk - $head: head of chunk - $tail: tail of chunk

readChunk() protected method

Has no check if $head and $tail are really at a new line
protected readChunk ( resource $fp, integer $head, integer $tail ) : array
$fp resource resource filepointer
$head integer start point chunck
$tail integer end point chunck
return array lines read from chunck

readloglines() protected method

If file larger than $chuncksize, only chunck is read that could contain $rev.
protected readloglines ( integer $rev ) : array | false
$rev integer revision timestamp
return array | false if success returns array(fp, array(changeloglines), $head, $tail, $eof) where fp only defined for chuck reading, needs closing. otherwise false

retrieveRevisionsAround() protected method

Collect the $max revisions near to the timestamp $rev
protected retrieveRevisionsAround ( integer $rev, integer $max ) : boolean | array
$rev integer revision timestamp
$max integer maximum number of revisions to be returned
return boolean | 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

setChunkSize() public method

Set chunk size for file reading Chunk size zero let read whole file at once
public setChunkSize ( integer $chunk_size )
$chunk_size integer maximum block size read from file

Property Details

$cache protected property

protected array $cache
return array

$chunk_size protected property

protected int $chunk_size
return integer

$id protected property

protected string $id
return string