Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277982
Change subject: Split out language staging
......................................................................
Split out language staging
Change-Id: Iba744e3bdfc9481fcc4db077e679730f3f29cf83
---
M DonationInterface.php
A gateway_common/DonorLanguage.php
A globalcollect_gateway/IngenicoLanguage.php
M globalcollect_gateway/globalcollect.adapter.php
4 files changed, 39 insertions(+), 25 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/82/277982/1
diff --git a/DonationInterface.php b/DonationInterface.php
index 533b5c4..e429406 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -50,6 +50,7 @@
$wgAutoloadClasses['DonationQueue'] = __DIR__ .
'/gateway_common/DonationQueue.php';
$wgAutoloadClasses['DonorEmail'] = __DIR__ . '/gateway_common/DonorEmail.php';
$wgAutoloadClasses['DonorFullName'] = __DIR__ .
'/gateway_common/DonorFullName.php';
+$wgAutoloadClasses['DonorLanguage'] = __DIR__ .
'/gateway_common/DonorLanguage.php';
$wgAutoloadClasses['EncodingMangler'] = __DIR__ .
'/gateway_common/EncodingMangler.php';
$wgAutoloadClasses['FinalStatus'] = __DIR__ .
'/gateway_common/FinalStatus.php';
$wgAutoloadClasses['GatewayAdapter'] = __DIR__ .
'/gateway_common/gateway.adapter.php';
@@ -85,6 +86,7 @@
$wgAutoloadClasses['GlobalCollectAdapter'] = __DIR__ .
'/globalcollect_gateway/globalcollect.adapter.php';
$wgAutoloadClasses['GlobalCollectOrphanAdapter'] = __DIR__ .
'/globalcollect_gateway/orphan.adapter.php';
$wgAutoloadClasses['GlobalCollectOrphanRectifier'] = __DIR__ .
'/globalcollect_gateway/GlobalCollectOrphanRectifier.php';
+$wgAutoloadClasses['IngenicoLanguage'] = __DIR__ .
'/globalcollect_gateway/IngenicoLanguage.php';
// Amazon
$wgAutoloadClasses['AmazonGateway'] = __DIR__ .
'/amazon_gateway/amazon_gateway.body.php';
diff --git a/gateway_common/DonorLanguage.php b/gateway_common/DonorLanguage.php
new file mode 100644
index 0000000..c654c0c
--- /dev/null
+++ b/gateway_common/DonorLanguage.php
@@ -0,0 +1,23 @@
+<?php
+
+class DonorLanguage implements StagingHelper {
+ public function stage( GatewayType $adapter, $unstagedData,
&$stagedData ) {
+ $language = strtolower( $unstagedData['language'] );
+ $adapterLanguages = $adapter->getAvailableLanguages();
+ if ( !in_array( $language, $adapterLanguages ) ) {
+ $fallbacks = Language::getFallbacksFor( $language );
+ foreach ( $fallbacks as $fallback ) {
+ if ( in_array( $fallback, $adapterLanguages ) )
{
+ $language = $fallback;
+ break;
+ }
+ }
+ }
+
+ if ( !in_array( $language, $adapterLanguages ) ){
+ $language = 'en';
+ }
+
+ $stagedData['language'] = $language;
+ }
+}
diff --git a/globalcollect_gateway/IngenicoLanguage.php
b/globalcollect_gateway/IngenicoLanguage.php
new file mode 100644
index 0000000..8f822a9
--- /dev/null
+++ b/globalcollect_gateway/IngenicoLanguage.php
@@ -0,0 +1,12 @@
+<?php
+
+class IngenicoLanguage extends DonorLanguage {
+ public function stage( GatewayType $adapter, $unstagedData,
&$stagedData ) {
+ parent::stage( $adapter, $unstagedData, $stagedData );
+
+ // Handle GC's mutant Chinese code.
+ if ( $stagedData['language'] === 'zh' ) {
+ $stagedData['language'] = 'sc';
+ }
+ }
+}
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index 7fd931e..c7b4d63 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -2293,38 +2293,15 @@
$this->data_transformers = array_merge(
parent::getCoreDataTransformers(), array(
new BrazilianFiscalNumber(),
new ContributionTrackingPlusUnique(),
+ new IngenicoLanguage(),
) );
- }
-
- protected function stage_language() {
- $language = strtolower( $this->getData_Unstaged_Escaped(
'language' ) );
-
- if ( !in_array( $language, $this->getAvailableLanguages() ) ) {
- $fallbacks = Language::getFallbacksFor( $language );
- foreach ( $fallbacks as $fallback ) {
- if ( in_array( $fallback,
$this->getAvailableLanguages() ) ) {
- $language = $fallback;
- break;
- }
- }
- }
-
- if ( !in_array( $language, $this->getAvailableLanguages() ) ){
- $language = 'en';
- }
-
- if ( $language === 'zh' ) { //Handles GC's mutant Chinese code.
- $language = 'sc';
- }
-
- $this->staged_data['language'] = $language;
}
/**
* OUR language codes which are available to use in GlobalCollect.
* @return string
*/
- function getAvailableLanguages(){
+ public function getAvailableLanguages(){
$languages = array(
'ar', //Arabic
'cs', //Czech
--
To view, visit https://gerrit.wikimedia.org/r/277982
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba744e3bdfc9481fcc4db077e679730f3f29cf83
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits