Versions
in package
NacoWiki Versions
This plugin implements version history for documents.
It uses the properties
change log records to identify
versions.
Versions are stored either as full version strings or as
patches (the output of the diff
command) from the next
version.
The version file is in JSON format and contains a root
entry which is the latest base version for the file.
From then on there are different versions timestamped
matching the properties change log entries. These
time stamped entries are either a delta
or rewrite
.
If rewrite
it is just a full version text. Otherwise
delta
contains a diff from the next version. i.e. to
recreate this particular version, you need to patch the
next version (starting with root
and going backwards in
time).
Tags
Table of Contents
Constants
- FPREFIX = '/.vers;'
- FPREFIX_YAML = '/.ver;'
- VERSION = '0.0.0'
- var string
Methods
- calcVersion() : string
- calculate specific version
- compareVers() : bool|null
- Compare versions
- countVers() : int
- count versions
- diffStr() : string
- Create diff between two strings
- diffVers() : bool|null
- Diff versions
- getVersion() : bool|null
- get a specific version
- infoBox() : bool|null
- Add InfoBox data
- load() : void
- Loading entry point for this class
- navtools() : bool|null
- Add navigation tools
- patchStr() : string|null
- apply patches to string
- path() : path
- Return this plugin's path
- rawVersion() : bool|null
- This is the event handler that handles the `do:rawv` event.
- readVerData() : array<string|int, mixed>|null
- Read versioning data
- saveVerData() : bool
- Save versioning data
- vcli() : bool|null
- Version testing
- viewVers() : bool|null
- View versions
Constants
FPREFIX
public
mixed
FPREFIX
= '/.vers;'
FPREFIX_YAML
public
mixed
FPREFIX_YAML
= '/.ver;'
VERSION
var string
public
mixed
VERSION
= '0.0.0'
Methods
calcVersion()
calculate specific version
public
static calcVersion(NanoWikiApp $wiki, string $page, int $tvid) : string
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $page : string
- $tvid : int
Return values
string —calculated version
compareVers()
Compare versions
public
static compareVers(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
Tags
Return values
bool|nullcountVers()
count versions
public
static countVers(NanoWikiApp $wiki) : int
Determine how many versions are in the current page
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
Tags
Return values
intdiffStr()
Create diff between two strings
public
static diffStr(string $a, string $b) : string
Will compare string $a and string $b line by line and create a patch string that can be used by patchStr to bring the $a to be like $b.
Parameters
- $a : string
-
source string to compare
- $b : string
-
dest string to compare
Return values
string —containing patch or NULL in case of error
diffVers()
Diff versions
public
static diffVers(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Create a new file version before saving to file.
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
Tags
Return values
bool|nullgetVersion()
get a specific version
public
static getVersion(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
Tags
Return values
bool|nullinfoBox()
Add InfoBox data
public
static infoBox(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Add version count to the InfoBox.
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
Tags
Return values
bool|nullload()
Loading entry point for this class
public
static load(array<string|int, mixed> $cfg) : void
Adds event hooks implemented by this class
Parameters
- $cfg : array<string|int, mixed>
navtools()
Add navigation tools
public
static navtools(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
Tags
Return values
bool|nullpatchStr()
apply patches to string
public
static patchStr(string $orig, string $diff) : string|null
Applies patches to a string so that you can recreate a file.
Parameters
- $orig : string
-
Original string that will be patched
- $diff : string
-
string contains patches to be applied
Return values
string|null —updated string or NULL in case of error.
path()
Return this plugin's path
public
static path([string $f = '' ]) : path
Parameters
- $f : string = ''
-
optional item
Return values
path —to filesystem for $f
rawVersion()
This is the event handler that handles the `do:rawv` event.
public
static rawVersion(NanoWikiApp $wiki, array<string|int, mixed> &$data) : bool|null
Will serve version without rendering i.e. raw source code.
Parameters
- $wiki : NanoWikiApp
-
current wiki instance
- $data : array<string|int, mixed>
-
ignored
Tags
Return values
bool|nullreadVerData()
Read versioning data
public
static readVerData(string $pgfile) : array<string|int, mixed>|null
Parameters
- $pgfile : string
-
File path to document. Usually
$wiki->filePath()
.
Return values
array<string|int, mixed>|null —NULL on Error, otherwise an array structure.
The returned array structure has the following components:
-
vfile
- name of the version file. -
vs
- version data (delta's or rewrites) -
root
- root entry. Delta's would start from this root.
saveVerData()
Save versioning data
public
static saveVerData(array<string|int, mixed> $vdata) : bool
Save versioning data to a file.
Parameters
- $vdata : array<string|int, mixed>
-
versioning data to save (same structure as returned by readVerData)
Return values
bool —True on success, False on failure
vcli()
Version testing
public
static vcli(NanoWikiApp $wiki, array<string|int, mixed> $argv) : bool|null
This implements the cli sub-command vv
This used for Version plugin debuging
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $argv : array<string|int, mixed>
-
Command line arguments
Tags
Return values
bool|nullviewVers()
View versions
public
static viewVers(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>