r73996 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73995‎ | r73996 | r73997 >
Date:22:44, 29 September 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Added single column form; Refactored form generation in TwoColumnLetter to facilitate form creation of SingleColumn; Added dynamic CSS loading in Form.php and its subclasses
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/Form.css (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -202,7 +202,7 @@
203203 public function setFormClass( $class_name=NULL ) {
204204 if ( !$class_name ) {
205205 global $wgRequest, $wgPayflowGatewayDefaultForm;
206 - $form_class = ( strlen( $wgRequest->getText( 'form_name' ))) ? $wgRequest->getText( 'form_name' ) : $wgPayflowGatewayDefaultForm;
 206+ $form_class = $wgRequest->getText( 'form_name', $wgPayflowGatewayDefaultForm );
207207
208208 // make sure our form class exists before going on, if not try loading default form class
209209 $class_name = "PayflowProGateway_Form_" . $form_class;
@@ -909,7 +909,8 @@
910910 'utm_source' => $this->getUtmSource(),
911911 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
912912 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
913 - 'language' => $wgRequest->getText( 'language' ),
 913+ // try to honr the user-set language (uselang), otherwise the language set in the URL (language)
 914+ 'language' => $wgRequest->getText( 'uselang', $wgRequest->getText( 'language' )),
914915 'comment' => $wgRequest->getText( 'comment' ),
915916 'comment-option' => $wgRequest->getText( 'comment-option' ),
916917 'email-opt' => $wgRequest->getText( 'email-opt' ),
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php
@@ -0,0 +1,19 @@
 2+<?php
 3+
 4+class PayflowProGateway_Form_SingleColumn extends PayflowProGateway_Form_TwoColumnLetter {
 5+
 6+ public function __construct( &$form_data, &$form_errors ) {
 7+ global $wgOut, $wgScriptPath;
 8+
 9+ // set the path to css, before the parent constructor is called, checking to make sure some child class hasn't already set this
 10+ if ( !strlen( $this->getStylePath())) {
 11+ $this->setStylePath( $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css' );
 12+ }
 13+
 14+ parent::__construct( $form_data, $form_errors );
 15+ }
 16+
 17+ public function generateFormEnd() {
 18+ return $this->generateFormClose();
 19+ }
 20+}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css
@@ -0,0 +1,3 @@
 2+.payflow-cc-form-section {
 3+ float: none;
 4+}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/Form.css
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
@@ -26,19 +26,59 @@
2727 */
2828 public $form_errors;
2929
 30+ /**
 31+ * The full path to CSS for the current form
 32+ * @var string
 33+ */
 34+ protected $style_path;
 35+
3036 abstract public function generateFormStart();
3137 abstract public function generateFormSubmit();
3238 abstract public function generateFormEnd();
3339
3440 public function __construct( &$data, &$error ) {
35 - global $wgPayflowGatewayTest;
 41+ global $wgPayflowGatewayTest, $wgOut;
3642
3743 $this->test = $wgPayflowGatewayTest;
3844 $this->form_data =& $data;
3945 $this->form_errors =& $error;
 46+
 47+ /**
 48+ * add form-specific css - the path can be set using $this->setStylePath,
 49+ * which should be called before loading this constructor
 50+ */
 51+ if ( !strlen( $this->getStylePath())) {
 52+ $this->setStylePath();
 53+ }
 54+ $wgOut->addExtensionStyle( $this->getStylePath() );
4055 }
4156
4257 /**
 58+ * Set the path to the CSS file for the form
 59+ *
 60+ * This should be a full path, perhaps taking advantage of $wgScriptPath.
 61+ * If you do not pass the path to the method, the style path will default
 62+ * to the default css in css/Form.css
 63+ * @param string $style_path
 64+ */
 65+ public function setStylePath( $style_path=null ) {
 66+ global $wgScriptPath;
 67+ if ( !$style_path ) {
 68+ // load the default form CSS if the style path not explicitly set
 69+ $style_path = $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/Form.css';
 70+ }
 71+ $this->style_path = $style_path;
 72+ }
 73+
 74+ /**
 75+ * Get the path to CSS
 76+ * @return String
 77+ */
 78+ public function getStylePath() {
 79+ return $this->style_path;
 80+ }
 81+
 82+ /**
4383 * Generates the donation footer ("There are other ways to give...")
4484 * @returns string of HTML
4585 */
@@ -287,6 +327,4 @@
288328 }
289329 return $this->hidden_fields;
290330 }
291 -
292 -
293 -}
 331+}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
@@ -82,8 +82,13 @@
8383 global $wgPayflowGatewayHeader, $wgOut;
8484 // intro text
8585 if ( $wgPayflowGatewayHeader ) {
86 - $header = str_replace( '@language', $this->form_data['language'], $wgPayflowGatewayHeader );
87 - $wgOut->addHtml( $wgOut->parse( $header ));
 86+ $header = str_replace( '@language', $this->form_data[ 'language' ], $wgPayflowGatewayHeader );
 87+ $template = $wgOut->parse( $header );
 88+
 89+ // make sure that we actually have a matching template to display so we don't display the 'redlink'
 90+ if ( !preg_match( '/redlink\=1/', $template )) {
 91+ $wgOut->addHtml( $template );
 92+ }
8893 }
8994 }
9095
@@ -224,4 +229,4 @@
225230
226231 return $form;
227232 }
228 -}
 233+}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
