r111992 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111991‎ | r111992 | r111993 >
Date:08:18, 21 February 2012
Author:pgehres
Status:resolved (Comments)
Tags:
Comment:
Adding two functions to RapidHTML to genericize the country dropdowns in the forms as well as enhance the support for country variant messages.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php
@@ -68,6 +68,7 @@
6969 // @appeal -> name of the appeal text to load
7070 // @appeal_title -> name of the appeal title to load
7171 // @verisign_logo -> placeholder to load the secure verisign logo
 72+ // @select_country -> generates a select containing all country names
7273 );
7374
7475 /**
@@ -217,6 +218,9 @@
218219 // handle script path
219220 $form = str_replace( "@verisign_logo", $this->getSmallSecureLogo(), $form );
220221
 222+ // handle country drop-down
 223+ $form = str_replace( "@select_country", $this->getCountryDropdown(), $form );
 224+
221225 $form = $this->fix_dropdowns( $form );
222226
223227 return $this->add_messages( $form );
@@ -256,9 +260,11 @@
257261 $params[ $k ] .= "language=" . $this->getEscapedValue( 'language' ) . "&country=" . $this->getEscapedValue( 'country' );
258262 }
259263 }
 264+ // TODO: add support for message variations here as well
260265 $html = str_replace( $matches[ 0 ][ $i ], wfMsg( $msg_key, $params ), $html );
261266 } else {
262 - $html = str_replace( '%' . $msg_key . '%', wfMsg( $msg_key ), $html );
 267+ // look for a country variant of the message and use that if found
 268+ $html = str_replace( '%' . $msg_key . '%', $this->get_message_variation( $msg_key ), $html );
263269 }
264270 }
265271
@@ -435,4 +441,73 @@
436442 }
437443 return $default;
438444 }
 445+
 446+ /**
 447+ * This function looks for a country variant of the specified message and
 448+ * returns the variant if found for the current language. If the variant
 449+ * does not have a message for the current language, the original message
 450+ * is used (checking first the current language and then falling back as
 451+ * is normal for wfMessage).
 452+ *
 453+ * @param $key The original message key to be evaluated
 454+ * @return string A string representing the message requested
 455+ */
 456+ function get_message_variation( $key ) {
 457+ $langCode = strtolower( $this->getEscapedValue( 'language' ) );
 458+ $countryCode = strtolower( $this->getEscapedValue( 'country' ) );
 459+
 460+ # construct the country-specific message key
 461+ $msg_alt_key = $key . '-' . $countryCode;
 462+ $msg_alt = wfMessage( $msg_alt_key );
 463+
 464+ # load the default
 465+ $to_return = wfMessage( $key )->inLanguage( $langCode )->text();
 466+
 467+ # check to see if an alternate exists
 468+ if ( $msg_alt->exists() ){
 469+ # get the English version of the alternate message
 470+ $msg_alt_en = $msg_alt->inLanguage( 'en' )->text();
 471+ # get the alternate message in the current language
 472+ $msg_alt_lang = $msg_alt->inLanguage( $langCode )->text();
 473+
 474+ # if we are looking for English, we're good
 475+ if ( $langCode == 'en' ){
 476+ $to_return = $msg_alt_en;
 477+ }
 478+ # check make sure we didn't fallback to English
 479+ elseif ( strcmp( $msg_alt_en, $msg_alt_lang ) != 0 ){
 480+ $to_return = $msg_alt_lang;
 481+ }
 482+ else {
 483+ # do nothing and return the original message
 484+ }
 485+ }
 486+
 487+ # strip the damned colons off of the right end
 488+ $to_return = rtrim( $to_return, ':' );
 489+
 490+ return $to_return;
 491+ }
 492+
 493+ /**
 494+ * Gets a list of the supported countries from the parent class
 495+ * and returns an option list representing all of those countries
 496+ * in a translatable fashion.
 497+ *
 498+ * @return string An option list containing all supported countries
 499+ */
 500+ function getCountryDropdown() {
 501+ # get the list of supported countries
 502+ $countries = GatewayForm::getCountries();
 503+
 504+ $output = "";
 505+
 506+ # iterate through the countris, ignoring the value since we
 507+ # will generate a message key to replace later
 508+ foreach( $countries as $c => $v ) {
 509+ $output .= "<option value=\"" . $c . "\">%donate_interface-country-dropdown-" . $c . "%</option>\n";
 510+ }
 511+
 512+ return $output;
 513+ }
439514 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r111993Updating existing personal information templates to make use of getCountryDro...pgehres08:31, 21 February 2012
r112177Updating RapidHTML after r112175 and r112171. Partial revert of r111992pgehres01:22, 23 February 2012
r112262MFT r111992, r111993, r112177, r112187, r112188khorn23:10, 23 February 2012

Comments

#Comment by Khorn (WMF) (talk | contribs)   01:28, 23 February 2012

Aw dang. We had several in-person conversations that are now lost to the world. Suffice it to say, I looked at this and said "Hey, we should really do some of this outside RapidHTML so we could reuse it all over the place for things like ultra-specific error messages we might not have translations for!" and pgehres said "Okay!" and did it.

Hence: Resolved.
:)

Status & tagging log