MediaWiki master
Wikimedia\Diff\DiffFormatter Class Reference

Base class for diff formatters. More...

Inherited by Wikimedia\Diff\ArrayDiffFormatter, Wikimedia\Diff\TableDiffFormatter, and Wikimedia\Diff\UnifiedDiffFormatter.

Public Member Functions

 format ( $diff)
 Format a diff.

Protected Member Functions

 added ( $lines)
 block ( $xbeg, $xlen, $ybeg, $ylen, &$edits)
 blockHeader ( $xbeg, $xlen, $ybeg, $ylen)
 changed ( $orig, $closing)
 Writes the two sets of lines to the output buffer, separated by "---" and a newline.
 context ( $lines)
 deleted ( $lines)
 endBlock ()
 Called at the end of a block of connected edits.
 endDiff ()
 lines ( $lines, $prefix=' ')
 Writes all (optionally prefixed) lines to the output buffer, separated by newlines.
 startBlock ( $header)
 Called at the start of a block of connected edits.
 startDiff ()
 writeOutput ( $text)
 Writes a string to the output buffer.

Protected Attributes

int $leadingContextLines = 0
 Number of leading context "lines" to preserve.
int $trailingContextLines = 0
 Number of trailing context "lines" to preserve.

Detailed Description

Base class for diff formatters.

This class formats the diff in classic diff format. It is intended that this class be customized via inheritance, to obtain fancier outputs.

Todo
document

Definition at line 26 of file DiffFormatter.php.

Member Function Documentation

◆ added()

Wikimedia\Diff\DiffFormatter::added ( $lines)
protected
Parameters
string[]$lines

Reimplemented in Wikimedia\Diff\TableDiffFormatter, and Wikimedia\Diff\UnifiedDiffFormatter.

Definition at line 219 of file DiffFormatter.php.

References lines().

Referenced by block(), and changed().

◆ block()

Wikimedia\Diff\DiffFormatter::block ( $xbeg,
$xlen,
$ybeg,
$ylen,
& $edits )
protected
Parameters
int$xbeg
int$xlen
int$ybeg
int$ylen
array&$edits

Definition at line 120 of file DiffFormatter.php.

References added(), blockHeader(), changed(), context(), deleted(), endBlock(), and startBlock().

Referenced by format().

◆ blockHeader()

Wikimedia\Diff\DiffFormatter::blockHeader ( $xbeg,
$xlen,
$ybeg,
$ylen )
protected
Parameters
int$xbeg
int$xlen
int$ybeg
int$ylen
Returns
string

Reimplemented in Wikimedia\Diff\TableDiffFormatter, and Wikimedia\Diff\UnifiedDiffFormatter.

Definition at line 169 of file DiffFormatter.php.

Referenced by block().

◆ changed()

Wikimedia\Diff\DiffFormatter::changed ( $orig,
$closing )
protected

Writes the two sets of lines to the output buffer, separated by "---" and a newline.

Parameters
string[]$orig
string[]$closing

Reimplemented in Wikimedia\Diff\TableDiffFormatter, and Wikimedia\Diff\UnifiedDiffFormatter.

Definition at line 236 of file DiffFormatter.php.

References added(), deleted(), and writeOutput().

Referenced by block().

◆ context()

Wikimedia\Diff\DiffFormatter::context ( $lines)
protected
Parameters
string[]$lines

Reimplemented in Wikimedia\Diff\TableDiffFormatter.

Definition at line 212 of file DiffFormatter.php.

References lines().

Referenced by block().

◆ deleted()

Wikimedia\Diff\DiffFormatter::deleted ( $lines)
protected
Parameters
string[]$lines

Reimplemented in Wikimedia\Diff\TableDiffFormatter, and Wikimedia\Diff\UnifiedDiffFormatter.

Definition at line 226 of file DiffFormatter.php.

References lines().

Referenced by block(), and changed().

◆ endBlock()

Wikimedia\Diff\DiffFormatter::endBlock ( )
protected

Called at the end of a block of connected edits.

This default implementation does nothing.

Reimplemented in Wikimedia\Diff\TableDiffFormatter.

Definition at line 194 of file DiffFormatter.php.

Referenced by block().

◆ endDiff()

Wikimedia\Diff\DiffFormatter::endDiff ( )
protected
Returns
string

Definition at line 154 of file DiffFormatter.php.

Referenced by format().

◆ format()

Wikimedia\Diff\DiffFormatter::format ( $diff)

Format a diff.

Parameters
Diff$diff
Returns
string The formatted output.

Reimplemented in Wikimedia\Diff\ArrayDiffFormatter.

Definition at line 52 of file DiffFormatter.php.

References $leadingContextLines, $trailingContextLines, block(), endDiff(), and startDiff().

◆ lines()

Wikimedia\Diff\DiffFormatter::lines ( $lines,
$prefix = ' ' )
protected

Writes all (optionally prefixed) lines to the output buffer, separated by newlines.

Parameters
string[]$lines
string$prefix

Reimplemented in Wikimedia\Diff\UnifiedDiffFormatter.

Definition at line 203 of file DiffFormatter.php.

References writeOutput().

Referenced by added(), context(), and deleted().

◆ startBlock()

Wikimedia\Diff\DiffFormatter::startBlock ( $header)
protected

Called at the start of a block of connected edits.

This default implementation writes the header and a newline to the output buffer.

Parameters
string$header

Reimplemented in Wikimedia\Diff\TableDiffFormatter.

Definition at line 186 of file DiffFormatter.php.

References writeOutput().

Referenced by block().

◆ startDiff()

Wikimedia\Diff\DiffFormatter::startDiff ( )
protected

Definition at line 138 of file DiffFormatter.php.

Referenced by format().

◆ writeOutput()

Member Data Documentation

◆ $leadingContextLines

int Wikimedia\Diff\DiffFormatter::$leadingContextLines = 0
protected

Number of leading context "lines" to preserve.

This should be left at zero for this class, but subclasses may want to set this to other values.

Definition at line 33 of file DiffFormatter.php.

Referenced by format().

◆ $trailingContextLines

int Wikimedia\Diff\DiffFormatter::$trailingContextLines = 0
protected

Number of trailing context "lines" to preserve.

This should be left at zero for this class, but subclasses may want to set this to other values.

Definition at line 40 of file DiffFormatter.php.

Referenced by format().


The documentation for this class was generated from the following file: