Convert to new array syntax

Change-Id: Iaec0c9ad47d28559adb8c46a82a00a61fba3602d
This commit is contained in:
Max Semenik 2016-12-01 16:49:13 -08:00
parent e0d6962b5b
commit 5145dd3d74
5 changed files with 115 additions and 116 deletions

View file

@ -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 ) {

View file

@ -74,9 +74,9 @@ class ApiQueryPageImages extends ApiQueryBase {
$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' );

View file

@ -4,7 +4,7 @@ $IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
require_once( "$IP/maintenance/Maintenance.php" );
require_once ( "$IP/maintenance/Maintenance.php" );
use MediaWiki\MediaWikiServices;
@ -31,16 +31,16 @@ class InitImageData extends Maintenance {
$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 @@ class InitImageData extends Maintenance {
}
$maintClass = 'InitImageData';
require_once( DO_MAINTENANCE );
require_once ( DO_MAINTENANCE );

View file

@ -94,7 +94,7 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
public function testGetCacheMode() {
$instance = $this->newInstance();
$this->assertSame( 'public', $instance->getCacheMode( array() ) );
$this->assertSame( 'public', $instance->getCacheMode( [] ) );
}
public function testGetAllowedParams() {
@ -104,7 +104,7 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
$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 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
}
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 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
$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 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
$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 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
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 @@ class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
$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 ] ]

View file

@ -10,7 +10,6 @@ use PHPUnit_Framework_TestCase;
use RepoGroup;
use TestingAccessWrapper;
/**
* @covers PageImages\Hooks\LinksUpdateHookHandler
*
@ -78,7 +77,7 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
$linksUpdate = $this->getLinksUpdate( $images );
$mock = TestingAccessWrapper::newFromObject(
$this->getMockBuilder( LinksUpdateHookHandler::class )
->setMethods( ['getScore', 'isImageFree'] )
->setMethods( [ 'getScore', 'isImageFree' ] )
->getMock()
);
@ -86,8 +85,8 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
$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 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
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 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
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 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
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 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase {
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 ],
];
}
}