r99226 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99225‎ | r99226 | r99227 >
Date:18:38, 7 October 2011
Author:khorn
Status:ok
Tags:fundraising 
Comment:
Changed the getGlobal function in the gateway adapter to automatically pull defaults globals if the specific ones do not exist.
What this means is that installing DonationInterface will be a whole lot easier: Define the extension default in $wgDonationInterface[value], and override it by defining a $wg[GatewayID][value] if you want one gateway to behave differently from the default behavior.

Then changed all the forms (including the GatewayForm class that calls 'em all) to handle all the globals that could possibly be gateway-specific, through the new sweetness.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/OneStepTwoColumn.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/RapidHtml.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter2.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter3.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter4.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter5.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter6.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter7.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnPayPal.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetter3.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnPremiumUS.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter2.php
@@ -82,7 +82,7 @@
8383 }
8484
8585 protected function generateBillingFields() {
86 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 86+ global $wgScriptPath, $wgRequest;
8787 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8888
8989 $form = '';
@@ -107,7 +107,7 @@
108108 if ( !$this->paypal ) {
109109 // PayPal button
110110 // make sure we have a paypal url set to redirect the user to before displaying the button
111 - if ( strlen( $wgPayflowProGatewayPaypalURL ) ) {
 111+ if ( strlen( $this->gateway->getGlobal( "PaypalURL" ) ) ) {
112112 $form .= '<tr>';
113113 $form .= '<td class="label"></td>';
114114 $form .= '<td>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter3.php
@@ -82,7 +82,7 @@
8383 }
8484
8585 protected function generateBillingFields() {
86 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 86+ global $wgScriptPath, $wgRequest;
8787 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8888
8989 $form = '';
@@ -107,7 +107,7 @@
108108 if ( !$this->paypal ) {
109109 // PayPal button
110110 // make sure we have a paypal url set to redirect the user to before displaying the button
111 - if ( strlen( $wgPayflowProGatewayPaypalURL ) ) {
 111+ if ( strlen( $this->gateway->getGlobal( "PaypalURL" ) ) ) {
112112 $form .= '<tr>';
113113 $form .= '<td class="label"></td>';
114114 $form .= '<td>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter4.php
@@ -82,7 +82,7 @@
8383 }
8484
8585 protected function generateBillingFields() {
86 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 86+ global $wgScriptPath, $wgRequest;
8787 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8888
8989 $form = '';
@@ -107,7 +107,7 @@
108108 if ( !$this->paypal ) {
109109 // PayPal button
110110 // make sure we have a paypal url set to redirect the user to before displaying the button
111 - if ( strlen( $wgPayflowProGatewayPaypalURL ) ) {
 111+ if ( strlen( $this->gateway->getGlobal( "PaypalURL" ) ) ) {
112112 $form .= '<tr>';
113113 $form .= '<td class="label"></td>';
114114 $form .= '<td>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter5.php
@@ -79,7 +79,7 @@
8080 }
8181
8282 protected function generateBillingFields() {
83 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 83+ global $wgScriptPath, $wgRequest;
8484 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8585
8686 $form = '';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter6.php
@@ -79,7 +79,7 @@
8080 }
8181
8282 protected function generateBillingFields() {
83 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 83+ global $wgScriptPath, $wgRequest;
8484 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8585
8686 $form = '';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter7.php
@@ -192,7 +192,7 @@
193193 }
194194
195195 protected function generateBillingFields() {
196 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL, $wgRequest;
 196+ global $wgScriptPath, $wgRequest;
197197 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
198198
199199 $form = '';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnPayPal.php
@@ -58,7 +58,6 @@
5959 }
6060
6161 protected function generatePersonalFields() {
62 - global $wgPayflowProGatewayPaypalURL;
6362 $form = '';
6463
6564 // name
@@ -83,7 +82,7 @@
8483 $form .= $this->getAmountField();
8584
8685 // PayPal button
87 - if ( strlen( $wgPayflowProGatewayPaypalURL ) ) {
 86+ if ( strlen( $this->gateway->getGlobal( "PaypalURL" ) ) ) {
8887 $form .= $this->getPaypalButton();
8988 }
9089
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php
@@ -50,12 +50,12 @@
5151 abstract function getForm();
5252
5353 public function __construct( &$data, &$error, &$gateway ) {
54 - global $wgDonationInterfaceTest, $wgOut;
 54+ global $wgOut;
5555
56 - $this->test = $wgDonationInterfaceTest;
 56+ $this->gateway = & $gateway;
 57+ $this->test = $this->gateway->getGlobal( "Test" );
5758 $this->form_data = & $data;
5859 $this->form_errors = & $error;
59 - $this->gateway = & $gateway;
6060
6161 /**
6262 * add form-specific css - the path can be set in child classes
@@ -456,8 +456,7 @@
457457 }
458458
459459 protected function getCardnumberField() {
460 - global $wgDonationInterfaceTest;
461 - $card_num = ( $wgDonationInterfaceTest ) ? $this->form_data['card_num'] : '';
 460+ $card_num = ( $this->gateway->getGlobal( "Test" ) ) ? $this->form_data['card_num'] : '';
462461 $form = '';
463462 if ( $this->form_errors['card_num'] ) {
464463 $form .= '<tr>';
@@ -478,8 +477,7 @@
479478 }
480479
481480 protected function getCvvField() {
482 - global $wgDonationInterfaceTest;
483 - $cvv = ( $wgDonationInterfaceTest ) ? $this->form_data['cvv'] : '';
 481+ $cvv = ( $this->gateway->getGlobal( "Test" ) ) ? $this->form_data['cvv'] : '';
484482
485483 $form = '<tr>';
486484 $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['cvv'] . '</span></td>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoColumnLetter.php
@@ -82,7 +82,7 @@
8383 }
8484
8585 protected function generateBillingFields() {
86 - global $wgScriptPath, $wgPayflowProGatewayPaypalURL;
 86+ global $wgScriptPath;
8787 $scriptPath = "$wgScriptPath/extensions/DonationInterface/payflowpro_gateway/includes";
8888
8989 $form = '';
@@ -111,7 +111,7 @@
112112 if ( !$this->paypal ) {
113113 // PayPal button
114114 // make sure we have a paypal url set to redirect the user to before displaying the button
115 - if ( strlen( $wgPayflowProGatewayPaypalURL ) ) {
 115+ if ( strlen( $this->gateway->getGlobal( "PaypalURL" ) ) ) {
116116 $form .= '<tr>';
117117 $form .= '<td class="label"></td>';
118118 $form .= '<td class="paypal-button">';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetter3.php
@@ -193,7 +193,7 @@
194194 }
195195
196196 protected function generateBillingFields() {
197 - global $wgScriptPath, $wgDonationInterfaceTest;
 197+ global $wgScriptPath;
198198
199199 $form = '';
200200
@@ -238,7 +238,7 @@
239239 $form .= '</tr>';
240240
241241 // card number
242 - $card_num = ( $wgDonationInterfaceTest ) ? $this->form_data[ 'card_num' ] : '';
 242+ $card_num = ( $this->gateway->getGlobal( "Test" ) ) ? $this->form_data[ 'card_num' ] : '';
243243 $form .= '';
244244 if ( $this->form_errors['card_num'] ) {
245245 $form .= '<tr>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/RapidHtml.php
@@ -229,6 +229,7 @@
230230 * @param string $file_name
231231 */
232232 public function set_html_file_path( $file_name ) {
 233+ //This ONE TIME, this is okay, because we actually want to compare to the default HTML form dir as well.
233234 global $wgDonationInterfaceHtmlFormDir;
234235
235236 $g = $this->gateway;
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnPremiumUS.php
@@ -174,7 +174,7 @@
175175 }
176176
177177 protected function generateBillingFields() {
178 - global $wgScriptPath, $wgDonationInterfaceTest;
 178+ global $wgScriptPath;
179179
180180 $form = '';
181181
@@ -216,7 +216,7 @@
217217 $form .= '</tr>';
218218
219219 // card number
220 - $card_num = ( $wgDonationInterfaceTest ) ? $this->form_data[ 'card_num' ] : '';
 220+ $card_num = ( $this->gateway->getGlobal( "Test" ) ) ? $this->form_data[ 'card_num' ] : '';
221221 $form .= '';
222222 if ( $this->form_errors['card_num'] ) {
223223 $form .= '<tr>';
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/OneStepTwoColumn.php
@@ -192,14 +192,14 @@
193193 }
194194
195195 protected function generateBannerHeader() {
196 - global $wgPayflowProGatewayHeader, $wgOut, $wgRequest;
 196+ global $wgOut, $wgRequest;
197197 $template = '';
198198
199199 // intro text
200200 if ( $wgRequest->getText( 'masthead', false ) ) {
201201 $template = $wgOut->parse( '{{' . $wgRequest->getText( 'masthead' ) . '/' . $this->form_data[ 'language' ] . '}}' );
202 - } elseif ( $wgPayflowProGatewayHeader ) {
203 - $header = str_replace( '@language', $this->form_data[ 'language' ], $wgPayflowProGatewayHeader );
 202+ } elseif ( $this->gateway->getGlobal( "Header" ) ) {
 203+ $header = str_replace( '@language', $this->form_data[ 'language' ], $this->gateway->getGlobal( "Header" ) );
204204 $template = $wgOut->parse( $header );
205205 }
206206
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -109,17 +109,13 @@
110110 const GLOBAL_PREFIX = 'wgDonationGateway'; //...for example.
111111
112112 public function __construct() {
113 - global $wgDonationInterfaceTest; //this is so the forms can see it.
114 - //TODO: Alter the forms so they don't need the global?
115113 if ( !self::getGlobal( 'Test' ) ) {
116114 $this->url = self::getGlobal( 'URL' );
117 - $wgDonationInterfaceTest = false;
118115 } else {
119116 $this->url = self::getGlobal( 'TestingURL' );
120 - $wgDonationInterfaceTest = true;
121117 }
122118
123 - $this->dataObj = new DonationData( get_called_class(), $wgDonationInterfaceTest );
 119+ $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ) );
124120
125121 $this->postdata = $this->dataObj->getData();
126122 //TODO: Fix this a bit.
@@ -196,19 +192,42 @@
197193 return $this->dataObj->isCache();
198194 }
199195
 196+ /**
 197+ * This function is important.
 198+ * All the globals in Donation Interface should be accessed in this manner
 199+ * if they are meant to have a default value, but can be overridden by any
 200+ * of the gateways. It will check to see if a gateway-specific global
 201+ * exists, and if one is not set, it will pull the default from the
 202+ * wgDonationInterface definitions. Through this function, it is no longer
 203+ * necessary to define gateway-specific globals in LocalSettings unless you
 204+ * wish to override the default value for all gateways.
 205+ * @staticvar array $gotten A cache of all the globals we've already...
 206+ * gotten.
 207+ * @param type $varname The global value we're looking for. It will first
 208+ * look for a global named for the instantiated gateway's GLOBAL_PREFIX,
 209+ * plus the $varname value. If that doesn't come up with anything that has
 210+ * been set, it will use the default value for all of donation interface,
 211+ * stored in $wgDonationInterface . $varname.
 212+ * @return mixed The configured value for that gateway if it exists. If not,
 213+ * the configured value for Donation Interface if it exists or not.
 214+ */
200215 static function getGlobal( $varname ) {
201216 static $gotten = array( ); //cache.
202 - $globalname = self::getGlobalPrefix() . $varname;
203 - if ( !array_key_exists( $globalname, $gotten ) ) {
 217+ if ( !array_key_exists( $varname, $gotten ) ) {
 218+ $globalname = self::getGlobalPrefix() . $varname;
204219 global $$globalname;
205 - $gotten[$globalname] = $$globalname;
 220+ if ( !isset( $$globalname )) {
 221+ $globalname = "wgDonationInterface" . $varname;
 222+ global $$globalname; //set or not. This is fine.
 223+ }
 224+ $gotten[$varname] = $$globalname;
206225 }
207 - return $gotten[$globalname];
 226+ return $gotten[$varname];
208227 }
209228
210229 function getValue( $gateway_field_name, $token = false ) {
211230 if ( empty( $this->transactions ) ) {
212 - //TODO: These dies should all just throw fatal errors instead.
 231+ //TODO: These dies should all throw exceptions or something less completely fatal.
213232 die( 'Transactions structure is empty! Aborting.' );
214233 }
215234 //How do we determine the value of a field asked for in a particular transaction?
@@ -416,8 +435,7 @@
417436 }
418437
419438 if ( is_array( $statuses ) ) { //only then will we consider doing this again.
420 - global $wgDonationInterfaceRetrySeconds; //TODO: Deal with this global in the new usual way, once the DI install mess gets cleaned up
421 - if ( $this->getStopwatch( __FUNCTION__ ) < $wgDonationInterfaceRetrySeconds ) {
 439+ if ( $this->getStopwatch( __FUNCTION__ ) < self::getGlobal( "RetrySeconds" ) ) {
422440 if ( $txn_ok === false ) {
423441 $stopflag = false;
424442 } else {
@@ -880,8 +898,6 @@
881899 }
882900
883901 function getPaypalRedirectURL() {
884 - global $wgDonationInterfacePaypalURL;
885 -
886902 $utm_source = $this->getData( 'utm_source' );
887903
888904 // update the utm source to set the payment instrument to pp rather than cc
@@ -899,7 +915,7 @@
900916 //update contribution tracking
901917 $this->dataObj->updateContributionTracking( true );
902918
903 - $ret = $wgDonationInterfacePaypalURL . "/" . $this->postdata['language'] . "?gateway=paypal&" . http_build_query( $this->postdata );
 919+ $ret = self::getGlobal( "PaypalURL" ) . "/" . $this->postdata['language'] . "?gateway=paypal&" . http_build_query( $this->postdata );
904920 self::log( $ret );
905921 return $ret;
906922 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -334,8 +334,8 @@
335335 }
336336
337337 function displayResultsForDebug( $results ) {
338 - global $wgOut, $wgDonationInterfaceDisplayDebug;
339 - if ( $wgDonationInterfaceDisplayDebug !== true ){
 338+ global $wgOut;
 339+ if ( $this->adapter->getGlobal( 'DisplayDebug' ) !== true ){
340340 return;
341341 }
342342 $wgOut->addHTML( $results['message'] );
@@ -496,10 +496,10 @@
497497 * This would make this a lot less hack-ish
498498 */
499499 public function paypalRedirect() {
500 - global $wgOut, $wgDonationInterfacePaypalURL;
 500+ global $wgOut;
501501
502502 // if we don't have a URL enabled throw a graceful error to the user
503 - if ( !strlen( $wgDonationInterfacePaypalURL ) ) {
 503+ if ( !strlen( $this->adapter->getGlobal( 'PaypalURL' ) ) ) {
504504 $gateway_identifier = $this->adapter->getIdentifier();
505505 $this->errors['general']['nopaypal'] = wfMsg( $gateway_identifier . '_gateway-error-msg-nopaypal' );
506506 return;

Status & tagging log