r64053 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64052‎ | r64053 | r64054 >
Date:01:33, 23 March 2010
Author:conrad
Status:deferred
Tags:
Comment:
Localise option names better, still needs work for booleans and list/rawlist
Modified paths:
  • /trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.magic.php (added) (history)
  • /trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.php (modified) (history)
  • /trunk/extensions/NaturalLanguageList/NaturalLanguageList.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.magic.php
@@ -0,0 +1,12 @@
 2+<?php
 3+
 4+$magicWords = array();
 5+
 6+$magicWords['en'] = array(
 7+ 'nll_blanks' => array( 0, 'blanks' ),
 8+ 'nll_duplicates' => array( 0, 'duplicates' ),
 9+ 'nll_itemcover' => array( 0, 'itemcover' ),
 10+ 'nll_fieldsperitem' => array( 0, 'itemsperitem', 'fieldsperitem' ),
 11+ 'nll_lastseparator' => array( 0, 'lastseparator' ),
 12+ 'nll_outputseparator' => array( 0, 'outputseparator', 'separator' ),
 13+);
Property changes on: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.magic.php
___________________________________________________________________
Added: svn:eol-style
114 + native
Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.php
@@ -1,4 +1,6 @@
22 <?php
 3+
 4+require_once( dirname(__FILE__) . '/NaturalLanguageList.i18n.magic.php' );
35 $messages['en'] = array (
46 'nll-itemcover' => '$1',
57 'nll-separator' => ', ',
Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.php
@@ -320,26 +320,18 @@
321321 }
322322 }
323323 # Still here? Then it must be an option
324 - switch ( trim( $var ) ) {
 324+ switch ( $name = self::parseOptionName( $var ) ) {
325325 case 'duplicates':
326 - $this->mOptions['duplicates'] = self::trueCheck ( $value );
327 - break;
328326 case 'blanks':
329 - $this->mOptions['blanks'] = self::trueCheck ( $value );
 327+ $this->mOptions[$name] = self::parseBoolean( $value );
330328 break;
331329 case 'outputseparator':
332 - case 'separator':
333 - $this->mOptions['outputseparator'] = self::trimString ( $value );
334 - break;
335330 case 'lastseparator':
336 - $this->mOptions['lastseparator'] = self::trimString ( $value );
337 - break;
338331 case 'itemcover':
339 - $this->mOptions['itemcover'] = self::trimString ( $value );
 332+ $this->mOptions[$name] = self::parseString( $value );
340333 break;
341334 case 'fieldsperitem':
342 - case 'itemsperitem':
343 - $this->mOptions['fieldsperitem'] = self::numeralCheck ( $value );
 335+ $this->mOptions[$name] = self::parseNumeral( $value );
344336 break;
345337 default:
346338 # Wasn't an option after all
@@ -347,22 +339,42 @@
348340 ? trim( $this->mFrame->expand( $arg ) )
349341 : $arg;
350342 }
 343+ return false;
351344 }
352345
353 - private static function numeralCheck ( $value, $default = 1 ) {
354 - if ( is_numeric ( $value ) && $value > 0 ) {
 346+ private static function parseOptionName( $value ) {
 347+
 348+ static $magicWords = null;
 349+ if ( $magicWords === null ) {
 350+ $magicWords = new MagicWordArray( array(
 351+ 'nll_blanks', 'nll_duplicates',
 352+ 'nll_fieldsperitem', 'nll_itemcover',
 353+ 'nll_lastseparator', 'nll_outputseparator'
 354+ ) );
 355+ }
 356+
 357+ if ( $name = $magicWords->matchStartToEnd( trim($value) ) ) {
 358+ return str_replace( 'nll_', '', $name );
 359+ }
 360+
 361+ return false;
 362+ }
 363+
 364+
 365+ private static function parseNumeral( $value, $default = 1 ) {
 366+ if ( is_numeric( $value ) && $value > 0 ) {
355367 return floor( $value ); # only integers
356368 }
357369 return $default;
358370 }
359371
360 - private static function trimString ( $value, $default = null ) {
 372+ private static function parseString( $value, $default = null ) {
361373 if ( $value !== '' )
362374 return $value;
363375 return $default;
364376 }
365377
366 - private static function trueCheck ( $value ) {
 378+ private static function parseBoolean( $value ) {
367379 return in_array( $value, array( 1, true, '1', 'true' ), true );
368380 }
369381 }

Status & tagging log