X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=55a2ee792cb08143b7efe55cf2b6a5a970977151;hb=d136c4b227c1ff3aec80df67f4993510f96fd612;hp=7ada2cab5f0360aa15aa2e25804ce6cb66957db3;hpb=8bfd19b451649c88225670fe657b4a7aebf18f5d;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 7ada2cab5f..55a2ee792c 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -504,7 +504,8 @@ class Language { $this->getMessage( 'qbsettings-fixedleft' ), $this->getMessage( 'qbsettings-fixedright' ), $this->getMessage( 'qbsettings-floatingleft' ), - $this->getMessage( 'qbsettings-floatingright' ) + $this->getMessage( 'qbsettings-floatingright' ), + $this->getMessage( 'qbsettings-directionality' ) ); } @@ -550,13 +551,6 @@ class Language { return self::$dataCache->getSubitem( $this->mCode, 'imageFiles', $image ); } - /** - * @return array - */ - function getDefaultUserOptionOverrides() { - return self::$dataCache->getItem( $this->mCode, 'defaultUserOptionOverrides' ); - } - /** * @return array */ @@ -2357,10 +2351,14 @@ class Language { /** * A hidden direction mark (LRM or RLM), depending on the language direction * + * @param $opposite Boolean Get the direction mark opposite to your language * @return string */ - function getDirMark() { - return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E"; + function getDirMark( $opposite = false ) { + $rtl = "\xE2\x80\x8F"; + $ltr = "\xE2\x80\x8E"; + if( $opposite ) { return $this->isRTL() ? $ltr : $rtl; } + return $this->isRTL() ? $rtl : $ltr; } /** @@ -2425,7 +2423,7 @@ class Language { } if ( !is_array( $rawEntry ) ) { - error_log( "\"$rawEntry\" is not a valid magic thingie for \"$mw->mId\"" ); + error_log( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" ); } else { $mw->mCaseSensitive = $rawEntry[0]; $mw->mSynonyms = array_slice( $rawEntry, 1 ); @@ -2770,31 +2768,33 @@ class Language { return $text; // string short enough even *with* HTML (short-circuit) } - $displayLen = 0; // innerHTML legth so far + $dispLen = 0; // innerHTML legth so far $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 - $tag = $ret = $pRet = ''; // accumulated tag name, accumulated result string + $tag = $ret = ''; // accumulated tag name, accumulated result string $openTags = array(); // open tag stack - $pOpenTags = array(); + $maybeState = null; // possible truncation state $textLen = strlen( $text ); $neLength = max( 0, $length - strlen( $ellipsis ) ); // non-ellipsis len if truncated for ( $pos = 0; true; ++$pos ) { # Consider truncation once the display length has reached the maximim. + # We check if $dispLen > 0 to grab tags for the $neLength = 0 case. # Check that we're not in the middle of a bracket/entity... - if ( $displayLen >= $neLength && $bracketState == 0 && $entityState == 0 ) { + if ( $dispLen && $dispLen >= $neLength && $bracketState == 0 && !$entityState ) { if ( !$testingEllipsis ) { $testingEllipsis = true; # Save where we are; we will truncate here unless there turn out to # be so few remaining characters that truncation is not necessary. - $pOpenTags = $openTags; // save state - $pRet = $ret; // save state - } elseif ( $displayLen > $length && $displayLen > strlen( $ellipsis ) ) { + if ( !$maybeState ) { // already saved? ($neLength = 0 case) + $maybeState = array( $ret, $openTags ); // save state + } + } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) { # String in fact does need truncation, the truncation point was OK. - $openTags = $pOpenTags; // reload state - $ret = $this->removeBadCharLast( $pRet ); // reload state, multi-byte char fix + list( $ret, $openTags ) = $maybeState; // reload state + $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix $ret .= $ellipsis; // add ellipsis break; } @@ -2832,25 +2832,27 @@ class Language { if ( $entityState ) { if ( $ch == ';' ) { $entityState = 0; - $displayLen++; // entity is one displayed char + $dispLen++; // entity is one displayed char } } else { + if ( $neLength == 0 && !$maybeState ) { + // Save state without $ch. We want to *hit* the first + // display char (to get tags) but not *use* it if truncating. + $maybeState = array( substr( $ret, 0, -1 ), $openTags ); + } if ( $ch == '&' ) { $entityState = 1; // entity found, (e.g. " ") } else { - $displayLen++; // this char is displayed + $dispLen++; // this char is displayed // Add the next $max display text chars after this in one swoop... - $max = ( $testingEllipsis ? $length : $neLength ) - $displayLen; + $max = ( $testingEllipsis ? $length : $neLength ) - $dispLen; $skipped = $this->truncate_skip( $ret, $text, "<>&", $pos + 1, $max ); - $displayLen += $skipped; + $dispLen += $skipped; $pos += $skipped; } } } } - if ( $displayLen == 0 ) { - return ''; // no text shown, nothing to format - } // Close the last tag if left unclosed by bad HTML $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); while ( count( $openTags ) > 0 ) { @@ -2990,9 +2992,8 @@ class Language { } /** - * Maybe translate block durations. Note that this function is somewhat misnamed: it - * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time - * (which is an absolute timestamp). + * This translates the duration ("1 week", "4 days", etc) + * as well as the expiry time (which is an absolute timestamp). * @param $str String: the validated block duration in English * @return Somehow translated block duration * @see LanguageFi.php for example implementation @@ -3016,8 +3017,8 @@ class Language { } } } - // If all else fails, return the original string. - return $str; + // If no duration is given, but a timestamp, display that + return ( strtotime( $str ) ? $this->timeanddate( strtotime( $str ) ) : $str ); } /** @@ -3410,14 +3411,19 @@ class Language { /** * @todo Document - * @param $seconds String + * @param $seconds int|float + * @param $format String Optional, one of ("avoidseconds","avoidminutes"): + * "avoidseconds" - don't mention seconds if $seconds >= 1 hour + * "avoidminutes" - don't mention seconds/minutes if $seconds > 48 hours * @return string */ - function formatTimePeriod( $seconds ) { + function formatTimePeriod( $seconds, $format = false ) { if ( round( $seconds * 10 ) < 100 ) { - return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' ); + $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ); + $s .= $this->getMessageFromDB( 'seconds-abbrev' ); } elseif ( round( $seconds ) < 60 ) { - return $this->formatNum( round( $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' ); + $s = $this->formatNum( round( $seconds ) ); + $s .= $this->getMessageFromDB( 'seconds-abbrev' ); } elseif ( round( $seconds ) < 3600 ) { $minutes = floor( $seconds / 60 ); $secondsPart = round( fmod( $seconds, 60 ) ); @@ -3425,9 +3431,10 @@ class Language { $secondsPart = 0; $minutes++; } - return $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' . - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); - } else { + $s = $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); + $s .= ' '; + $s .= $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); + } elseif ( round( $seconds ) <= 2*86400 ) { $hours = floor( $seconds / 3600 ); $minutes = floor( ( $seconds - $hours * 3600 ) / 60 ); $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 ); @@ -3439,10 +3446,47 @@ class Language { $minutes = 0; $hours++; } - return $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ) . ' ' . - $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' . - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); + $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); + $s .= ' '; + $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); + if ( !in_array( $format, array( 'avoidseconds', 'avoidminutes' ) ) ) { + $s .= ' ' . $this->formatNum( $secondsPart ) . + $this->getMessageFromDB( 'seconds-abbrev' ); + } + } else { + $days = floor( $seconds / 86400 ); + if ( $format === 'avoidminutes' ) { + $hours = round( ( $seconds - $days * 86400 ) / 3600 ); + if ( $hours == 24 ) { + $hours = 0; + $days++; + } + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); + $s .= ' '; + $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); + } elseif ( $format === 'avoidseconds' ) { + $hours = floor( ( $seconds - $days * 86400 ) / 3600 ); + $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 ); + if ( $minutes == 60 ) { + $minutes = 0; + $hours++; + } + if ( $hours == 24 ) { + $hours = 0; + $days++; + } + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); + $s .= ' '; + $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); + $s .= ' '; + $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); + } else { + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); + $s .= ' '; + $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format ); + } } + return $s; } /**