Umherirrender has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/356240 )
Change subject: Add phpcs and make pass
......................................................................
Add phpcs and make pass
Change-Id: I129fd23a375b4f7de893d3b98f67fdd8de89b4bd
---
M composer.json
M includes/ApiQueryPageImages.php
M includes/Job/InitImageDataJob.php
M includes/PageImages.php
M maintenance/initImageData.php
A phpcs.xml
M tests/phpunit/ApiQueryPageImagesTest.php
M tests/phpunit/LinksUpdateHookHandlerTest.php
8 files changed, 77 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages
refs/changes/40/356240/1
diff --git a/composer.json b/composer.json
index 686b65b..b8f68fb 100644
--- a/composer.json
+++ b/composer.json
@@ -1,11 +1,14 @@
{
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2",
- "jakub-onderka/php-console-highlighter": "0.3.2"
+ "jakub-onderka/php-console-highlighter": "0.3.2",
+ "mediawiki/mediawiki-codesniffer": "0.7.2"
},
"scripts": {
+ "fix": "phpcbf",
"test": [
- "parallel-lint . --exclude vendor"
+ "parallel-lint . --exclude vendor",
+ "phpcs -p -s"
]
}
}
diff --git a/includes/ApiQueryPageImages.php b/includes/ApiQueryPageImages.php
index bd89f38..9d957f8 100644
--- a/includes/ApiQueryPageImages.php
+++ b/includes/ApiQueryPageImages.php
@@ -216,13 +216,14 @@
// DEPRECATED: The original image URL
was originally provided as a property of
// the "thumbnail" object, but we now
provide the original image info in its own
// object on the same level as the
thumbnail.
- //
// Remove this functionality, and the
warning, after a reasonable amount of time
// has passed since December 2016.
if ( is_callable( [ $this, 'addWarning'
] ) ) {
$this->addWarning(
'apiwarn-query+pageimages-original-in-thumbnail-deprecated' );
} else {
- $this->setWarning( "The
original image's source URL is now provided with its dimensions in its own
property for the page object. It will be removed from the 'thumbnail' property
in a future release." );
+ $this->setWarning( "The
original image's source URL is now provided with " .
+ "its dimensions in its
own property for the page object. It will be " .
+ "removed from the
'thumbnail' property in a future release." );
}
$vals['thumbnail']['original'] =
$original_url;
}
diff --git a/includes/Job/InitImageDataJob.php
b/includes/Job/InitImageDataJob.php
index a6ec772..238732e 100644
--- a/includes/Job/InitImageDataJob.php
+++ b/includes/Job/InitImageDataJob.php
@@ -20,7 +20,7 @@
try {
RefreshLinks::fixLinksFromArticle( $id );
$lbFactory->waitForReplication();
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
// There are some broken pages out there that
just don't parse.
// Log it and keep on trucking.
MWExceptionHandler::logException( $e );
diff --git a/includes/PageImages.php b/includes/PageImages.php
index 4a8004b..51d37c5 100644
--- a/includes/PageImages.php
+++ b/includes/PageImages.php
@@ -50,7 +50,10 @@
$dbr = wfGetDB( DB_SLAVE );
$fileName = $dbr->selectField( 'page_props',
[ 'pp_value' ],
- [ 'pp_page' => $title->getArticleID(), 'pp_propname' =>
[ self::PROP_NAME, self::PROP_NAME_FREE ] ],
+ [
+ 'pp_page' => $title->getArticleID(),
+ 'pp_propname' => [ self::PROP_NAME,
self::PROP_NAME_FREE ]
+ ],
__METHOD__,
[ 'ORDER BY' => 'pp_propname' ]
);
diff --git a/maintenance/initImageData.php b/maintenance/initImageData.php
index 53e104d..69d6bab 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;
use PageImages\Job\InitImageDataJob;
@@ -22,7 +22,8 @@
$this->addOption( 'earlier-than',
'Run only on pages earlier than this timestamp', false,
true );
$this->addOption( 'start', 'Starting page ID', false, true );
- $this->addOption( 'queue-pressure', 'Maximum number of jobs to
enqueue at a time. If not provided or 0 will be run in-process.', false, true );
+ $this->addOption( 'queue-pressure', 'Maximum number of jobs to
enqueue at a time. ' .
+ 'If not provided or 0 will be run in-process.', false,
true );
$this->addOption( 'quiet', "Don't report on job queue pressure"
);
$this->setBatchSize( 100 );
}
@@ -98,12 +99,13 @@
$abandoned = $group->getAbandonedCount();
if ( !$isQuiet && ++$i % 10 === 0 ) {
- $now = date( 'Y-m-d H:i:s T');
- $this->output( "[$now] Queued: $queued Running:
$running Abandoned: $abandoned Max: $maxPressure\n" );
+ $now = date( 'Y-m-d H:i:s T' );
+ $this->output( "[$now] Queued: $queued Running:
$running " .
+ "Abandoned: $abandoned Max:
$maxPressure\n" );
}
} while ( $queued + $running - $abandoned >= $maxPressure );
}
}
$maintClass = 'InitImageData';
-require_once ( DO_MAINTENANCE );
+require_once DO_MAINTENANCE;
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..4ffde0b
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset>
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="UTF-8"/>
+ <exclude-pattern>vendor</exclude-pattern>
+ <exclude-pattern>node_modules</exclude-pattern>
+</ruleset>
diff --git a/tests/phpunit/ApiQueryPageImagesTest.php
b/tests/phpunit/ApiQueryPageImagesTest.php
index 7747cc7..dd2859a 100644
--- a/tests/phpunit/ApiQueryPageImagesTest.php
+++ b/tests/phpunit/ApiQueryPageImagesTest.php
@@ -61,7 +61,7 @@
private function newInstance() {
$config = new \HashConfig( [
'PageImagesAPIDefaultLicense' => 'free'
- ]);
+ ] );
$context = $this->getMockBuilder( 'IContextSource' )
->disableOriginalConstructor()
@@ -179,7 +179,9 @@
* @param array $queryResults Results of the DB select query
* @param int $setResultValueCount The number results the API returned
*/
- public function testExecute( $requestParams, $titles, $queryPageIds,
$queryResults, $setResultValueCount ) {
+ public function testExecute( $requestParams, $titles, $queryPageIds,
+ $queryResults, $setResultValueCount
+ ) {
$mock = TestingAccessWrapper::newFromObject(
$this->getMockBuilder( ApiQueryPageImages::class )
->disableOriginalConstructor()
@@ -198,8 +200,10 @@
->willReturn( new FakeResultWrapper( $queryResults ) );
// continue page ID is not found
- if ( isset( $requestParams['continue'] ) &&
$requestParams['continue'] > count( $titles ) ) {
- $mock->expects( $this->exactly( 1 ) )
+ if ( isset( $requestParams['continue'] )
+ && $requestParams['continue'] > count( $titles )
+ ) {
+ $mock->expects( $this->exactly( 1 ) )
->method( 'dieUsage' );
}
@@ -229,9 +233,12 @@
[ 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
],
@@ -243,12 +250,15 @@
0
],
[
- [ 'prop' => [ 'thumbnail' ], 'continue' => 1,
'thumbsize' => 400, 'limit' => 10, 'license' => 'any' ],
+ [ '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
],
@@ -257,16 +267,19 @@
[ 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' ],
+ [ '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
],
@@ -282,18 +295,29 @@
[ 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
],
[
- ['prop' => ['thumbnail', 'original'],
'thumbsize' => 510, 'limit' => 10, 'license' => 'free'],
- [Title::newFromText( 'Page 1' ),
Title::newFromText( 'Page 2' )],
- [0, 1],
+ [ 'prop' => [ 'thumbnail', 'original' ],
'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_value_original' => 'A_Free_original.jpg', 'pp_original_width'
=> 80, 'pp_original_height' => 80, 'pp_propname' => PageImages::PROP_NAME_FREE],
- (object) ['pp_page' => 1, 'pp_value' =>
'B_Free.jpg', 'pp_value_original' => 'B_Free_original.jpg', 'pp_original_width'
=> 80, 'pp_original_height' => 80, 'pp_propname' => PageImages::PROP_NAME_FREE],
+ (object) [
+ 'pp_page' => 0, 'pp_value' =>
'A_Free.jpg',
+ 'pp_value_original' =>
'A_Free_original.jpg', 'pp_original_width' => 80,
+ 'pp_original_height' => 80,
'pp_propname' => PageImages::PROP_NAME_FREE
+ ],
+ (object) [
+ 'pp_page' => 1, 'pp_value' =>
'B_Free.jpg',
+ 'pp_value_original' =>
'B_Free_original.jpg', 'pp_original_width' => 80,
+ 'pp_original_height' => 80,
'pp_propname' => PageImages::PROP_NAME_FREE
+ ],
],
2
],
@@ -330,7 +354,7 @@
}
private function noResultsHaveProperty( $queryResults, $propName ) {
- foreach( $queryResults as $result ) {
+ foreach ( $queryResults as $result ) {
if ( property_exists( $result, $propName ) ) {
return false;
}
@@ -339,7 +363,7 @@
}
private function allResultsHaveProperty( $queryResults, $propName ) {
- foreach( $queryResults as $result ) {
+ foreach ( $queryResults as $result ) {
if ( !property_exists( $result, $propName ) ) {
return false;
}
diff --git a/tests/phpunit/LinksUpdateHookHandlerTest.php
b/tests/phpunit/LinksUpdateHookHandlerTest.php
index 619d589..5a94559 100644
--- a/tests/phpunit/LinksUpdateHookHandlerTest.php
+++ b/tests/phpunit/LinksUpdateHookHandlerTest.php
@@ -149,7 +149,8 @@
if ( is_null( $expectedFreeFileName ) ) {
$this->assertFalse( isset(
$linksUpdate->mProperties[PageImages::PROP_NAME_FREE] ) );
} else {
- $this->assertSame( $expectedFreeFileName,
$linksUpdate->mProperties[PageImages::PROP_NAME_FREE] );
+ $this->assertSame( $expectedFreeFileName,
+
$linksUpdate->mProperties[PageImages::PROP_NAME_FREE] );
}
if ( is_null( $expectedNonFreeFileName ) ) {
$this->assertFalse( isset(
$linksUpdate->mProperties[PageImages::PROP_NAME] ) );
--
To view, visit https://gerrit.wikimedia.org/r/356240
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I129fd23a375b4f7de893d3b98f67fdd8de89b4bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits