to running searchText/searchTitle.
* (T199657) Messages for $wgFilterLogTypes labels should be no longer be in the
'log-show-hide-[type]' format. Instead use 'logeventslist-[type]-log'.
+* Global functions wfArrayFilter() and wfArrayFilterByKey() are deprecated.
+ use array_filter() directly.
=== Other changes in 1.32 ===
* (T198811) The following tables have had their UNIQUE indexes turned into
}
/**
- * Like array_filter with ARRAY_FILTER_USE_BOTH, but works pre-5.6.
+ * @deprecated since 1.32, use array_filter() with ARRAY_FILTER_USE_BOTH directly
*
* @param array $arr
* @param callable $callback Will be called with the array value and key (in that order) and
* @return array
*/
function wfArrayFilter( array $arr, callable $callback ) {
- if ( defined( 'ARRAY_FILTER_USE_BOTH' ) ) {
- return array_filter( $arr, $callback, ARRAY_FILTER_USE_BOTH );
- }
- $filteredKeys = array_filter( array_keys( $arr ), function ( $key ) use ( $arr, $callback ) {
- return call_user_func( $callback, $arr[$key], $key );
- } );
- return array_intersect_key( $arr, array_fill_keys( $filteredKeys, true ) );
+ return array_filter( $arr, $callback, ARRAY_FILTER_USE_BOTH );
}
/**
- * Like array_filter with ARRAY_FILTER_USE_KEY, but works pre-5.6.
+ * @deprecated since 1.32, use array_filter() with ARRAY_FILTER_USE_KEY directly
*
* @param array $arr
* @param callable $callback Will be called with the array key and should return a bool which
* @return array
*/
function wfArrayFilterByKey( array $arr, callable $callback ) {
- return wfArrayFilter( $arr, function ( $val, $key ) use ( $callback ) {
- return call_user_func( $callback, $key );
- } );
+ return array_filter( $arr, $callback, ARRAY_FILTER_USE_KEY );
}
/**
$attribs = [ 'data-mw-revid' => $rev->getId() ];
Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes, &$attribs ] );
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
if ( $classes ) {
$attribs['class'] = implode( ' ', $classes );
// skip entry if hook aborted it
return [];
}
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
$lineParams['recentChangesFlagsRaw'] = [];
if ( isset( $data['recentChangesFlags'] ) ) {
}
$attribs = $data['attribs'];
unset( $data['attribs'] );
- $attribs = wfArrayFilterByKey( $attribs, function ( $key ) {
+ $attribs = array_filter( $attribs, function ( $key ) {
return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
- } );
+ }, ARRAY_FILTER_USE_KEY );
$prefix = '';
if ( is_callable( $this->changeLinePrefixer ) ) {
// Let extensions add data
Hooks::run( 'LogEventsListLineEnding', [ $this, &$ret, $entry, &$classes, &$attribs ] );
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
$attribs['class'] = implode( ' ', $classes );
return Html::rawElement( 'li', $attribs, $ret ) . "\n";
@trigger_error( '' );
restore_error_handler();
- $readPipes = wfArrayFilterByKey( $pipes, function ( $fd ) use ( $desc ) {
+ $readPipes = array_filter( $pipes, function ( $fd ) use ( $desc ) {
return $desc[$fd][0] === 'pipe' && $desc[$fd][1] === 'r';
- } );
- $writePipes = wfArrayFilterByKey( $pipes, function ( $fd ) use ( $desc ) {
+ }, ARRAY_FILTER_USE_KEY );
+ $writePipes = array_filter( $pipes, function ( $fd ) use ( $desc ) {
return $desc[$fd][0] === 'pipe' && $desc[$fd][1] === 'w';
- } );
+ }, ARRAY_FILTER_USE_KEY );
// stream_select parameter names are from the POV of us being able to do the operation;
// proc_open desriptor types are from the POV of the process doing it.
// So $writePipes is passed as the $read parameter and $readPipes as $write.
// Let extensions add data
Hooks::run( 'NewPagesLineEnding', [ $this, &$ret, $result, &$classes, &$attribs ] );
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
if ( count( $classes ) ) {
$attribs['class'] = implode( ' ', $classes );
// Let extensions add data
Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
// TODO: Handle exceptions in the catch block above. Do any extensions rely on
// receiving empty rows?
// Let extensions add data
Hooks::run( 'DeletedContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
- $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
+ $attribs = array_filter( $attribs,
+ [ Sanitizer::class, 'isReservedDataAttribute' ],
+ ARRAY_FILTER_USE_KEY
+ );
if ( $classes === [] && $attribs === [] && $ret === '' ) {
wfDebug( "Dropping Special:DeletedContribution row that could not be formatted\n" );
* @covers ::wfArrayFilter
* @covers ::wfArrayFilterByKey
*/
-class WfArrayFilterTest extends \PHPUnit\Framework\TestCase {
+class WfArrayFilterTest extends MediaWikiTestCase {
public function testWfArrayFilter() {
+ $this->hideDeprecated( 'wfArrayFilter' );
$arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
$filtered = wfArrayFilter( $arr, function ( $val, $key ) {
return $key !== 'b';
}
public function testWfArrayFilterByKey() {
+ $this->hideDeprecated( 'wfArrayFilterByKey' );
$arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
$filtered = wfArrayFilterByKey( $arr, function ( $key ) {
return $key !== 'b';