r74977 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74976‎ | r74977 | r74978 >
Date:23:17, 18 October 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Changed convention to detect cacheable page to use '_cache_' request param; updateContributionTracking will now insert if no contribution tracking id is present rather than attempting to udpate; updated getNoCacheAction() to conform to new caching convention; updated execute() in payflowpro_gateway.body.php to not initiate a session/token stuffs if _cache_ is set (these will get set with AJAX)
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -56,15 +56,6 @@
5757 $wgPayFlowProGatewayCSSVersion, $wgPayflowGatewayPaypalURL,
5858 $wgPayflowGatewaySalt;
5959
60 - // disable caching - this will likely be set in the URL to prevent form caching
61 - if ( $wgRequest->getText( '_nocache_' ) == 'true' ) {
62 - session_cache_limiter( 'nocache' );
63 - }
64 -
65 - $this->fnPayflowEnsureSession();
66 - $this->setHeaders();
67 -
68 -
6960 $wgOut->addExtensionStyle(
7061 "{$wgScriptPath}/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.css?284" .
7162 $wgPayFlowProGatewayCSSVersion);
@@ -92,15 +83,11 @@
9384 <script type="text/javascript">
9485 jQuery(document).ready(function() {
9586 jQuery("div#p-logo a").attr("href","#");
96 -}
 87+});
9788 </script>
9889 EOT;
9990 $wgOut->addHeadItem( 'logolinkoverride', $js );
10091
101 - // establish the edit token to prevent csrf
102 - $token = self::fnPayflowEditToken( $wgPayflowGatewaySalt );
103 -
104 -
10592 // find out if amount was a radio button or textbox, set amount
10693 if( isset( $_REQUEST['amount'] ) && preg_match( '/^\d+(\.(\d+)?)?$/', $wgRequest->getText( 'amount' ) ) ) {
10794 $amount = $wgRequest->getText( 'amount' );
@@ -121,14 +108,32 @@
122109 require_once( 'includes/payflowUser.inc' );
123110
124111 $payflow_data = payflowUser();
 112+
 113+ // if _cache_ is requested by the user, do not set a session/token; dynamic data will be loaded via ajax
 114+ if ( $wgRequest->getText( '_cache_', false ) ) {
 115+ $cache = true;
 116+ $token = '';
 117+ $token_match = false;
 118+ } else {
 119+ $cache = false;
 120+
 121+ // make sure we have a session open for tracking a CSRF-prevention token
 122+ $this->fnPayflowEnsureSession();
 123+
 124+ // establish the edit token to prevent csrf
 125+ $token = self::fnPayflowEditToken( $wgPayflowGatewaySalt );
125126
 127+ // match token
 128+ $token_check = ( $wgRequest->getText( 'token' ) ) ? $wgRequest->getText( 'token' ) : $token;
 129+ $token_match = $this->fnPayflowMatchEditToken( $token_check, $wgPayflowGatewaySalt );
 130+ }
 131+
 132+ $this->setHeaders();
 133+
126134 // Populate form data
127135 $data = $this->fnGetFormData( $amount, $numAttempt, $token, $payflow_data['order_id'] );
128136
129 - // Check form for errors and display
130 - // match token
131 - $token_check = ( $wgRequest->getText( 'token' ) ) ? $wgRequest->getText( 'token' ) : $token;
132 - $token_match = $this->fnPayflowMatchEditToken( $token_check, $wgPayflowGatewaySalt );
 137+ // dispatch forms/handling
133138 if( $token_match ) {
134139 /**
135140 * handle PayPal redirection
@@ -189,8 +194,10 @@
190195 $this->fnPayflowDisplayForm( $data, $this->errors );
191196 }
192197 } else {
193 - // there's a token mismatch
194 - $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' );
 198+ if ( !$cache ) {
 199+ // if we're not caching, there's a token mismatch
 200+ $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' );
 201+ }
195202 $this->fnPayflowDisplayForm( $data, $this->errors );
196203 }
197204 }
@@ -1132,8 +1139,13 @@
11331140 $tracked_contribution[$key] = null;
11341141 }
11351142 }
1136 -
1137 - $db->update( 'contribution_tracking', $tracked_contribution, array( 'id' => $data[ 'contribution_tracking_id' ] ));
 1143+
 1144+ // if contrib tracking id is not already set, we need to insert the data, otherwise update
 1145+ if ( !$data[ 'contribution_tracking_id' ] ) {
 1146+ $data[ 'contribution_tracking_id' ] = $this->insertContributionTracking( $tracked_contribution );
 1147+ } else {
 1148+ $db->update( 'contribution_tracking', $tracked_contribution, array( 'id' => $data[ 'contribution_tracking_id' ] ));
 1149+ }
11381150 }
11391151
11401152 /**
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
@@ -678,15 +678,21 @@
679679 * @return string $url The full URL for the form to post to
680680 */
681681 protected function getNoCacheAction() {
682 - global $wgRequest;
 682+ global $wgRequest, $wgTitle;
683683
684684 $url = $wgRequest->getFullRequestURL();
685 -
686 - // it the _nocache_ param != true, add it to the URL
687 - if ( !$wgRequest->getText( '_nocache_' )) {
688 - $url = wfAppendQuery( $url, array( '_nocache_' => 'true' ));
 685+ $url_parts = wfParseUrl( $url );
 686+ $query_array = wfCgiToArray( $url_parts[ 'query' ] );
 687+
 688+ // ensure that _cache_ does not get set in the URL
 689+ unset( $query_array[ '_cache_' ]);
 690+
 691+ // make sure no other data that might overwrite posted data makes it into the URL
 692+ foreach ( $this->form_data as $key => $value ) {
 693+ unset( $query_array[ $key ] );
689694 }
690 -
691 - return $url;
 695+
 696+ // construct the submission url
 697+ return wfAppendQuery( $wgTitle->getLocalURL(), $query_array );
692698 }
693699 }
Index: trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js
@@ -26,6 +26,6 @@
2727 } )( jQuery );
2828
2929 // Do not fire the AJAX request if _nocache_ is set or we are not using a single-step form (known by lack of utm_source_id)
30 -if( String(window.location).indexOf( '_nocache_' ) == -1 && String(window.location).indexOf( 'utm_source_id' ) != -1){
 30+if( String(window.location).indexOf( '_cache_' ) != -1 && String(window.location).indexOf( 'utm_source_id' ) != -1){
3131 jQuery( document ).ready( jQuery.getDynamicFormElements );
3232 }
\ No newline at end of file

Status & tagging log