aboutsummaryrefslogtreecommitdiffstats
path: root/includes/diff
diff options
context:
space:
mode:
authorKunal Mehta <legoktm@member.fsf.org>2016-02-17 01:09:32 -0800
committerKunal Mehta <legoktm@member.fsf.org>2016-02-17 01:33:00 -0800
commit6e9b4f0e9ce4ccd6089c18b205065ef7fa077484 (patch)
tree58645fbce5c12d01b0d0fa87e338d4745e08920d /includes/diff
parent2fd379fa95f223c6b3f3c8eff6de068eca9e1a1a (diff)
downloadmediawikicore-6e9b4f0e9ce4ccd6089c18b205065ef7fa077484.tar.gz
mediawikicore-6e9b4f0e9ce4ccd6089c18b205065ef7fa077484.zip
Convert all array() syntax to []
Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
Diffstat (limited to 'includes/diff')
-rw-r--r--includes/diff/ArrayDiffFormatter.php14
-rw-r--r--includes/diff/DairikiDiff.php54
-rw-r--r--includes/diff/DiffFormatter.php4
-rw-r--r--includes/diff/DifferenceEngine.php88
-rw-r--r--includes/diff/WikiDiff3.php20
5 files changed, 90 insertions, 90 deletions
diff --git a/includes/diff/ArrayDiffFormatter.php b/includes/diff/ArrayDiffFormatter.php
index c12b76adac2a..70a963ba1070 100644
--- a/includes/diff/ArrayDiffFormatter.php
+++ b/includes/diff/ArrayDiffFormatter.php
@@ -38,36 +38,36 @@ class ArrayDiffFormatter extends DiffFormatter {
public function format( $diff ) {
$oldline = 1;
$newline = 1;
- $retval = array();
+ $retval = [];
foreach ( $diff->getEdits() as $edit ) {
switch ( $edit->getType() ) {
case 'add':
foreach ( $edit->getClosing() as $line ) {
- $retval[] = array(
+ $retval[] = [
'action' => 'add',
'new' => $line,
'newline' => $newline++
- );
+ ];
}
break;
case 'delete':
foreach ( $edit->getOrig() as $line ) {
- $retval[] = array(
+ $retval[] = [
'action' => 'delete',
'old' => $line,
'oldline' => $oldline++,
- );
+ ];
}
break;
case 'change':
foreach ( $edit->getOrig() as $key => $line ) {
- $retval[] = array(
+ $retval[] = [
'action' => 'change',
'old' => $line,
'new' => $edit->getClosing( $key ),
'oldline' => $oldline++,
'newline' => $newline++,
- );
+ ];
}
break;
case 'copy':
diff --git a/includes/diff/DairikiDiff.php b/includes/diff/DairikiDiff.php
index ad6e81e386ba..bc57c9359238 100644
--- a/includes/diff/DairikiDiff.php
+++ b/includes/diff/DairikiDiff.php
@@ -220,10 +220,10 @@ class DiffEngine {
protected $xchanged, $ychanged;
- protected $xv = array(), $yv = array();
- protected $xind = array(), $yind = array();
+ protected $xv = [], $yv = [];
+ protected $xind = [], $yind = [];
- protected $seq = array(), $in_seq = array();
+ protected $seq = [], $in_seq = [];
protected $lcs = 0;
@@ -246,14 +246,14 @@ class DiffEngine {
$n_from = count( $from_lines );
$n_to = count( $to_lines );
- $edits = array();
+ $edits = [];
$xi = $yi = 0;
while ( $xi < $n_from || $yi < $n_to ) {
assert( '$yi < $n_to || $this->xchanged[$xi]' );
assert( '$xi < $n_from || $this->ychanged[$yi]' );
// Skip matching "snake".
- $copy = array();
+ $copy = [];
while ( $xi < $n_from && $yi < $n_to
&& !$this->xchanged[$xi] && !$this->ychanged[$yi]
) {
@@ -265,12 +265,12 @@ class DiffEngine {
}
// Find deletes & adds.
- $delete = array();
+ $delete = [];
while ( $xi < $n_from && $this->xchanged[$xi] ) {
$delete[] = $from_lines[$xi++];
}
- $add = array();
+ $add = [];
while ( $yi < $n_to && $this->ychanged[$yi] ) {
$add[] = $to_lines[$yi++];
}
@@ -305,11 +305,11 @@ class DiffEngine {
// old diff
$n_from = count( $from_lines );
$n_to = count( $to_lines );
- $this->xchanged = $this->ychanged = array();
- $this->xv = $this->yv = array();
- $this->xind = $this->yind = array();
- $this->seq = array();
- $this->in_seq = array();
+ $this->xchanged = $this->ychanged = [];
+ $this->xv = $this->yv = [];
+ $this->xind = $this->yind = [];
+ $this->seq = [];
+ $this->in_seq = [];
$this->lcs = 0;
// Skip leading common lines.
@@ -406,7 +406,7 @@ class DiffEngine {
// Things seems faster (I'm not sure I understand why)
// when the shortest sequence in X.
$flip = true;
- list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
+ list( $xoff, $xlim, $yoff, $ylim ) = [ $yoff, $ylim, $xoff, $xlim ];
}
if ( $flip ) {
@@ -421,8 +421,8 @@ class DiffEngine {
$this->lcs = 0;
$this->seq[0] = $yoff - 1;
- $this->in_seq = array();
- $ymids[0] = array();
+ $this->in_seq = [];
+ $ymids[0] = [];
$numer = $xlim - $xoff + $nchunks - 1;
$x = $xoff;
@@ -471,16 +471,16 @@ class DiffEngine {
}
}
- $seps[] = $flip ? array( $yoff, $xoff ) : array( $xoff, $yoff );
+ $seps[] = $flip ? [ $yoff, $xoff ] : [ $xoff, $yoff ];
$ymid = $ymids[$this->lcs];
for ( $n = 0; $n < $nchunks - 1; $n++ ) {
$x1 = $xoff + (int)( ( $numer + ( $xlim - $xoff ) * $n ) / $nchunks );
$y1 = $ymid[$n] + 1;
- $seps[] = $flip ? array( $y1, $x1 ) : array( $x1, $y1 );
+ $seps[] = $flip ? [ $y1, $x1 ] : [ $x1, $y1 ];
}
- $seps[] = $flip ? array( $ylim, $xlim ) : array( $xlim, $ylim );
+ $seps[] = $flip ? [ $ylim, $xlim ] : [ $xlim, $ylim ];
- return array( $this->lcs, $seps );
+ return [ $this->lcs, $seps ];
}
/**
@@ -755,7 +755,7 @@ class Diff {
*/
public function reverse() {
$rev = $this;
- $rev->edits = array();
+ $rev->edits = [];
/** @var DiffOp $edit */
foreach ( $this->edits as $edit ) {
$rev->edits[] = $edit->reverse();
@@ -806,7 +806,7 @@ class Diff {
* @return string[] The original sequence of strings.
*/
public function orig() {
- $lines = array();
+ $lines = [];
foreach ( $this->edits as $edit ) {
if ( $edit->orig ) {
@@ -826,7 +826,7 @@ class Diff {
* @return string[] The sequence of strings.
*/
public function closing() {
- $lines = array();
+ $lines = [];
foreach ( $this->edits as $edit ) {
if ( $edit->closing ) {
@@ -903,7 +903,7 @@ class HWLDFWordAccumulator {
public $insClass = ' class="diffchange diffchange-inline"';
public $delClass = ' class="diffchange diffchange-inline"';
- private $lines = array();
+ private $lines = [];
private $line = '';
private $group = '';
private $tag = '';
@@ -1002,8 +1002,8 @@ class WordLevelDiff extends MappedDiff {
*/
private function split( $lines ) {
- $words = array();
- $stripped = array();
+ $words = [];
+ $stripped = [];
$first = true;
foreach ( $lines as $line ) {
# If the line is too long, just pretend the entire line is one big word
@@ -1018,7 +1018,7 @@ class WordLevelDiff extends MappedDiff {
$words[] = $line;
$stripped[] = $line;
} else {
- $m = array();
+ $m = [];
if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
$line, $m )
) {
@@ -1032,7 +1032,7 @@ class WordLevelDiff extends MappedDiff {
}
}
- return array( $words, $stripped );
+ return [ $words, $stripped ];
}
/**
diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php
index 23e39ea73bd3..4b44b3c4b25d 100644
--- a/includes/diff/DiffFormatter.php
+++ b/includes/diff/DiffFormatter.php
@@ -63,7 +63,7 @@ abstract class DiffFormatter {
$xi = $yi = 1;
$block = false;
- $context = array();
+ $context = [];
$nlead = $this->leadingContextLines;
$ntrail = $this->trailingContextLines;
@@ -94,7 +94,7 @@ abstract class DiffFormatter {
$context = array_slice( $context, count( $context ) - $nlead );
$x0 = $xi - count( $context );
$y0 = $yi - count( $context );
- $block = array();
+ $block = [];
if ( $context ) {
$block[] = new DiffOpCopy( $context );
}
diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index f59fd61aea57..99eefc0106a3 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -180,16 +180,16 @@ class DifferenceEngine extends ContextSource {
if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'archive', '*',
- array( 'ar_rev_id' => $id ),
+ [ 'ar_rev_id' => $id ],
__METHOD__ );
if ( $row ) {
$rev = Revision::newFromArchiveRow( $row );
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
- return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
+ return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( [
'target' => $title->getPrefixedText(),
'timestamp' => $rev->getTimestamp()
- ) );
+ ] );
}
}
@@ -215,7 +215,7 @@ class DifferenceEngine extends ContextSource {
private function showMissingRevision() {
$out = $this->getOutput();
- $missing = array();
+ $missing = [];
if ( $this->mOldRev === null ||
( $this->mOldRev && $this->mOldContent === null )
) {
@@ -260,7 +260,7 @@ class DifferenceEngine extends ContextSource {
$rollback = '';
- $query = array();
+ $query = [];
# Carry over 'diffonly' param via navigation links
if ( $diffOnly != $user->getBoolOption( 'diffonly' ) ) {
$query['diffonly'] = $diffOnly;
@@ -274,7 +274,7 @@ class DifferenceEngine extends ContextSource {
$deleted = $suppressed = false;
$allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
- $revisionTools = array();
+ $revisionTools = [];
# mOldRev is false if the difference engine is called with a "vague" query for
# a diff between a version V and its previous version V' AND the version V
@@ -284,7 +284,7 @@ class DifferenceEngine extends ContextSource {
$samePage = true;
$oldHeader = '';
} else {
- Hooks::run( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
+ Hooks::run( 'DiffViewHeader', [ $this, $this->mOldRev, $this->mNewRev ] );
if ( $this->mNewPage->equals( $this->mOldPage ) ) {
$out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
@@ -308,14 +308,14 @@ class DifferenceEngine extends ContextSource {
if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) &&
!$this->mNewRev->isDeleted( Revision::DELETED_TEXT )
) {
- $undoLink = Html::element( 'a', array(
- 'href' => $this->mNewPage->getLocalURL( array(
+ $undoLink = Html::element( 'a', [
+ 'href' => $this->mNewPage->getLocalURL( [
'action' => 'edit',
'undoafter' => $this->mOldid,
'undo' => $this->mNewid
- ) ),
+ ] ),
'title' => Linker::titleAttrib( 'undo' ),
- ),
+ ],
$this->msg( 'editundo' )->text()
);
$revisionTools['mw-diff-undo'] = $undoLink;
@@ -327,8 +327,8 @@ class DifferenceEngine extends ContextSource {
$prevlink = Linker::linkKnown(
$this->mOldPage,
$this->msg( 'previousdiff' )->escaped(),
- array( 'id' => 'differences-prevlink' ),
- array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
+ [ 'id' => 'differences-prevlink' ],
+ [ 'diff' => 'prev', 'oldid' => $this->mOldid ] + $query
);
} else {
$prevlink = '&#160;';
@@ -371,8 +371,8 @@ class DifferenceEngine extends ContextSource {
$nextlink = Linker::linkKnown(
$this->mNewPage,
$this->msg( 'nextdiff' )->escaped(),
- array( 'id' => 'differences-nextlink' ),
- array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
+ [ 'id' => 'differences-nextlink' ],
+ [ 'diff' => 'next', 'oldid' => $this->mNewid ] + $query
);
} else {
$nextlink = '&#160;';
@@ -389,14 +389,14 @@ class DifferenceEngine extends ContextSource {
# Allow extensions to define their own revision tools
Hooks::run( 'DiffRevisionTools',
- array( $this->mNewRev, &$revisionTools, $this->mOldRev, $user ) );
- $formattedRevisionTools = array();
+ [ $this->mNewRev, &$revisionTools, $this->mOldRev, $user ] );
+ $formattedRevisionTools = [];
// Put each one in parentheses (poor man's button)
foreach ( $revisionTools as $key => $tool ) {
$toolClass = is_string( $key ) ? $key : 'mw-diff-tool';
$element = Html::rawElement(
'span',
- array( 'class' => $toolClass ),
+ [ 'class' => $toolClass ],
$this->msg( 'parentheses' )->rawParams( $tool )->escaped()
);
$formattedRevisionTools[] = $element;
@@ -430,7 +430,7 @@ class DifferenceEngine extends ContextSource {
$msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
# Give explanation for why revision is not visible
$out->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
- array( $msg ) );
+ [ $msg ] );
} else {
# Give explanation and add a link to view the diff...
$query = $this->getRequest()->appendQueryValue( 'unhide', '1' );
@@ -438,7 +438,7 @@ class DifferenceEngine extends ContextSource {
$msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
$out->wrapWikiMsg(
"<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
- array( $msg, $link )
+ [ $msg, $link ]
);
}
# Otherwise, output a regular diff...
@@ -477,12 +477,12 @@ class DifferenceEngine extends ContextSource {
$this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
$this->mNewPage,
$this->msg( 'markaspatrolleddiff' )->escaped(),
- array(),
- array(
+ [],
+ [
'action' => 'markpatrolled',
'rcid' => $linkInfo['rcid'],
'token' => $linkInfo['token'],
- )
+ ]
) . ']</span>';
}
}
@@ -512,11 +512,11 @@ class DifferenceEngine extends ContextSource {
// Look for an unpatrolled change corresponding to this diff
$db = wfGetDB( DB_SLAVE );
$change = RecentChange::newFromConds(
- array(
+ [
'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
'rc_this_oldid' => $this->mNewid,
'rc_patrolled' => 0
- ),
+ ],
__METHOD__
);
@@ -537,10 +537,10 @@ class DifferenceEngine extends ContextSource {
}
$token = $user->getEditToken( $rcid );
- return array(
+ return [
'rcid' => $rcid,
'token' => $token,
- );
+ ];
}
}
@@ -747,7 +747,7 @@ class DifferenceEngine extends ContextSource {
$difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
// Save to cache for 7 days
- if ( !Hooks::run( 'AbortDiffCache', array( &$this ) ) ) {
+ if ( !Hooks::run( 'AbortDiffCache', [ &$this ] ) ) {
wfIncrStats( 'diff_cache.uncacheable' );
} elseif ( $key !== false && $difftext !== false ) {
wfIncrStats( 'diff_cache.miss' );
@@ -915,7 +915,7 @@ class DifferenceEngine extends ContextSource {
if ( !$this->enableDebugComment ) {
return '';
}
- $data = array( $generator );
+ $data = [ $generator ];
if ( $wgShowHostnames ) {
$data[] = wfHostname();
}
@@ -936,7 +936,7 @@ class DifferenceEngine extends ContextSource {
public function localiseLineNumbers( $text ) {
return preg_replace_callback(
'/<!--LINE (\d+)-->/',
- array( &$this, 'localiseLineNumbersCb' ),
+ [ &$this, 'localiseLineNumbersCb' ],
$text
);
}
@@ -1040,11 +1040,11 @@ class DifferenceEngine extends ContextSource {
$title = $rev->getTitle();
- $header = Linker::linkKnown( $title, $header, array(),
- array( 'oldid' => $rev->getID() ) );
+ $header = Linker::linkKnown( $title, $header, [],
+ [ 'oldid' => $rev->getID() ] );
if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
- $editQuery = array( 'action' => 'edit' );
+ $editQuery = [ 'action' => 'edit' ];
if ( !$rev->isCurrent() ) {
$editQuery['oldid'] = $rev->getID();
}
@@ -1052,21 +1052,21 @@ class DifferenceEngine extends ContextSource {
$key = $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold';
$msg = $this->msg( $key )->escaped();
$editLink = $this->msg( 'parentheses' )->rawParams(
- Linker::linkKnown( $title, $msg, array(), $editQuery ) )->escaped();
+ Linker::linkKnown( $title, $msg, [], $editQuery ) )->escaped();
$header .= ' ' . Html::rawElement(
'span',
- array( 'class' => 'mw-diff-edit' ),
+ [ 'class' => 'mw-diff-edit' ],
$editLink
);
if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$header = Html::rawElement(
'span',
- array( 'class' => 'history-deleted' ),
+ [ 'class' => 'history-deleted' ],
$header
);
}
} else {
- $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header );
+ $header = Html::rawElement( 'span', [ 'class' => 'history-deleted' ], $header );
}
return $header;
@@ -1087,10 +1087,10 @@ class DifferenceEngine extends ContextSource {
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
// shared.css sets diff in interface language/dir, but the actual content
// is often in a different language, mostly the page content language/dir
- $header = Html::openElement( 'table', array(
- 'class' => array( 'diff', 'diff-contentalign-' . $this->getDiffLang()->alignStart() ),
+ $header = Html::openElement( 'table', [
+ 'class' => [ 'diff', 'diff-contentalign-' . $this->getDiffLang()->alignStart() ],
'data-mw' => 'interface',
- ) );
+ ] );
$userLang = htmlspecialchars( $this->getLanguage()->getHtmlCode() );
if ( !$diff && !$otitle ) {
@@ -1195,7 +1195,7 @@ class DifferenceEngine extends ContextSource {
$newid = intval( $new );
}
- return array( $oldid, $newid );
+ return [ $oldid, $newid ];
}
/**
@@ -1220,7 +1220,7 @@ class DifferenceEngine extends ContextSource {
Hooks::run(
'NewDifferenceEngine',
- array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new )
+ [ $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ]
);
}
@@ -1295,7 +1295,7 @@ class DifferenceEngine extends ContextSource {
$this->mOldTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mOldid ),
+ [ 'ts_rev_id' => $this->mOldid ],
__METHOD__
);
} else {
@@ -1304,7 +1304,7 @@ class DifferenceEngine extends ContextSource {
$this->mNewTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mNewid ),
+ [ 'ts_rev_id' => $this->mNewid ],
__METHOD__
);
diff --git a/includes/diff/WikiDiff3.php b/includes/diff/WikiDiff3.php
index 7a0f7403a640..f35e30f325fd 100644
--- a/includes/diff/WikiDiff3.php
+++ b/includes/diff/WikiDiff3.php
@@ -70,8 +70,8 @@ class WikiDiff3 {
$this->heuristicUsed = false;
// output
- $removed = $m > 0 ? array_fill( 0, $m, true ) : array();
- $added = $n > 0 ? array_fill( 0, $n, true ) : array();
+ $removed = $m > 0 ? array_fill( 0, $m, true ) : [];
+ $added = $n > 0 ? array_fill( 0, $n, true ) : [];
// reduce the complexity for the next step (intentionally done twice)
// remove common tokens at the start
@@ -90,10 +90,10 @@ class WikiDiff3 {
++$j;
}
- $this->from = $newFromIndex = $this->to = $newToIndex = array();
+ $this->from = $newFromIndex = $this->to = $newToIndex = [];
// remove tokens not in both sequences
- $shared = array();
+ $shared = [];
foreach ( $from as $key ) {
$shared[$key] = false;
}
@@ -119,8 +119,8 @@ class WikiDiff3 {
$this->m = count( $this->from );
$this->n = count( $this->to );
- $this->removed = $this->m > 0 ? array_fill( 0, $this->m, true ) : array();
- $this->added = $this->n > 0 ? array_fill( 0, $this->n, true ) : array();
+ $this->removed = $this->m > 0 ? array_fill( 0, $this->m, true ) : [];
+ $this->added = $this->n > 0 ? array_fill( 0, $this->n, true ) : [];
if ( $this->m == 0 || $this->n == 0 ) {
$this->length = 0;
@@ -154,8 +154,8 @@ class WikiDiff3 {
}
$temp = array_fill( 0, $this->m + $this->n + 1, 0 );
- $V = array( $temp, $temp );
- $snake = array( 0, 0, 0 );
+ $V = [ $temp, $temp ];
+ $snake = [ 0, 0, 0 ];
$this->length = $forwardBound + $this->m - $backBoundL1 - 1
+ $this->lcs_rec(
@@ -192,7 +192,7 @@ class WikiDiff3 {
$this->diff( $from_lines, $to_lines );
unset( $from_lines, $to_lines );
- $ranges = array();
+ $ranges = [];
$xi = $yi = 0;
while ( $xi < $this->m || $yi < $this->n ) {
// Matching "snake".
@@ -509,7 +509,7 @@ class WikiDiff3 {
$backward_end_diag = -min( $M, $limit );
- $temp = array( 0, 0, 0 );
+ $temp = [ 0, 0, 0 ];
$max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
$backward_end_diag - $backward_start_diag ) / 2 ), $temp );