MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324845

Change subject: Convert to new array syntax
......................................................................

Convert to new array syntax

Change-Id: Iaec0c9ad47d28559adb8c46a82a00a61fba3602d
---
M PageImages.i18n.php
M includes/ApiQueryPageImages.php
M maintenance/initImageData.php
M tests/phpunit/ApiQueryPageImagesTest.php
M tests/phpunit/LinksUpdateHookHandlerTest.php
5 files changed, 115 insertions(+), 116 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages 
refs/changes/45/324845/1

diff --git a/PageImages.i18n.php b/PageImages.i18n.php
index d099936..5bb744c 100644
--- a/PageImages.i18n.php
+++ b/PageImages.i18n.php
@@ -10,12 +10,12 @@
  *
  * This shim maintains compatibility back to MediaWiki 1.17.
  */
-$messages = array();
+$messages = [];
 if ( !function_exists( 'wfJsonI18nShim74e07e31dc460199' ) ) {
        function wfJsonI18nShim74e07e31dc460199( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
+               $codeSequence = array_merge( [ $code ], 
$cachedData['fallbackSequence'] );
                foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
+                       $fileName = __DIR__ . "/i18n/$csCode.json";
                        if ( is_readable( $fileName ) ) {
                                $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
                                foreach ( array_keys( $data ) as $key ) {
diff --git a/includes/ApiQueryPageImages.php b/includes/ApiQueryPageImages.php
index a83f79d..00cf969 100644
--- a/includes/ApiQueryPageImages.php
+++ b/includes/ApiQueryPageImages.php
@@ -74,9 +74,9 @@
                $params = $this->extractRequestParams();
                $prop = array_flip( $params['prop'] );
                if ( !count( $prop ) ) {
-                       if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
                                $this->dieWithError(
-                                       array( 'apierror-paramempty', 
$this->encodeParamName( 'prop' ) ), 'noprop'
+                                       [ 'apierror-paramempty', 
$this->encodeParamName( 'prop' ) ], 'noprop'
                                );
                        } else {
                                $this->dieUsage( 'No properties selected', 
'_noprop' );
diff --git a/maintenance/initImageData.php b/maintenance/initImageData.php
index 9f2af9e..af3453d 100644
--- a/maintenance/initImageData.php
+++ b/maintenance/initImageData.php
@@ -4,7 +4,7 @@
 if ( $IP === false ) {
        $IP = __DIR__ . '/../../..';
 }
-require_once( "$IP/maintenance/Maintenance.php" );
+require_once ( "$IP/maintenance/Maintenance.php" );
 
 use MediaWiki\MediaWikiServices;
 
@@ -31,16 +31,16 @@
                $lbFactory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 
                do {
-                       $tables = array( 'page', 'imagelinks' );
-                       $conds = array(
+                       $tables = [ 'page', 'imagelinks' ];
+                       $conds = [
                                'page_id > ' . (int) $id,
                                'il_from IS NOT NULL',
                                'page_is_redirect' => 0,
-                       );
-                       $fields = array( 'page_id' );
-                       $joinConds = array( 'imagelinks' => array(
+                       ];
+                       $fields = [ 'page_id' ];
+                       $joinConds = [ 'imagelinks' => [
                                'LEFT JOIN', 'page_id = il_from',
-                       ) );
+                       ] ];
 
                        $dbr = wfGetDB( DB_SLAVE );
                        if ( $this->hasOption( 'namespaces' ) ) {
@@ -69,4 +69,4 @@
 }
 
 $maintClass = 'InitImageData';
-require_once( DO_MAINTENANCE );
+require_once ( DO_MAINTENANCE );
diff --git a/tests/phpunit/ApiQueryPageImagesTest.php 
b/tests/phpunit/ApiQueryPageImagesTest.php
index 1359279..de22c8a 100644
--- a/tests/phpunit/ApiQueryPageImagesTest.php
+++ b/tests/phpunit/ApiQueryPageImagesTest.php
@@ -94,7 +94,7 @@
 
        public function testGetCacheMode() {
                $instance = $this->newInstance();
-               $this->assertSame( 'public', $instance->getCacheMode( array() ) 
);
+               $this->assertSame( 'public', $instance->getCacheMode( [] ) );
        }
 
        public function testGetAllowedParams() {
@@ -104,7 +104,7 @@
                $this->assertNotEmpty( $params );
                $this->assertContainsOnly( 'array', $params );
                $this->assertArrayHasKey( 'license', $params );
-               $this->assertEquals( $params['license'][\ApiBase::PARAM_TYPE], 
['free', 'any'] );
+               $this->assertEquals( $params['license'][\ApiBase::PARAM_TYPE], 
[ 'free', 'any' ] );
                $this->assertEquals( $params['license'][\ApiBase::PARAM_DFLT], 
'any' );
                $this->assertEquals( 
$params['license'][\ApiBase::PARAM_ISMULTI], false );
        }
@@ -127,34 +127,34 @@
        }
 
        public function provideGetTitles() {
-               return array(
-                       array(
-                               array( Title::newFromText( 'Foo' ) ),
-                               array(),
-                               array( Title::newFromText( 'Foo' ) ),
-                       ),
-                       array(
-                               array( Title::newFromText( 'Foo' ) ),
-                               array(
-                                       NS_TALK => array(
+               return [
+                       [
+                               [ Title::newFromText( 'Foo' ) ],
+                               [],
+                               [ Title::newFromText( 'Foo' ) ],
+                       ],
+                       [
+                               [ Title::newFromText( 'Foo' ) ],
+                               [
+                                       NS_TALK => [
                                                'Bar' => -1,
-                                       ),
-                               ),
-                               array( Title::newFromText( 'Foo' ) ),
-                       ),
-                       array(
-                               array( Title::newFromText( 'Foo' ) ),
-                               array(
-                                       NS_FILE => array(
+                                       ],
+                               ],
+                               [ Title::newFromText( 'Foo' ) ],
+                       ],
+                       [
+                               [ Title::newFromText( 'Foo' ) ],
+                               [
+                                       NS_FILE => [
                                                'Bar' => -1,
-                                       ),
-                               ),
-                               array(
+                                       ],
+                               ],
+                               [
                                        0 => Title::newFromText( 'Foo' ),
                                        -1 => Title::newFromText( 'Bar', 
NS_FILE ),
-                               ),
-                       ),
-               );
+                               ],
+                       ],
+               ];
        }
 
        /**
@@ -169,8 +169,8 @@
                $mock = TestingAccessWrapper::newFromObject(
                        $this->getMockBuilder( ApiQueryPageImages::class )
                                ->disableOriginalConstructor()
-                               -> setMethods( ['extractRequestParams', 
'getTitles', 'setContinueParameter', 'dieUsage',
-                                       'addTables', 'addFields', 'addWhere', 
'select', 'setResultValues'] )
+                               -> setMethods( [ 'extractRequestParams', 
'getTitles', 'setContinueParameter', 'dieUsage',
+                                       'addTables', 'addFields', 'addWhere', 
'select', 'setResultValues' ] )
                                ->getMock()
                );
                $mock->expects( $this->any() )
@@ -191,13 +191,13 @@
 
                $license = isset( $requestParams['license'] ) ? 
$requestParams['license'] : 'free';
                if ( $license == ApiQueryPageImages::PARAM_LICENSE_ANY ) {
-                       $propName = [PageImages::getPropName( true ), 
PageImages::getPropName( false )];
+                       $propName = [ PageImages::getPropName( true ), 
PageImages::getPropName( false ) ];
                } else {
                        $propName = PageImages::getPropName( true );
                }
-               $mock->expects( $this->exactly( count ( $queryPageIds ) > 0 ? 1 
: 0 ) )
+               $mock->expects( $this->exactly( count( $queryPageIds ) > 0 ? 1 
: 0 ) )
                        ->method( 'addWhere' )
-                       ->with( ['pp_page' => $queryPageIds, 'pp_propname' => 
$propName] );
+                       ->with( [ 'pp_page' => $queryPageIds, 'pp_propname' => 
$propName ] );
 
                $mock->expects( $this->exactly( $setResultValueCount ) )
                        ->method( 'setResultValues' );
@@ -208,65 +208,65 @@
        public function provideExecute() {
                return [
                        [
-                               ['prop' => ['thumbnail'], 'thumbsize' => 100, 
'limit' => 10, 'license' => 'any'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [0, 1],
+                               [ 'prop' => [ 'thumbnail' ], 'thumbsize' => 
100, 'limit' => 10, 'license' => 'any' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 0, 1 ],
                                [
-                                       (object) ['pp_page' => 0, 'pp_value' => 
'A_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE],
-                                       (object) ['pp_page' => 0, 'pp_value' => 
'A.jpg', 'pp_propname' => PageImages::PROP_NAME],
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B.jpg', 'pp_propname' => PageImages::PROP_NAME],
+                                       (object) [ 'pp_page' => 0, 'pp_value' 
=> 'A_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE ],
+                                       (object) [ 'pp_page' => 0, 'pp_value' 
=> 'A.jpg', 'pp_propname' => PageImages::PROP_NAME ],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B.jpg', 'pp_propname' => PageImages::PROP_NAME ],
                                ],
                                2
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'thumbsize' => 200, 
'limit' => 10],
+                               [ 'prop' => [ 'thumbnail' ], 'thumbsize' => 
200, 'limit' => 10 ],
                                [],
                                [],
                                [],
                                0
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'continue' => 1, 
'thumbsize' => 400, 'limit' => 10, 'license' => 'any'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [1],
+                               [ 'prop' => [ 'thumbnail' ], 'continue' => 1, 
'thumbsize' => 400, 'limit' => 10, 'license' => 'any' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 1 ],
                                [
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE],
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B.jpg', 'pp_propname' => PageImages::PROP_NAME],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE ],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B.jpg', 'pp_propname' => PageImages::PROP_NAME ],
                                ],
                                1
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'thumbsize' => 500, 
'limit' => 10, 'license' => 'any'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [0, 1],
+                               [ 'prop' => [ 'thumbnail' ], 'thumbsize' => 
500, 'limit' => 10, 'license' => 'any' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 0, 1 ],
                                [
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME ],
                                ],
                                1
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'continue' => 1, 
'thumbsize' => 500, 'limit' => 10, 'license' => 'any'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [1],
+                               [ 'prop' => [ 'thumbnail' ], 'continue' => 1, 
'thumbsize' => 500, 'limit' => 10, 'license' => 'any' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 1 ],
                                [
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE ],
                                ],
                                1
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'thumbsize' => 510, 
'limit' => 10, 'license' => 'free'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [0, 1],
+                               [ 'prop' => [ 'thumbnail' ], 'thumbsize' => 
510, 'limit' => 10, 'license' => 'free' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 0, 1 ],
                                [],
                                0
                        ],
                        [
-                               ['prop' => ['thumbnail'], 'thumbsize' => 510, 
'limit' => 10, 'license' => 'free'],
-                               [Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' )],
-                               [0, 1],
+                               [ 'prop' => [ 'thumbnail' ], 'thumbsize' => 
510, 'limit' => 10, 'license' => 'free' ],
+                               [ Title::newFromText( 'Page 1' ), 
Title::newFromText( 'Page 2' ) ],
+                               [ 0, 1 ],
                                [
-                                       (object) ['pp_page' => 0, 'pp_value' => 
'A_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE],
-                                       (object) ['pp_page' => 1, 'pp_value' => 
'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE],
+                                       (object) [ 'pp_page' => 0, 'pp_value' 
=> 'A_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE ],
+                                       (object) [ 'pp_page' => 1, 'pp_value' 
=> 'B_Free.jpg', 'pp_propname' => PageImages::PROP_NAME_FREE ],
                                ],
                                2
                        ],
@@ -282,8 +282,8 @@
                $this->assertEquals( $expected, 
ApiQueryPageImagesProxy::getPropNames( $license ) );
        }
 
-       public function provideGetPropName()
-       {
+       public function provideGetPropName() {
+
                return [
                        [ 'free', \PageImages::PROP_NAME_FREE ],
                        [ 'any', [ \PageImages::PROP_NAME_FREE, 
\PageImages::PROP_NAME ] ]
diff --git a/tests/phpunit/LinksUpdateHookHandlerTest.php 
b/tests/phpunit/LinksUpdateHookHandlerTest.php
index 5655633..08a70d4 100644
--- a/tests/phpunit/LinksUpdateHookHandlerTest.php
+++ b/tests/phpunit/LinksUpdateHookHandlerTest.php
@@ -10,7 +10,6 @@
 use RepoGroup;
 use TestingAccessWrapper;
 
-
 /**
  * @covers PageImages\Hooks\LinksUpdateHookHandler
  *
@@ -78,7 +77,7 @@
                $linksUpdate = $this->getLinksUpdate( $images );
                $mock = TestingAccessWrapper::newFromObject(
                                $this->getMockBuilder( 
LinksUpdateHookHandler::class )
-                               ->setMethods( ['getScore', 'isImageFree'] )
+                               ->setMethods( [ 'getScore', 'isImageFree' ] )
                                ->getMock()
                );
 
@@ -86,8 +85,8 @@
                $isFreeMap = [];
                $counter = 0;
                foreach ( $images as $image ) {
-                       array_push( $scoreMap, [$image, $counter++, 
$image['score']] );
-                       array_push( $isFreeMap, [$image['filename'], 
$image['isFree']] );
+                       array_push( $scoreMap, [ $image, $counter++, 
$image['score'] ] );
+                       array_push( $isFreeMap, [ $image['filename'], 
$image['isFree'] ] );
                }
 
                $mock->expects( $this->any() )
@@ -160,18 +159,18 @@
        public function testGetScore( $image, $scoreFromTable, $position, 
$expected ) {
                $mock = TestingAccessWrapper::newFromObject(
                        $this->getMockBuilder( LinksUpdateHookHandler::class )
-                               ->setMethods( ['scoreFromTable', 'getMetadata', 
'getRatio', 'getBlacklist'] )
+                               ->setMethods( [ 'scoreFromTable', 
'getMetadata', 'getRatio', 'getBlacklist' ] )
                                ->getMock()
                );
-        $mock->expects( $this->any() )
-            ->method( 'scoreFromTable' )
+               $mock->expects( $this->any() )
+                       ->method( 'scoreFromTable' )
                ->will( $this->returnValue( $scoreFromTable ) );
                $mock->expects( $this->any() )
                        ->method( 'getRatio' )
                        ->will( $this->returnValue( 0 ) );
                $mock->expects( $this->any() )
                        ->method( 'getBlacklist' )
-                       ->will( $this->returnValue( ['blacklisted.jpg' => 1] ) 
);
+                       ->will( $this->returnValue( [ 'blacklisted.jpg' => 1 ] 
) );
 
                $score = $mock->getScore( $image, $position );
                $this->assertEquals( $expected, $score );
@@ -180,35 +179,35 @@
        public function provideGetScore() {
                return [
                        [
-                               ['filename' => 'A.jpg', 'handler' => ['width' 
=> 100]],
+                               [ 'filename' => 'A.jpg', 'handler' => [ 'width' 
=> 100 ] ],
                                100,
                                0,
                                // width score + ratio score + position score
                                100 + 100 + 8
                        ],
                        [
-                               ['filename' => 'A.jpg', 'fullwidth' => 100],
+                               [ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
                                50,
                                1,
                                // width score + ratio score + position score
                                106
                        ],
                        [
-                               ['filename' => 'A.jpg', 'fullwidth' => 100],
+                               [ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
                                50,
                                2,
                                // width score + ratio score + position score
                                104
                        ],
                        [
-                               ['filename' => 'A.jpg', 'fullwidth' => 100],
+                               [ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
                                50,
                                3,
                                // width score + ratio score + position score
                                103
                        ],
                        [
-                               ['filename' => 'blacklisted.jpg', 'fullwidth' 
=> 100],
+                               [ 'filename' => 'blacklisted.jpg', 'fullwidth' 
=> 100 ],
                                50,
                                3,
                                // blacklist score
@@ -231,27 +230,27 @@
 
        public function provideScoreFromTable() {
                return [
-                       ['width', 100, -100],
-                       ['width', 119, -100],
-                       ['width', 300, 10],
-                       ['width', 400, 10],
-                       ['width', 500, 5],
-                       ['width', 600, 5],
-                       ['width', 601, 0],
-                       ['width', 999, 0],
-                       ['galleryImageWidth', 99, -100],
-                       ['galleryImageWidth', 100, 0],
-                       ['galleryImageWidth', 500, 0],
-                       ['ratio', 1, -100],
-                       ['ratio', 3, -100],
-                       ['ratio', 4, 0],
-                       ['ratio', 5, 0],
-                       ['ratio', 10, 5],
-                       ['ratio', 20, 5],
-                       ['ratio', 25, 0],
-                       ['ratio', 30, 0],
-                       ['ratio', 31, -100],
-                       ['ratio', 40, -100],
+                       [ 'width', 100, -100 ],
+                       [ 'width', 119, -100 ],
+                       [ 'width', 300, 10 ],
+                       [ 'width', 400, 10 ],
+                       [ 'width', 500, 5 ],
+                       [ 'width', 600, 5 ],
+                       [ 'width', 601, 0 ],
+                       [ 'width', 999, 0 ],
+                       [ 'galleryImageWidth', 99, -100 ],
+                       [ 'galleryImageWidth', 100, 0 ],
+                       [ 'galleryImageWidth', 500, 0 ],
+                       [ 'ratio', 1, -100 ],
+                       [ 'ratio', 3, -100 ],
+                       [ 'ratio', 4, 0 ],
+                       [ 'ratio', 5, 0 ],
+                       [ 'ratio', 10, 5 ],
+                       [ 'ratio', 20, 5 ],
+                       [ 'ratio', 25, 0 ],
+                       [ 'ratio', 30, 0 ],
+                       [ 'ratio', 31, -100 ],
+                       [ 'ratio', 40, -100 ],
                ];
        }
 
@@ -264,23 +263,23 @@
                RepoGroup::setSingleton( $this->getRepoGroup() );
                $mock = TestingAccessWrapper::newFromObject(
                        $this->getMockBuilder( LinksUpdateHookHandler::class )
-                               ->setMethods( ['fetchFileMetadata'] )
+                               ->setMethods( [ 'fetchFileMetadata' ] )
                                ->getMock()
                );
                $mock->expects( $this->any() )
                        ->method( 'fetchFileMetadata' )
                        ->will( $this->returnValue( $metadata ) );
-               $this->assertEquals( $expected, $mock->isImageFree( $fileName 
));
+               $this->assertEquals( $expected, $mock->isImageFree( $fileName ) 
);
        }
 
        public function provideIsFreeImage() {
                return [
-                       ['A.jpg', [], true],
-                       ['A.jpg', ['NonFree' => ['value' => '0']], true],
-                       ['A.jpg', ['NonFree' => ['value' => 0]], true],
-                       ['A.jpg', ['NonFree' => ['value' => false]], true],
-                       ['A.jpg', ['NonFree' => ['value' => 'something']], 
false],
-                       ['A.jpg', ['something' => ['value' => 'something']], 
true],
+                       [ 'A.jpg', [], true ],
+                       [ 'A.jpg', [ 'NonFree' => [ 'value' => '0' ] ], true ],
+                       [ 'A.jpg', [ 'NonFree' => [ 'value' => 0 ] ], true ],
+                       [ 'A.jpg', [ 'NonFree' => [ 'value' => false ] ], true 
],
+                       [ 'A.jpg', [ 'NonFree' => [ 'value' => 'something' ] ], 
false ],
+                       [ 'A.jpg', [ 'something' => [ 'value' => 'something' ] 
], true ],
                ];
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/324845
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaec0c9ad47d28559adb8c46a82a00a61fba3602d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: MaxSem <maxsem.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to