r93115 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93114‎ | r93115 | r93116 >
Date:21:04, 25 July 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Revert r79408 and delete countryCodes.inc - were changes made immediately post-fundraiser but were never completed and are no longer applicable
Modified paths:
  • /trunk/extensions/ContributionTracking/ContributionTracking_body.php (modified) (history)
  • /trunk/extensions/ContributionTracking/countryCodes.inc (deleted) (history)

Diff [purge]

Index: trunk/extensions/ContributionTracking/countryCodes.inc
@@ -1,254 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * List of ISO numeric country codes to display as select menu to user
6 - * needed to translate country to name-value pair 3-digit variable
7 - */
8 -function countryCodes() {
9 - $countryCode = array(
10 - '840' => 'United States',
11 - '124' => 'Canada',
12 - '826' => 'United Kingdom',
13 - '004' => 'Afghanistan',
14 - '008' => 'Albania',
15 - '012' => 'Algeria',
16 - '016' => 'American Samoa',
17 - '020' => 'Andorra',
18 - '024' => 'Angola',
19 - '660' => 'Anguilla',
20 - '010' => 'Antarctica',
21 - '028' => 'Antigua and Barbuda',
22 - '032' => 'Argentina',
23 - '051' => 'Armenia',
24 - '533' => 'Aruba',
25 - '036' => 'Australia',
26 - '040' => 'Austria',
27 - '031' => 'Azerbaijan',
28 - '044' => 'Bahamas',
29 - '048' => 'Bahrain',
30 - '050' => 'Bangladesh',
31 - '052' => 'Barbados',
32 - '112' => 'Belarus',
33 - '056' => 'Belgium',
34 - '084' => 'Belize',
35 - '204' => 'Benin',
36 - '060' => 'Bermuda',
37 - '064' => 'Bhutan',
38 - '068' => 'Bolivia, Plurinational State of',
39 - '070' => 'Bosnia and Herzegovina',
40 - '072' => 'Botswana',
41 - '074' => 'Bouvet Island',
42 - '076' => 'Brazil',
43 - '086' => 'British Indian Ocean Territory',
44 - '096' => 'Brunei Darussalam',
45 - '100' => 'Bulgaria',
46 - '854' => 'Burkina Faso',
47 - '108' => 'Burundi',
48 - '116' => 'Cambodia',
49 - '120' => 'Cameroon',
50 - '124' => 'Canada',
51 - '132' => 'Cape Verde',
52 - '136' => 'Cayman Islands',
53 - '140' => 'Central African Republic',
54 - '148' => 'Chad',
55 - '152' => 'Chile',
56 - '156' => 'China',
57 - '162' => 'Christmas Island',
58 - '166' => 'Cocos (Keeling) Islands',
59 - '017' => 'Colombia',
60 - '174' => 'Comoros',
61 - '178' => 'Congo',
62 - '180' => 'Congo, the Democratic Republic of the',
63 - '184' => 'Cook Islands',
64 - '188' => 'Costa Rica',
65 - '384' => "Cote D'Ivoire",
66 - '191' => 'Croatia',
67 - '192' => 'Cuba',
68 - '196' => 'Cyprus',
69 - '203' => 'Czech Republic',
70 - '208' => 'Denmark',
71 - '262' => 'Djibouti',
72 - '212' => 'Dominica',
73 - '214' => 'Dominican Republic',
74 - '626' => 'East Timor',
75 - '218' => 'Ecuador',
76 - '818' => 'Egypt',
77 - '222' => 'El Salvador',
78 - '226' => 'Equatorial Guinea',
79 - '232' => 'Eritrea',
80 - '233' => 'Estonia',
81 - '231' => 'Ethiopia',
82 - '238' => 'Falkland Islands (Malvinas)',
83 - '234' => 'Faroe Islands',
84 - '242' => 'Fiji',
85 - '246' => 'Finland',
86 - '250' => 'France',
87 - '254' => 'French Guiana',
88 - '258' => 'French Polynesia',
89 - '260' => 'French Southern Territories',
90 - '266' => 'Gabon',
91 - '270' => 'Gambia',
92 - '268' => 'Georgia',
93 - '276' => 'Germany',
94 - '288' => 'Ghana',
95 - '292' => 'Gibraltar',
96 - '300' => 'Greece',
97 - '304' => 'Greenland',
98 - '308' => 'Grenada',
99 - '312' => 'Guadeloupe',
100 - '316' => 'Guam',
101 - '320' => 'Guatemala',
102 - '324' => 'Guinea',
103 - '624' => 'Guinea-Bissau',
104 - '328' => 'Guyana',
105 - '332' => 'Haiti',
106 - '334' => 'Heard Island and McDonald Islands',
107 - '340' => 'Honduras',
108 - '344' => 'Hong Kong',
109 - '348' => 'Hungary',
110 - '352' => 'Iceland',
111 - '356' => 'India',
112 - '360' => 'Indonesia',
113 - '364' => 'Iran, Islamic Republic of',
114 - '368' => 'Iraq',
115 - '372' => 'Ireland',
116 - '376' => 'Israel',
117 - '380' => 'Italy',
118 - '388' => 'Jamaica',
119 - '392' => 'Japan',
120 - '400' => 'Jordan',
121 - '398' => 'Kazakhstan',
122 - '404' => 'Kenya',
123 - '296' => 'Kiribati',
124 - '408' => "Korea, Democratic People's Republic of",
125 - '410' => 'Korea, Republic of',
126 - '414' => 'Kuwait',
127 - '417' => 'Kyrgyzstan',
128 - '418' => 'Laos',
129 - '428' => 'Latvia',
130 - '422' => 'Lebanon',
131 - '426' => 'Lesotho',
132 - '430' => 'Liberia',
133 - '434' => 'Libyan Arab Jamahiriya',
134 - '438' => 'Liechtenstein',
135 - '440' => 'Lithuania',
136 - '442' => 'Luxembourg',
137 - '446' => 'Macao',
138 - '807' => 'Macedonia',
139 - '450' => 'Madagascar',
140 - '454' => 'Malawi',
141 - '458' => 'Malaysia',
142 - '462' => 'Maldives',
143 - '466' => 'Mali',
144 - '470' => 'Malta',
145 - '584' => 'Marshall Islands',
146 - '474' => 'Martinique',
147 - '478' => 'Mauritania',
148 - '480' => 'Mauritius',
149 - '175' => 'Mayotte',
150 - '484' => 'Mexico',
151 - '583' => 'Micronesia, Federated States of',
152 - '498' => 'Moldova, Republic of',
153 - '492' => 'Monaco',
154 - '496' => 'Mongolia',
155 - '499' => 'Montenegro',
156 - '500' => 'Montserrat',
157 - '504' => 'Morocco',
158 - '508' => 'Mozambique',
159 - '104' => 'Myanmar',
160 - '516' => 'Namibia',
161 - '520' => 'Nauru',
162 - '524' => 'Nepal',
163 - '528' => 'Netherlands',
164 - '530' => 'Netherlands Antilles',
165 - '540' => 'New Caledonia',
166 - '554' => 'New Zealand',
167 - '558' => 'Nicaragua',
168 - '562' => 'Niger',
169 - '566' => 'Nigeria',
170 - '570' => 'Niue',
171 - '574' => 'Norfolk Island',
172 - '580' => 'Northern Mariana Islands',
173 - '578' => 'Norway',
174 - '512' => 'Oman',
175 - '586' => 'Pakistan',
176 - '585' => 'Palau',
177 - '591' => 'Panama',
178 - '598' => 'Papua New Guinea',
179 - '600' => 'Paraguay',
180 - '604' => 'Peru',
181 - '608' => 'Philippines',
182 - '612' => 'Pitcairn',
183 - '616' => 'Poland',
184 - '620' => 'Portugal',
185 - '630' => 'Puerto Rico',
186 - '634' => 'Qatar',
187 - '642' => 'Romania',
188 - '643' => 'Russian Federation',
189 - '646' => 'Rwanda',
190 - '659' => 'Saint Kitts and Nevis',
191 - '662' => 'Saint Lucia',
192 - '670' => 'Saint Vincent and the Grenadines',
193 - '882' => 'Samoa',
194 - '674' => 'San Marino',
195 - '678' => 'Sao Tome and Principe',
196 - '682' => 'Saudi Arabia',
197 - '686' => 'Senegal',
198 - '688' => 'Serbia',
199 - '690' => 'Seychelles',
200 - '694' => 'Sierra Leone',
201 - '702' => 'Singapore',
202 - '703' => 'Slovakia',
203 - '705' => 'Slovenia',
204 - '090' => 'Solomon Islands',
205 - '706' => 'Somalia',
206 - '710' => 'South Africa',
207 - //'239' => 'South Georgia and the South Sandwich Islands',
208 - '724' => 'Spain',
209 - '144' => 'Sri Lanka',
210 - '654' => 'Saint Helena',
211 - '666' => 'Saint Pierre and Miquelon',
212 - '736' => 'Sudan',
213 - '740' => 'Suriname',
214 - '744' => 'Svalbard and Jan Mayen',
215 - '748' => 'Swaziland',
216 - '752' => 'Sweden',
217 - '756' => 'Switzerland',
218 - '760' => 'Syrian Arab Republic',
219 - '762' => 'Tajikistan',
220 - '834' => 'Tanzania, United Republic of',
221 - '158' => 'Taiwan',
222 - '764' => 'Thailand',
223 - '768' => 'Togo',
224 - '772' => 'Tokelau',
225 - '776' => 'Tonga',
226 - '780' => 'Trinidad and Tobago',
227 - '788' => 'Tunisia',
228 - '792' => 'Turkey',
229 - '795' => 'Turkmenistan',
230 - '796' => 'Turks and Caicos Islands',
231 - '798' => 'Tuvalu',
232 - '800' => 'Uganda',
233 - '804' => 'Ukraine',
234 - '784' => 'United Arab Emirates',
235 - '826' => 'United Kingdom',
236 - '840' => 'United States',
237 - '581' => 'United States Minor Outlying Islands',
238 - '858' => 'Uruguay',
239 - '860' => 'Uzbekistan',
240 - '548' => 'Vanuatu',
241 - '336' => 'Vatican City State',
242 - '862' => 'Venezuela, Bolivarian Republic of',
243 - '704' => 'Viet Nam',
244 - '092' => 'Virgin Islands, British',
245 - '850' => 'Virgin Islands, U.S.',
246 - '876' => 'Wallis and Futuna',
247 - '732' => 'Western Sahara',
248 - '882' => 'Western Samoa',
249 - '887' => 'Yemen',
250 - '894' => 'Zambia',
251 - '716' => 'Zimbabwe'
252 - );
253 -
254 - return $countryCode;
255 -}
Index: trunk/extensions/ContributionTracking/ContributionTracking_body.php
@@ -28,23 +28,22 @@
2929
3030
3131 function execute( $language ) {
32 - require_once( 'countryCodes.inc' );
3332 global $wgRequest, $wgOut, $wgContributionTrackingPayPalIPN, $wgContributionTrackingReturnToURLDefault,
3433 $wgContributionTrackingPayPalRecurringIPN, $wgContributionTrackingPayPalBusiness;
35 -
 34+
3635 if ( !preg_match( '/^[a-z-]+$/', $language ) ) {
3736 $language = 'en';
3837 }
3938 $this->lang = Language::factory( $language );
40 -
 39+
4140 $this->setHeaders();
42 -
 41+
4342 $gateway = $wgRequest->getText( 'gateway' );
4443 if( !in_array( $gateway, array( 'paypal', 'moneybookers' ) ) ) {
4544 $wgOut->showErrorPage( 'contrib-tracking-error', 'contrib-tracking-error-text' );
4645 return;
4746 }
48 -
 47+
4948 $db = contributionTrackingConnection();
5049
5150 $ts = $db->timestamp();
@@ -54,14 +53,6 @@
5554 $owa_ref = $this->get_owa_ref_id($owa_ref);
5655 }
5756
58 - // Translate the shipping country from a code to a country name
59 - $country = '';
60 - $code = $wgRequest->getText('country2');
61 - if ( $code ) {
62 - $countries = countryCodes();
63 - $country = $countries[$code];
64 - }
65 -
6657 $tracked_contribution = array(
6758 'note' => $wgRequest->getText('comment', null),
6859 'referrer' => $wgRequest->getText('referrer', null),
@@ -71,25 +62,24 @@
7263 'utm_campaign' => $wgRequest->getText('utm_campaign', null),
7364 'optout' => ($wgRequest->getCheck('email-opt', 0) ? 0 : 1),
7465 'language' => $wgRequest->getText('language', null),
75 - 'country' => $country,
7666 'owa_session' => $wgRequest->getText('owa_session', null),
7767 'owa_ref' => $owa_ref,
7868 'ts' => $ts,
7969 );
80 -
 70+
