r58195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58194‎ | r58195 | r58196 >
Date:14:47, 27 October 2009
Author:ashley
Status:ok (Comments)
Tags:
Comment:
initial cleanup to DonateInterface extension:
*use tabs for indentation instead of spaces
*NULL -> null, TRUE -> true etc.
*changed XML::func calls to Xml::func because the class is defined as "Xml"
*removed some backwards compatibility stuff (per r55838)
*use $wgOut->addScriptFile() to add the .js file to <head>
*removed/commented out some debug code (a var_dump() and one bit of code marked "for testing")
*removed donate_interface.setup.php -- broken and not needed since donate_interface.php does not contain a class but rather just some functions

TODO: these files should be renamed according to MW's conventions (i.e. DonateInterface.php instead of donate_interface.php and so on)
Modified paths:
  • /trunk/extensions/DonationInterface/donate_interface/donate_interface.i18n.php (modified) (history)
  • /trunk/extensions/DonationInterface/donate_interface/donate_interface.php (modified) (history)
  • /trunk/extensions/DonationInterface/donate_interface/donate_interface.setup.php (deleted) (history)
  • /trunk/extensions/DonationInterface/donate_interface/validate_donation.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/donate_interface/donate_interface.setup.php
@@ -1,15 +0,0 @@
2 -testing<?php
3 -
4 -# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
5 -if (!defined('MEDIAWIKI')) {
6 - echo <<<EOT
7 -To install my extension, put the following line in LocalSettings.php:
8 -require_once( "\$IP/extensions/donate_interface/donate_interface.php" );
9 -EOT;
10 - exit( 1 );
11 -}
12 -
13 -
14 -$dir = dirname(__FILE__) . '/';
15 -
16 -$wgAutoloadClasses['donate_interface'] = $dir . 'donate_interface.php'; # Tell MediaWiki to load the extension body.
Index: trunk/extensions/DonationInterface/donate_interface/validate_donation.js
@@ -1,53 +1,54 @@
22 //<![CDATA[
33 function validateForm( form ) {
44
5 - var minimums = {
6 - 'USD' : 1,
7 - 'GBP' : 1, // $1.26
8 - 'EUR' : 1, // $1.26
9 - 'AUD' : 2, // $1.35
10 - 'CAD' : 1, // $0.84
11 - 'CHF' : 1, // $0.85
12 - 'CZK' : 20, // $1.03
13 - 'DKK' : 5, // $0.85
14 - 'HKD' : 10, // $1.29
15 - 'HUF' : 200, // $0.97
16 - 'JPY' : 100, // $1
17 - 'NZD' : 2, // $1.18
18 - 'NOK' : 10, // $1.44
19 - 'PLN' : 5, // $1.78
20 - 'SGD' : 2, // $1.35
21 - 'SEK' : 10, // $1.28
22 - };
 5+ var minimums = {
 6+ 'USD' : 1,
 7+ 'GBP' : 1, // $1.26
 8+ 'EUR' : 1, // $1.26
 9+ 'AUD' : 2, // $1.35
 10+ 'CAD' : 1, // $0.84
 11+ 'CHF' : 1, // $0.85
 12+ 'CZK' : 20, // $1.03
 13+ 'DKK' : 5, // $0.85
 14+ 'HKD' : 10, // $1.29
 15+ 'HUF' : 200, // $0.97
 16+ 'JPY' : 100, // $1
 17+ 'NZD' : 2, // $1.18
 18+ 'NOK' : 10, // $1.44
 19+ 'PLN' : 5, // $1.78
 20+ 'SGD' : 2, // $1.35
 21+ 'SEK' : 10, // $1.28
 22+ };
2323
24 - var error = true;
 24+ var error = true;
2525
26 - // Get amount selection
27 - var amount = null;
28 - for ( var i = 0; i < form.amount.length; i++ ) {
29 - if ( form.amount[i].checked ) {
30 - amount = form.amount[i].value;
31 - }
32 - }
33 - if ( form.amount2.value != "" ) {
34 - amount = form.amount2.value;
35 - }
36 - // Check amount is a real number
37 - error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
38 - if ( error ) {
39 - alert( 'You must enter a valid amount.' );
40 - }
 26+ // Get amount selection
 27+ var amount = null;
 28+ for ( var i = 0; i < form.amount.length; i++ ) {
 29+ if ( form.amount[i].checked ) {
 30+ amount = form.amount[i].value;
 31+ }
 32+ }
 33+ if ( form.amount2.value != '' ) {
 34+ amount = form.amount2.value;
 35+ }
 36+ // Check amount is a real number
 37+ error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
 38+ if ( error ) {
 39+ alert( 'You must enter a valid amount.' );
 40+ }
4141
42 - // Check amount is at least the minimum
43 - var currency = form.currency_code[form.currency_code.selectedIndex].value;
44 - if ( typeof( minimums[currency] ) == 'undefined' ) {
45 - minimums[currency] = 1;
46 - }
47 - if ( amount < minimums[currency] ) {
48 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
49 - error = true;
50 - }
51 -
52 - return !error;
 42+ // Check amount is at least the minimum
 43+ var currency = form.currency_code[form.currency_code.selectedIndex].value;
 44+ if ( typeof( minimums[currency] ) == 'undefined' ) {
 45+ minimums[currency] = 1;
 46+ }
 47+
 48+ if ( amount < minimums[currency] ) {
 49+ alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 50+ error = true;
 51+ }
 52+
 53+ return !error;
5354 }
54 -//]]>
 55+//]]>