@@ -4,11 +4,14 @@
55
66 public function __construct( &$form_data, &$form_errors ) {
77 global $wgOut, $wgScriptPath;
 8+
 9+ // set the path to css, before the parent constructor is called, checking to make sure some child class hasn't already set this
 10+ if ( !strlen( $this->getStylePath())) {
 11+ $this->setStylePath( $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter.css' );
 12+ }
 13+
814 parent::__construct( $form_data, $form_errors );
9 -
10 - // add form-specific css
11 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter.css');
12 -
 15+
1316 // update the list of hidden fields we need to use in this form.
1417 $this->updateHiddenFields();
1518 }
@@ -34,7 +37,7 @@
3538 } else {
3639 $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
3740 }
38 - $form .= Xml::closeElement( 'div' );
 41+ $form .= Xml::closeElement( 'div' ); // close div#mw-payflow-general-error
3942 }
4043
4144 // open form
@@ -53,28 +56,23 @@
5457 public function generateFormEnd() {
5558 global $wgRequest, $wgOut;
5659 $form = '';
57 - // add hidden fields
58 - $hidden_fields = $this->getHiddenFields();
59 - foreach ( $hidden_fields as $field => $value ) {
60 - $form .= Xml::hidden( $field, $value );
61 - }
62 -
63 - $form .= Xml::closeElement( 'form' );
 60+
 61+ $form .= $this->generateFormClose();
6462
65 - $form .= $this->generateDonationFooter();
66 -
67 - $form .= Xml::closeElement( 'div' );
68 - $form .= Xml::closeElement( 'div' );
69 - $form .= Xml::closeElement( 'div' );
70 -
7163 $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-cc_form_letter', 'class' => 'payflowpro_gateway-cc_form_column'));
7264 $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-cc_form_letter_inside' ));
 65+
7366 $text_template = $wgRequest->getText( 'text_template' );
74 - if ( $wgRequest->getText( 'language' )) $text_template .= '/' . $wgRequest->getText( 'language' );
 67+ // if the user has uselang set, honor that, otherwise default to the language set for the form defined by 'language' in the query string
 68+ if ( $wgRequest->getText( 'language' )) $text_template .= '/' . $this->form_data[ 'language' ];
7569
76 - $form .= ( strlen( $text_template )) ? $wgOut->parse( '{{'.$text_template.'}}' ) : '';
77 - $form .= Xml::closeElement( 'div' );
78 - $form .= Xml::closeElement( 'div' );
 70+ $template = ( strlen( $text_template )) ? $wgOut->parse( '{{'.$text_template.'}}' ) : '';
 71+ // if the template doesn't exist, prevent the display of the red link
 72+ if ( preg_match( '/redlink\=1/', $template )) $template = NULL;
 73+ $form .= $template;
 74+
 75+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-cc_form_letter
 76+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-cc_form_letter_inside
7977 return $form;
8078 }
8179
@@ -103,7 +101,12 @@
104102 $email_opt_value = ( $this->form_data[ 'numAttempt' ]) ? $this->form_data[ 'email-opt' ] : true;
105103 $form .= '<tr>';
106104 $form .= '<td>' . Xml::check( 'email-opt', $email_opt_value ) . '</td>';
107 - $form .= '<td>' . Xml::label( wfMsg( 'donate_interface-email-agreement' ), 'email-opt' ) . '</td>';
 105+ $form .= '<td>';
 106+ // put the label inside Xml::openElement so any HTML in the msg might get rendered (right, Germany?)
 107+ $form .= Xml::openElement( 'label', array( 'for' => 'email-opt' ));
 108+ $form .= wfMsg( 'donate_interface-email-agreement' );
 109+ $form .= Xml::closeElement( 'label' );
 110+ $form .= '</td>';
108111 $form .= '</tr>';
109112
110113 $form .= Xml::closeElement( 'table' );
@@ -126,4 +129,25 @@
127130
128131 $this->setHiddenFields( $hidden_fields );
129132 }
 133+
 134+ /**
 135+ * Generate form closing elements
 136+ */
 137+ public function generateFormClose() {
 138+ $form = '';
 139+ // add hidden fields
 140+ $hidden_fields = $this->getHiddenFields();
 141+ foreach ( $hidden_fields as $field => $value ) {
 142+ $form .= Xml::hidden( $field, $value );
 143+ }
 144+
 145+ $form .= Xml::closeElement( 'form' ); // close form 'payment'
 146+
 147+ $form .= $this->generateDonationFooter();
 148+
 149+ $form .= Xml::closeElement( 'div' ); //close div#mw-creditcard
 150+ $form .= Xml::closeElement( 'div' ); //close div#payflowpro_gateway-cc_form_form
 151+ $form .= Xml::closeElement( 'div' ); //close div#payflowpro_gateway-cc_form_container
 152+ return $form;
 153+ }
130154 }
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
@@ -24,6 +24,7 @@
2525 $wgAutoloadClasses[ 'PayflowProGateway_Form' ] = $dir . 'forms/Form.php';
2626 $wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumn' ] = $dir . 'forms/TwoColumn.php';
2727 $wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter' ] = $dir . 'forms/TwoColumnLetter.php';
 28+$wgAutoloadClasses[ 'PayflowProGateway_Form_SingleColumn' ] = $dir . 'forms/SingleColumn.php';
2829 $wgExtensionMessagesFiles['PayflowProGateway'] = $dir . 'payflowpro_gateway.i18n.php';
2930 $wgExtensionAliasesFiles['PayflowProGateway'] = $dir . 'payflowpro_gateway.alias.php';
3031 $wgSpecialPages['PayflowProGateway'] = 'PayflowProGateway';

Status & tagging log