Linker: Deprecate non-Language types for $lang of tocList() and generateTOC()
authorFomafix <fomafix@googlemail.com>
Mon, 16 Jul 2018 08:44:54 +0000 (10:44 +0200)
committerFomafix <fomafix@googlemail.com>
Fri, 21 Dec 2018 16:41:30 +0000 (17:41 +0100)
$lang still defaults to $wgLang on unset parameter.

Change-Id: I15b65fec987641885374dfef9e1229ea405f7c30

RELEASE-NOTES-1.33
includes/DummyLinker.php
includes/Linker.php

index f357aae..7566b63 100644 (file)
@@ -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 ===
index 2f5455e..ba1233e 100644 (file)
@@ -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 );
        }
 
index 731317e..b605acd 100644 (file)
@@ -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 '<div id="toc" class="toc">'
@@ -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 ) {