public function uc( $str, $first = false ) {
if ( $first ) {
if ( $this->isMultibyte( $str ) ) {
- return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
+ return $this->mbUpperChar( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
} else {
return ucfirst( $str );
}
}
}
+ /**
+ * Convert character to uppercase, allowing overrides of the default mb_upper
+ * behaviour, which is buggy in many ways. Having a conversion table can be
+ * useful during transitions between PHP versions where unicode changes happen.
+ * This can make some resources unreachable on-wiki, see discussion at T219279.
+ * Providing such a conversion table can allow to manage the transition period.
+ *
+ * @since 1.34
+ *
+ * @param string $char
+ *
+ * @return string
+ */
+ protected function mbUpperChar( $char ) {
+ global $wgOverrideUcfirstCharacters;
+ if ( array_key_exists( $char, $wgOverrideUcfirstCharacters ) ) {
+ return $wgOverrideUcfirstCharacters[$char];
+ } else {
+ return mb_strtoupper( $char );
+ }
+ }
+
/**
* @param string $str
* @return mixed|string
}
/**
- * @return array
+ * @return string
*/
function fallback8bitEncoding() {
return self::$dataCache->getItem( $this->mCode, 'fallback8bitEncoding' );
* @return string
*/
private function truncateInternal(
- $string, $length, $ellipsis, $adjustLength, $measureLength, $getSubstring
+ $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
) {
- if ( !is_callable( $measureLength ) || !is_callable( $getSubstring ) ) {
- throw new InvalidArgumentException( 'Invalid callback provided' );
- }
-
# Check if there is no need to truncate
if ( $measureLength( $string ) <= abs( $length ) ) {
return $string; // no need to truncate
}
} elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) {
# String in fact does need truncation, the truncation point was OK.
+ // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring
list( $ret, $openTags ) = $maybeState; // reload state
$ret = $this->removeBadCharLast( $ret ); // multi-byte char fix
$ret .= $ellipsis; // add ellipsis
* Checks that convertPlural was given an array and pads it to requested
* amount of forms by copying the last one.
*
- * @param array $forms Array of forms given to convertPlural
+ * @param array $forms
* @param int $count How many forms should there be at least
- * @return array Padded array of forms or an exception if not an array
+ * @return array Padded array of forms
*/
protected function preConvertPlural( /* Array */ $forms, $count ) {
- while ( count( $forms ) < $count ) {
- $forms[] = $forms[count( $forms ) - 1];
- }
- return $forms;
+ return array_pad( $forms, $count, end( $forms ) );
}
/**
return $this->mHtmlCode;
}
- /**
- * @param string $code
- * @deprecated since 1.32, use Language::factory to create a new object instead.
- */
- public function setCode( $code ) {
- wfDeprecated( __METHOD__, '1.32' );
- $this->mCode = $code;
- // Ensure we don't leave incorrect cached data lying around
- $this->mHtmlCode = null;
- $this->mParentLanguage = false;
- }
-
/**
* Get the language code from a file name. Inverse of getFileName()
* @param string $filename $prefix . $languageCode . $suffix
* @param array $query Optional URL query parameter string
* @param bool $atend Optional param for specified if this is the last page
* @return string
+ * @deprecated since 1.33, use SpecialPage::viewPrevNext()
+ * instead.
*/
public function viewPrevNext( Title $title, $offset, $limit,
array $query = [], $atend = false