jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/357019 )
Change subject: Add phpcs and make pass ...................................................................... Add phpcs and make pass Change-Id: I6521ab780b64b724a3342b8d795d0bd13f32051d --- M ApiContributionTracking.php M ContributionTracking.hooks.php M ContributionTracking.php M ContributionTracking.processor.php M ContributionTracking_Tester.php M ContributionTracking_body.php M composer.json A phpcs.xml M special/SpecialFundraiserMaintenance.php 9 files changed, 149 insertions(+), 139 deletions(-) Approvals: jenkins-bot: Verified Jforrester: Looks good to me, approved diff --git a/ApiContributionTracking.php b/ApiContributionTracking.php index fbb91c9..6ed4812 100644 --- a/ApiContributionTracking.php +++ b/ApiContributionTracking.php @@ -30,7 +30,7 @@ foreach ( $params as $key => $value ) { if ( $value === '' ) { - unset( $params[$key] ); //gotcha. And might I add: BOO-URNS. + unset( $params[$key] ); // gotcha. And might I add: BOO-URNS. } } return $params; @@ -42,18 +42,18 @@ * @param array $params Original (staged) request paramaters. */ function doReturn( $id, $params ) { -// foreach ($params as $key=>$value){ -// if ($value != ''){ -// $this->getResult()->addValue(array('returns', 'parrot'), $key, $value); -// } -// } + // foreach ($params as $key=>$value){ + // if ($value != ''){ + // $this->getResult()->addValue(array('returns', 'parrot'), $key, $value); + // } + // } $params['contribution_tracking_id'] = $id; $repost = ContributionTrackingProcessor::getRepostFields( $params ); - $this->getResult()->addValue( array( 'returns', 'action' ), 'url', $repost['action'] ); + $this->getResult()->addValue( [ 'returns', 'action' ], 'url', $repost['action'] ); foreach ( $repost['fields'] as $key => $value ) { - $this->getResult()->addValue( array( 'returns', 'fields' ), $key, $value ); + $this->getResult()->addValue( [ 'returns', 'fields' ], $key, $value ); } } @@ -62,101 +62,101 @@ * @return array An array of parameters allowed by ApiContributionTracking */ public function getAllowedParams() { - return array( - 'amount' => array( + return [ + 'amount' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, - ), - 'referrer' => array( + ], + 'referrer' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, - ), - 'gateway' => array( + ], + 'gateway' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, - ), - 'comment' => array( + ], + 'comment' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'comment-option' => array( + ], + 'comment-option' => [ ApiBase::PARAM_TYPE => 'boolean', - ), - 'utm_source' => array( + ], + 'utm_source' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'utm_medium' => array( + ], + 'utm_medium' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'utm_campaign' => array( + ], + 'utm_campaign' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'utm_key' => array( + ], + 'utm_key' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'payments_form' => array( + ], + 'payments_form' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'email-opt' => array( + ], + 'email-opt' => [ ApiBase::PARAM_TYPE => 'boolean', - ), - 'language' => array( + ], + 'language' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'country' => array( + ], + 'country' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'owa_session' => array( + ], + 'owa_session' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'owa_ref' => array( + ], + 'owa_ref' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'contribution_tracking_id' => array( + ], + 'contribution_tracking_id' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'returnto' => array( + ], + 'returnto' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'tshirt' => array( + ], + 'tshirt' => [ ApiBase::PARAM_TYPE => 'boolean', - ), - 'size' => array( + ], + 'size' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'premium_language' => array( + ], + 'premium_language' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'currency_code' => array( + ], + 'currency_code' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'fname' => array( + ], + 'fname' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'lname' => array( + ], + 'lname' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'email' => array( + ], + 'email' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'recurring_paypal' => array( + ], + 'recurring_paypal' => [ ApiBase::PARAM_TYPE => 'boolean', - ), - 'amountGiven' => array( + ], + 'amountGiven' => [ ApiBase::PARAM_TYPE => 'string', - ), - ); + ], + ]; } /** * @deprecated since MediaWiki core 1.25 */ public function getParamDescription() { - return array( + return [ 'amount' => 'Transaction amount (required)', 'referrer' => 'String identifying the referring entity (required)', - 'gateway' => array( + 'gateway' => [ 'String identifying the specific entity used to process this payment. ', - 'Probably "paypal". (required)' ), + 'Probably "paypal". (required)' ], 'comment' => 'String with a comment. Actually saved as "note" in the database', 'comment-option' => 'Boolean assumed to be from a checkbox. ' . 'This is actually the inverse of the anonymous flag.', @@ -168,13 +168,13 @@ 'which the donation was made', 'email-opt' => 'Boolean assumed to be from a checkbox. This is actually the inverse ' . 'of the email opt-out checkbox.', - 'language' => array( + 'language' => [ 'User language code. Messages will be translated appropriately (where possible).', 'This will also determine what "Thank You" page the user sees upon completion of ' . - 'a donation at the gateway.' ), + 'a donation at the gateway.' ], 'country' => 'User country code.', 'contribution_tracking_id' => 'Our ID for the current contribution. ' . - 'Not supplied for new contributions.', //in fact, why is this here? + 'Not supplied for new contributions.', // in fact, why is this here? 'returnto' => 'String identifying an alternate "Thank You" page to show the user ' . 'on completion of their transaction.', 'tshirt' => 'Boolean indicating whether or not there is a t-shirt involved.', @@ -188,38 +188,38 @@ 'recurring_paypal' => 'Boolean identifying a recurring donation. ' . 'Do not supply at all for a one-time donation.', 'amountGiven' => 'Normalized amount.' - ); + ]; } /** * @deprecated since MediaWiki core 1.25 */ public function getDescription() { - return array( + return [ 'Track donor contributions via API', 'This API exists so we are able to eliminate the interstitial page', 'that would otherwise be used to track contributions before sending', 'the donor off to paypal (or wherever).', - ); + ]; } /** * @deprecated since MediaWiki core 1.25 */ public function getExamples() { - return array( + return [ 'api.php?action=contributiontracking&comment=examplecomment&referrer=examplereferrer' . '&gateway=paypal&amount=5.50', - ); + ]; } /** * @see ApiBase::getExamplesMessages() */ protected function getExamplesMessages() { - return array( + return [ 'action=contributiontracking&comment=examplecomment&referrer=examplereferrer' . '&gateway=paypal&amount=5.50' => 'apihelp-contributiontracking-example-1', - ); + ]; } } diff --git a/ContributionTracking.hooks.php b/ContributionTracking.hooks.php index 4076260..5d93f7f 100644 --- a/ContributionTracking.hooks.php +++ b/ContributionTracking.hooks.php @@ -17,42 +17,42 @@ if ( $updater === null ) { global $wgExtNewTables, $wgExtNewFields; - $wgExtNewTables[] = array( 'contribution_tracking', $dir . 'ContributionTracking.sql' ); - $wgExtNewTables[] = array( 'contribution_tracking_owa_ref', - $dir . 'ContributionTracking_OWA_ref.sql' ); + $wgExtNewTables[] = [ 'contribution_tracking', $dir . 'ContributionTracking.sql' ]; + $wgExtNewTables[] = [ 'contribution_tracking_owa_ref', + $dir . 'ContributionTracking_OWA_ref.sql' ]; - $wgExtNewFields[] = array( + $wgExtNewFields[] = [ 'contribution_tracking', 'owa_session', $dir . 'patch-owa.sql', - ); + ]; } else { global $wgContributionTrackingDBname; - if( $updater->getDB()->getDBname() === $wgContributionTrackingDBname ) { + if ( $updater->getDB()->getDBname() === $wgContributionTrackingDBname ) { $updater->addExtensionTable( 'contribution_tracking', $dir . 'ContributionTracking.sql' ); $updater->addExtensionTable( 'contribution_tracking_owa_ref', $dir . 'ContributionTracking_OWA_ref.sql' ); - $updater->addExtensionUpdate( array( 'addField', 'contribution_tracking', - 'owa_session', $dir . 'patches/patch-owa.sql', true ) ); - $updater->addExtensionUpdate( array( 'addField', 'contribution_tracking', 'utm_key', - $dir . 'patches/patch-owa.sql', true ) ); + $updater->addExtensionUpdate( [ 'addField', 'contribution_tracking', + 'owa_session', $dir . 'patches/patch-owa.sql', true ] ); + $updater->addExtensionUpdate( [ 'addField', 'contribution_tracking', 'utm_key', + $dir . 'patches/patch-owa.sql', true ] ); if ( $updater->getDB()->getType() !== 'sqlite' ) { // Not sure how to do this in the other configurations, but I guess // "manually" might be the answer. - $updater->addExtensionUpdate( array( 'modifyField', 'contribution_tracking', - 'anonymous', $dir . 'patches/make-null.patch.sql', true ) ); + $updater->addExtensionUpdate( [ 'modifyField', 'contribution_tracking', + 'anonymous', $dir . 'patches/make-null.patch.sql', true ] ); } if ( $updater->getDB()->getType() !== 'postgres' ) { - $updater->addExtensionUpdate( array( 'addTable', 'contribution_tracking', - $dir . 'ContributionTracking.pg.sql', true ) ); + $updater->addExtensionUpdate( [ 'addTable', 'contribution_tracking', + $dir . 'ContributionTracking.pg.sql', true ] ); } - } else { //We are configured not to use the main mediawiki db. - //Unless the updater is modified not to run - //'LoadExtensionSchemaUpdates' hooks in its constructor (or do so - //conditionally), we're going to have to do these manually. + } else { // We are configured not to use the main mediawiki db. + // Unless the updater is modified not to run + // 'LoadExtensionSchemaUpdates' hooks in its constructor (or do so + // conditionally), we're going to have to do these manually. $ctDB = ContributionTrackingProcessor::contributionTrackingConnection(); if ( !$ctDB->tableExists( 'contribution_tracking' ) ){ $ctDB->sourceFile( $dir . 'ContributionTracking.sql' ); diff --git a/ContributionTracking.php b/ContributionTracking.php index b7365e3..175f68c 100644 --- a/ContributionTracking.php +++ b/ContributionTracking.php @@ -16,13 +16,13 @@ * Setup for pre-1.25 wikis. Make sure this is kept in sync with extension.json */ -$wgExtensionCredits['specialpage'][] = array( +$wgExtensionCredits['specialpage'][] = [ 'path' => __FILE__, 'name' => 'ContributionTracking', 'url' => 'https://www.mediawiki.org/wiki/Extension:ContributionTracking', 'author' => 'David Strauss', 'descriptionmsg' => 'contributiontracking-desc', -); +]; $dir = __DIR__ . '/'; @@ -39,31 +39,31 @@ $dir . 'special/SpecialFundraiserMaintenance.php'; $wgSpecialPages['FundraiserMaintenance'] = 'SpecialFundraiserMaintenance'; -//give sysops access to the tracking tester form. +// give sysops access to the tracking tester form. $wgGroupPermissions['sysop']['ViewContributionTrackingTester'] = true; $wgAvailableRights[] = 'ViewContributionTrackingTester'; $wgAutoloadClasses['ApiContributionTracking'] = $dir . 'ApiContributionTracking.php'; $wgAutoloadClasses['ContributionTrackingProcessor'] = $dir . 'ContributionTracking.processor.php'; -//this only works if contribution tracking is inside a mediawiki DB, which typically it isn't. +// this only works if contribution tracking is inside a mediawiki DB, which typically it isn't. $wgHooks['LoadExtensionSchemaUpdates'][] = 'ContributionTrackingHooks::onLoadExtensionSchemaUpdates'; // Resource modules -$ctResourceTemplate = array( +$ctResourceTemplate = [ 'localBasePath' => $dir . 'modules', 'remoteExtPath' => 'ContributionTracking/modules', -); -$wgResourceModules['jquery.contributionTracking'] = array( +]; +$wgResourceModules['jquery.contributionTracking'] = [ 'scripts' => 'jquery.contributionTracking.js', -) + $ctResourceTemplate; +] + $ctResourceTemplate; -$wgResourceModules['contributionTracking.fundraiserMaintenance'] = array( - 'styles' => array('skinOverride.css',), - 'scripts' => array(), +$wgResourceModules['contributionTracking.fundraiserMaintenance'] = [ + 'styles' => [ 'skinOverride.css', ], + 'scripts' => [], 'position' => 'top', -) + $ctResourceTemplate; +] + $ctResourceTemplate; /** * The default 'return to' URL for a thank you page after posting to the contribution diff --git a/ContributionTracking.processor.php b/ContributionTracking.processor.php index f69b155..50d61c6 100644 --- a/ContributionTracking.processor.php +++ b/ContributionTracking.processor.php @@ -52,7 +52,7 @@ * @return integer The id of the saved contribution in the * contribution_tracking table */ - static function saveNewContribution( $params = array( ) ) { + static function saveNewContribution( $params = [] ) { $db = ContributionTrackingProcessor::contributionTrackingConnection(); $params['ts'] = $db->timestamp(); @@ -72,10 +72,10 @@ * @return array Staged key-value pairs ready to be saved as a contribution. */ static function stage_contribution( $params ) { - //change the posted names to match the db where necessary + // change the posted names to match the db where necessary ContributionTrackingProcessor::rekey( $params, 'comment', 'note' ); - if( !array_key_exists( 'form_amount', $params ) ){ + if ( !array_key_exists( 'form_amount', $params ) ){ if ( array_key_exists( 'currency_code', $params ) && array_key_exists( 'amount', $params ) ) { @@ -95,12 +95,12 @@ * @return array Staged array */ static function stage_repost( $params ) { - //TODO: assert that gateway makes The Sense here. - //change the posted names to match the db where necessary + // TODO: assert that gateway makes The Sense here. + // change the posted names to match the db where necessary ContributionTrackingProcessor::rekey( $params, 'amountGiven', 'amount_given' ); ContributionTrackingProcessor::rekey( $params, 'returnto', 'return' ); - //booleanize! + // booleanize! ContributionTrackingProcessor::stage_checkbox( $params, 'recurring_paypal' ); // poke our language function with the current parameters - @@ -142,8 +142,8 @@ * @param string $key The key of a checkbox-generated value */ static function stage_checkbox( &$array, $key ) { - //apparently so far in the code, if the key exists, the value is considered true - //and is therefore set to "1" + // apparently so far in the code, if the key exists, the value is considered true + // and is therefore set to "1" if ( array_key_exists( $key, $array ) && $array[$key] !== false ) { $array[$key] = 1; } @@ -154,7 +154,7 @@ * @return array Default values for a new contribution. */ static function getContributionDefaults() { - return array( //defaults + return [ // defaults 'form_amount' => null, 'usd_amount' => null, 'note' => null, @@ -169,7 +169,7 @@ 'language' => null, 'country' => null, 'ts' => null, - ); + ]; } /** @@ -177,7 +177,7 @@ * @return array Default values for a payment gateway repost */ static function getRepostDefaults() { - return array( //defaults + return [ // defaults 'gateway' => '', 'tshirt' => false, 'size' => false, @@ -201,7 +201,7 @@ 'country' => 'US', 'address_override' => '0' - ); + ]; } /** @@ -248,7 +248,7 @@ // Set the action and tracking ID fields $input = ContributionTrackingProcessor::stage_repost( $input ); - $repost = array( ); + $repost = []; $repost['action'] = 'https://donate.wikimedia.org/'; // the amount fieldname may be different depending on the service $amount_field_name = 'amount'; @@ -319,7 +319,6 @@ $repost['fields']['address_override'] = $input['address_override']; } - // if this is a recurring donation, we have add'l fields to send to paypal if ( $input['recurring_paypal'] && $input['recurring_paypal'] != 0 ) { @@ -383,11 +382,11 @@ if ( is_array( $params ) && array_key_exists( 'language', $params ) && $params['language'] != null ) { - //set/reset if something inteligable got sent. + // set/reset if something inteligable got sent. $language = $params['language']; } - if ( $language == '' ) { //if we have nothing by this point... + if ( $language == '' ) { // if we have nothing by this point... global $wgLang; $language = $wgLang->getCode(); } diff --git a/ContributionTracking_Tester.php b/ContributionTracking_Tester.php index dc13232..f204c60 100644 --- a/ContributionTracking_Tester.php +++ b/ContributionTracking_Tester.php @@ -1,7 +1,7 @@ <?php /** - * This is a page that exists solely for the purpose of manually testing all + * This is a page that exists solely for the purpose of manually testing all * aspects of the ContributionTracking API: Both send (querystring) and receive * (jquery processing and reposting). Could also be used for browser-based * regression testing of these components. @@ -37,7 +37,7 @@ $apiObj = new ApiContributionTracking( null, null ); $formfields = $apiObj->getFinalParams(); - //$wgOut->addWikiText(print_r($formfields, true)); + // $wgOut->addWikiText(print_r($formfields, true)); $wgOut->addHTML( '<form id="landingpage_submit"><table>' ); foreach ( $formfields as $name => $attribs ) { diff --git a/ContributionTracking_body.php b/ContributionTracking_body.php index 8c29788..2ede76a 100644 --- a/ContributionTracking_body.php +++ b/ContributionTracking_body.php @@ -9,19 +9,19 @@ function execute( $language ) { global $wgContributionTrackingFundraiserMaintenance, - $wgContributionTrackingFundraiserMaintenanceUnsched; + $wgContributionTrackingFundraiserMaintenanceUnsched; - if( $wgContributionTrackingFundraiserMaintenance + if ( $wgContributionTrackingFundraiserMaintenance || $wgContributionTrackingFundraiserMaintenanceUnsched ){ $this->getOutput()->redirect( - Title::newFromText("Special:FundraiserMaintenance")->getFullURL(), "302" + Title::newFromText( "Special:FundraiserMaintenance" )->getFullURL(), "302" ); } $request = $this->getRequest(); $gateway = $request->getText( 'gateway' ); - if ( !in_array( $gateway, array( 'paypal', 'moneybookers' ) ) ) { + if ( !in_array( $gateway, [ 'paypal', 'moneybookers' ] ) ) { $this->getOutput()->showErrorPage( 'contrib-tracking-error', 'contrib-tracking-error-text' ); return; @@ -35,20 +35,20 @@ $this->setHeaders(); $out = $this->getOutput(); - $out->setPageTitle(''); + $out->setPageTitle( '' ); // Store the contribution data if ( $request->getVal( 'contribution_tracking_id' ) ) { $contribution_tracking_id = $request->getVal( 'contribution_tracking_id', 0 ); } else { - $amount = $request->getVal('amount'); + $amount = $request->getVal( 'amount' ); - if( $amount == "Other" && is_numeric( $request->getVal('amountGiven') )){ - $amount = floatval( $request->getVal('amountGiven') ); + if ( $amount == "Other" && is_numeric( $request->getVal( 'amountGiven' ) ) ){ + $amount = floatval( $request->getVal( 'amountGiven' ) ); } - $tracked_contribution = array( - 'form_amount' => $request->getVal('currency_code') . ' ' . $amount, + $tracked_contribution = [ + 'form_amount' => $request->getVal( 'currency_code' ) . ' ' . $amount, 'note' => $request->getVal( 'comment' ), 'referrer' => $request->getVal( 'referrer' ), 'utm_source' => $request->getVal( 'utm_source' ), @@ -57,12 +57,12 @@ 'utm_key' => $request->getVal( 'utm_key' ), 'language' => $request->getVal( 'language' ), 'country' => $request->getVal( 'country' ), - ); + ]; $contribution_tracking_id = ContributionTrackingProcessor::saveNewContribution( $tracked_contribution ); } - $params = array( + $params = [ 'gateway' => $gateway, 'tshirt' => $request->getVal( 'tshirt' ), 'return' => $request->getText( 'returnto', "Donate-thanks/$language" ), @@ -81,7 +81,7 @@ 'amount_given' => $request->getVal( 'amountGiven' ), 'contribution_tracking_id' => $contribution_tracking_id, 'language' => $language, - ); + ]; if ( $params['tshirt'] ) { $params['size'] = $request->getText( 'size' ); 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/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/special/SpecialFundraiserMaintenance.php b/special/SpecialFundraiserMaintenance.php index 9df9b59..6b00582 100644 --- a/special/SpecialFundraiserMaintenance.php +++ b/special/SpecialFundraiserMaintenance.php @@ -23,7 +23,6 @@ class SpecialFundraiserMaintenance extends UnlistedSpecialPage { - public function __construct() { parent::__construct( 'FundraiserMaintenance' ); } -- To view, visit https://gerrit.wikimedia.org/r/357019 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6521ab780b64b724a3342b8d795d0bd13f32051d Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ContributionTracking Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits