Localization update for he.
[lhc/web/wiklou.git] / languages / Language.php
index 9c7cae2..aa1a65c 100644 (file)
@@ -1367,8 +1367,7 @@ class Language {
                        if( $usePrefs ) {
                                $datePreference = $wgUser->getDatePreference();
                        } else {
-                               $options = User::getDefaultOptions();
-                               $datePreference = (string)$options['date'];
+                               $datePreference = (string)User::getDefaultOption( 'date' );
                        }
                } else {
                        $datePreference = (string)$usePrefs;
@@ -1695,7 +1694,7 @@ class Language {
         * @param $string String
         * @return String
         */
-       function wordSegmentation( $string ) {
+       function segmentByWord( $string ) {
                return $string;
        }
 
@@ -1707,7 +1706,7 @@ class Language {
         * @return String
         */
        function normalizeForSearch( $string ) {
-               return $string;
+               return self::convertDoubleWidth($string);
        }
 
        /**
@@ -1715,8 +1714,17 @@ class Language {
         * range: ff00-ff5f ~= 0020-007f
         */
        protected static function convertDoubleWidth( $string ) {
-               $string = preg_replace( '/\xef\xbc([\x80-\xbf])/e', 'chr((ord("$1") & 0x3f) + 0x20)', $string );
-               $string = preg_replace( '/\xef\xbd([\x80-\x99])/e', 'chr((ord("$1") & 0x3f) + 0x60)', $string );
+               static $full = null;
+               static $half = null;
+
+               if( $full === null ) {
+                       $fullWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+                       $halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+                       $full = str_split( $fullWidth, 3 );
+                       $half = str_split( $halfWidth );
+               }
+
+               $string = str_replace( $full, $half, $string );
                return $string;
        }
 
@@ -2174,7 +2182,7 @@ class Language {
                        $string = $this->removeBadCharFirst( $string );
                        $string = $ellipsis . $string;
                }
-               # Do not truncate if the ellipsis makes the string longer (bug 22181)
+               # Do not truncate if the ellipsis makes the string longer/equal (bug 22181)
                if ( strlen( $string ) < strlen( $stringOriginal ) ) {
                        return $string;
                } else {
@@ -2248,7 +2256,7 @@ class Language {
                }
                $text = MWTidy::tidy( $text ); // fix tags
                $displayLen = 0; // innerHTML legth so far
-               $doTruncate = true; // truncated string plus '...' shorter than original?
+               $testingEllipsis = false; // checking if ellipses will make string longer/equal?
                $tagType = 0; // 0-open, 1-close
                $bracketState = 0; // 1-tag start, 2-tag name, 0-neither
                $entityState = 0; // 0-not entity, 1-entity
@@ -2301,15 +2309,20 @@ class Language {
                                        }
                                }
                        }
-                       if( !$doTruncate ) continue;
-                       # Truncate if not in the middle of a bracket/entity...
+                       # Consider truncation once the display length has reached the maximim.
+                       # Double-check that we're not in the middle of a bracket/entity...
                        if ( $displayLen >= $length && $bracketState == 0 && $entityState == 0 ) {
-                               $remaining = substr( $text, $pos + 1 ); // remaining string
-                               $remaining = StringUtils::delimiterReplace( '<', '>', '', $remaining ); // rm tags
-                               $remaining = StringUtils::delimiterReplace( '&', ';', '', $remaining ); // rm entities
-                               $doTruncate = ( strlen($remaining) > strlen($ellipsis) );
-                               if ( $doTruncate ) {
-                                       $ret = $this->removeBadCharLast( $ret ) . $ellipsis;
+                               if ( !$testingEllipsis ) {
+                                       $testingEllipsis = true;
+                                       # Save where we are; we will truncate here unless
+                                       # the ellipsis actually makes the string longer.
+                                       $pOpenTags = $openTags; // save state
+                                       $pRet = $ret; // save state
+                               } elseif ( $displayLen > ($length + strlen($ellipsis)) ) {
+                                       # Ellipsis won't make string longer/equal, the truncation point was OK.
+                                       $openTags = $pOpenTags; // reload state
+                                       $ret = $this->removeBadCharLast( $pRet ); // reload state, multi-byte char fix
+                                       $ret .= $ellipsis; // add ellipsis
                                        break;
                                }
                        }
@@ -2706,19 +2719,19 @@ class Language {
 
        function formatTimePeriod( $seconds ) {
                if ( $seconds < 10 ) {
-                       return $this->formatNum( sprintf( "%.1f", $seconds ) ) . wfMsg( 'seconds-abbrev' );
+                       return $this->formatNum( sprintf( "%.1f", $seconds ) ) . ' ' . wfMsg( 'seconds-abbrev' );
                } elseif ( $seconds < 60 ) {
-                       return $this->formatNum( round( $seconds ) ) . wfMsg( 'seconds-abbrev' );
+                       return $this->formatNum( round( $seconds ) ) . ' ' . wfMsg( 'seconds-abbrev' );
                } elseif ( $seconds < 3600 ) {
-                       return $this->formatNum( floor( $seconds / 60 ) ) . wfMsg( 'minutes-abbrev' ) .
-                               $this->formatNum( round( fmod( $seconds, 60 ) ) ) . wfMsg( 'seconds-abbrev' );
+                       return $this->formatNum( floor( $seconds / 60 ) ) . ' ' . wfMsg( 'minutes-abbrev' ) . ' ' .
+                               $this->formatNum( round( fmod( $seconds, 60 ) ) ) . ' ' . wfMsg( 'seconds-abbrev' );
                } else {
                        $hours = floor( $seconds / 3600 );
                        $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
                        $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
-                       return $this->formatNum( $hours ) . wfMsg( 'hours-abbrev' ) .
-                               $this->formatNum( $minutes ) . wfMsg( 'minutes-abbrev' ) .
-                               $this->formatNum( $secondsPart ) . wfMsg( 'seconds-abbrev' );
+                       return $this->formatNum( $hours ) . ' ' . wfMsg( 'hours-abbrev' ) . ' ' .
+                               $this->formatNum( $minutes ) . ' ' . wfMsg( 'minutes-abbrev' ) . ' ' .
+                               $this->formatNum( $secondsPart ) . ' ' . wfMsg( 'seconds-abbrev' );
                }
        }