8171 // Make all empty strings NULL
8272 foreach ($tracked_contribution as $key => $value) {
8373 if ($value === '') {
8474 $tracked_contribution[$key] = null;
8575 }
8676 }
87 -
 77+
8878 // Store the contribution data
8979 if ( !$wgRequest->getVal( 'contribution_tracking_id', 0 )) {
9080 $db->insert( 'contribution_tracking', $tracked_contribution );
9181 }
9282 $contribution_tracking_id = $wgRequest->getVal( 'contribution_tracking_id', $db->insertId());
93 -
 83+
9484 $returnText = $wgRequest->getText( 'returnto', "Donate-thanks/$language" );
9585 $returnTitle = Title::newFromText( $returnText );
9686 if( $returnTitle ) {
@@ -97,13 +87,13 @@
9888 } else {
9989 $returnto = $wgContributionTrackingReturnToURLDefault . "/$language";
10090 }
101 -
 91+
10292 // Set the action and tracking ID fields
10393 $repost = array();
10494 $action = 'http://wikimediafoundation.org/';
10595 $amount_field_name = 'amount'; // the amount fieldname may be different depending on the service
10696 if ( $gateway == 'paypal' ) {
107 -
 97+
10898 $action = 'https://www.paypal.com/cgi-bin/webscr';
10999
110100 // Premiums
@@ -114,25 +104,25 @@
115105 $repost['os1'] = $wgRequest->getText( 'premium_language' );
116106 $repost['no_shipping'] = 2;
117107 }
118 -
 108+
