Bmansurov has uploaded a new change for review. https://gerrit.wikimedia.org/r/322793
Change subject: Fix phpcs warnings and errors ...................................................................... Fix phpcs warnings and errors Change-Id: I5c3c685f286fb379c7a1be3d483665cbb43ca803 --- M includes/ApiQueryPageImages.php M includes/LinksUpdateHookHandler.php M includes/PageImages.php M includes/ParserFileProcessingHookHandlers.php 4 files changed, 68 insertions(+), 57 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages refs/changes/93/322793/1 diff --git a/includes/ApiQueryPageImages.php b/includes/ApiQueryPageImages.php index 0f6437a..4a207d8 100644 --- a/includes/ApiQueryPageImages.php +++ b/includes/ApiQueryPageImages.php @@ -53,7 +53,7 @@ $missingTitles = $pageSet->getMissingTitlesByNamespace(); $missingFileTitles = isset( $missingTitles[NS_FILE] ) ? $missingTitles[NS_FILE] - : array(); + : []; // $titles is a map of ID to title object, which is ideal, // whereas $missingFileTitles is a map of title text to ID. @@ -92,7 +92,10 @@ $offset = array_search( intval( $params['continue'] ), $pageIds ); // If the 'continue' page wasn't found, die with error if ( !$offset ) { - $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query' , '_badcontinue' ); + $this->dieUsage( + 'Invalid continue param. You should pass the original value returned by the previous query', + '_badcontinue' + ); } } @@ -107,7 +110,7 @@ } // Find any titles in the file namespace so we can handle those separately - $filePageTitles = array(); + $filePageTitles = []; foreach ( $titles as $id => $title ) { if ( $title->inNamespace( NS_FILE ) ) { $filePageTitles[$id] = $title; @@ -119,9 +122,9 @@ // Extract page images from the page_props table if ( count( $titles ) > 0 ) { $this->addTables( 'page_props' ); - $this->addFields( array( 'pp_page', 'pp_propname', 'pp_value' ) ); - $this->addWhere( array( 'pp_page' => array_keys( $titles ), - 'pp_propname' => self::getPropNames( $params['license'] ) ) ); + $this->addFields( [ 'pp_page', 'pp_propname', 'pp_value' ] ); + $this->addWhere( [ 'pp_page' => array_keys( $titles ), + 'pp_propname' => self::getPropNames( $params['license'] ) ] ); $res = $this->select( __METHOD__ ); @@ -179,22 +182,22 @@ * @param int $size The thumbsize value from the API request */ protected function setResultValues( array $prop, $pageId, $fileName, $size ) { - $vals = array(); + $vals = []; if ( isset( $prop['thumbnail'] ) || isset( $prop['original'] ) ) { $file = wfFindFile( $fileName ); if ( $file ) { if ( isset( $prop['thumbnail'] ) ) { - $thumb = $file->transform( array( 'width' => $size, 'height' => $size ) ); + $thumb = $file->transform( [ 'width' => $size, 'height' => $size ] ); if ( $thumb && $thumb->getUrl() ) { // You can request a thumb 1000x larger than the original // which (in case of bitmap original) will return a Thumb object // that will lie about its size but have the original as an image. $reportedSize = $thumb->fileIsSource() ? $file : $thumb; - $vals['thumbnail'] = array( + $vals['thumbnail'] = [ 'source' => wfExpandUrl( $thumb->getUrl(), PROTO_CURRENT ), 'width' => $reportedSize->getWidth(), 'height' => $reportedSize->getHeight(), - ); + ]; } } @@ -203,9 +206,9 @@ if ( isset( $vals['thumbnail'] ) ) { $vals['thumbnail']['original'] = $original_url; } else { - $vals['thumbnail'] = array( + $vals['thumbnail'] = [ 'original' => $original_url, - ); + ]; } } } @@ -215,7 +218,7 @@ $vals['pageimage'] = $fileName; } - $this->getResult()->addValue( array( 'query', 'pages' ), $pageId, $vals ); + $this->getResult()->addValue( [ 'query', 'pages' ], $pageId, $vals ); } /** @@ -226,60 +229,65 @@ } public function getAllowedParams() { - return array( - 'prop' => array( - ApiBase::PARAM_TYPE => array( 'thumbnail', 'name', 'original' ), + return [ + 'prop' => [ + ApiBase::PARAM_TYPE => [ 'thumbnail', 'name', 'original' ], ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'thumbnail|name', - ), - 'thumbsize' => array( + ], + 'thumbsize' => [ ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_DFLT => 50, - ), - 'limit' => array( + ], + 'limit' => [ ApiBase::PARAM_DFLT => 1, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => 50, ApiBase::PARAM_MAX2 => 100, - ), + ], 'license' => [ ApiBase::PARAM_TYPE => [ self::PARAM_LICENSE_FREE, self::PARAM_LICENSE_ANY ], ApiBase::PARAM_ISMULTI => false, ApiBase::PARAM_DFLT => self::PARAM_LICENSE_FREE, ], - 'continue' => array( + 'continue' => [ ApiBase::PARAM_TYPE => 'integer', - /** @todo Once support for MediaWiki < 1.25 is dropped, just use ApiBase::PARAM_HELP_MSG directly */ - defined( 'ApiBase::PARAM_HELP_MSG' ) ? ApiBase::PARAM_HELP_MSG : '' => 'api-help-param-continue', - ), - ); + /** + * @todo + * Once support for MediaWiki < 1.25 is dropped, just use + * ApiBase::PARAM_HELP_MSG directly + */ + defined( 'ApiBase::PARAM_HELP_MSG' ) + ? ApiBase::PARAM_HELP_MSG : '' => 'api-help-param-continue', + ], + ]; } /** * @deprecated since MediaWiki core 1.25 */ public function getParamDescription() { - return array( - 'prop' => array( 'What information to return', + return [ + 'prop' => [ 'What information to return', ' thumbnail - URL and dimensions of image associated with page, if any', ' name - image title', ' original - URL to the image original', - ), + ], 'thumbsize' => 'Maximum thumbnail dimension', 'limit' => 'Properties of how many pages to return', 'continue' => 'When more results are available, use this to continue', - ); + ]; } /** * @see ApiBase::getExamplesMessages() */ protected function getExamplesMessages() { - return array( + return [ 'action=query&prop=pageimages&titles=Albert%20Einstein&pithumbsize=100' => 'apihelp-query+pageimages-example-1', - ); + ]; } } diff --git a/includes/LinksUpdateHookHandler.php b/includes/LinksUpdateHookHandler.php index d63e879..5d73f7a 100644 --- a/includes/LinksUpdateHookHandler.php +++ b/includes/LinksUpdateHookHandler.php @@ -42,7 +42,7 @@ return; } - $scores = array(); + $scores = []; $counter = 0; foreach ( $images as $image ) { @@ -206,7 +206,7 @@ } wfDebug( __METHOD__ . "(): cache miss\n" ); - $list = array(); + $list = []; foreach ( $wgPageImagesBlacklist as $source ) { switch ( $source['type'] ) { @@ -217,7 +217,8 @@ $list = array_merge( $list, $this->getUrlBlacklist( $source['url'] ) ); break; default: - throw new Exception( __METHOD__ . "(): unrecognized image blacklist type '{$source['type']}'" ); + throw new Exception( + __METHOD__ . "(): unrecognized image blacklist type '{$source['type']}'" ); } } @@ -235,21 +236,21 @@ * @return string[] */ private function getDbBlacklist( $dbName, $page ) { - $dbr = wfGetDB( DB_SLAVE, array(), $dbName ); + $dbr = wfGetDB( DB_SLAVE, [], $dbName ); $title = Title::newFromText( $page ); - $list = array(); + $list = []; $id = $dbr->selectField( 'page', 'page_id', - array( 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() ), + [ 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() ], __METHOD__ ); if ( $id ) { $res = $dbr->select( 'pagelinks', 'pl_title', - array( 'pl_from' => $id, 'pl_namespace' => NS_FILE ), + [ 'pl_from' => $id, 'pl_namespace' => NS_FILE ], __METHOD__ ); foreach ( $res as $row ) { @@ -272,7 +273,7 @@ private function getUrlBlacklist( $url ) { global $wgFileExtensions; - $list = array(); + $list = []; $text = Http::get( $url, 3 ); $regex = '/\[\[:([^|\#]*?\.(?:' . implode( '|', $wgFileExtensions ) . '))/i'; diff --git a/includes/PageImages.php b/includes/PageImages.php index d84df6b..96b7a9f 100644 --- a/includes/PageImages.php +++ b/includes/PageImages.php @@ -41,7 +41,7 @@ $dbr = wfGetDB( DB_SLAVE ); $name = $dbr->selectField( 'page_props', 'pp_value', - array( 'pp_page' => $title->getArticleID(), 'pp_propname' => self::PROP_NAME ), + [ 'pp_page' => $title->getArticleID(), 'pp_propname' => self::PROP_NAME ], __METHOD__ ); @@ -74,21 +74,21 @@ $thumbSetting = $context->getUser()->getOption( 'thumbsize' ); $thumbSize = $wgThumbLimits[$thumbSetting]; - $thumb = $imageFile->transform( array( 'width' => $thumbSize ) ); + $thumb = $imageFile->transform( [ 'width' => $thumbSize ] ); if ( !$thumb ) { return; } $imageHtml = $thumb->toHtml( - array( + [ 'alt' => $imageFile->getTitle()->getText(), 'desc-link' => true, - ) + ] ); - $pageInfo['header-basic'][] = array( + $pageInfo['header-basic'][] = [ $context->msg( 'pageimages-info-label' ), $imageHtml - ); + ]; } /** @@ -121,10 +121,10 @@ * @param array[] $watchlist * @param array[] &$images */ - public static function onSpecialMobileEditWatchlist_images( IContextSource $context, array $watchlist, - array &$images + public static function onSpecialMobileEditWatchlist_images( + IContextSource $context, array $watchlist, array &$images ) { - $ids = array(); + $ids = []; foreach ( $watchlist as $ns => $pages ) { foreach ( array_keys( $pages ) as $dbKey ) { $title = Title::makeTitle( $ns, $dbKey ); @@ -154,13 +154,13 @@ * @return array[] */ private static function getImages( array $pageIds, $size = 0 ) { - $request = array( + $request = [ 'action' => 'query', 'prop' => 'pageimages', 'piprop' => 'name', 'pageids' => implode( '|', $pageIds ), 'pilimit' => 'max', - ); + ]; if ( $size ) { $request['piprop'] = 'thumbnail'; @@ -171,14 +171,14 @@ $api->execute(); if ( defined( 'ApiResult::META_CONTENT' ) ) { - return (array)$api->getResult()->getResultData( array( 'query', 'pages' ), - array( 'Strip' => 'base' ) ); + return (array)$api->getResult()->getResultData( [ 'query', 'pages' ], + [ 'Strip' => 'base' ] ); } else { $data = $api->getResultData(); if ( isset( $data['query']['pages'] ) ) { return $data['query']['pages']; } - return array(); + return []; } } diff --git a/includes/ParserFileProcessingHookHandlers.php b/includes/ParserFileProcessingHookHandlers.php index 2cc5a1e..658bcb7 100644 --- a/includes/ParserFileProcessingHookHandlers.php +++ b/includes/ParserFileProcessingHookHandlers.php @@ -42,7 +42,9 @@ * @param Parser $parser * @param ImageGalleryBase $gallery */ - public static function onAfterParserFetchFileAndTitle( Parser $parser, ImageGalleryBase $gallery ) { + public static function onAfterParserFetchFileAndTitle( + Parser $parser, ImageGalleryBase $gallery + ) { $handler = new self(); $handler->doAfterParserFetchFileAndTitle( $parser, $gallery ); } @@ -93,7 +95,7 @@ $myParams = $handlerParams; $this->calcWidth( $myParams, $file ); } else { - $myParams = array(); + $myParams = []; } $myParams['filename'] = $file->getTitle()->getDBkey(); @@ -101,7 +103,7 @@ $myParams['fullheight'] = $file->getHeight(); $out = $parser->getOutput(); - $pageImages = $out->getExtensionData( 'pageImages' ) ?: array(); + $pageImages = $out->getExtensionData( 'pageImages' ) ?: []; $pageImages[] = $myParams; $out->setExtensionData( 'pageImages', $pageImages ); } -- To view, visit https://gerrit.wikimedia.org/r/322793 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c3c685f286fb379c7a1be3d483665cbb43ca803 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageImages Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits