Index: trunk/extensions/ParserFunctions/Convert.php |
— | — | @@ -19,8 +19,11 @@ |
20 | 20 | const UNITS_REGEX = '/^(.+?)([a-z]+\^?\d?(?:\/\w+\^?\d?)*)$/i'; |
21 | 21 | |
22 | 22 | # A regex which matches a number |
23 | | - const NUM_REGEX = '/\b((?:\+|\-|−|\x2212)?(\d+(?:\.\d+)?)(?:E(?:\+|\-|−|\x2212)?\d+)?)\b/i'; |
| 23 | + const NUM_REGEX = '/\b((?:\+|\-|−|\x{2212})?(\d+(?:\.\d+)?)(?:E(?:\+|\-|−|\x{2212})?\d+)?)\b/iu'; |
24 | 24 | |
| 25 | + # A regex *FRAGMENT* which matches SI prefixes |
| 26 | + const PREFIX_REGEX = '[YZEPTGMkh(da)dcm\x{03BC}\x{00B5}npfazy]?'; |
| 27 | + |
25 | 28 | # ConvertUnit objects |
26 | 29 | protected $sourceUnit; |
27 | 30 | protected $targetUnit; |
— | — | @@ -464,138 +467,148 @@ |
465 | 468 | * DIMENSION => array( |
466 | 469 | * UNIT => array( |
467 | 470 | * CONVERSION, |
468 | | - * REGEX |
| 471 | + * REGEX, |
| 472 | + * TAKES_SI_PREFIXES, |
469 | 473 | * ) |
470 | 474 | * ) |
471 | 475 | * ) |
472 | 476 | */ |
473 | 477 | protected static $units = array( |
474 | 478 | ConvertDimension::DIM_LENGTH => array( |
475 | | - 'gigametre' => array( 1000000000, 'Gm' ), |
476 | | - 'megametre' => array( 1000000, 'Mm' ), # Case-sensitivity is forced |
477 | | - 'kilometre' => array( 1000, 'km' ), |
478 | | - 'hectometre' => array( 100, 'hm' ), |
479 | | - 'decametre' => array( 10, 'dam' ), |
480 | | - 'metre' => array( 1, 'm' ), |
481 | | - 'decimetre' => array( 0.1, 'dm' ), |
482 | | - 'centimetre' => array( 0.01, 'cm' ), |
483 | | - 'millimetre' => array( 0.001, 'mm' ), # Case-sensitivity is forced |
484 | | - 'micrometre' => array( 0.0001, '\x03BCm|\x00B5m|um' ), # There are two similar mu characters |
485 | | - 'nanometre' => array( 0.0000001, 'nm' ), |
486 | | - 'angstrom' => array( 0.00000001, '\x00C5' ), |
| 479 | + 'metre' => array( 1, 'm', true ), |
| 480 | + 'angstrom' => array( 0.00000001, '\x{00C5}', false ), |
487 | 481 | |
488 | | - 'mile' => array( 1609.344, 'mi|miles?' ), |
489 | | - 'furlong' => array( 201.168, 'furlong' ), |
490 | | - 'chain' => array( 20.1168 , 'chain' ), |
491 | | - 'rod' => array( 5.0292, 'rod|pole|perch' ), |
492 | | - 'fathom' => array( 1.8288, 'fathom' ), |
493 | | - 'yard' => array( 0.9144, 'yards?|yd' ), |
494 | | - 'foot' => array( 0.3048, 'foot|feet|ft' ), |
495 | | - 'hand' => array( 0.1016, 'hands?' ), |
496 | | - 'inch' => array( 0.0254, 'inch|inches|in' ), |
| 482 | + 'mile' => array( 1609.344, 'mi|miles?', false ), |
| 483 | + 'furlong' => array( 201.168, 'furlong', false ), |
| 484 | + 'chain' => array( 20.1168 , 'chain', false ), |
| 485 | + 'rod' => array( 5.0292, 'rod|pole|perch', false ), |
| 486 | + 'fathom' => array( 1.8288, 'fathom', false ), |
| 487 | + 'yard' => array( 0.9144, 'yards?|yd', false ), |
| 488 | + 'foot' => array( 0.3048, 'foot|feet|ft', false ), |
| 489 | + 'hand' => array( 0.1016, 'hands?', false ), |
| 490 | + 'inch' => array( 0.0254, 'inch|inches|in', false ), |
497 | 491 | |
498 | | - 'nauticalmile' => array( 1852, 'nauticalmiles?|nmi' ), |
499 | | - 'nauticalmileuk' => array( 1853.184, 'old[Uu][Kk]nmi|[Bb]rnmi|admi' ), |
500 | | - 'nauticalmileus' => array( 1853.24496, 'old[Uu][Ss]nmi' ), |
| 492 | + 'nauticalmile' => array( 1852, 'nauticalmiles?|nmi', false ), |
| 493 | + 'nauticalmileuk' => array( 1853.184, 'old[Uu][Kk]nmi|[Bb]rnmi|admi', false ), |
| 494 | + 'nauticalmileus' => array( 1853.24496, 'old[Uu][Ss]nmi', false ), |
501 | 495 | |
502 | | - 'gigaparsec' => array( 3.0856775813057E25, 'gigaparsecs?|Gpc' ), |
503 | | - 'megaparsec' => array( 3.0856775813057E22, 'megaparsecs?|Mpc' ), |
504 | | - 'kiloparsec' => array( 3.0856775813057E19, 'kiloparsecs?|kpc' ), |
505 | | - 'parsec' => array( 3.0856775813057E16, 'parsecs?|pc' ), |
506 | | - 'gigalightyear' => array( 9.4607304725808E24, 'gigalightyears?|Gly' ), |
507 | | - 'mrgalightyear' => array( 9.4607304725808E21, 'megalightyears?|Mly' ), |
508 | | - 'kilolightyear' => array( 9.4607304725808E18, 'kilolightyears?|kly' ), |
509 | | - 'lightyear' => array( 9.4607304725808E15, 'lightyears?|ly' ), |
510 | | - 'astronomicalunit' => array( 149597870700, 'astronomicalunits?|AU|au' ), |
| 496 | + 'parsec' => array( 3.0856775813057E16, 'parsecs?|pc', true ), |
| 497 | + 'lightyear' => array( 9.4607304725808E15, 'lightyears?|ly', true ), |
| 498 | + 'astronomicalunit' => array( 149597870700, 'astronomicalunits?|AU|au', false ), |
511 | 499 | ), |
512 | 500 | |
513 | 501 | ConvertDimension::DIM_AREA => array( |
514 | | - 'squarekilometre' => array( 1E6, 'km2|km\^2' ), |
515 | | - 'squaremetre' => array( 1, 'm2|m\^2' ), |
516 | | - 'squarecentimetre' => array( 1E-4, 'cm2|cm\^2' ), |
517 | | - 'squaremillimetre' => array( 1E-6, 'mm2|mm\^2' ), |
518 | | - 'hectare' => array( 1E4, 'hectares?|ha' ), |
| 502 | + 'squarekilometre' => array( 1E6, 'km2|km\^2', false ), |
| 503 | + 'squaremetre' => array( 1, 'm2|m\^2', false ), |
| 504 | + 'squarecentimetre' => array( 1E-4, 'cm2|cm\^2', false ), |
| 505 | + 'squaremillimetre' => array( 1E-6, 'mm2|mm\^2', false ), |
| 506 | + 'hectare' => array( 1E4, 'hectares?|ha', false ), |
519 | 507 | |
520 | | - 'squaremile' => array( 2589988.110336, 'sqmi|mi2|mi\^2' ), |
521 | | - 'acre' => array( 4046.856422 , 'acres?' ), |
522 | | - 'squareyard' => array( 0.83612736, 'sqyd|yd2|yd\^2' ), |
523 | | - 'squarefoot' => array( 0.09290304, 'sqft|ft2|ft\^2' ), |
524 | | - 'squareinch' => array( 0.00064516, 'sqin|in2|in\^2' ), |
| 508 | + 'squaremile' => array( 2589988.110336, 'sqmi|mi2|mi\^2', false ), |
| 509 | + 'acre' => array( 4046.856422, 'acres?', false ), |
| 510 | + 'squareyard' => array( 0.83612736, 'sqyd|yd2|yd\^2', false ), |
| 511 | + 'squarefoot' => array( 0.09290304, 'sqft|ft2|ft\^2', false ), |
| 512 | + 'squareinch' => array( 0.00064516, 'sqin|in2|in\^2', false ), |
525 | 513 | |
526 | | - 'squarenauticalmile' => array( 3429904, 'sqnmi|nmi2|nmi\^2' ), |
527 | | - 'dunam' => array( 1000, 'dunam' ), |
528 | | - 'tsubo' => array( 3.305785, 'tsubo' ), |
| 514 | + 'squarenauticalmile' => array( 3429904, 'sqnmi|nmi2|nmi\^2', false ), |
| 515 | + 'dunam' => array( 1000, 'dunam', false ), |
| 516 | + 'tsubo' => array( 3.305785, 'tsubo', false ), |
529 | 517 | ), |
530 | 518 | |
531 | 519 | ConvertDimension::DIM_VOLUME => array( |
532 | | - 'cubicmetre' => array( 1, 'm3|m\^3' ), |
533 | | - 'cubiccentimetre' => array( 1E-6, 'cm3|cm\^3' ), |
534 | | - 'cubicmillimetre' => array( 1E-9, 'mm3|mm\^3' ), |
535 | | - 'kilolitre' => array( 1, 'kl' ), |
536 | | - 'litre' => array( 1E-3 , 'l' ), |
537 | | - 'centilitre' => array( 1E-5, 'cl' ), |
538 | | - 'millilitre' => array( 1E-6, 'ml' ), |
| 520 | + 'cubicmetre' => array( 1, 'm3|m\^3', false ), |
| 521 | + 'cubiccentimetre' => array( 1E-6, 'cm3|cm\^3', false ), |
| 522 | + 'cubicmillimetre' => array( 1E-9, 'mm3|mm\^3', false ), |
| 523 | + 'litre' => array( 1E-3 , 'l', true ), |
539 | 524 | |
540 | | - 'cubicyard' => array( 0.764554857984, 'cuyd|yd3|yd\^3' ), |
541 | | - 'cubicfoot' => array( 0.028316846592, 'cuft|ft3|ft\^3' ), |
542 | | - 'cubicinch' => array( 0.000016387064, 'cuin|in3|in\^3' ), |
543 | | - 'barrel' => array( 0.16365924, 'bbl|barrels?|impbbl' ), |
544 | | - 'bushel' => array( 0.03636872, 'bsh|bushels?|impbsh' ), |
545 | | - 'gallon' => array( 0.00454609, 'gal|gallons?|impgal' ), |
546 | | - 'quart' => array( 0.0011365225, 'qt|quarts?|impqt' ), |
547 | | - 'pint' => array( 0.00056826125, 'pt|pints?|imppt' ), |
548 | | - 'fluidounce' => array( 0.0000284130625, 'floz|impfloz' ), |
| 525 | + 'cubicyard' => array( 0.764554857984, 'cuyd|yd3|yd\^3', false ), |
| 526 | + 'cubicfoot' => array( 0.028316846592, 'cuft|ft3|ft\^3', false ), |
| 527 | + 'cubicinch' => array( 0.000016387064, 'cuin|in3|in\^3', false ), |
| 528 | + 'barrel' => array( 0.16365924, 'bbl|barrels?|impbbl', false ), |
| 529 | + 'bushel' => array( 0.03636872, 'bsh|bushels?|impbsh', false ), |
| 530 | + 'gallon' => array( 0.00454609, 'gal|gallons?|impgal', false ), |
| 531 | + 'quart' => array( 0.0011365225, 'qt|quarts?|impqt', false ), |
| 532 | + 'pint' => array( 0.00056826125, 'pt|pints?|imppt', false ), |
| 533 | + 'fluidounce' => array( 0.0000284130625, 'floz|impfloz', false ), |
549 | 534 | |
550 | | - 'barrelus' => array( 0.119240471196, 'usbbl' ), |
551 | | - 'barreloil' => array( 0.158987294928, 'oilbbl' ), |
552 | | - 'barrelbeer' => array( 0.117347765304, 'beerbbl' ), |
553 | | - 'usgallon' => array( 0.003785411784, 'usgal' ), |
554 | | - 'usquart' => array( 0.000946352946, 'usqt' ), |
555 | | - 'uspint' => array( 0.000473176473, 'uspt' ), |
556 | | - 'usfluidounce' => array( 0.0000295735295625, 'usfloz' ), |
557 | | - 'usdrybarrel' => array( 0.11562819898508, 'usdrybbl' ), |
558 | | - 'usbushel' => array( 0.03523907016688, 'usbsh' ), |
559 | | - 'usdrygallon' => array( 0.00440488377086, 'usdrygal' ), |
560 | | - 'usdryquart' => array( 0.001101220942715, 'usdryqt' ), |
561 | | - 'usdrypint' => array( 0.0005506104713575, 'usdrypt' ), |
| 535 | + 'barrelus' => array( 0.119240471196, 'usbbl', false ), |
| 536 | + 'barreloil' => array( 0.158987294928, 'oilbbl', false ), |
| 537 | + 'barrelbeer' => array( 0.117347765304, 'beerbbl', false ), |
| 538 | + 'usgallon' => array( 0.003785411784, 'usgal', false ), |
| 539 | + 'usquart' => array( 0.000946352946, 'usqt', false ), |
| 540 | + 'uspint' => array( 0.000473176473, 'uspt', false ), |
| 541 | + 'usfluidounce' => array( 0.0000295735295625, 'usfloz', false ), |
| 542 | + 'usdrybarrel' => array( 0.11562819898508, 'usdrybbl', false ), |
| 543 | + 'usbushel' => array( 0.03523907016688, 'usbsh', false ), |
| 544 | + 'usdrygallon' => array( 0.00440488377086, 'usdrygal', false ), |
| 545 | + 'usdryquart' => array( 0.001101220942715, 'usdryqt', false ), |
| 546 | + 'usdrypint' => array( 0.0005506104713575, 'usdrypt', false ), |
562 | 547 | ), |
563 | 548 | |
564 | 549 | ConvertDimension::DIM_TIME => array( |
565 | | - 'year' => array( 31557600, 'yr' ), |
566 | | - 'day' => array( 86400, 'days?' ), |
567 | | - 'hour' => array( 3600, 'hours?|hr|h' ), |
568 | | - 'minute' => array( 60, 'minutes?|mins?' ), |
569 | | - 'second' => array( 1, 's' ), |
| 550 | + 'year' => array( 31557600, 'yr', true ), |
| 551 | + 'day' => array( 86400, 'd|days?', false ), |
| 552 | + 'hour' => array( 3600, 'hours?|hr|h', false ), |
| 553 | + 'minute' => array( 60, 'minutes?|mins?', false ), |
| 554 | + 'second' => array( 1, 's', false ), |
570 | 555 | ), |
571 | 556 | |
572 | 557 | ConvertDimension::DIM_SPEED => array( |
573 | | - 'knot' => array( 0.514444444, 'knot|kn' ), |
574 | | - 'speedoflight' => array( 2.9979E8, 'c' ), |
| 558 | + 'knot' => array( 0.514444444, 'knot|kn', false ), |
| 559 | + 'speedoflight' => array( 2.9979E8, 'c', false ), |
575 | 560 | ), |
576 | 561 | |
577 | 562 | ConvertDimension::DIM_PRESSURE => array( |
578 | | - 'gigapascal' => array( 1000000000, 'GPa' ), |
579 | | - 'megapascal' => array( 1000000, 'MPa' ), # Case-sensitivity is forced |
580 | | - 'kilopascal' => array( 1000, 'kPa' ), |
581 | | - 'hectopascal' => array( 100, 'hPa' ), |
582 | | - 'pascal' => array( 1, 'Pa' ), |
583 | | - 'millipascal' => array( 0.001, 'mPa' ), # Case-sensitivity is forced |
| 563 | + 'pascal' => array( 1, 'Pa', true ), |
584 | 564 | |
585 | | - 'bar' => array( 100000, 'bar' ), |
586 | | - 'decibar' => array( 10000, 'dbar' ), |
587 | | - 'milibar' => array( 100 , 'mbar|mb' ), |
588 | | - 'kilobarye' => array( 100, 'kba' ), |
589 | | - 'barye' => array( 0.1, 'ba' ), |
| 565 | + 'bar' => array( 100000, 'bar', false ), |
| 566 | + 'decibar' => array( 10000, 'dbar', false ), |
| 567 | + 'milibar' => array( 100 , 'mbar|mb', false ), |
| 568 | + 'kilobarye' => array( 100, 'kba', false ), |
| 569 | + 'barye' => array( 0.1, 'ba', false ), |
590 | 570 | |
591 | | - 'atmosphere' => array( 101325, 'atm|atmospheres?' ), |
592 | | - 'torr' => array( 133.32237, 'torr' ), |
593 | | - 'mmhg' => array( 133.322387415, 'mmHg' ), |
594 | | - 'inhg' => array( 3386.38864034, 'inHg' ), |
595 | | - 'psi' => array( 6894.757293, 'psi' ), |
| 571 | + 'atmosphere' => array( 101325, 'atm|atmospheres?', false ), |
| 572 | + 'torr' => array( 133.32237, 'torr', false ), |
| 573 | + 'mmhg' => array( 133.322387415, 'mmHg', false ), |
| 574 | + 'inhg' => array( 3386.38864034, 'inHg', false ), |
| 575 | + 'psi' => array( 6894.757293, 'psi', false ), |
596 | 576 | ), |
597 | 577 | # TODO: other dimensions as needed |
598 | 578 | ); |
599 | 579 | |
| 580 | + /** |
| 581 | + * array( |
| 582 | + * PREFIX => array( |
| 583 | + * CONVERSION, |
| 584 | + * REGEX, |
| 585 | + * ) |
| 586 | + * ) |
| 587 | + * They're out of order because this is the order in which they are tested, and |
| 588 | + * some prefixes are much more likely to occur than others |
| 589 | + */ |
| 590 | + protected static $prefixes = array( |
| 591 | + 'kilo' => array( 1E3, 'k' ), |
| 592 | + 'mili' => array( 1E-3, 'm' ), |
| 593 | + 'centi' => array( 1E-2, 'c' ), |
| 594 | + 'giga' => array( 1E9, 'G' ), |
| 595 | + 'micro' => array( 1E-6, '(?:\x{03BC}|\x{00B5})' ), # There are two similar mu characters |
| 596 | + 'mega' => array( 1E6, 'M' ), |
| 597 | + 'nano' => array( 1E-9, 'n' ), |
| 598 | + 'hecto' => array( 1E2, 'h' ), |
| 599 | + 'deca' => array( 1E1, 'da' ), |
| 600 | + 'deci' => array( 1E-1, 'd' ), |
| 601 | + 'yotta' => array( 1E24, 'Y' ), |
| 602 | + 'zetta' => array( 1E21, 'Z' ), |
| 603 | + 'exa' => array( 1E18, 'E' ), |
| 604 | + 'peta' => array( 1E15, 'P' ), |
| 605 | + 'tera' => array( 1E12, 'T' ), |
| 606 | + 'pico' => array( 1E-12, 'p' ), |
| 607 | + 'femto' => array( 1E-15, 'f' ), |
| 608 | + 'atto' => array( 1E-18, 'a' ), |
| 609 | + 'zepto' => array( 1E-21, 'z' ), |
| 610 | + 'yocto' => array( 1E-24, 'y' ), |
| 611 | + ); |
| 612 | + |
600 | 613 | # Default units for each dimension |
601 | 614 | # TODO: this should ideally be localisable |
602 | 615 | protected static $defaultUnit = array( |
— | — | @@ -630,6 +643,9 @@ |
631 | 644 | # The name of the unit (key into $units[$dimension] above |
632 | 645 | protected $unitName; |
633 | 646 | |
| 647 | + # The SI prefix, if applicable |
| 648 | + protected $prefix = null; |
| 649 | + |
634 | 650 | /***************** MEMBER FUNCTIONS *****************/ |
635 | 651 | |
636 | 652 | /** |
— | — | @@ -664,11 +680,25 @@ |
665 | 681 | # Single unit |
666 | 682 | foreach( self::$units as $dimension => $units ){ |
667 | 683 | foreach( $units as $unit => $data ){ |
668 | | - if( $rawUnit == $unit || preg_match( "/^({$data[1]})$/u", $parts[0] ) ){ |
| 684 | + if( $rawUnit == $unit |
| 685 | + || ( !$data[2] && preg_match( "/^({$data[1]})$/u", $parts[0] ) ) |
| 686 | + || ( $data[2] && preg_match( "/^(" . ConvertParser::PREFIX_REGEX . ")(" . $data[1] . ")$/u", $parts[0] ) ) ) |
| 687 | + { |
669 | 688 | $this->dimension = new ConvertDimension( self::$dimensionMap[$unit] ); |
670 | | - $this->conversion = self::$units[$this->dimension->value][$unit][0]; |
| 689 | + $this->conversion = $data[0]; |
671 | 690 | $this->regex = $data[1]; |
672 | 691 | $this->unitName = $unit; |
| 692 | + |
| 693 | + # Grab the SI prefix, if it's allowed and there is one |
| 694 | + if( $data[2] && !preg_match( "/^({$data[1]})$/u", $parts[0] ) ){ |
| 695 | + foreach( self::$prefixes as $prefix => $pdata ){ |
| 696 | + if( preg_match( "/^({$pdata[1]})({$data[1]})$/u", $parts[0] ) ){ |
| 697 | + $this->prefix = $prefix; |
| 698 | + break; |
| 699 | + } |
| 700 | + } |
| 701 | + } |
| 702 | + |
673 | 703 | return; |
674 | 704 | } |
675 | 705 | } |
— | — | @@ -685,6 +715,7 @@ |
686 | 716 | $this->conversion = $top->conversion / $bottom->conversion; |
687 | 717 | $this->regex = "(?:{$top->regex})/(?:{$bottom->regex})"; |
688 | 718 | $this->unitName = array( $top->unitName, $bottom->unitName ); |
| 719 | + $this->prefix = array( $top->prefix, $bottom->prefix ); |
689 | 720 | return; |
690 | 721 | |
691 | 722 | } else { |
— | — | @@ -694,7 +725,9 @@ |
695 | 726 | } |
696 | 727 | |
697 | 728 | public function getConversion(){ |
698 | | - return $this->conversion; |
| 729 | + return $this->prefix |
| 730 | + ? $this->conversion * self::$prefixes[$this->prefix][0] |
| 731 | + : $this->conversion; |
699 | 732 | } |
700 | 733 | |
701 | 734 | public function getRegex(){ |
— | — | @@ -714,7 +747,9 @@ |
715 | 748 | |
716 | 749 | if( !is_array( $this->unitName ) ){ |
717 | 750 | $msgText = $this->getTextFromMessage( |
718 | | - "pfunc-convert-unit-{$this->dimension->getName()}-{$this->unitName}", |
| 751 | + $this->dimension->getName(), |
| 752 | + $this->unitName, |
| 753 | + $this->prefix, |
719 | 754 | $value, $link, $abbreviate, $language |
720 | 755 | ); |
721 | 756 | |
— | — | @@ -723,18 +758,24 @@ |
724 | 759 | # so they can have it display "<metres per second>" rather than |
725 | 760 | # "<metres>/<second>" |
726 | 761 | $msgText = $this->getTextFromMessage( |
727 | | - "pfunc-convert-unit-{$this->dimension->getName(true)}-{$this->unitName[0]}-{$this->unitName[1]}", |
| 762 | + $this->dimension->getName(true), |
| 763 | + "{$this->unitName[0]}-{$this->unitName[1]}", |
| 764 | + $this->prefix, # This will probably be rubbish, but it's the wiki users' problem, not ours |
728 | 765 | $value, $link, $abbreviate, $language |
729 | 766 | ); |
730 | 767 | |
731 | 768 | } else { |
732 | 769 | $dimensionNames = $this->dimension->getName(); |
733 | 770 | $msgText = $this->getTextFromMessage( |
734 | | - "pfunc-convert-unit-{$dimensionNames[0]}-{$this->unitName[0]}", |
| 771 | + $dimensionNames[0], |
| 772 | + $this->unitName[0], |
| 773 | + $this->prefix[0], |
735 | 774 | $value, $link, $abbreviate, $language |
736 | 775 | ); |
737 | 776 | $msg2Text = $this->getTextFromMessage( |
738 | | - "pfunc-convert-unit-{$dimensionNames[1]}-{$this->unitName[1]}", |
| 777 | + $dimensionNames[1], |
| 778 | + $this->unitName[1], |
| 779 | + $this->prefix[1], |
739 | 780 | 1, # Singular for denominator |
740 | 781 | $link, $abbreviate, $language |
741 | 782 | ); |
— | — | @@ -744,17 +785,24 @@ |
745 | 786 | return trim( $msgText ); |
746 | 787 | } |
747 | 788 | |
748 | | - protected function getTextFromMessage( $key, $number, $link, $abbreviate, $language ){ |
| 789 | + protected function getTextFromMessage( $dimension, $unit, $prefix, $number, $link, $abbreviate, $language ){ |
749 | 790 | $abbr = $abbreviate ? '-abbr' : ''; |
| 791 | + $prefix = $prefix === null |
| 792 | + ? '' |
| 793 | + : wfMsgExt( "pfunc-convert-prefix-$prefix$abbr", array( 'parsemag', 'language' => $language ) ); |
750 | 794 | |
751 | 795 | $text = wfMsgExt( |
752 | | - "$key$abbr", |
| 796 | + "pfunc-convert-unit-$dimension-$unit$abbr", |
753 | 797 | array( 'parsemag', 'language' => $language ), |
754 | | - $number |
| 798 | + $number, |
| 799 | + $prefix |
755 | 800 | ); |
756 | 801 | |
757 | | - if( $link && !wfEmptyMsg( "$key-link" ) ){ |
758 | | - $title = Title::newFromText( wfMsgForContentNoTrans( "$key-link" ) ); |
| 802 | + if( $link && !wfEmptyMsg( "pfunc-convert-unit-$dimension-$unit-link" ) ){ |
| 803 | + $title = Title::newFromText( |
| 804 | + wfMsgForContentNoTrans( "pfunc-convert-unit-$dimension-$unit-link" ), |
| 805 | + $prefix |
| 806 | + ); |
759 | 807 | if( $title instanceof Title ){ |
760 | 808 | $text = "[[{$title->getFullText()}|$text]]"; |
761 | 809 | } |
Index: trunk/extensions/ParserFunctions/ParserFunctions.i18n.php |
— | — | @@ -54,18 +54,52 @@ |
55 | 55 | 'pfunc-convert-dimension-fuelefficiencypositive' => 'fuelefficiencypositive', |
56 | 56 | 'pfunc-convert-dimension-fuelefficiencynegative' => 'fuelefficiencynegative', |
57 | 57 | |
| 58 | + # SI PREFIXES |
| 59 | + |
| 60 | + 'pfunc-convert-prefix-yotta' => 'yotta', |
| 61 | + 'pfunc-convert-prefix-zetta' => 'zetta', |
| 62 | + 'pfunc-convert-prefix-exa' => 'exa', |
| 63 | + 'pfunc-convert-prefix-peta' => 'peta', |
| 64 | + 'pfunc-convert-prefix-tera' => 'tera', |
| 65 | + 'pfunc-convert-prefix-giga' => 'giga', |
| 66 | + 'pfunc-convert-prefix-mega' => 'mega', |
| 67 | + 'pfunc-convert-prefix-kilo' => 'kilo', |
| 68 | + 'pfunc-convert-prefix-hecto' => 'hecto', |
| 69 | + 'pfunc-convert-prefix-deca' => 'deca', |
| 70 | + 'pfunc-convert-prefix-deci' => 'deci', |
| 71 | + 'pfunc-convert-prefix-centi' => 'centi', |
| 72 | + 'pfunc-convert-prefix-mili' => 'mili', |
| 73 | + 'pfunc-convert-prefix-micro' => 'micro', |
| 74 | + 'pfunc-convert-prefix-nano' => 'nano', |
| 75 | + 'pfunc-convert-prefix-pico' => 'pico', |
| 76 | + 'pfunc-convert-prefix-femto' => 'femto', |
| 77 | + 'pfunc-convert-prefix-atto' => 'atto', |
| 78 | + 'pfunc-convert-prefix-zepto' => 'zepto', |
| 79 | + 'pfunc-convert-prefix-yocto' => 'yocto', |
| 80 | + |
| 81 | + 'pfunc-convert-prefix-yotta-abbr' => 'Y', |
| 82 | + 'pfunc-convert-prefix-zetta-abbr' => 'Z', |
| 83 | + 'pfunc-convert-prefix-exa-abbr' => 'E', |
| 84 | + 'pfunc-convert-prefix-peta-abbr' => 'P', |
| 85 | + 'pfunc-convert-prefix-tera-abbr' => 'T', |
| 86 | + 'pfunc-convert-prefix-giga-abbr' => 'G', |
| 87 | + 'pfunc-convert-prefix-mega-abbr' => 'M', |
| 88 | + 'pfunc-convert-prefix-kilo-abbr' => 'k', |
| 89 | + 'pfunc-convert-prefix-hecto-abbr' => 'h', |
| 90 | + 'pfunc-convert-prefix-deca-abbr' => 'da', |
| 91 | + 'pfunc-convert-prefix-deci-abbr' => 'd', |
| 92 | + 'pfunc-convert-prefix-centi-abbr' => 'c', |
| 93 | + 'pfunc-convert-prefix-mili-abbr' => 'm', |
| 94 | + 'pfunc-convert-prefix-micro-abbr' => 'μ', |
| 95 | + 'pfunc-convert-prefix-nano-abbr' => 'n', |
| 96 | + 'pfunc-convert-prefix-pico-abbr' => 'p', |
| 97 | + 'pfunc-convert-prefix-femto-abbr' => 'f', |
| 98 | + 'pfunc-convert-prefix-atto-abbr' => 'a', |
| 99 | + 'pfunc-convert-prefix-zepto-abbr' => 'z', |
| 100 | + 'pfunc-convert-prefix-yocto-abbr' => 'y', |
| 101 | + |
58 | 102 | # LENGTH |
59 | | - 'pfunc-convert-unit-length-gigametre' => '{{PLURAL:$1|gigameter|gigameters}}', |
60 | | - 'pfunc-convert-unit-length-megametre' => '{{PLURAL:$1|megameter|megameters}}', |
61 | | - 'pfunc-convert-unit-length-kilometre' => '{{PLURAL:$1|kilometer|kilometers}}', |
62 | | - 'pfunc-convert-unit-length-hectometre' => '{{PLURAL:$1|hectometer|hectometers}}', |
63 | | - 'pfunc-convert-unit-length-decametre' => '{{PLURAL:$1|decameter|decameters}}', |
64 | | - 'pfunc-convert-unit-length-metre' => '{{PLURAL:$1|meter|meters}}', |
65 | | - 'pfunc-convert-unit-length-decimetre' => '{{PLURAL:$1|decimeter|decimeters}}', |
66 | | - 'pfunc-convert-unit-length-centimetre' => '{{PLURAL:$1|centimeter|centimeters}}', |
67 | | - 'pfunc-convert-unit-length-millimetre' => '{{PLURAL:$1|millimeter|millimeters}}', |
68 | | - 'pfunc-convert-unit-length-micrometre' => '{{PLURAL:$1|micrometer|micrometers}}', |
69 | | - 'pfunc-convert-unit-length-nanometre' => '{{PLURAL:$1|nanometer|nanometers}}', |
| 103 | + 'pfunc-convert-unit-length-metre' => '{{PLURAL:$1|$2meter|$2meters}}', |
70 | 104 | 'pfunc-convert-unit-length-angstrom' => '{{PLURAL:$1|angstrom|angstroms}}', |
71 | 105 | 'pfunc-convert-unit-length-mile' => '{{PLURAL:$1|mile|miles}}', |
72 | 106 | 'pfunc-convert-unit-length-furlong' => '{{PLURAL:$1|furlong|furlongs}}', |
— | — | @@ -79,27 +113,11 @@ |
80 | 114 | 'pfunc-convert-unit-length-nauticalmile' => '{{PLURAL:$1|nautical mile|nautical miles}}', |
81 | 115 | 'pfunc-convert-unit-length-nauticalmileuk' => '{{PLURAL:$1|nautical mile (pre-1970 British)|nautical miles (pre-1970 British)}}', |
82 | 116 | 'pfunc-convert-unit-length-nauticalmileus' => '{{PLURAL:$1|nautical mile (pre-1954 US)|nautical miles (pre-1954 US)}}', |
83 | | - 'pfunc-convert-unit-length-gigaparsec' => '{{PLURAL:$1|gigaparsec|gigaparsecs}}', |
84 | | - 'pfunc-convert-unit-length-megaparsec' => '{{PLURAL:$1|megaparsec|megaparsecs}}', |
85 | | - 'pfunc-convert-unit-length-kiloparsec' => '{{PLURAL:$1|kiloparsec|kiloparsecs}}', |
86 | | - 'pfunc-convert-unit-length-parsec' => '{{PLURAL:$1|parsec|parsecs}}', |
87 | | - 'pfunc-convert-unit-length-gigalightyear' => '{{PLURAL:$1|gigalightyear|gigalightyears}}', |
88 | | - 'pfunc-convert-unit-length-mrgalightyear' => '{{PLURAL:$1|megalightyear|megalightyears}}', |
89 | | - 'pfunc-convert-unit-length-kilolightyear' => '{{PLURAL:$1|kilolightyear|kilolightyears}}', |
90 | | - 'pfunc-convert-unit-length-lightyear' => '{{PLURAL:$1|lightyear|lightyears}}', |
| 117 | + 'pfunc-convert-unit-length-parsec' => '{{PLURAL:$1|$2parsec|$2parsecs}}', |
| 118 | + 'pfunc-convert-unit-length-lightyear' => '{{PLURAL:$1|$2lightyear|$2lightyears}}', |
91 | 119 | 'pfunc-convert-unit-length-astronomicalunit' => '{{PLURAL:$1|astronomical unit|astronomical units}}', |
92 | 120 | |
93 | | - 'pfunc-convert-unit-length-gigametre-abbr' => 'Gm', |
94 | | - 'pfunc-convert-unit-length-megametre-abbr' => 'Mm', |
95 | | - 'pfunc-convert-unit-length-kilometre-abbr' => 'km', |
96 | | - 'pfunc-convert-unit-length-hectometre-abbr' => 'hm', |
97 | | - 'pfunc-convert-unit-length-decametre-abbr' => 'dam', |
98 | | - 'pfunc-convert-unit-length-metre-abbr' => 'm', |
99 | | - 'pfunc-convert-unit-length-decimetre-abbr' => 'dm', |
100 | | - 'pfunc-convert-unit-length-centimetre-abbr' => 'cm', |
101 | | - 'pfunc-convert-unit-length-milimetre-abbr' => 'mm', |
102 | | - 'pfunc-convert-unit-length-micrometre-abbr' => 'μm', |
103 | | - 'pfunc-convert-unit-length-nanometre-abbr' => 'nm', |
| 121 | + 'pfunc-convert-unit-length-metre-abbr' => '$2m', |
104 | 122 | 'pfunc-convert-unit-length-angstrom-abbr' => 'Å', |
105 | 123 | 'pfunc-convert-unit-length-mile-abbr' => 'mi', |
106 | 124 | 'pfunc-convert-unit-length-furlong-abbr' => 'furlong', |
— | — | @@ -113,14 +131,8 @@ |
114 | 132 | 'pfunc-convert-unit-length-nauticalmile-abbr' => 'nmi', |
115 | 133 | 'pfunc-convert-unit-length-nauticalmileuk-abbr' => 'nmi (Brit)', |
116 | 134 | 'pfunc-convert-unit-length-nauticalmileus-abbr' => 'nmi (pre-1954 US)', |
117 | | - 'pfunc-convert-unit-length-gigaparsec-abbr' => 'Gpc', |
118 | | - 'pfunc-convert-unit-length-megaparsec-abbr' => 'Mpc', |
119 | | - 'pfunc-convert-unit-length-kiloparsec-abbr' => 'kpc', |
120 | | - 'pfunc-convert-unit-length-parsec-abbr' => 'pc', |
121 | | - 'pfunc-convert-unit-length-gigalightyear-abbr' => 'Gly', |
122 | | - 'pfunc-convert-unit-length-mrgalightyear-abbr' => 'Mly', |
123 | | - 'pfunc-convert-unit-length-kilolightyear-abbr' => 'kly', |
124 | | - 'pfunc-convert-unit-length-lightyear-abbr' => 'ly', |
| 135 | + 'pfunc-convert-unit-length-parsec-abbr' => '$2pc', |
| 136 | + 'pfunc-convert-unit-length-lightyear-abbr' => '$2ly', |
125 | 137 | 'pfunc-convert-unit-length-astronomicalunit-abbr' => 'AU', |
126 | 138 | |
127 | 139 | # AREA # |
— | — | @@ -154,13 +166,13 @@ |
155 | 167 | |
156 | 168 | # TIME # |
157 | 169 | 'pfunc-convert-unit-time-second' => '{{PLURAL:$1|second|seconds}}', |
158 | | - 'pfunc-convert-unit-time-year' => '{{PLURAL:$1|year|years}}', |
| 170 | + 'pfunc-convert-unit-time-year' => '{{PLURAL:$1|$2year|$2years}}', |
159 | 171 | 'pfunc-convert-unit-time-day' => '{{PLURAL:$1|day|days}}', |
160 | 172 | 'pfunc-convert-unit-time-hour' => '{{PLURAL:$1|hour|hours}}', |
161 | 173 | 'pfunc-convert-unit-time-minute' => '{{PLURAL:$1|minute|minutes}}', |
162 | 174 | |
163 | 175 | 'pfunc-convert-unit-time-second-abbr' => 's', |
164 | | - 'pfunc-convert-unit-time-year-abbr' => 'yr', |
| 176 | + 'pfunc-convert-unit-time-year-abbr' => '$2yr', |
165 | 177 | 'pfunc-convert-unit-time-day-abbr' => 'day', |
166 | 178 | 'pfunc-convert-unit-time-hour-abbr' => 'hr', |
167 | 179 | 'pfunc-convert-unit-time-minute-abbr' => 'min', |
— | — | @@ -198,10 +210,7 @@ |
199 | 211 | 'pfunc-convert-unit-volume-cubicmetre-abbr' => 'm<sup>3</sup>', |
200 | 212 | 'pfunc-convert-unit-volume-cubiccentimetre-abbr' => 'cm<sup>3</sup>', |
201 | 213 | 'pfunc-convert-unit-volume-cubicmillimetre-abbr' => 'mm<sup>3</sup>', |
202 | | - 'pfunc-convert-unit-volume-kilolitre-abbr' => 'kl', |
203 | | - 'pfunc-convert-unit-volume-litre-abbr' => 'l', |
204 | | - 'pfunc-convert-unit-volume-centilitre-abbr' => 'cl', |
205 | | - 'pfunc-convert-unit-volume-millilitre-abbr' => 'ml', |
| 214 | + 'pfunc-convert-unit-volume-litre-abbr' => '$2l', |
206 | 215 | 'pfunc-convert-unit-volume-cubicyard-abbr' => 'cu yd', |
207 | 216 | 'pfunc-convert-unit-volume-cubicfoot-abbr' => 'cu ft', |
208 | 217 | 'pfunc-convert-unit-volume-cubicinch-abbr' => 'cu in', |
— | — | @@ -232,12 +241,7 @@ |
233 | 242 | 'pfunc-convert-unit-speed-speedoflight-abbr' => 'c', |
234 | 243 | |
235 | 244 | # PRESSURE |
236 | | - 'pfunc-convert-unit-pressure-gigapascal' => '{{PLURAL:$1|gigapascal|gigapascals}}', |
237 | | - 'pfunc-convert-unit-pressure-megapascal' => '{{PLURAL:$1|megapascal|megapascals}}', |
238 | | - 'pfunc-convert-unit-pressure-kilopascal' => '{{PLURAL:$1|kilopascal|kilopascals}}', |
239 | | - 'pfunc-convert-unit-pressure-hectopascal' => '{{PLURAL:$1|hectopascal|hectopascals}}', |
240 | | - 'pfunc-convert-unit-pressure-pascal' => '{{PLURAL:$1|pascal|pascals}}', |
241 | | - 'pfunc-convert-unit-pressure-millipascal' => '{{PLURAL:$1|millipascal|millipascals}}', |
| 245 | + 'pfunc-convert-unit-pressure-pascal' => '{{PLURAL:$1|$2pascal|$2pascals}}', |
242 | 246 | 'pfunc-convert-unit-pressure-bar' => 'bar', |
243 | 247 | 'pfunc-convert-unit-pressure-decibar' => 'decibar', |
244 | 248 | 'pfunc-convert-unit-pressure-millibar' => 'millibar', |
— | — | @@ -248,13 +252,8 @@ |
249 | 253 | 'pfunc-convert-unit-pressure-mmhg' => '{{PLURAL:$1|milimeter of mercury|milimeters of mercury}}', |
250 | 254 | 'pfunc-convert-unit-pressure-inhg' => '{{PLURAL:$1|inch of mercury|inches of mercury}}', |
251 | 255 | 'pfunc-convert-unit-pressure-psi' => '{{PLURAL:$1|pound per square-inch|pounds per square-inch}}', |
252 | | - |
253 | | - 'pfunc-convert-unit-pressure-gigapascal-abbr' => 'GPa', |
254 | | - 'pfunc-convert-unit-pressure-megapascal-abbr' => 'MPa', |
255 | | - 'pfunc-convert-unit-pressure-kilopascal-abbr' => 'kPa', |
256 | | - 'pfunc-convert-unit-pressure-hectopascal-abbr' => 'hPa', |
257 | | - 'pfunc-convert-unit-pressure-pascal-abbr' => 'Pa', |
258 | | - 'pfunc-convert-unit-pressure-millipascal-abbr' => 'mPa', |
| 256 | + |
| 257 | + 'pfunc-convert-unit-pressure-pascal-abbr' => '$2Pa', |
259 | 258 | 'pfunc-convert-unit-pressure-bar-abbr' => 'bar', |
260 | 259 | 'pfunc-convert-unit-pressure-decibar-abbr' => 'dbar', |
261 | 260 | 'pfunc-convert-unit-pressure-milibar-abbr' => 'mbar', |
— | — | @@ -817,17 +816,7 @@ |
818 | 817 | */ |
819 | 818 | $messages['en-gb'] = array( |
820 | 819 | # LENGTH |
821 | | - 'pfunc-convert-unit-length-gigametre' => '{{PLURAL:$1|gigametre|gigametres}}', |
822 | | - 'pfunc-convert-unit-length-megametre' => '{{PLURAL:$1|megametre|megametres}}', |
823 | | - 'pfunc-convert-unit-length-kilometre' => '{{PLURAL:$1|kilometre|kilometres}}', |
824 | | - 'pfunc-convert-unit-length-hectometre' => '{{PLURAL:$1|hectometre|hectometres}}', |
825 | | - 'pfunc-convert-unit-length-decametre' => '{{PLURAL:$1|decametre|decametres}}', |
826 | | - 'pfunc-convert-unit-length-metre' => '{{PLURAL:$1|metre|metres}}', |
827 | | - 'pfunc-convert-unit-length-decimetre' => '{{PLURAL:$1|decimetre|decimetres}}', |
828 | | - 'pfunc-convert-unit-length-centimetre' => '{{PLURAL:$1|centimetre|centimetres}}', |
829 | | - 'pfunc-convert-unit-length-millimetre' => '{{PLURAL:$1|millimetre|millimetres}}', |
830 | | - 'pfunc-convert-unit-length-micrometre' => '{{PLURAL:$1|micrometre|micrometres}}', |
831 | | - 'pfunc-convert-unit-length-nanometre' => '{{PLURAL:$1|nanometre|nanometres}}', |
| 820 | + 'pfunc-convert-unit-length-metre' => '{{PLURAL:$1|$2metre|$2metres}}', |
832 | 821 | |
833 | 822 | # AREA # |
834 | 823 | 'pfunc-convert-unit-area-squarekilometre' => '{{PLURAL:$1|square kilometre|square kilometres}}', |
— | — | @@ -839,10 +828,7 @@ |
840 | 829 | 'pfunc-convert-unit-volume-cubicmetre' => '{{PLURAL:$1|cubic metre|cubic metres}}', |
841 | 830 | 'pfunc-convert-unit-volume-cubiccentimetre' => '{{PLURAL:$1|cubic centimetre|cubic centimetres}}', |
842 | 831 | 'pfunc-convert-unit-volume-cubicmillimetre' => '{{PLURAL:$1|cubic millimetre|cubic millimetres}}', |
843 | | - 'pfunc-convert-unit-volume-kilolitre' => '{{PLURAL:$1|kilolitre|kilolitres}}', |
844 | | - 'pfunc-convert-unit-volume-litre' => '{{PLURAL:$1|litre|litres}}', |
845 | | - 'pfunc-convert-unit-volume-centilitre' => '{{PLURAL:$1|centilitre|centilitres}}', |
846 | | - 'pfunc-convert-unit-volume-millilitre' => '{{PLURAL:$1|millilitre|millilitres}}', |
| 832 | + 'pfunc-convert-unit-volume-litre' => '{{PLURAL:$1|$2litre|$2litres}}', |
847 | 833 | |
848 | 834 | # PRESSURE |
849 | 835 | 'pfunc-convert-unit-pressure-mmhg' => '{{PLURAL:$1|milimetre of mercury|milimetres of mercury}}', |