Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/110834
Change subject: Get rid of form_name parameter.
......................................................................
Get rid of form_name parameter.
It was unused. Now form type is not dynamic, and is specified by the adapter.
There is some more work to do cleaning up the form interface.
Change-Id: I9166f85d88041d1340ef79d8efa3c9a55c66e21f
---
M gateway_common/DonationData.php
M gateway_common/GatewayForm.php
M gateway_common/gateway.adapter.php
D gateway_forms/TwoStepTwoColumn.php
D gateway_forms/TwoStepTwoColumnLetter.php
M special/GatewayFormChooser.php
6 files changed, 5 insertions(+), 420 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/34/110834/1
diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php
index 16788d9..d1eadf4 100644
--- a/gateway_common/DonationData.php
+++ b/gateway_common/DonationData.php
@@ -398,7 +398,6 @@
$this->setCountry(); //must do this AFTER
setIPAddress...
$this->handleContributionTrackingID();
$this->setCurrencyCode(); // AFTER setCountry
- $this->setFormClass();
$this->renameCardType();
$this->setEmail();
@@ -431,65 +430,6 @@
}
- /**
- * normalize helper function
- * Sets the form class we will be using.
- * In the case that we are using forms, form_name will be harvested
from
- * $wgRequest by populateData. If we are coming from somewhere that
does not
- * use a form interface (like an api call), this logic should be
skipped.
- *
- * For any specified form, if it is enabled and available, the class
would
- * have been autoloaded at this point. If it is not enabled and
available,
- * we will check the default for the calling gateway, and failing that,
- * form_class will be set to null, which should result in a redirect.
- *
- * Do not actually try to load the forms here.
- * Do determine if the requested forms will load or not.
- *
- * @see GatewayForm::displayForm()
- */
- protected function setFormClass(){
-
- // Is this the default form
- $default = false;
-
- if ( $this->isSomething( 'form_name' ) ){
- $class_name = "Gateway_Form_" . $this->getVal(
'form_name' );
- } else {
- $default = true;
- $class_name = "Gateway_Form_" .
$this->getGatewayGlobal( 'DefaultForm' );
- }
- $utm_source = $this->getVal( 'utm_source' );
-
- if ( !class_exists( $class_name ) ) {
- $class_name_orig = $class_name;
-
- /*
- * If $class_name is not the default form, then check
to see if the
- * default form is available.
- */
- if (!$default) {
-
- $log_message = '[ ' . $class_name . ' ]
utm_source = "' . $utm_source . '"';
- $this->log( $this->getLogMessagePrefix() .
'Specified form class not found ' . $log_message , LOG_ERR );
-
- $class_name = "Gateway_Form_" .
$this->getGatewayGlobal( 'DefaultForm' );
- }
-
- if ( class_exists( $class_name ) ) {
- $this->setVal( 'form_name',
$this->getGatewayGlobal( 'DefaultForm' ) );
- } else {
- $log_message = 'Specified form class not found
[ ' . $class_name_orig . ' ], default form class not found [ ' . $class_name .
' ] utm_source = "' . $utm_source . '"';
- $this->log( $this->getLogMessagePrefix() .
$log_message , LOG_ALERT );
-
- // Unset class name
- $class_name = null;
- }
- }
-
- $this->setVal( 'form_class', $class_name );
- }
-
/**
* munge the legacy card_type field into payment_submethod
*/
diff --git a/gateway_common/GatewayForm.php b/gateway_common/GatewayForm.php
index f454958..b1b72a7 100644
--- a/gateway_common/GatewayForm.php
+++ b/gateway_common/GatewayForm.php
@@ -131,6 +131,7 @@
global $wgOut;
$form_class = $this->getFormClass();
+ // TODO: use interface. static ctor.
if ( $form_class && class_exists( $form_class ) ){
$form_obj = new $form_class( $this->adapter );
$form = $form_obj->getForm();
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 86df89e..dcf9bc4 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -2202,14 +2202,7 @@
}
public function getFormClass() {
- // FIXME: this is not actually a security hole, but looks like
one.
- // The logic to populate form_class should be moved out of
DonationData
- $form_class = $this->getData_Unstaged_Escaped( 'form_class' );
- if ( ( $form_class ) && class_exists( $form_class ) ) {
- return $form_class;
- } else {
- return false;
- }
+ return 'Gateway_Form_RapidHtml';
}
public function getGatewayAdapterClass() {
diff --git a/gateway_forms/TwoStepTwoColumn.php
b/gateway_forms/TwoStepTwoColumn.php
deleted file mode 100644
index 12ee010..0000000
--- a/gateway_forms/TwoStepTwoColumn.php
+++ /dev/null
@@ -1,195 +0,0 @@
-<?php
-
-class Gateway_Form_TwoStepTwoColumn extends Gateway_Form {
-
- public function __construct( &$gateway ) {
- parent::__construct( $gateway );
- }
-
- public function loadPlaceholders() {
- global $wgOut;
- $wgOut->addModules( 'pfp.form.core.placeholders' );
- }
-
- /**
- * Required method for constructing the entire form
- *
- * This can of course be overloaded by a child class.
- * @return string The entire form HTML
- */
- public function getForm() {
- $this->loadResources();
- $form = $this->generateFormStart();
- $form .= $this->getCaptchaHTML();
- $form .= $this->generateFormSubmit();
- $form .= $this->generateFormEnd();
- return $form;
- }
-
- /**
- * Load resources required by this form
- *
- * This will get called in getForm(). If getForm() is not defined in any
- * child classes, but child classes should not load the same resources
- * as are defined here, just overload this method in the child class
- * to define what (if any) resources ought to be loaded.
- */
- public function loadResources() {
- $this->loadValidateJs();
- $this->loadPlaceholders();
- }
-
- public function generateFormStart() {
- $form = $this->generateBannerHeader();
-
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard' ) );
-
- // provide a place at the top of the form for displaying
general messages
- if ( $this->form_errors['general'] ) {
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-payflow-general-error' ) );
- if ( is_array( $this->form_errors['general'] ) ) {
- foreach ( $this->form_errors['general'] as
$this->form_errors_msg ) {
- $form .= Xml::tags( 'p', array( 'class'
=> 'creditcard-error-msg' ), $this->form_errors_msg );
- }
- } else {
- $form .= Xml::tags( 'p', array( 'class' =>
'creditcard-error-msg' ), $this->form_errors_msg );
- }
- $form .= Xml::closeElement( 'div' );
- }
-
- // add noscript tags for javascript disabled browsers
- $form .= $this->getNoScript();
-
- // open form
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-creditcard-form' ) );
-
- // Xml::element seems to convert html to htmlentities
- $form .= "<p class='creditcard-error-msg'>" .
$this->form_errors['retryMsg'] . "</p>";
- $form .= Xml::openElement( 'form', array( 'name' => 'payment',
'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' =>
'return formCheck(this)', 'autocomplete' => 'off' ) );
-
- $form .= Xml::openElement( 'div', array( 'id' => 'left-column',
'class' => 'payflow-cc-form-section' ) );
- $form .= $this->generatePersonalContainer();
- $form .= Xml::closeElement( 'div' ); // close div#left-column
-
- $form .= Xml::openElement( 'div', array( 'id' =>
'right-column', 'class' => 'payflow-cc-form-section' ) );
- $form .= $this->generatePaymentContainer();
-
- return $form;
- }
-
- public function generateFormSubmit() {
- // submit button
- $form = Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-form-submit' ) );
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-donate-submit-button' ) );
- $form .= Xml::element( 'input', array( 'class' =>
'button-plain', 'value' => wfMessage( 'donate_interface-cc-button' )->text(),
'type' => 'submit' ) );
- $form .= Xml::closeElement( 'div' ); // close
div#mw-donate-submit-button
- $form .= Xml::openElement( 'div', array( 'class' =>
'mw-donate-submessage', 'id' => 'payflowpro_gateway-donate-submessage' ) ) .
- wfMessage( 'donate_interface-donate-click' )->text();
- $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-donate-submessage
- $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-form-submit
- return $form;
- }
-
- public function generateFormEnd() {
- $form = '';
- // add hidden fields
- $hidden_fields = $this->getHiddenFields();
- foreach ( $hidden_fields as $field => $value ) {
- $form .= Html::hidden( $field, $value );
- }
- $form .= Xml::closeElement( 'div' ); // close div#right-column
- $form .= Xml::closeElement( 'form' );
- $form .= Xml::closeElement( 'div' ); // close
div#mw-creditcard-form
- $form .= $this->generateDonationFooter();
- $form .= Xml::closeElement( 'div' ); // div#close mw-creditcard
- return $form;
- }
-
- protected function generatePersonalContainer() {
- $form = '';
- $form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-personal-info' ) ); ;
- $form .= Xml::openElement( 'table', array( 'id' =>
'payflow-table-donor' ) );
-
- $form .= $this->generatePersonalFields();
-
- $form .= Xml::closeElement( 'table' ); // close
table#payflow-table-donor
- $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-personal-info
-
- return $form;
- }
-
- protected function generatePersonalFields() {
- // first name
- $form = $this->getNameField();
-
- // country
- $form .= $this->getCountryField();
-
- // street
- $form .= $this->getStreetField();
-
-
- // city
- $form .= $this->getCityField();
-
- // state
- $form .= $this->getStateField();
-
- // zip
- $form .= $this->getZipField();
-
- // email
- $form .= $this->getEmailField();
-
- return $form;
- }
-
- protected function generatePaymentContainer() {
- $form = '';
- // credit card info
- $form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-payment-info' ) );
- $form .= Xml::openElement( 'table', array( 'id' =>
'payflow-table-cc' ) );
-
- $form .= $this->generatePaymentFields();
-
- $form .= Xml::closeElement( 'table' ); // close
table#payflow-table-cc
- $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-payment-info
-
- return $form;
- }
-
- protected function generatePaymentFields() {
- global $wgScriptPath;
-
- // amount
- $form = '<tr>';
- $form .= '<td colspan="2"><span class="creditcard-error-msg">'
. $this->form_errors['amount'] . '</span></td>';
- $form .= '</tr>';
- $form .= '<tr>';
- $form .= '<td class="label">' . Xml::label( wfMessage(
'donate_interface-donor-amount' )->text(), 'amount' ) . '</td>';
- $form .= '<td>' . Xml::input( 'amount', '7',
$this->getEscapedValue( 'amount' ), array( 'type' => 'text', 'maxlength' =>
'10', 'id' => 'amount' ) ) .
- ' ' . $this->generateCurrencyDropdown() . '</td>';
- $form .= '</tr>';
-
- // card logos
- $form .= '<tr>';
- $form .= '<td />';
- $form .= '<td>' . Xml::element( 'img', array( 'src' =>
$wgScriptPath .
"/extensions/DonationInterface/gateway_forms/includes/credit_card_logos.gif" )
) . '</td>';
- $form .= '</tr>';
-
- // credit card type
- $form .= $this->getCreditCardTypeField();
-
- // card number
- $form .= $this->getCardnumberField();
-
- // expiry
- $form .= $this->getExpiryField();
-
- // cvv
- $form .= $this->getCvvField();
-
- return $form;
- }
-}
-
diff --git a/gateway_forms/TwoStepTwoColumnLetter.php
b/gateway_forms/TwoStepTwoColumnLetter.php
deleted file mode 100644
index 5915f58..0000000
--- a/gateway_forms/TwoStepTwoColumnLetter.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-
-class Gateway_Form_TwoStepTwoColumnLetter extends
Gateway_Form_TwoStepTwoColumn {
- public function __construct( &$gateway ) {
- global $wgScriptPath;
-
- // set the path to css, before the parent constructor is
called, checking to make sure some child class hasn't already set this
- if ( !strlen( $this->getStylePath() ) ) {
- $this->setStylePath( $wgScriptPath .
'/extensions/DonationInterface/gateway_forms/css/TwoStepTwoColumnLetter.css' );
- }
-
- parent::__construct( $gateway );
- }
-
- public function generateFormStart() {
- $form = parent::generateBannerHeader();
-
- $form .= Xml::openElement( 'table', array( 'width' => '100%',
'cellspacing' => 0, 'cellpadding' => 0, 'border' => 0 ) );
- $form .= Xml::openElement( 'tr' );
- $form .= Xml::openElement( 'td', array( 'id' => 'appeal',
'valign' => 'top' ) );
-
- $template = self::generateTextTemplate();
- $form .= $template;
-
- $form .= Xml::closeElement( 'td' );
-
- $form .= Xml::openElement( 'td', array( 'id' => 'donate',
'valign' => 'top' ) );
-
- // add noscript tags for javascript disabled browsers
- $form .= $this->getNoScript();
-
- $form .= Xml::tags( 'h2', array( 'id' => 'donate-head' ),
wfMessage( 'donate_interface-please-complete' )->escaped() );
-
- // provide a place at the top of the form for displaying
general messages
- if ( $this->form_errors['general'] ) {
- $form .= Xml::openElement( 'div', array( 'id' =>
'mw-payflow-general-error' ) );
- if ( is_array( $this->form_errors['general'] ) ) {
- foreach ( $this->form_errors['general'] as
$this->form_errors_msg ) {
- $form .= Xml::tags( 'p', array( 'class'
=> 'creditcard-error-msg' ), $this->form_errors_msg );
- }
- } else {
- $form .= Xml::tags( 'p', array( 'class' =>
'creditcard-error-msg' ), $this->form_errors_msg );
- }
- $form .= Xml::closeElement( 'div' ); // close
div#mw-payflow-general-error
- }
-
- // Xml::element seems to convert html to htmlentities
- $form .= "<p class='creditcard-error-msg'>" .
$this->form_errors['retryMsg'] . "</p>";
- $form .= Xml::openElement( 'form', array( 'name' => 'payment',
'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' =>
'return formCheck(this)', 'autocomplete' => 'off' ) );
-
- $form .= $this->generateBillingContainer();
- return $form;
- }
-
- public function generateFormEnd() {
- $form = '';
- $form .= $this->generateFormClose();
- return $form;
- }
-
- protected function generateBillingContainer() {
- $form = '';
- $form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-personal-info' ) );
- $form .= Xml::openElement( 'table', array( 'id' =>
'payflow-table-donor' ) );
- $form .= $this->generateBillingFields();
- $form .= Xml::closeElement( 'table' ); // close
table#payflow-table-donor
- $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-personal-info
-
- return $form;
- }
-
- protected function generateBillingFields() {
- global $wgScriptPath;
-
- $form = '';
-
- // name
- $form .= $this->getNameField();
-
- // email
- $form .= $this->getEmailField();
-
- // amount
- $form .= '<tr>';
- $form .= '<td colspan="2"><span class="creditcard-error-msg">'
. $this->form_errors['amount'] . '</span></td>';
- $form .= '</tr>';
- $form .= '<tr>';
- $form .= '<td class="label">' . Xml::label( wfMessage(
'donate_interface-donor-amount' )->text(), 'amount' ) . '</td>';
- $form .= '<td>' . Xml::input( 'amount', '7',
$this->getEscapedValue( 'amount' ), array( 'type' => 'text', 'maxlength' =>
'10', 'id' => 'amount' ) ) .
- ' ' . $this->generateCurrencyDropdown() . '</td>';
- $form .= '</tr>';
-
- // card logos
- if ( $this->getEscapedValue( 'currency_code' ) == 'USD' ) {
- $form .= '<tr id="four_cards"
style="display:table-row;">';
- $form .= '<td class="label"> </td><td>' . Xml::element(
'img', array( 'src' => $wgScriptPath .
"/extensions/DonationInterface/gateway_forms/includes/credit_card_logos.gif" )
) . '</td>';
- $form .= '</tr>';
- $form .= '<tr id="two_cards" style="display:none;">';
- $form .= '<td class="label"> </td><td>' . Xml::element(
'img', array( 'src' => $wgScriptPath .
"/extensions/DonationInterface/gateway_forms/includes/credit_card_logos3.gif" )
) . '</td>';
- $form .= '</tr>';
- } else {
- $form .= '<tr id="four_cards" style="display:none;">';
- $form .= '<td class="label"> </td><td>' . Xml::element(
'img', array( 'src' => $wgScriptPath .
"/extensions/DonationInterface/gateway_forms/includes/credit_card_logos.gif" )
) . '</td>';
- $form .= '</tr>';
- $form .= '<tr id="two_cards"
style="display:table-row;">';
- $form .= '<td class="label"> </td><td>' . Xml::element(
'img', array( 'src' => $wgScriptPath .
"/extensions/DonationInterface/gateway_forms/includes/credit_card_logos3.gif" )
) . '</td>';
- $form .= '</tr>';
- }
-
- // card number
- $form .= $this->getCardNumberField();
-
- // cvv
- $form .= $this->getCvvField();
-
- // expiry
- $form .= $this->getExpiryField();
-
- // street
- $form .= $this->getStreetField();
-
- // city
- $form .= $this->getCityField();
-
- // state
- $form .= $this->getStateField();
- // zip
- $form .= $this->getZipField();
-
- // country
- $form .= $this->getCountryField();
-
- return $form;
- }
-
- /**
- * Generate form closing elements
- */
- public function generateFormClose() {
- $form = '';
- // add hidden fields
- $hidden_fields = $this->getHiddenFields();
- foreach ( $hidden_fields as $field => $value ) {
- $form .= Html::hidden( $field, $value );
- }
-
- $form .= Xml::closeElement( 'form' ); // close form 'payment'
- $form .= $this->generateDonationFooter();
- $form .= Xml::closeElement( 'td' );
- $form .= Xml::closeElement( 'tr' );
- $form .= Xml::closeElement( 'table' );
- return $form;
- }
-}
diff --git a/special/GatewayFormChooser.php b/special/GatewayFormChooser.php
index aae8e5b..68521dd 100644
--- a/special/GatewayFormChooser.php
+++ b/special/GatewayFormChooser.php
@@ -85,7 +85,6 @@
static function buildPaymentsFormURL( $form_key, $other_params = array
( ) ) {
// And... construct the URL
$params = array (
- 'form_name' => "RapidHtml",
'appeal' => "JimmyQuote",
'ffname' => $form_key,
);
@@ -281,7 +280,7 @@
* Gets the array of settings and capability definitions for the form
* specified in $form_key.
* @global array $wgDonationInterfaceAllowedHtmlForms The global array
- * of whitelisted (enabled) RapidHTML forms.
+ * of whitelisted (enabled) forms.
* @param string $form_key The name of the form (ffname) we're looking
* for. Should map to a first-level key in
* $wgDonationInterfaceAllowedHtmlForms.
@@ -464,6 +463,7 @@
foreach ( $wgDonationInterfaceAllowedHtmlForms as $ffname =>
$data ) {
if ( array_key_exists( 'special_type', $data ) &&
$data['special_type'] === 'error' ) {
$is_match = true;
+ # XXX what is this magick? Do something less
evil.
$group = 2; //default group
//check to make sure it fits our needs.
if ( is_array( $data['gateway'] ) ) {
@@ -500,7 +500,7 @@
}
if ( !sizeof( $error_forms ) ) {
- throw new MWException( __FUNCTION__ . "No RapidHTML
Error form found for gateway '$gateway', method '$payment_method', submethod
'$payment_submethod'" );
+ throw new MWException( __FUNCTION__ . "No error form
found for gateway '$gateway', method '$payment_method', submethod
'$payment_submethod'" );
}
//sort the error_forms by $group; get the most specific form
defined
--
To view, visit https://gerrit.wikimedia.org/r/110834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9166f85d88041d1340ef79d8efa3c9a55c66e21f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits