r102480 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102479‎ | r102480 | r102481 >
Date:02:21, 9 November 2011
Author:khorn
Status:ok (Comments)
Tags:fundraising 
Comment:
More updates in the name of language cleanup.
Now sets defaults for language and premium_language in normalization, rather that during the actual initial data pull from a form.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -52,7 +52,7 @@
5353 */
5454 'country2' => ( strlen( $wgRequest->getText( 'country2' ) ) ) ? $wgRequest->getText( 'country2' ) : $wgRequest->getText( 'country' ),
5555 'size' => $wgRequest->getText( 'size' ),
56 - 'premium_language' => $wgRequest->getText( 'premium_language', "en" ),
 56+ 'premium_language' => $wgRequest->getText( 'premium_language', null ),
5757 'card_num' => str_replace( ' ', '', $wgRequest->getText( 'card_num' ) ),
5858 'card_type' => $wgRequest->getText( 'card_type' ),
5959 'expiration' => $wgRequest->getText( 'mos' ) . substr( $wgRequest->getText( 'year' ), 2, 2 ),
@@ -71,8 +71,9 @@
7272 'utm_source_id' => $wgRequest->getVal( 'utm_source_id', null ),
7373 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
7474 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
75 - // try to honor the user-set language (uselang), otherwise the language set in the URL (language)
76 - 'language' => $wgRequest->getText( 'uselang', $wgRequest->getText( 'language' ) ),
 75+ // Pull both of these here. We can logic out which one to use in the normalize bits.
 76+ 'language' => $wgRequest->getText( 'language', null ),
 77+ 'uselang' => $wgRequest->getText( 'uselang', null ),
7778 'comment-option' => $wgRequest->getText( 'comment-option' ),
7879 'comment' => $wgRequest->getText( 'comment' ),
7980 'email-opt' => $wgRequest->getText( 'email-opt' ),
@@ -237,6 +238,11 @@
238239 }
239240 }
240241
 242+ /**
 243+ * Sets a key in the normalized data array, to a new value.
 244+ * @param string $key The key you want to set.
 245+ * @param string $val The value you'd like to assign to the key.
 246+ */
241247 function setVal( $key, $val ) {
242248 $this->normalized[$key] = $val;
243249 }
@@ -264,6 +270,7 @@
265271 'optout',
266272 'anonymous',
267273 'language',
 274+ 'premium_language',
268275 'contribution_tracking_id', //sort of...
269276 'currency_code',
270277 );
@@ -473,14 +480,32 @@
474481 * normalizeAndSanitize helper function.
475482 * If the language has not yet been set or is not valid, pulls the language code
476483 * from the current global language object.
 484+ * Also sets the premium_language as the calculated language if it's not
 485+ * already set coming in (had been defaulting to english).
477486 */
478487 function setLanguage() {
479488 global $wgLang;
480 - if ( !$this->isSomething( 'language' )
 489+ $language = false;
 490+
 491+ if ( $this->isSomething( 'uselang' ) ) {
 492+ $language = $this->getVal( 'uselang' );
 493+ } elseif ( $this->isSomething( 'language' ) ) {
 494+ $language = $this->getVal( 'language' );
 495+ }
 496+
 497+ if ( $language == false
481498 || !Language::isValidBuiltInCode( $this->normalized['language'] ) )
482499 {
483 - $this->setVal( 'language', $wgLang->getCode() );
 500+ $language = $wgLang->getCode() ;
484501 }
 502+
 503+ $this->setVal( 'language', $language );
 504+ $this->expunge( 'uselang' );
 505+
 506+ if ( !$this->isSomething( 'premium_language' ) ){
 507+ $this->setVal( 'premium_language', $language );
 508+ }
 509+
485510 }
486511
487512 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r102732MFT r100644, r100785, r101785, r102120, r102318, r102332, r102341, r102342, r...awjrichards01:31, 11 November 2011

Comments

#Comment by Jpostlethwaite (talk | contribs)   23:02, 9 November 2011

Should we use getVal()?

'premium_language' => $wgRequest->getText( 'premium_language', null ),

#Comment by Khorn (WMF) (talk | contribs)   17:20, 10 November 2011

Nope. Here's the argument: getText uses getVal, does some texty-things to whatever comes back (like dealing with line breaks), and then defaults to an empty string unless you tell it otherwise. getVal is, according to the documentation, supposed to be used with scalars. In other words, the difference goes beyond the default return value. Remember, we're not always pulling from forms with identical fields, here. We _need_ to be able to tell the difference between an explicitly empty string being passed in, and the field not existing in the post.

Status & tagging log