http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73996
Revision: 73996
Author: awjrichards
Date: 2010-09-29 22:44:55 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
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
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
Added Paths:
-----------
trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/Form.css
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css
Modified: trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
===================================================================
--- trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
2010-09-29 22:44:32 UTC (rev 73995)
+++ trunk/extensions/DonationInterface/payflowpro_gateway/forms/Form.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -26,19 +26,59 @@
*/
public $form_errors;
+ /**
+ * The full path to CSS for the current form
+ * @var string
+ */
+ protected $style_path;
+
abstract public function generateFormStart();
abstract public function generateFormSubmit();
abstract public function generateFormEnd();
public function __construct( &$data, &$error ) {
- global $wgPayflowGatewayTest;
+ global $wgPayflowGatewayTest, $wgOut;
$this->test = $wgPayflowGatewayTest;
$this->form_data =& $data;
$this->form_errors =& $error;
+
+ /**
+ * add form-specific css - the path can be set using
$this->setStylePath,
+ * which should be called before loading this constructor
+ */
+ if ( !strlen( $this->getStylePath())) {
+ $this->setStylePath();
+ }
+ $wgOut->addExtensionStyle( $this->getStylePath() );
}
/**
+ * Set the path to the CSS file for the form
+ *
+ * This should be a full path, perhaps taking advantage of
$wgScriptPath.
+ * If you do not pass the path to the method, the style path will
default
+ * to the default css in css/Form.css
+ * @param string $style_path
+ */
+ public function setStylePath( $style_path=null ) {
+ global $wgScriptPath;
+ if ( !$style_path ) {
+ // load the default form CSS if the style path not
explicitly set
+ $style_path = $wgScriptPath .
'/extensions/DonationInterface/payflowpro_gateway/forms/css/Form.css';
+ }
+ $this->style_path = $style_path;
+ }
+
+ /**
+ * Get the path to CSS
+ * @return String
+ */
+ public function getStylePath() {
+ return $this->style_path;
+ }
+
+ /**
* Generates the donation footer ("There are other ways to give...")
* @returns string of HTML
*/
@@ -287,6 +327,4 @@
}
return $this->hidden_fields;
}
-
-
-}
+}
\ No newline at end of file
Added:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php
(rev 0)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/forms/SingleColumn.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -0,0 +1,19 @@
+<?php
+
+class PayflowProGateway_Form_SingleColumn extends
PayflowProGateway_Form_TwoColumnLetter {
+
+ public function __construct( &$form_data, &$form_errors ) {
+ global $wgOut, $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/payflowpro_gateway/forms/css/SingleColumn.css' );
+ }
+
+ parent::__construct( $form_data, $form_errors );
+ }
+
+ public function generateFormEnd() {
+ return $this->generateFormClose();
+ }
+}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
===================================================================
--- trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
2010-09-29 22:44:32 UTC (rev 73995)
+++ trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumn.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -82,8 +82,13 @@
global $wgPayflowGatewayHeader, $wgOut;
// intro text
if ( $wgPayflowGatewayHeader ) {
- $header = str_replace( '@language',
$this->form_data['language'], $wgPayflowGatewayHeader );
- $wgOut->addHtml( $wgOut->parse( $header ));
+ $header = str_replace( '@language', $this->form_data[
'language' ], $wgPayflowGatewayHeader );
+ $template = $wgOut->parse( $header );
+
+ // make sure that we actually have a matching template
to display so we don't display the 'redlink'
+ if ( !preg_match( '/redlink\=1/', $template )) {
+ $wgOut->addHtml( $template );
+ }
}
}
@@ -224,4 +229,4 @@
return $form;
}
-}
+}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
2010-09-29 22:44:32 UTC (rev 73995)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoColumnLetter.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -4,11 +4,14 @@
public function __construct( &$form_data, &$form_errors ) {
global $wgOut, $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/payflowpro_gateway/forms/css/TwoColumnLetter.css'
);
+ }
+
parent::__construct( $form_data, $form_errors );
-
- // add form-specific css
- $wgOut->addExtensionStyle( $wgScriptPath .
'/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoColumnLetter.css');
-
+
// update the list of hidden fields we need to use in this form.
$this->updateHiddenFields();
}
@@ -34,7 +37,7 @@
} else {
$form .= Xml::tags( 'p', array( 'class' =>
'creditcard-error-msg' ), $this->form_errors_msg );
}
- $form .= Xml::closeElement( 'div' );
+ $form .= Xml::closeElement( 'div' ); // close
div#mw-payflow-general-error
}
// open form
@@ -53,28 +56,23 @@
public function generateFormEnd() {
global $wgRequest, $wgOut;
$form = '';
- // add hidden fields
- $hidden_fields = $this->getHiddenFields();
- foreach ( $hidden_fields as $field => $value ) {
- $form .= Xml::hidden( $field, $value );
- }
-
- $form .= Xml::closeElement( 'form' );
+
+ $form .= $this->generateFormClose();
- $form .= $this->generateDonationFooter();
-
- $form .= Xml::closeElement( 'div' );
- $form .= Xml::closeElement( 'div' );
- $form .= Xml::closeElement( 'div' );
-
$form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-cc_form_letter', 'class' =>
'payflowpro_gateway-cc_form_column'));
$form .= Xml::openElement( 'div', array( 'id' =>
'payflowpro_gateway-cc_form_letter_inside' ));
+
$text_template = $wgRequest->getText( 'text_template' );
- if ( $wgRequest->getText( 'language' )) $text_template .= '/' .
$wgRequest->getText( 'language' );
+ // if the user has uselang set, honor that, otherwise default
to the language set for the form defined by 'language' in the query string
+ if ( $wgRequest->getText( 'language' )) $text_template .= '/' .
$this->form_data[ 'language' ];
- $form .= ( strlen( $text_template )) ? $wgOut->parse(
'{{'.$text_template.'}}' ) : '';
- $form .= Xml::closeElement( 'div' );
- $form .= Xml::closeElement( 'div' );
+ $template = ( strlen( $text_template )) ? $wgOut->parse(
'{{'.$text_template.'}}' ) : '';
+ // if the template doesn't exist, prevent the display of the
red link
+ if ( preg_match( '/redlink\=1/', $template )) $template = NULL;
+ $form .= $template;
+
+ $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-cc_form_letter
+ $form .= Xml::closeElement( 'div' ); // close
div#payflowpro_gateway-cc_form_letter_inside
return $form;
}
@@ -103,7 +101,12 @@
$email_opt_value = ( $this->form_data[ 'numAttempt' ]) ?
$this->form_data[ 'email-opt' ] : true;
$form .= '<tr>';
$form .= '<td>' . Xml::check( 'email-opt', $email_opt_value ) .
'</td>';
- $form .= '<td>' . Xml::label( wfMsg(
'donate_interface-email-agreement' ), 'email-opt' ) . '</td>';
+ $form .= '<td>';
+ // put the label inside Xml::openElement so any HTML in the msg
might get rendered (right, Germany?)
+ $form .= Xml::openElement( 'label', array( 'for' => 'email-opt'
));
+ $form .= wfMsg( 'donate_interface-email-agreement' );
+ $form .= Xml::closeElement( 'label' );
+ $form .= '</td>';
$form .= '</tr>';
$form .= Xml::closeElement( 'table' );
@@ -126,4 +129,25 @@
$this->setHiddenFields( $hidden_fields );
}
+
+ /**
+ * Generate form closing elements
+ */
+ public function generateFormClose() {
+ $form = '';
+ // add hidden fields
+ $hidden_fields = $this->getHiddenFields();
+ foreach ( $hidden_fields as $field => $value ) {
+ $form .= Xml::hidden( $field, $value );
+ }
+
+ $form .= Xml::closeElement( 'form' ); // close form 'payment'
+
+ $form .= $this->generateDonationFooter();
+
+ $form .= Xml::closeElement( 'div' ); //close div#mw-creditcard
+ $form .= Xml::closeElement( 'div' ); //close
div#payflowpro_gateway-cc_form_form
+ $form .= Xml::closeElement( 'div' ); //close
div#payflowpro_gateway-cc_form_container
+ return $form;
+ }
}
Added:
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css
(rev 0)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/SingleColumn.css
2010-09-29 22:44:55 UTC (rev 73996)
@@ -0,0 +1,3 @@
+.payflow-cc-form-section {
+ float: none;
+}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
2010-09-29 22:44:32 UTC (rev 73995)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -202,7 +202,7 @@
public function setFormClass( $class_name=NULL ) {
if ( !$class_name ) {
global $wgRequest, $wgPayflowGatewayDefaultForm;
- $form_class = ( strlen( $wgRequest->getText(
'form_name' ))) ? $wgRequest->getText( 'form_name' ) :
$wgPayflowGatewayDefaultForm;
+ $form_class = $wgRequest->getText( 'form_name',
$wgPayflowGatewayDefaultForm );
// make sure our form class exists before going on, if
not try loading default form class
$class_name = "PayflowProGateway_Form_" . $form_class;
@@ -909,7 +909,8 @@
'utm_source' => $this->getUtmSource(),
'utm_medium' => $wgRequest->getText(
'utm_medium' ),
'utm_campaign' => $wgRequest->getText(
'utm_campaign' ),
- 'language' => $wgRequest->getText( 'language' ),
+ // try to honr the user-set language (uselang),
otherwise the language set in the URL (language)
+ 'language' => $wgRequest->getText( 'uselang',
$wgRequest->getText( 'language' )),
'comment' => $wgRequest->getText( 'comment' ),
'comment-option' => $wgRequest->getText(
'comment-option' ),
'email-opt' => $wgRequest->getText( 'email-opt'
),
Modified:
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
===================================================================
---
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
2010-09-29 22:44:32 UTC (rev 73995)
+++
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
2010-09-29 22:44:55 UTC (rev 73996)
@@ -24,6 +24,7 @@
$wgAutoloadClasses[ 'PayflowProGateway_Form' ] = $dir . 'forms/Form.php';
$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumn' ] = $dir .
'forms/TwoColumn.php';
$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter' ] = $dir .
'forms/TwoColumnLetter.php';
+$wgAutoloadClasses[ 'PayflowProGateway_Form_SingleColumn' ] = $dir .
'forms/SingleColumn.php';
$wgExtensionMessagesFiles['PayflowProGateway'] = $dir .
'payflowpro_gateway.i18n.php';
$wgExtensionAliasesFiles['PayflowProGateway'] = $dir .
'payflowpro_gateway.alias.php';
$wgSpecialPages['PayflowProGateway'] = 'PayflowProGateway';
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs