r109038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109037‎ | r109038 | r109039 >
Date:14:48, 16 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
moved country options function to utils class
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPUtils.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php
@@ -54,7 +54,7 @@
5555 'label-message' => 'educationprogram-org-edit-country',
5656 'maxlength' => 255,
5757 'required' => true,
58 - 'options' => efEpGetCountryOptions( $this->getLanguage()->getCode() ),
 58+ 'options' => EPUtils::getCountryOptions( $this->getLanguage()->getCode() ),
5959 'validation-callback' => array( $this, 'countryIsValid' ),
6060 );
6161
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -68,7 +68,7 @@
6969 );
7070 break;
7171 case 'country':
72 - $countries = array_flip( efEpGetCountryOptions( $this->getLanguage()->getCode() ) );
 72+ $countries = array_flip( EPUtils::getCountryOptions( $this->getLanguage()->getCode() ) );
7373 $value = htmlspecialchars( $countries[$value] );
7474 break;
7575 case 'courses': case 'students': case 'terms':
@@ -122,7 +122,7 @@
123123 return array(
124124 'country' => array(
125125 'type' => 'select',
126 - 'options' => efEpGetCountryOptions( $this->getLanguage()->getCode() ),
 126+ 'options' => EPUtils::getCountryOptions( $this->getLanguage()->getCode() ),
127127 'value' => ''
128128 ),
129129 'active' => array(
Index: trunk/extensions/EducationProgram/includes/EPUtils.php
@@ -13,6 +13,14 @@
1414 */
1515 class EPUtils {
1616
 17+ /**
 18+ * Create a log entry using the provided info.
 19+ * Takes care about the logging interface changes in MediaWiki 1.19.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @param array $info
 24+ */
1725 public static function log( array $info ) {
1826 $user = array_key_exists( 'user', $info ) ? $info['user'] : $GLOBALS['wgUser'];
1927
@@ -49,4 +57,32 @@
5058 }
5159 }
5260
 61+ /**
 62+ * Returns a list of country names that can be used by
 63+ * a select input localized in the lang of which the code is provided.
 64+ *
 65+ * @since 0.1
 66+ *
 67+ * @param string $langCode
 68+ *
 69+ * @return array
 70+ */
 71+ public static function getCountryOptions( $langCode ) {
 72+ $countries = CountryNames::getNames( $langCode );
 73+
 74+ return array_merge(
 75+ array( '' => '' ),
 76+ array_combine(
 77+ array_map(
 78+ function( $value, $key ) {
 79+ return $key . ' - ' . $value;
 80+ } ,
 81+ array_values( $countries ),
 82+ array_keys( $countries )
 83+ ),
 84+ array_keys( $countries )
 85+ )
 86+ );
 87+ }
 88+
5389 }
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -358,22 +358,3 @@
359359
360360 # The default value for the user preferences.
361361 $wgDefaultUserOptions['ep_showtoplink'] = false;
362 -
363 -// TODO: put somewhere decent + document
364 -function efEpGetCountryOptions( $langCode ) {
365 - $countries = CountryNames::getNames( $langCode );
366 -
367 - return array_merge(
368 - array( '' => '' ),
369 - array_combine(
370 - array_map(
371 - function( $value, $key ) {
372 - return $key . ' - ' . $value;
373 - } ,
374 - array_values( $countries ),
375 - array_keys( $countries )
376 - ),
377 - array_keys( $countries )
378 - )
379 - );
380 -}
\ No newline at end of file

Status & tagging log