119109 // PayPal
120110 $repost['business'] = $wgContributionTrackingPayPalBusiness;
121111 $repost['item_number'] = 'DONATE';
122112 $repost['no_note'] = '0';
123113 $repost['return'] = $returnto;
124114 $repost['currency_code'] = $wgRequest->getText( 'currency_code', 'USD' );
125 -
 115+
126116 // additional fields to pass to PayPal from single-step credit card form
127117 $repost[ 'first_name' ] = $wgRequest->getText( 'fname', null );
128118 $repost[ 'last_name' ] = $wgRequest->getText( 'lname', null );
129119 $repost[ 'email' ] = $wgRequest->getText( 'email', null );
130 -
 120+
131121 // if this is a recurring donation, we have add'l fields to send to paypal
132122 if ( $wgRequest->getText( 'recurring_paypal' ) == 'true' ) {
133123 $repost[ 't3' ] = "M"; // The unit of measurement for for p3 (M = month)
134124 $repost[ 'p3' ] = '1'; // Billing cycle duration
135125 $repost[ 'srt' ] = '12'; // # of billing cycles
136 - $repost[ 'src' ] = '1'; // Make this 'recurring'
 126+ $repost[ 'src' ] = '1'; // Make this 'recurring'
137127 $repost[ 'sra' ] = '1'; // Turn on re-attempt on failure
138128 $repost[ 'cmd' ] = '_xclick-subscriptions';
139129 $amount_field_name = 'a3';
@@ -144,7 +134,7 @@
145135 $repost['item_name'] = $this->msg( 'contrib-tracking-item-name-onetime' );
146136 }
147137 }
148 - elseif ( $gateway == 'moneybookers' ) {
 138+ else if ( $gateway == 'moneybookers' ) {
149139 $action = 'https://www.moneybookers.com/app/payment.pl';
150140
151141 // Tracking
@@ -160,28 +150,28 @@
161151 } else {
162152 throw new MWException( "This shouldn't happen, we validated the gateway earlier." );
163153 }
164 -
 154+
165155 // Normalized amount
166156 $repost[ $amount_field_name ] = $wgRequest->getVal( 'amount' );
167157 if ( $wgRequest->getVal( 'amountGiven' ) ) {
168158 $repost[ $amount_field_name ] = $wgRequest->getVal( 'amountGiven' );
169159 }
170 -
 160+
171161 // Tracking
172162 $repost['custom'] = $contribution_tracking_id;
173 -
 163+
174164 $wgOut->addWikiText( "{{2009/Donate-banner/$language}}" );
175165 $wgOut->addHTML( $this->msgWiki( 'contrib-tracking-submitting' ) );
176 -
 166+
177167 // Output the repost form
178168 $output = '<form method="post" name="contributiontracking" action="' . $action . '">';
179169
180170 foreach ( $repost as $key => $value ) {
181171 $output .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
182172 }
183 -
 173+
184174 $output .= $this->msgWiki( 'contrib-tracking-redirect' );
185 -
 175+
186176 // Offer a button to post the form if the user has no Javascript support
187177 $output .= '<noscript>';
188178 $output .= $this->msgWiki( 'contrib-tracking-continue' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79408adding country to tracking tablekaldari02:07, 1 January 2011

Status & tagging log