diff options
Diffstat (limited to 'MLEB/Translate/TranslateUtils.php')
-rw-r--r-- | MLEB/Translate/TranslateUtils.php | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/MLEB/Translate/TranslateUtils.php b/MLEB/Translate/TranslateUtils.php index 4b51ed06..0ee7a349 100644 --- a/MLEB/Translate/TranslateUtils.php +++ b/MLEB/Translate/TranslateUtils.php @@ -253,11 +253,9 @@ class TranslateUtils { public static function getLanguageNames( $code ) { $languageNames = Language::fetchLanguageNames( $code ); - // Remove languages with deprecated codes (bug T37475) - global $wgDummyLanguageCodes; - - foreach ( array_keys( $wgDummyLanguageCodes ) as $dummyLanguageCode ) { - unset( $languageNames[$dummyLanguageCode] ); + $deprecatedCodes = LanguageCode::getDeprecatedCodeMapping(); + foreach ( array_keys( $deprecatedCodes ) as $deprecatedCode ) { + unset( $languageNames[ $deprecatedCode ] ); } Hooks::run( 'TranslateSupportedLanguages', [ &$languageNames, $code ] ); @@ -493,7 +491,7 @@ class TranslateUtils { * @param string $text * @return array */ - public static function resolveSpecialPageAlias( $text ) { + public static function resolveSpecialPageAlias( $text ) : array { if ( method_exists( MediaWikiServices::class, 'getSpecialPageFactory' ) ) { return MediaWikiServices::getInstance()->getSpecialPageFactory()->resolveAlias( $text ); } @@ -533,4 +531,64 @@ class TranslateUtils { ); } } + + /** + * Compatibility for pre-1.32, before OutputPage::wrapWikiTextAsInterface() + * + * @see OutputPage::wrapWikiTextAsInterface + * @param OutputPage $out + * @param string $wrapperClass The class attribute value for the <div> + * wrapper in the output HTML + * @param string $text The wikitext in the user interface language to + * add to the output. + */ + public static function wrapWikiTextAsInterface( OutputPage $out, $wrapperClass, $text ) { + if ( is_callable( [ $out, 'wrapWikiTextAsInterface' ] ) ) { + $out->wrapWikiTextAsInterface( $wrapperClass, $text ); + } else { + // wfDeprecated( 'use OutputPage::wrapWikiTextAsInterface', '1.32') + if ( !$wrapperClass ) { + $wrapperClass = ''; + } + $out->addHTML( Html::openElement( + 'div', [ 'class' => $wrapperClass ] + ) ); + self::addWikiTextAsInterface( $out, $text ); + $out->addHtml( Html::closeElement( + 'div' + ) ); + } + } + + /** + * Compatibility for pre-1.33, before OutputPage::parseAsInterface() + * + * @see OutputPage::parseAsInterface + * @param OutputPage $out + * @param string $text The wikitext in the user interface language to + * be parsed + * @return string HTML + */ + public static function parseAsInterface( OutputPage $out, $text ) { + if ( is_callable( [ $out, 'parseAsInterface' ] ) ) { + return $out->parseAsInterface( $text ); + } else { + // wfDeprecated( 'use OutputPage::parseAsInterface', '1.33') + return $out->parse( $text, /*linestart*/true, /*interface*/true ); + } + } + + public static function parseInlineAsInterface( OutputPage $out, $text ) { + if ( is_callable( [ $out, 'parseInlineAsInterface' ] ) ) { + return $out->parseInlineAsInterface( $text ); + } else { + // wfDeprecated( 'use OutputPage::parseInlineAsInterface', '1.33') + // The block wrapper stripping was slightly broken before 1.33 + // as well. + $contents = $out->parse( $text, /*linestart*/true, /*interface*/true ); + // Remove whatever block element wrapup the parser likes to add + $contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2', $contents ); + return $contents; + } + } } |