\ No newline at end of file
Index: trunk/extensions/DonationInterface/donate_interface/donate_interface.php
@@ -1,297 +1,304 @@
22 <?php
3 -//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
4 -if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
5 - $wgHooks['ParserFirstCallInit'][] = 'efDonateSetup';
6 -} else { // Otherwise do things the old fashioned way
7 - $wgExtensionFunctions[] = 'efDonateSetup';
 3+/**
 4+ * DonateInterface extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @link http://www.mediawiki.org/wiki/Extension:DonateInterface Documentation
 9+ */
 10+
 11+if( !defined( 'MEDIAWIKI' ) ) {
 12+ die( "This is not a valid entry point.\n" );
813 }
914
10 -$dir = dirname(__FILE__) . '/';
11 -$wgExtensionMessagesFiles['donate_interface'] = $dir . 'donate_interface.i18n.php';
12 -
 15+// Extension credits that will show up on Special:Version
1316 $wgExtensionCredits['specialpage'][] = array(
14 - 'path' => __FILE__,
15 - 'name' => 'DonateInterface',
16 - //'author' => array( 'diana' ), // FIXME: Committer does not have details in http://svn.wikimedia.org/viewvc/mediawiki/USERINFO/
17 - 'description' => 'Donate interface',
 17+ 'path' => __FILE__,
 18+ 'name' => 'DonateInterface',
 19+ //'author' => array( 'diana' ), // FIXME: Committer does not have details in http://svn.wikimedia.org/viewvc/mediawiki/USERINFO/
 20+ 'description' => 'Donate interface',
1821 'descriptionmsg' => 'donor-desc',
19 - 'url' => 'http://www.mediawiki.org/wiki/Extension:DonateInterface',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:DonateInterface',
2023 );
2124
22 -/*
23 -* Create <donate /> tag to include landing page donation form
24 -*/
25 -function efDonateSetup(&$parser) {
 25+// Set up i18n
 26+$dir = dirname( __FILE__ ) . '/';
 27+$wgExtensionMessagesFiles['DonateInterface'] = $dir . 'donate_interface.i18n.php';
 28+
 29+$wgHooks['ParserFirstCallInit'][] = 'efDonateSetup';
 30+/**
 31+ * Create <donate /> tag to include landing page donation form
 32+ */
 33+function efDonateSetup( &$parser ) {
2634 global $wgParser, $wgOut, $wgRequest;
27 -
28 - //load extension messages
29 - wfLoadExtensionMessages( 'donate_interface' );
30 -
 35+
 36+ // Load extension messages
 37+ wfLoadExtensionMessages( 'DonateInterface' );
 38+
3139 $parser->disableCache();
32 -
 40+
3341 $wgParser->setHook( 'donate', 'efDonateRender' );
34 -
 42+
3543 // declare variables used to hold post data
36 - $userInput = array (
37 - 'currency' => 'USD',
38 - 'amount' => '0.00',
39 - 'payment_method' => '',
40 - 'referrer' => '',
41 - 'utm_source' => '',
42 - 'utm_medium' => '',
43 - 'utm_campaign' => '',
44 - 'language' => '',
45 - 'comment' => '',
46 - 'comment-option' => '',
47 - 'email' => '',
48 - );
49 -
 44+ $userInput = array (
 45+ 'currency' => 'USD',
 46+ 'amount' => '0.00',
 47+ 'payment_method' => '',
 48+ 'referrer' => '',
 49+ 'utm_source' => '',
 50+ 'utm_medium' => '',
 51+ 'utm_campaign' => '',
 52+ 'language' => '',
 53+ 'comment' => '',
 54+ 'comment-option' => '',
 55+ 'email' => '',
 56+ );
 57+
5058 // if form has been submitted, assign data and redirect user to chosen payment gateway
51 - if ($_POST['process'] == "_yes_") {
52 - //find out which amount option was chosen for amount, redefined buttons or text box
53 - if (isset($_POST['amount'])) {
54 - $amount = number_format($wgRequest->getText('amount'), 2);
55 - } else { $amount = number_format($wgRequest->getText('amount2'), 2, '.', ''); }
56 -
57 - // create array of user input from post data
58 - $userInput = array (
59 - 'currency' => $wgRequest->getText('currency_code'),
60 - 'amount' => $amount,
61 - 'payment_method' => $wgRequest->getText('payment_method'),
62 - 'referrer' => $wgRequest->getText('referrer'),
63 - 'utm_source' => $wgRequest->getText('utm_source'),
64 - 'utm_medium' => $wgRequest->getText('utm_medium'),
65 - 'utm_campaign' => $wgRequest->getText('utm_campaign'),
66 - 'language' => $wgRequest->getText('language'),
67 - 'comment' => $wgRequest->getText('comment'),
68 - 'comment-option' => $wgRequest->getText('comment-option'),
69 - 'email' => $wgRequest->getText('opt'),
70 - );
71 -
72 - // ask payment processor extensions for their URL/page title
73 - wfRunHooks('gwPage', array(&$url));
74 -
75 - var_dump($userInput);
76 - // send user to correct page for payment
77 - redirectToProcessorPage($userInput, $url);
78 -
79 - }// end if form has been submitted
80 -
81 - return true;
 59+ if ( $_POST['process'] == '_yes_' ) {
 60+ // find out which amount option was chosen for amount, redefined buttons or text box
 61+ if( isset( $_POST['amount'] ) ) {
 62+ $amount = number_format( $wgRequest->getText( 'amount' ), 2 );
 63+ } else {
 64+ $amount = number_format( $wgRequest->getText( 'amount2' ), 2, '.', '' );
 65+ }
 66+
 67+ // create array of user input from post data
 68+ $userInput = array(
 69+ 'currency' => $wgRequest->getText( 'currency_code' ),
 70+ 'amount' => $amount,
 71+ 'payment_method' => $wgRequest->getText( 'payment_method' ),
 72+ 'referrer' => $wgRequest->getText( 'referrer' ),
 73+ 'utm_source' => $wgRequest->getText( 'utm_source' ),
 74+ 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
 75+ 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
 76+ 'language' => $wgRequest->getText( 'language' ),
 77+ 'comment' => $wgRequest->getText( 'comment' ),
 78+ 'comment-option' => $wgRequest->getText( 'comment-option' ),
 79+ 'email' => $wgRequest->getText( 'opt' ),
 80+ );
 81+
 82+ // ask payment processor extensions for their URL/page title
 83+ wfRunHooks( 'gwPage', array( &$url ) );
 84+
 85+ // send user to correct page for payment
 86+ redirectToProcessorPage( $userInput, $url );
 87+ } // end if form has been submitted
 88+
 89+ return true;
8290 }
8391
 92+/**
 93+ * Function called by the <donate> parser tag
 94+ *
 95+ * Outputs the donation landing page form which collects
 96+ * the donation amount, currency and payment processor type.
 97+ */
 98+function efDonateRender( $input, $args, &$parser ) {
 99+ global $wgOut, $wgScriptPath;
84100
85 -/*
86 -* Function called by the <donate> parser tag
87 -*
88 -* Outputs the donation landing page form which collects
89 -* the donation amount, currency and payment processor type.
90 -*
91 -*/
92 -function efDonateRender( $input, $args, &$parser) {
93 - global $wgOut;
94 -
95 - $parser->disableCache();
96 -
97 - // if chapter exists for user's country, redirect
98 - $chapter = fnDonateChapterRedirect();
99 -
100 -
101 - //add javascript validation to <head>
102 - $parser->mOutput->addHeadItem('<script type="text/javascript" language="javascript" src="/extensions/DonationInterface/donate_interface/validate_donation.js"></script>');
103 -
104 -
105 - //display form to gather data from user
106 - $output = createOutput();
107 -
108 - return $output;
 101+ $parser->disableCache();
 102+
 103+ // if chapter exists for user's country, redirect
 104+ $chapter = fnDonateChapterRedirect();
 105+
 106+ // add JavaScript validation to <head>
 107+ $wgOut->addScriptFile( $wgScriptPath . '/extensions/DonationInterface/donate_interface/validate_donation.js' );
 108+
 109+ // display form to gather data from user
 110+ $output = createOutput();
 111+
 112+ return $output;
109113 }
110114
111 -/*
112 -* Supplies the form to efDonateRender()
113 -*
114 -* Payment gateway options are created with the hook 'gwValue". Each potential payment
115 -* option supplies it's value and name for the form, as well as currencies it supports.
116 -*/
 115+/**
 116+ * Supplies the form to efDonateRender()
 117+ *
 118+ * Payment gateway options are created with the hook "gwValue". Each potential payment
 119+ * option supplies it's value and name for the form, as well as currencies it supports.
 120+ */
117121 function createOutput() {
118 - global $wgOut, $wgRequest;
119 -
120 - // declare variable
121 - $utm_source = '';
122 - $utm_medium = '';
123 - $utm_campaign = '';
124 - $referrer = '';
 122+ global $wgOut, $wgRequest;
125123
126 - // set them equal to post data
127 - $utm_source = $wgRequest->getText('utm_source');
128 - $utm_medium = $wgRequest->getText('utm_medium');
129 - $utm_campaign = $wgRequest->getText('utm_campaign');
130 - $referrer = $_SERVER['HTTP_REFERER'];
131 -
132 - //get language from URL
133 - $url = $_SERVER['REQUEST_URI'];
134 -
135 - if ($url) {
136 - $getLang = explode('/', $url);
137 - $language = substr($getLang[3], 0, 2);
138 - }
139 -
140 - // error check and set "en" as default
141 - if ( !preg_match( '/^[a-z-]+$/', $language ) ) {
142 - $language = 'en';
143 - }
 124+ // declare variable
 125+ $utm_source = '';
 126+ $utm_medium = '';
 127+ $utm_campaign = '';
 128+ $referrer = '';
144129
145 - //get payment method gateway value and name from each gateway and create menu of options
146 - $values = '';
147 - wfRunHooks('gwValue', array(&$values));
148 -
 130+ // set them equal to post data
 131+ $utm_source = $wgRequest->getText( 'utm_source' );
 132+ $utm_medium = $wgRequest->getText( 'utm_medium' );
 133+ $utm_campaign = $wgRequest->getText( 'utm_campaign' );
 134+ $referrer = $_SERVER['HTTP_REFERER'];
 135+
 136+ // Get language from URL
 137+ $url = $_SERVER['REQUEST_URI'];
 138+
 139+ if( $url ) {
 140+ $getLang = explode( '/', $url );
 141+ $language = substr( $getLang[3], 0, 2 );
 142+ }
 143+
 144+ // error check and set "en" as default
 145+ if ( !preg_match( '/^[a-z-]+$/', $language ) ) {
 146+ $language = 'en';
 147+ }
 148+
 149+ // Get payment method gateway value and name from each gateway and create menu of options
 150+ $values = '';
 151+ wfRunHooks( 'gwValue', array( &$values ) );
 152+
149153 $gatewayMenu = '';
150 -
151 - foreach($values as $current) {
152 - $gatewayMenu .= XML::option($current['display_name'], $current['form_value']);
153 - }
154 -
155 - //get available currencies
156 - //NOTE: currently all available currencies are accepted by all developed gateways
157 - //the next version will include gateway/currency checking
158 - //and inform user of gateways that aren't an option for that currency
159 - foreach($values as $key) {
160 - $currencies = $key['currencies'];
161 - }
162154
 155+ foreach( $values as $current ) {
 156+ $gatewayMenu .= Xml::option( $current['display_name'], $current['form_value'] );
 157+ }
 158+
 159+ // Get available currencies
 160+ // NOTE: currently all available currencies are accepted by all developed gateways
 161+ // the next version will include gateway/currency checking
 162+ // and inform user of gateways that aren't an option for that currency
 163+ foreach( $values as $key ) {
 164+ $currencies = $key['currencies'];
 165+ }
 166+
163167 $currencyMenu = '';
164 -
165 - foreach($currencies as $value => $fullName) {
166 - $currencyMenu .= XML::option($fullName, $value);
167 - }
168 -
169 - $output = XML::openElement('form', array('name' => "donate", 'method' => "post", 'action' => "", 'onsubmit' => 'return validateForm(this)')) .
170 - XML::openElement('div', array('id' => 'mw-donation-intro')) .
171 - XML::element('p', array('class' => 'mw-donation-intro-text'), wfMsg('donor-intro')) .
172 - XML::closeElement('div');
173 -
174 - $output .= XML::hidden("utm_source", $utm_source) .
175 - XML::hidden("utm_medium", $utm_medium) .
176 - XML::hidden("utm_campaign", $utm_campaign) .
177 - XML::hidden("language", $language) .
178 - XML::hidden("referrer", $referrer);
179 -
180 - $amount = array(
181 - XML::radioLabel('$100', 'amount', '100', 'input_amount_3', FALSE, array("")),
182 - XML::radioLabel('$75', 'amount', '75', 'input_amount_2', FALSE, array("")),
183 - XML::radioLabel('$30', 'amount', '30', 'input_amount_1', FALSE, array("")),
184 - XML::inputLabel(wfMsg( 'donor-other-amount' ), "amount2", "input_amount_other", "5"),
185 - );
186 -
187 - $amountFields = "<table><tr>";
188 - foreach($amount as $value) {
189 - $amountFields .= '<td>' . $value . '</td>';
190 - }
191 - $amountFields .= '</tr></table>';
192 -
193 - $output .= XML::fieldset(wfMsg( 'donor-amount' ), $amountFields, array('class' => "mw-donation-amount"));
194 -
195 - //$output .= '<p>Some test IPs: 91.189.90.211 (uk), 217.70.184.38 (fr)</p>';
196 -
197 - // Build currency options
198 - $default_currency = fnDonateDefaultCurrency();
199 -
200 - $currency_options = '';
201 - foreach ($currencies as $code => $name) {
202 - $selected = '';
203 - if ($code == $default_currency) {
204 - $selected = ' selected="selected"';
205 - }
206 - $currency_options .= '<option value="' . $code . '"' . $selected . '>' . $name . '</option>';
207 - }
208 -
209 - $currencyFields = XML::openElement('select', array('name' => "currency_code", 'id' => "input_currency_code")) .
210 - $currency_options .
211 - XML::closeElement('select');
212 -
213 - $output .= XML::fieldset(wfMsg( 'donor-currency' ), $currencyFields, array('class' => "mw-donation-currency"));
214 -
215 - $gatewayFields = XML::openElement('select', array('name' => "payment_method", 'id' => "select_payment_method")) .
216 - $gatewayMenu .
217 - XML::closeElement('select');
218 -
219 - $output .= XML::fieldset(wfMsg( 'donor-gateway' ), $gatewayFields, array('class' => "mw-donation-gateway"));
220 -
221 - $publicComment = XML::element('div', array('class' => 'mw-donation-comment-message'), wfMsg( 'donor-comment-message' )) .
222 - XML::inputLabel(wfMsg( 'donor-comment-label' ), "comment", "comment", "30", '', array('maxlength' => "200")) .
223 - XML::openElement('div', array('id' => 'mw-donation-checkbox')) .
224 - XML::checkLabel(wfMsg( 'donor-anon-message' ), 'comment-option', 'input_comment-option', TRUE) .
225 - XML::closeElement('div') .
226 - XML::openElement('div', array('id' => 'mw-donation-checkbox')) .
227 - XML::check('opt', TRUE) .
228 - XML::tags('span', array('class' => 'mw-email-agreement'), wfMsg( 'donor-email-agreement' )) .
229 - XML::closeElement('div');
230 -
231 - $output .= XML::fieldset(wfMsg( 'donor-comment-title' ), $publicComment, array('class' => 'mw-donation-public-comment'));
232 -
233 - $output .= XML::hidden('process', '_yes_') .
234 - XML::submitButton(wfMsg( 'donor-submit-button' ));
235 -
236 - $output .= XML::closeElement('form');
237 -
238 - // NOTE: For testing: show country of origin
239 - //$country = fnDonateGetCountry();
240 - //$output .= XML::element('p', array('class' => 'mw-donation-test-message'), 'Country:' . $country);
241 -
242 - // NOTE: for testing: show default currency
243 - //$currencyTest = fnDonateDefaultCurrency();
244 - //$output .= XML::element('p', array('class' => 'mw-donation-test-message'), wfMsg( 'donor-currency' ) . $currencyTest);
245 -
246 - // NOTE: for testing: show IP address
247 - //$referrer = $_SERVER['HTTP_REFERER'];
248 - //$output .= '<p>' . "Referrer:" . $referrer . '</p>';
249 -
250 - //for testing to show language culled from URL
251 - $output .= '<p>' . " Language: " . $language . '</p>';
252 -
253 - return $output;
 168+
 169+ foreach( $currencies as $value => $fullName ) {
 170+ $currencyMenu .= Xml::option( $fullName, $value );
 171+ }
 172+
 173+ $output = Xml::openElement( 'form', array( 'name' => 'donate', 'method' => 'post', 'action' => '', 'onsubmit' => 'return validateForm(this)' ) ) .
 174+ Xml::openElement( 'div', array( 'id' => 'mw-donation-intro' ) ) .
 175+ Xml::element( 'p', array( 'class' => 'mw-donation-intro-text' ), wfMsg( 'donor-intro' ) ) .
 176+ Xml::closeElement( 'div' );
 177+
 178+ $output .= Xml::hidden( 'utm_source', $utm_source ) .
 179+ Xml::hidden( 'utm_medium', $utm_medium ) .
 180+ Xml::hidden( 'utm_campaign', $utm_campaign ) .
 181+ Xml::hidden( 'language', $language ) .
 182+ Xml::hidden( 'referrer', $referrer );
 183+
 184+ $amount = array(
 185+ Xml::radioLabel( '$100', 'amount', '100', 'input_amount_3', false, array( '' ) ),
 186+ Xml::radioLabel( '$75', 'amount', '75', 'input_amount_2', false, array( '' ) ),
 187+ Xml::radioLabel( '$30', 'amount', '30', 'input_amount_1', false, array( '' ) ),
 188+ Xml::inputLabel( wfMsg( 'donor-other-amount' ), 'amount2', 'input_amount_other', '5' ),
 189+ );
 190+
 191+ $amountFields = '<table><tr>';
 192+ foreach( $amount as $value ) {
 193+ $amountFields .= '<td>' . $value . '</td>';
 194+ }
 195+ $amountFields .= '</tr></table>';
 196+
 197+ $output .= Xml::fieldset( wfMsg( 'donor-amount' ), $amountFields, array( 'class' => 'mw-donation-amount' ) );
 198+
 199+ //$output .= '<p>Some test IPs: 91.189.90.211 (uk), 217.70.184.38 (fr)</p>';
 200+
 201+ // Build currency options
 202+ $default_currency = fnDonateDefaultCurrency();
 203+
 204+ $currency_options = '';
 205+ foreach( $currencies as $code => $name ) {
 206+ $selected = '';
 207+ if( $code == $default_currency ) {
 208+ $selected = ' selected="selected"';
 209+ }
 210+ $currency_options .= '<option value="' . $code . '"' . $selected . '>' . $name . '</option>';
 211+ }
 212+
 213+ $currencyFields = Xml::openElement( 'select', array( 'name' => 'currency_code', 'id' => 'input_currency_code' ) ) .
 214+ $currency_options .
 215+ Xml::closeElement( 'select' );
 216+
 217+ $output .= Xml::fieldset( wfMsg( 'donor-currency' ), $currencyFields, array( 'class' => 'mw-donation-currency' ) );
 218+
 219+ $gatewayFields = Xml::openElement( 'select', array( 'name' => 'payment_method', 'id' => 'select_payment_method' ) ) .
 220+ $gatewayMenu .
 221+ Xml::closeElement( 'select' );
 222+
 223+ $output .= Xml::fieldset( wfMsg( 'donor-gateway' ), $gatewayFields, array( 'class' => 'mw-donation-gateway' ) );
 224+
 225+ $publicComment = Xml::element( 'div', array( 'class' => 'mw-donation-comment-message' ), wfMsg( 'donor-comment-message' ) ) .
 226+ Xml::inputLabel(wfMsg( 'donor-comment-label' ), 'comment', 'comment', '30', '', array( 'maxlength' => '200' ) ) .
 227+ Xml::openElement( 'div', array( 'id' => 'mw-donation-checkbox' ) ) .
 228+ Xml::checkLabel( wfMsg( 'donor-anon-message' ), 'comment-option', 'input_comment-option', true ) .
 229+ Xml::closeElement( 'div' ) .
 230+ Xml::openElement( 'div', array( 'id' => 'mw-donation-checkbox' ) ) .
 231+ Xml::check( 'opt', true ) .
 232+ Xml::tags( 'span', array( 'class' => 'mw-email-agreement' ), wfMsg( 'donor-email-agreement' ) ) .
 233+ Xml::closeElement( 'div' );
 234+
 235+ $output .= Xml::fieldset( wfMsg( 'donor-comment-title' ), $publicComment, array( 'class' => 'mw-donation-public-comment' ) );
 236+
 237+ $output .= Xml::hidden( 'process', '_yes_' ) .
 238+ Xml::submitButton( wfMsg( 'donor-submit-button' ) );
 239+
 240+ $output .= Xml::closeElement( 'form' );
 241+
 242+
 243+ // NOTE: For testing: show country of origin
 244+ //$country = fnDonateGetCountry();
 245+ //$output .= Xml::element( 'p', array( 'class' => 'mw-donation-test-message' ), 'Country:' . $country );
 246+
 247+ // NOTE: for testing: show default currency
 248+ //$currencyTest = fnDonateDefaultCurrency();
 249+ //$output .= Xml::element( 'p', array( 'class' => 'mw-donation-test-message' ), wfMsg( 'donor-currency' ) . $currencyTest );
 250+
 251+ // NOTE: for testing: show IP address
 252+ //$referrer = $_SERVER['HTTP_REFERER'];
 253+ //$output .= '<p>' . 'Referrer:' . $referrer . '</p>';
 254+
 255+ // for testing to show language culled from URL
 256+ //$output .= '<p>' . ' Language: ' . $language . '</p>';
 257+
 258+ return $output;
254259 }
255260
 261+/**
 262+ * Redirects user to their chosen payment processor
 263+ *
 264+ * Includes the user's input passed as GET
 265+ * $url for the gateway was supplied with the gwPage hook and the key
 266+ * matches the form value (also supplied by the gateway)
 267+ */
 268+function redirectToProcessorPage( $userInput, $url ) {
 269+ global $wgOut, $wgPaymentGatewayHost;
256270
257 -/*
258 -* Redirects user to their chosen payment processor
259 -*
260 -* Includes the user's input passed as GET
261 -* $url for the gateway was supplied with the gwPage hook and the key
262 -* matches the form value (also supplied by the gateway)
263 -*/
264 -function redirectToProcessorPage($userInput, $url) {
265 - global $wgOut,$wgPaymentGatewayHost;
266 -
267 - $chosenGateway = $userInput['payment_method'];
268 -
269 -
270 - $wgOut->redirect($url[$chosenGateway].'&amount='.$userInput['amount'].'&currency_code='.$userInput['currency'].'&gateway='.$userInput['payment_method'].'&referrer='.$userInput['referrer'].'&utm_source='.$userInput['utm_source'].'&utm_medium='.$userInput['utm_medium'].'&utm_campaign='.$userInput['utm_campaign'].'&language='.$userInput['language'].'&comment='.$userInput['comment'].'&comment-option='.$userInput['comment-option'].'&email='.$userInput['email']);
271 -
 271+ $chosenGateway = $userInput['payment_method'];
272272
 273+ $wgOut->redirect(
 274+ $url[$chosenGateway] . '&amount=' . $userInput['amount'] .
 275+ '&currency_code=' . $userInput['currency'] . '&gateway=' .
 276+ $userInput['payment_method'] . '&referrer=' . $userInput['referrer'] .
 277+ '&utm_source=' . $userInput['utm_source'] . '&utm_medium=' .
 278+ $userInput['utm_medium'] . '&utm_campaign=' . $userInput['utm_campaign'] .
 279+ '&language=' . $userInput['language'] . '&comment=' .
 280+ $userInput['comment'] . '&comment-option=' . $userInput['comment-option'] .
 281+ '&email=' . $userInput['email']
 282+ );
273283 }
274284
275285 /**
276286 * Gets country code based on IP if GeoIP extension is installed
277287 * returns country code or UNKNOWN if unable to assign one
278 - *
279288 */
280289 function fnDonateGetCountry() {
281 - $country_code = NULL;
 290+ $country_code = null;
282291
283 - if (function_exists('fnGetGeoIP')) {
284 - try {
285 - $country_code = fnGetGeoIP();
286 - }
287 - catch (NotFoundGeoIP $e) {
288 - $country_code = "UNKNOWN";
289 - }
290 - catch (UnsupportedGeoIP $e) {
291 - $country_code = "UNKNOWN";
292 - }
293 - }
294 -
295 - return $country_code;
 292+ if( function_exists( 'fnGetGeoIP' ) ) {
 293+ try {
 294+ $country_code = fnGetGeoIP();
 295+ } catch ( NotFoundGeoIP $e ) {
 296+ $country_code = 'UNKNOWN';
 297+ } catch ( UnsupportedGeoIP $e ) {
 298+ $country_code = 'UNKNOWN';
 299+ }
 300+ }
 301+
 302+ return $country_code;
296303 }
297304
298305 /**
@@ -299,21 +306,18 @@
300307 * into default currency shown in drop down menu
301308 */
302309 function fnDonateDefaultCurrency() {
303 - require_once('country2currency.inc');
304 -
305 - $country_code = NULL;
306 - $currency = NULL;
 310+ require_once( 'country2currency.inc' );
307311
308 - if (function_exists('fnGetCountry')) {
309 - $country_code = fnGetCountry();
310 - }
311 -
312 - $currency = fnCountry2Currency($country_code);
313 -
314 -
315 - return $result = $currency ? $currency : 'USD';
316 -
317 -
 312+ $country_code = null;
 313+ $currency = null;
 314+
 315+ if( function_exists( 'fnGetCountry' ) ) {
 316+ $country_code = fnGetCountry();
 317+ }
 318+
 319+ $currency = fnCountry2Currency( $country_code );
 320+
 321+ return $result = $currency ? $currency : 'USD';
318322 }
319323
320324 /**
@@ -322,24 +326,21 @@
323327 * NOT CURRENTLY IN USE
324328 */
325329 function fnDonateChapterRedirect() {
326 - global $wgOut;
327 -
328 - require_once('chapters.inc');
329 -
330 - $country_code = NULL;
331 -
332 - if (function_exists('fnGetCountry')) {
333 - $country_code = fnDonateGetCountry();
334 - }
335 -
336 - $chapter = fnDonateGetChapter($country_code);
337 -
338 -
339 - if ($chapter) {
340 - $wgOut->redirect('http://' . $chapter);
341 - } else
342 - return NULL;
343 -
344 -}
 330+ require_once( 'chapters.inc' );
345331
 332+ $country_code = null;
346333
 334+ if( function_exists( 'fnGetCountry' ) ) {
 335+ $country_code = fnDonateGetCountry();
 336+ }
 337+
 338+ $chapter = fnDonateGetChapter( $country_code );
 339+
 340+ if( $chapter ) {
 341+ global $wgOut;
 342+ $wgOut->redirect( 'http://' . $chapter );
 343+ } else {
 344+ return null;
 345+ }
 346+
 347+}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/donate_interface/donate_interface.i18n.php
@@ -2,12 +2,14 @@
33 /**
44 * Internationalization file for the Donation Interface extension
55 *
6 - * @addtogroup Extensions
7 -*/
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
89
910 $messages = array();
10 -
11 -$messages['en'] = array(
 11+
 12+/** English */
 13+$messages['en'] = array(
1214 'donate_interface' => 'Support Wikimedia',
1315 'donate-desc' => 'Donation landing page that integrates gateway extensions',
1416 'donor-intro' => 'Please choose a payment method, amount, and currency.',
@@ -22,5 +24,5 @@
2325 'donor-email-agreement' => "I agree to receive future Wikimedia Foundation newsletters or emails.
2426 We will never sell or trade your information.
2527 Our donor privacy policy can be found <a title='Donate/Donor Privacy' href='/wiki/Donate/Donor_Privacy'>here</a>",
26 - 'donor-comment-title' => 'Public Comment',
27 -);
 28+ 'donor-comment-title' => 'Public Comment',
 29+);
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r55838Nuking fallback code for MW < 1.12 in most extensions (there's like 5 or 6 le...demon22:22, 4 September 2009

Comments

#Comment by Tim Starling (talk | contribs)   07:56, 30 December 2009

Good work.

Status & tagging log