From 943a06e6becb21867d13e1dcbc9e349c141b3efb Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Fri, 19 May 2017 15:26:17 +0200 Subject: [PATCH] Add phpcs and make pass Change-Id: Iae1194f930fe70ec82ac4ca9b96ac75416b8b904 --- MultimediaViewer.php | 3 +- MultimediaViewerHooks.php | 66 ++++++++++++++++++++++++--------------- composer.json | 7 +++-- phpcs.xml | 9 ++++++ 4 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 phpcs.xml diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 24ed1767a..aa2ba14df 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -27,7 +27,8 @@ if ( function_exists( 'wfLoadExtension' ) ) { // Keep i18n globals so mergeMessageFileList.php doesn't break $wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n'; /* wfWarn( - 'Deprecated PHP entry point used for MultimediaViewer extension. Please use wfLoadExtension instead, ' . + 'Deprecated PHP entry point used for MultimediaViewer extension. ' . + 'Please use wfLoadExtension instead, ' . 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' ); */ return; diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 2fb28cc6e..dbc667beb 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -23,23 +23,30 @@ class MultimediaViewerHooks { /** Link to more information about this module */ - protected static $infoLink = '//mediawiki.org/wiki/Special:MyLanguage/Extension:Media_Viewer/About'; + protected static $infoLink = + '//mediawiki.org/wiki/Special:MyLanguage/Extension:Media_Viewer/About'; /** Link to a page where this module can be discussed */ - protected static $discussionLink = '//mediawiki.org/wiki/Special:MyLanguage/Extension_talk:Media_Viewer/About'; + protected static $discussionLink = + '//mediawiki.org/wiki/Special:MyLanguage/Extension_talk:Media_Viewer/About'; /** Link to help about this module */ protected static $helpLink = '//mediawiki.org/wiki/Special:MyLanguage/Help:Extension:Media_Viewer'; public static function registerExtension() { - global $wgMediaViewerNetworkPerformanceSamplingFactor, $wgMediaViewerDurationLoggingSamplingFactor, - $wgMediaViewerDurationLoggingLoggedinSamplingFactor, $wgMediaViewerAttributionLoggingSamplingFactor, - $wgMediaViewerDimensionLoggingSamplingFactor, $wgMediaViewerActionLoggingSamplingFactorMap, - $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerEnableByDefault, + global $wgMediaViewerNetworkPerformanceSamplingFactor, + $wgMediaViewerDurationLoggingSamplingFactor, + $wgMediaViewerDurationLoggingLoggedinSamplingFactor, + $wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor, + $wgMediaViewerActionLoggingSamplingFactorMap, $wgMediaViewerIsInBeta, + $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerEnableByDefault, $wgMediaViewerEnableByDefaultForAnonymous, $wgMediaViewerImageQueryParameter, $wgMediaViewerRecordVirtualViewBeaconURI; + if ( !isset( $wgMediaViewerNetworkPerformanceSamplingFactor ) ) { - /** @var int|bool: If set, records image load network performance via EventLogging once per this many requests. False if unset. **/ + /** @var int|bool: If set, records image load network performance via + * EventLogging once per this many requests. False if unset. + */ $wgMediaViewerNetworkPerformanceSamplingFactor = false; } @@ -65,8 +72,8 @@ class MultimediaViewerHooks { if ( !isset( $wgMediaViewerAttributionLoggingSamplingFactor ) ) { /** - * If set, records whether image attribution data was available. A value of 1000 means there will be an - * 1:1000 chance to log the attribution event. + * If set, records whether image attribution data was available. + * A value of 1000 means there will be an 1:1000 chance to log the attribution event. * False if unset. * @var int|bool */ @@ -75,8 +82,8 @@ class MultimediaViewerHooks { if ( !isset( $wgMediaViewerDimensionLoggingSamplingFactor ) ) { /** - * If set, records whether image dimension data was available. A value of 1000 means there will be an - * 1:1000 chance to log the dimension event. + * If set, records whether image dimension data was available. + * A value of 1000 means there will be an 1:1000 chance to log the dimension event. * False if unset. * @var int|bool */ @@ -85,7 +92,8 @@ class MultimediaViewerHooks { if ( !isset( $wgMediaViewerActionLoggingSamplingFactorMap ) ) { /** - * If set, records user actions via EventLogging and applies a sampling factor according to the map. A "default" key in the map must be set. + * If set, records user actions via EventLogging and applies a sampling factor according + * to the map. A "default" key in the map must be set. * False if unset. * @var array|bool */ @@ -100,11 +108,12 @@ class MultimediaViewerHooks { if ( !isset( $wgMediaViewerUseThumbnailGuessing ) ) { /** * When this is enabled, MediaViewer will try to guess image URLs instead of making an - * imageinfo API to get them from the server. This speeds up image loading, but will result in 404s - * when $wgGenerateThumbnailOnParse (so the thumbnails are only generated as a result of the API request). - * MediaViewer will catch such 404 errors and fall back to the API request, but depending on how the site - * is set up, the 404 might get cached, or redirected, causing the image load to fail. The safe way to - * use URL guessing is with a 404 handler: https://www.mediawiki.org/wiki/Manual:Thumb.php#404_Handler + * imageinfo API to get them from the server. This speeds up image loading, but will + * result in 404s when $wgGenerateThumbnailOnParse (so the thumbnails are only generated + * as a result of the API request). MediaViewer will catch such 404 errors and fall back + * to the API request, but depending on how the site is set up, the 404 might get cached, + * or redirected, causing the image load to fail. The safe way to use URL guessing is + * with a 404 handler: https://www.mediawiki.org/wiki/Manual:Thumb.php#404_Handler * * @var bool */ @@ -113,7 +122,8 @@ class MultimediaViewerHooks { if ( !isset( $wgMediaViewerEnableByDefault ) ) { /** - * If trueish, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on by default. + * If trueish, and $wgMediaViewerIsInBeta is unset, + * Media Viewer will be turned on by default. * @var bool */ $wgMediaViewerEnableByDefault = true; @@ -290,11 +300,14 @@ class MultimediaViewerHooks { * @return bool */ public static function resourceLoaderGetConfigVars( &$vars ) { - global $wgMediaViewerActionLoggingSamplingFactorMap, $wgMediaViewerNetworkPerformanceSamplingFactor, - $wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor, - $wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor, - $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter, - $wgMediaViewerRecordVirtualViewBeaconURI, $wgMediaViewerExtensions; + global $wgMediaViewerActionLoggingSamplingFactorMap, + $wgMediaViewerNetworkPerformanceSamplingFactor, + $wgMediaViewerDurationLoggingSamplingFactor, + $wgMediaViewerDurationLoggingLoggedinSamplingFactor, + $wgMediaViewerAttributionLoggingSamplingFactor, + $wgMediaViewerDimensionLoggingSamplingFactor, + $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerExtensions, + $wgMediaViewerImageQueryParameter, $wgMediaViewerRecordVirtualViewBeaconURI; $vars['wgMultimediaViewer'] = [ 'infoLink' => self::$infoLink, @@ -329,7 +342,8 @@ class MultimediaViewerHooks { $user = $out->getUser(); $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user ); // needed because of bug 69942; could be different for anon and logged-in - $vars['wgMediaViewerEnabledByDefault'] = !empty( $wgDefaultUserOptions['multimediaviewer-enable'] ); + $vars['wgMediaViewerEnabledByDefault'] = + !empty( $wgDefaultUserOptions['multimediaviewer-enable'] ); } /** @@ -414,7 +428,9 @@ class MultimediaViewerHooks { * @param array $attribs Attributes of the element * @param array|boolean $linkAttribs Attributes of the wrapping element */ - public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs, &$linkAttribs ) { + public static function thumbnailBeforeProduceHTML( ThumbnailImage $thumbnail, array &$attribs, + &$linkAttribs + ) { $file = $thumbnail->getFile(); if ( $file ) { diff --git a/composer.json b/composer.json index 686b65b91..b8f68fb36 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/phpcs.xml b/phpcs.xml new file mode 100644 index 000000000..ede6c5da4 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,9 @@ + + + + . + + + vendor + node_modules +