Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/300805
Change subject: [WIP] WmfFramework-ization of some MediaWiki assumptions ...................................................................... [WIP] WmfFramework-ization of some MediaWiki assumptions When this patch is ready, it should give us orphan rectification code paths from within Drupal. Bug: T131798 Bug: T131275 Change-Id: Ic9d4636cdb140b4778e8380f87334983a0f29ec8 --- M gateway_common/ContributionTrackingPlusUnique.php M gateway_common/DonationData.php M gateway_common/DonorLanguage.php A gateway_common/LogPrefixProvider.php M gateway_common/WmfFramework.drupal.php M gateway_common/WmfFramework.mediawiki.php M globalcollect_gateway/IngenicoLanguage.php M globalcollect_gateway/IngenicoReturntoHelper.php M globalcollect_gateway/orphan.adapter.php 9 files changed, 60 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/05/300805/1 diff --git a/gateway_common/ContributionTrackingPlusUnique.php b/gateway_common/ContributionTrackingPlusUnique.php index a445e86..f047461 100644 --- a/gateway_common/ContributionTrackingPlusUnique.php +++ b/gateway_common/ContributionTrackingPlusUnique.php @@ -6,6 +6,9 @@ */ class ContributionTrackingPlusUnique implements StagingHelper, UnstagingHelper { public function stage( GatewayType $adapter, $normalized, &$stagedData ) { + if ( !isset( $normalized['contribution_tracking_id'] ) ) { + return; + } $ctid = $normalized['contribution_tracking_id']; //append timestamp to ctid $ctid .= '.' . (( microtime( true ) * 1000 ) % 100000); //least significant five diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php index 711fcd2..f5b57bf 100644 --- a/gateway_common/DonationData.php +++ b/gateway_common/DonationData.php @@ -126,6 +126,10 @@ */ protected function populateData( $external_data = false ) { $this->normalized = array(); + if ( $this->gateway->isBatchProcessor() && !$external_data ) { + // No harvesting to do if we're in batch mode. + return; + } if ( is_array( $external_data ) ) { //I don't care if you're a test or not. At all. $this->normalized = $external_data; @@ -160,12 +164,7 @@ * @return mixed The final value of the var, or null if we don't actually have it. */ protected function sourceHarvest( $var ) { - $ret = $this->gateway->getRequest()->getText( $var, null ); //all strings is just fine. - //getText never returns null: It just casts do an empty string. Soooo... - if ( $ret === '' && !array_key_exists( $var, $_POST ) && !array_key_exists( $var, $_GET ) ) { - $ret = null; //not really there, so stop pretending. - } - + $ret = WmfFramework::getRequestValue( $var, null ); return $ret; } diff --git a/gateway_common/DonorLanguage.php b/gateway_common/DonorLanguage.php index a7aa8af..8051dd0 100644 --- a/gateway_common/DonorLanguage.php +++ b/gateway_common/DonorLanguage.php @@ -2,10 +2,13 @@ class DonorLanguage implements StagingHelper { public function stage( GatewayType $adapter, $normalized, &$stagedData ) { + if ( !isset( $normalized['language'] ) ) { + return; + } $language = $normalized['language']; $adapterLanguages = $adapter->getAvailableLanguages(); if ( !in_array( $language, $adapterLanguages ) ) { - $fallbacks = Language::getFallbacksFor( $language ); + $fallbacks = WmfFramework::getLanguageFallbacks( $language ); foreach ( $fallbacks as $fallback ) { if ( in_array( $fallback, $adapterLanguages ) ) { $language = $fallback; diff --git a/gateway_common/LogPrefixProvider.php b/gateway_common/LogPrefixProvider.php new file mode 100644 index 0000000..1a60433 --- /dev/null +++ b/gateway_common/LogPrefixProvider.php @@ -0,0 +1,5 @@ +<?php + +interface LogPrefixProvider { + function getLogMessagePrefix(); +} diff --git a/gateway_common/WmfFramework.drupal.php b/gateway_common/WmfFramework.drupal.php index 00f8857..a4ce82d 100644 --- a/gateway_common/WmfFramework.drupal.php +++ b/gateway_common/WmfFramework.drupal.php @@ -21,6 +21,10 @@ return '127.0.0.1'; } + static function getRequestValue( $key, $default ) { + throw new Exception( 'Unimplemented' ); + } + static function getHostname() { return 'localhost'; } @@ -35,10 +39,19 @@ } /** - * @throws BadMethodCallException + * Do not guess. */ static function getLanguageCode() { - throw new BadMethodCallException( "Not implemented" ); + return null; + } + + static function getLanguageFallbacks( $language = null ) { + $fallbacks = array(); + if ( $language ) { + $fallbacks[] = $language; + } + $fallbacks[] = 'en'; + return $fallbacks; } static function isUseSquid() { diff --git a/gateway_common/WmfFramework.mediawiki.php b/gateway_common/WmfFramework.mediawiki.php index c3a20ab..8b55486 100644 --- a/gateway_common/WmfFramework.mediawiki.php +++ b/gateway_common/WmfFramework.mediawiki.php @@ -11,6 +11,16 @@ return $request->getIP(); } + static function getRequestValue( $key, $default ) { + //all strings is just fine. + $ret = RequestContext::getMain()->getRequest()->getText( $key, $default ); + //getText never returns null: It just casts do an empty string. Soooo... + if ( $ret === '' && !array_key_exists( $var, $_POST ) && !array_key_exists( $var, $_GET ) ) { + $ret = null; //not really there, so stop pretending. + } + return $ret; + } + static function getHostname() { return wfHostname(); } @@ -28,6 +38,10 @@ return $lang->getCode(); } + static function getLanguageFallbacks( $language = null ) { + return Language::getFallbacksFor( $language ); + } + static function isUseSquid() { global $wgUseSquid; return $wgUseSquid; diff --git a/globalcollect_gateway/IngenicoLanguage.php b/globalcollect_gateway/IngenicoLanguage.php index 8f822a9..73d13f4 100644 --- a/globalcollect_gateway/IngenicoLanguage.php +++ b/globalcollect_gateway/IngenicoLanguage.php @@ -1,8 +1,12 @@ <?php class IngenicoLanguage extends DonorLanguage { - public function stage( GatewayType $adapter, $unstagedData, &$stagedData ) { - parent::stage( $adapter, $unstagedData, $stagedData ); + public function stage( GatewayType $adapter, $normalized, &$stagedData ) { + parent::stage( $adapter, $normalized, $stagedData ); + + if ( !isset( $stagedData['language'] ) ) { + return; + } // Handle GC's mutant Chinese code. if ( $stagedData['language'] === 'zh' ) { diff --git a/globalcollect_gateway/IngenicoReturntoHelper.php b/globalcollect_gateway/IngenicoReturntoHelper.php index 8caf60c..dc89d4f 100644 --- a/globalcollect_gateway/IngenicoReturntoHelper.php +++ b/globalcollect_gateway/IngenicoReturntoHelper.php @@ -2,6 +2,10 @@ class IngenicoReturntoHelper implements StagingHelper { public function stage( GatewayType $adapter, $normalized, &$stagedData ) { + if ( $adapter->isBatchProcessor() ) { + // Only makes sense for real users. + return; + } if ( !empty( $normalized['returnto'] ) ) { $returnto = $normalized['returnto']; } else { diff --git a/globalcollect_gateway/orphan.adapter.php b/globalcollect_gateway/orphan.adapter.php index bb0f38b..d4273d3 100644 --- a/globalcollect_gateway/orphan.adapter.php +++ b/globalcollect_gateway/orphan.adapter.php @@ -166,6 +166,10 @@ return $transaction; } + public function setGatewayDefaults( $options = array ( ) ) { + // No-op to prevent MediaWiki code path. + } + /** * Override live adapter with a no-op since orphan doesn't have any new info * before GET_ORDERSTATUS -- To view, visit https://gerrit.wikimedia.org/r/300805 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic9d4636cdb140b4778e8380f87334983a0f29ec8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits