Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.
In one occurrence, a simple conditional instead of trickery was much more readable.
This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.
Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
29 files changed:
// Convert into a Status object
if ( $errors ) {
foreach ( $errors as $error ) {
// Convert into a Status object
if ( $errors ) {
foreach ( $errors as $error ) {
- call_user_func_array( [ $status, 'fatal' ], $error );
+ $status->fatal( ...$error );
// Convert into a Status object
if ( $errors ) {
foreach ( $errors as $error ) {
// Convert into a Status object
if ( $errors ) {
foreach ( $errors as $error ) {
- call_user_func_array( [ $status, 'fatal' ], $error );
+ $status->fatal( ...$error );
foreach ( $errors as $error ) {
$text .= '<li>';
foreach ( $errors as $error ) {
$text .= '<li>';
- $text .= call_user_func_array( [ $this, 'msg' ], $error )->plain();
+ $text .= $this->msg( ...$error )->plain();
$text .= "</li>\n";
}
$text .= '</ul>';
} else {
$text .= "<div class=\"permissions-errors\">\n" .
$text .= "</li>\n";
}
$text .= '</ul>';
} else {
$text .= "<div class=\"permissions-errors\">\n" .
- call_user_func_array( [ $this, 'msg' ], reset( $errors ) )->plain() .
+ $this->msg( ...reset( $errors ) )->plain() .
$permissionlist = implode( ', ', $permissions );
if ( $title === null ) {
wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
$permissionlist = implode( ', ', $permissions );
if ( $title === null ) {
wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
- return call_user_func_array( [ $user, 'isAllowedAny' ], $permissions );
+ return $user->isAllowedAny( ...$permissions );
} else {
$text = $title->getPrefixedText();
wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" );
} else {
$text = $title->getPrefixedText();
wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" );
if ( $cond ) {
$this->addWhere( $cond );
$multiNS = count( $lb->data ) !== 1;
if ( $cond ) {
$this->addWhere( $cond );
$multiNS = count( $lb->data ) !== 1;
- $multiTitle = count( call_user_func_array( 'array_merge', $lb->data ) ) !== 1;
+ $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
} else {
// No titles so no results
return;
} else {
// No titles so no results
return;
public static function getToken( User $user, MediaWiki\Session\Session $session, $salt ) {
if ( is_array( $salt ) ) {
$session->persist();
public static function getToken( User $user, MediaWiki\Session\Session $session, $salt ) {
if ( is_array( $salt ) ) {
$session->persist();
- return call_user_func_array( [ $session, 'getToken' ], $salt );
+ return $session->getToken( ...$salt );
} else {
return $user->getEditTokenObject( $salt, $session->getRequest() );
}
} else {
return $user->getEditTokenObject( $salt, $session->getRequest() );
}
foreach ( $res as $row ) {
$names[$row->user_name] = $row;
}
foreach ( $res as $row ) {
$names[$row->user_name] = $row;
}
- call_user_func_array(
- $this->params['dir'] == 'newer' ? 'ksort' : 'krsort', [ &$names, SORT_STRING ]
- );
+ if ( $this->params['dir'] == 'newer' ) {
+ ksort( $names, SORT_STRING );
+ } else {
+ krsort( $names, SORT_STRING );
+ }
$neg = $op === '>' ? -1 : 1;
$userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
foreach ( $names as $name => $row ) {
$neg = $op === '>' ? -1 : 1;
$userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
foreach ( $names as $name => $row ) {
} elseif ( is_string( $data['label'] ) ) {
$data['label'] = new \Message( $data['label'] );
} elseif ( is_array( $data['label'] ) ) {
} elseif ( is_string( $data['label'] ) ) {
$data['label'] = new \Message( $data['label'] );
} elseif ( is_array( $data['label'] ) ) {
- $data['label'] = call_user_func_array( 'Message::newFromKey', $data['label'] );
+ $data['label'] = Message::newFromKey( ...$data['label'] );
}
if ( !isset( $data['help'] ) ) {
$data['help'] = new \RawMessage( '$1', $data['name'] );
} elseif ( is_string( $data['help'] ) ) {
$data['help'] = new \Message( $data['help'] );
} elseif ( is_array( $data['help'] ) ) {
}
if ( !isset( $data['help'] ) ) {
$data['help'] = new \RawMessage( '$1', $data['name'] );
} elseif ( is_string( $data['help'] ) ) {
$data['help'] = new \Message( $data['help'] );
} elseif ( is_array( $data['help'] ) ) {
- $data['help'] = call_user_func_array( 'Message::newFromKey', $data['help'] );
+ $data['help'] = Message::newFromKey( ...$data['help'] );
}
$ret = new static( $data['name'], $data['label'], $data['help'] );
foreach ( $data as $k => $v ) {
}
$ret = new static( $data['name'], $data['label'], $data['help'] );
foreach ( $data as $k => $v ) {
global $wgPropagateErrors;
if ( in_array( $level, self::$fatalErrorTypes ) ) {
global $wgPropagateErrors;
if ( in_array( $level, self::$fatalErrorTypes ) ) {
- return call_user_func_array(
- 'MWExceptionHandler::handleFatalError', func_get_args()
- );
+ return self::handleFatalError( ...func_get_args() );
}
// Map error constant to error name (reverse-engineer PHP error
}
// Map error constant to error name (reverse-engineer PHP error
$hoistedErrors = Status::newGood();
if ( $this->mValidationErrorMessage ) {
foreach ( (array)$this->mValidationErrorMessage as $error ) {
$hoistedErrors = Status::newGood();
if ( $this->mValidationErrorMessage ) {
foreach ( (array)$this->mValidationErrorMessage as $error ) {
- call_user_func_array( [ $hoistedErrors, 'fatal' ], $error );
+ $hoistedErrors->fatal( ...$error );
}
} else {
$hoistedErrors->fatal( 'htmlform-invalid-input' );
}
} else {
$hoistedErrors->fatal( 'htmlform-invalid-input' );
*/
public function showHelpBox( $msg /*, ... */ ) {
$args = func_get_args();
*/
public function showHelpBox( $msg /*, ... */ ) {
$args = func_get_args();
- $html = call_user_func_array( [ $this, 'getHelpBox' ], $args );
+ $html = $this->getHelpBox( ...$args );
$this->output->addHTML( $html );
}
$this->output->addHTML( $html );
}
public function showStatusMessage( Status $status ) {
$errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
foreach ( $errors as $error ) {
public function showStatusMessage( Status $status ) {
$errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
foreach ( $errors as $error ) {
- call_user_func_array( [ $this, 'showMessage' ], $error );
+ $this->showMessage( ...$error );
public static function newFatal( $message /*, parameters...*/ ) {
$params = func_get_args();
$result = new static();
public static function newFatal( $message /*, parameters...*/ ) {
$params = func_get_args();
$result = new static();
- call_user_func_array( [ &$result, 'fatal' ], $params );
+ $result->fatal( ...$params );
final protected function newStatus() {
$args = func_get_args();
if ( count( $args ) ) {
final protected function newStatus() {
$args = func_get_args();
if ( count( $args ) ) {
- $sv = call_user_func_array( [ StatusValue::class, 'newFatal' ], $args );
+ $sv = StatusValue::newFatal( ...$args );
} else {
$sv = StatusValue::newGood();
}
} else {
$sv = StatusValue::newGood();
}
$memc = $this->getCache( $lockSrv );
// List of affected paths
$memc = $this->getCache( $lockSrv );
// List of affected paths
- $paths = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
+ $paths = array_merge( ...array_values( $pathsByType ) );
$paths = array_unique( $paths );
// List of affected lock record keys
$keys = array_map( [ $this, 'recordKeyForPath' ], $paths );
$paths = array_unique( $paths );
// List of affected lock record keys
$keys = array_map( [ $this, 'recordKeyForPath' ], $paths );
$memc = $this->getCache( $lockSrv );
// List of affected paths
$memc = $this->getCache( $lockSrv );
// List of affected paths
- $paths = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
+ $paths = array_merge( ...array_values( $pathsByType ) );
$paths = array_unique( $paths );
// List of affected lock record keys
$keys = array_map( [ $this, 'recordKeyForPath' ], $paths );
$paths = array_unique( $paths );
// List of affected lock record keys
$keys = array_map( [ $this, 'recordKeyForPath' ], $paths );
protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
$status = StatusValue::newGood();
protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
$status = StatusValue::newGood();
- $pathList = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
+ $pathList = array_merge( ...array_values( $pathsByType ) );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server, $this->logger );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server, $this->logger );
protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
$status = StatusValue::newGood();
protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
$status = StatusValue::newGood();
- $pathList = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
+ $pathList = array_merge( ...array_values( $pathsByType ) );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server, $this->logger );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server, $this->logger );
}
$permissionlist = implode( ', ', $permissions );
wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
}
$permissionlist = implode( ', ', $permissions );
wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
- return call_user_func_array( [ $user, 'isAllowedAny' ], $permissions );
+ return $user->isAllowedAny( ...$permissions );
$rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image );
list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
$rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image );
list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
- $cmd = call_user_func_array( 'wfEscapeShellArg', array_merge(
+ $cmd = wfEscapeShellArg( ...array_merge(
[ $wgImageMagickConvertCommand ],
$quality,
// Specify white background color, will be used for transparent images
[ $wgImageMagickConvertCommand ],
$quality,
// Specify white background color, will be used for transparent images
- $result = call_user_func_array( $callback, $allArgs );
+ $result = $callback( ...$allArgs );
# The interface for function hooks allows them to return a wikitext
# string or an array containing the string and any flags. This mungs
# The interface for function hooks allows them to return a wikitext
# string or an array containing the string and any flags. This mungs
}
$skin = $wgOut->getSkin();
}
$skin = $wgOut->getSkin();
- return call_user_func_array(
- [ $skin, 'doEditSectionLink' ],
- [ $editsectionPage, $editsectionSection,
- $editsectionContent, $wgLang->getCode() ]
+ return $skin->doEditSectionLink( $editsectionPage,
+ $editsectionSection,
+ $editsectionContent,
+ $wgLang->getCode()
* @return Message
*/
public function msg( $key ) {
* @return Message
*/
public function msg( $key ) {
- return call_user_func_array( 'wfMessage', func_get_args() )
+ return wfMessage( ...func_get_args() )
->inLanguage( $this->getLanguage() )
// Use a dummy title because there is no real title
// for this endpoint, and the cache won't vary on it
->inLanguage( $this->getLanguage() )
// Use a dummy title because there is no real title
// for this endpoint, and the cache won't vary on it
* @return Message
*/
public function getMsg( $name /* ... */ ) {
* @return Message
*/
public function getMsg( $name /* ... */ ) {
- return call_user_func_array( [ $this->getSkin(), 'msg' ], func_get_args() );
+ return $this->getSkin()->msg( ...func_get_args() );
$status = Status::newFatal( new RawMessage( '$1', $status ) );
} elseif ( is_array( $status ) ) {
if ( is_string( reset( $status ) ) ) {
$status = Status::newFatal( new RawMessage( '$1', $status ) );
} elseif ( is_array( $status ) ) {
if ( is_string( reset( $status ) ) ) {
- $status = call_user_func_array( 'Status::newFatal', $status );
+ $status = Status::newFatal( ...$status );
} elseif ( is_array( reset( $status ) ) ) {
$status = Status::newGood();
foreach ( $status as $message ) {
} elseif ( is_array( reset( $status ) ) ) {
$status = Status::newGood();
foreach ( $status as $message ) {
- call_user_func_array( [ $status, 'fatal' ], $message );
+ $status->fatal( ...$message );
}
} else {
throw new UnexpectedValueException( 'invalid HTMLForm::trySubmit() return value: '
}
} else {
throw new UnexpectedValueException( 'invalid HTMLForm::trySubmit() return value: '
- $knownParams = call_user_func_array(
- [ $this->getRequest(), 'getValues' ],
- array_keys( $this->getOptions()->getAllValues() )
+ $knownParams = $this->getRequest()->getValues(
+ ...array_keys( $this->getOptions()->getAllValues() )
);
// HACK: Temporarily until we can properly define "sticky" filters and parameters,
);
// HACK: Temporarily until we can properly define "sticky" filters and parameters,
* @see wfMessage
*/
public function msg( $key /* $args */ ) {
* @see wfMessage
*/
public function msg( $key /* $args */ ) {
- $message = call_user_func_array(
- [ $this->getContext(), 'msg' ],
- func_get_args()
- );
+ $message = $this->getContext()->msg( ...func_get_args() );
// RequestContext passes context to wfMessage, and the language is set from
// the context, but setting the language for Message class removes the
// interface message status, which breaks for example usernameless gender
// RequestContext passes context to wfMessage, and the language is set from
// the context, but setting the language for Message class removes the
// interface message status, which breaks for example usernameless gender
if ( !$status->isOK() ) {
$errors = $status->getErrorsArray();
if ( !$status->isOK() ) {
$errors = $status->getErrorsArray();
- return call_user_func_array( [ $form, 'msg' ], $errors[0] );
+ return $form->msg( ...$errors[0] );
if ( !is_array( $error ) ) {
$error = [ $error ];
}
if ( !is_array( $error ) ) {
$error = [ $error ];
}
- return call_user_func_array( 'Status::newFatal', $error );
+ return Status::newFatal( ...$error );
}
$status = $this->getLocalFile()->upload(
}
$status = $this->getLocalFile()->upload(
if ( !$isPartial ) {
$error = $this->runUploadStashFileHook( $user );
if ( $error ) {
if ( !$isPartial ) {
$error = $this->runUploadStashFileHook( $user );
if ( $error ) {
- return call_user_func_array( 'Status::newFatal', $error );
+ return Status::newFatal( ...$error );
// override doStashFile() with completely different functionality in this class...
$error = $this->runUploadStashFileHook( $this->user );
if ( $error ) {
// override doStashFile() with completely different functionality in this class...
$error = $this->runUploadStashFileHook( $this->user );
if ( $error ) {
- call_user_func_array( [ $status, 'fatal' ], $error );
+ $status->fatal( ...$error );
class UploadChunkVerificationException extends MWException {
public $msg;
class UploadChunkVerificationException extends MWException {
public $msg;
- public function __construct( $res ) {
- $this->msg = call_user_func_array( 'wfMessage', $res );
- parent::__construct( call_user_func_array( 'wfMessage', $res )
+ public function __construct( array $res ) {
+ $this->msg = wfMessage( ...$res );
+ parent::__construct( wfMessage( ...$res )
->inLanguage( 'en' )->useDatabase( false )->text() );
}
}
->inLanguage( 'en' )->useDatabase( false )->text() );
}
}
require_once $file;
}
$register = [ $class, 'register' ];
require_once $file;
}
$register = [ $class, 'register' ];
- call_user_func_array( $register, [ $this ] );
}
$cmd .= ' --child' .
' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
}
$cmd .= ' --child' .
' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
- ' ' . call_user_func_array( 'wfEscapeShellArg', $this->destClusters );
+ ' ' . wfEscapeShellArg( ...$this->destClusters );
$this->replicaPipes = $this->replicaProcs = [];
for ( $i = 0; $i < $this->numProcs; $i++ ) {
$this->replicaPipes = $this->replicaProcs = [];
for ( $i = 0; $i < $this->numProcs; $i++ ) {
$args = array_slice( $ids, 0, $this->orphanBatchSize );
$ids = array_slice( $ids, $this->orphanBatchSize );
array_unshift( $args, 'doOrphanList' );
$args = array_slice( $ids, 0, $this->orphanBatchSize );
$ids = array_slice( $ids, $this->orphanBatchSize );
array_unshift( $args, 'doOrphanList' );
- call_user_func_array( [ $this, 'dispatch' ], $args );
+ $this->dispatch( ...$args );
}
if ( count( $ids ) ) {
$args = $ids;
array_unshift( $args, 'doOrphanList' );
}
if ( count( $ids ) ) {
$args = $ids;
array_unshift( $args, 'doOrphanList' );
- call_user_func_array( [ $this, 'dispatch' ], $args );
+ $this->dispatch( ...$args );
}
$this->report( 'orphans', $i, $numOrphans );
}
$this->report( 'orphans', $i, $numOrphans );