From dffbbdbe3955b7ca97e787e9b95bc2e1a4d95fbd Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 16 Jul 2018 10:44:54 +0200 Subject: [PATCH] Linker: Deprecate non-Language types for $lang of tocList() and generateTOC() $lang still defaults to $wgLang on unset parameter. Change-Id: I15b65fec987641885374dfef9e1229ea405f7c30 --- RELEASE-NOTES-1.33 | 2 ++ includes/DummyLinker.php | 4 ++-- includes/Linker.php | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index f357aae4b5..7566b63624 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -193,6 +193,8 @@ because of Phabricator reports. Title::getDBKey(), which doesn't vary case. * User::getPasswordValidity() is now deprecated. User::checkPasswordValidity() returns the same information in a more useful format. +* For Linker::generateTOC() and Linker::tocList(), passing strings or booleans + as the $lang parameter was deprecated. The same applies to DummyLinker. * … === Other changes in 1.33 === diff --git a/includes/DummyLinker.php b/includes/DummyLinker.php index 2f5455ef5a..ba1233e546 100644 --- a/includes/DummyLinker.php +++ b/includes/DummyLinker.php @@ -345,11 +345,11 @@ class DummyLinker { return Linker::tocLineEnd(); } - public function tocList( $toc, $lang = false ) { + public function tocList( $toc, $lang = null ) { return Linker::tocList( $toc, $lang ); } - public function generateTOC( $tree, $lang = false ) { + public function generateTOC( $tree, $lang = null ) { return Linker::generateTOC( $tree, $lang ); } diff --git a/includes/Linker.php b/includes/Linker.php index 731317e5d0..b605acd894 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1575,11 +1575,18 @@ class Linker { * * @since 1.16.3 * @param string $toc Html of the Table Of Contents - * @param string|Language|bool $lang Language for the toc title, defaults to user language + * @param string|Language|bool|null $lang Language for the toc title, defaults to user language. + * The types string and bool are deprecated. * @return string Full html of the TOC */ - public static function tocList( $toc, $lang = false ) { - $lang = wfGetLangObj( $lang ); + public static function tocList( $toc, $lang = null ) { + global $wgLang; + $lang = $lang ?? $wgLang; + if ( !is_object( $lang ) ) { + wfDeprecated( __METHOD__ . ' with type other than Language for $lang', '1.33' ); + $lang = wfGetLangObj( $lang ); + } + $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped(); return '
' @@ -1611,10 +1618,11 @@ class Linker { * * @since 1.16.3. $lang added in 1.17 * @param array $tree Return value of ParserOutput::getSections() - * @param string|Language|bool $lang Language for the toc title, defaults to user language + * @param string|Language|bool|null $lang Language for the toc title, defaults to user language. + * The types string and bool are deprecated. * @return string HTML fragment */ - public static function generateTOC( $tree, $lang = false ) { + public static function generateTOC( $tree, $lang = null ) { $toc = ''; $lastLevel = 0; foreach ( $tree as $section ) { -- 2.20.1