Merge "Remove unused parameter"
[lhc/web/wiklou.git] / languages / Language.php
index eabd0fe..d7cd8b5 100644 (file)
@@ -58,7 +58,7 @@ class Language {
        public $mConverter;
 
        public $mVariants, $mCode, $mLoaded = false;
-       public $mMagicExtensions = [], $mMagicHookDone = false;
+       public $mMagicExtensions = [];
        private $mHtmlCode = null, $mParentLanguage = false;
 
        public $dateFormatStrings = [];
@@ -1833,22 +1833,19 @@ class Language {
                while ( $hebrewMonth <= 12 ) {
                        # Calculate days in this month
                        if ( $isLeap && $hebrewMonth == 6 ) {
-                               # Adar in a leap year
-                               if ( $isLeap ) {
-                                       # Leap year - has Adar I, with 30 days, and Adar II, with 29 days
-                                       $days = 30;
+                               # Leap year - has Adar I, with 30 days, and Adar II, with 29 days
+                               $days = 30;
+                               if ( $hebrewDay <= $days ) {
+                                       # Day in Adar I
+                                       $hebrewMonth = 13;
+                               } else {
+                                       # Subtract the days of Adar I
+                                       $hebrewDay -= $days;
+                                       # Try Adar II
+                                       $days = 29;
                                        if ( $hebrewDay <= $days ) {
-                                               # Day in Adar I
-                                               $hebrewMonth = 13;
-                                       } else {
-                                               # Subtract the days of Adar I
-                                               $hebrewDay -= $days;
-                                               # Try Adar II
-                                               $days = 29;
-                                               if ( $hebrewDay <= $days ) {
-                                                       # Day in Adar II
-                                                       $hebrewMonth = 14;
-                                               }
+                                               # Day in Adar II
+                                               $hebrewMonth = 14;
                                        }
                                }
                        } elseif ( $hebrewMonth == 2 && $yearPattern == 2 ) {
@@ -3205,34 +3202,14 @@ class Language {
                return self::$dataCache->getItem( $this->mCode, 'magicWords' );
        }
 
-       /**
-        * Run the LanguageGetMagic hook once.
-        */
-       protected function doMagicHook() {
-               if ( $this->mMagicHookDone ) {
-                       return;
-               }
-               $this->mMagicHookDone = true;
-               Hooks::run( 'LanguageGetMagic', [ &$this->mMagicExtensions, $this->getCode() ], '1.16' );
-       }
-
        /**
         * Fill a MagicWord object with data from here
         *
         * @param MagicWord $mw
         */
        function getMagic( $mw ) {
-               // Saves a function call
-               if ( !$this->mMagicHookDone ) {
-                       $this->doMagicHook();
-               }
-
-               if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
-                       $rawEntry = $this->mMagicExtensions[$mw->mId];
-               } else {
-                       $rawEntry = self::$dataCache->getSubitem(
-                               $this->mCode, 'magicWords', $mw->mId );
-               }
+               $rawEntry = $this->mMagicExtensions[$mw->mId] ??
+                       self::$dataCache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
 
                if ( !is_array( $rawEntry ) ) {
                        wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
@@ -3268,8 +3245,6 @@ class Language {
                        // Initialise array
                        $this->mExtendedSpecialPageAliases =
                                self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
-                       Hooks::run( 'LanguageGetSpecialPageAliases',
-                               [ &$this->mExtendedSpecialPageAliases, $this->getCode() ], '1.16' );
                }
 
                return $this->mExtendedSpecialPageAliases;
@@ -3522,28 +3497,6 @@ class Language {
                );
        }
 
-       /**
-        * This method is deprecated since 1.31 and kept as alias for truncateForDatabase, which
-        * has replaced it. This method provides truncation suitable for DB.
-        *
-        * The database offers limited byte lengths for some columns in the database;
-        * multi-byte character sets mean we need to ensure that only whole characters
-        * are included, otherwise broken characters can be passed to the user.
-        *
-        * @deprecated since 1.31, use truncateForDatabase or truncateForVisual as appropriate.
-        *
-        * @param string $string String to truncate
-        * @param int $length Maximum length (including ellipsis)
-        * @param string $ellipsis String to append to the truncated text
-        * @param bool $adjustLength Subtract length of ellipsis from $length.
-        *      $adjustLength was introduced in 1.18, before that behaved as if false.
-        * @return string
-        */
-       function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) {
-               wfDeprecated( __METHOD__, '1.31' );
-               return $this->truncateForDatabase( $string, $length, $ellipsis, $adjustLength );
-       }
-
        /**
         * Truncate a string to a specified length in bytes, appending an optional
         * string (e.g. for ellipsis)
@@ -4269,25 +4222,27 @@ class Language {
        }
 
        /**
-        * Check if the language has the specific variant
+        * Strict check if the language has the specific variant.
+        *
+        * Compare to LanguageConverter::validateVariant() which does a more
+        * lenient check and attempts to coerce the given code to a valid one.
         *
         * @since 1.19
         * @param string $variant
         * @return bool
         */
        public function hasVariant( $variant ) {
-               return (bool)$this->mConverter->validateVariant( $variant );
+               return $variant && ( $variant === $this->mConverter->validateVariant( $variant ) );
        }
 
        /**
         * Perform output conversion on a string, and encode for safe HTML output.
         * @param string $text Text to be converted
-        * @param bool $isTitle Whether this conversion is for the article title
         * @return string
         * @todo this should get integrated somewhere sane
         */
-       public function convertHtml( $text, $isTitle = false ) {
-               return htmlspecialchars( $this->convert( $text, $isTitle ) );
+       public function convertHtml( $text ) {
+               return htmlspecialchars( $this->convert( $text ) );
        }
 
        /**
@@ -5082,10 +5037,6 @@ class Language {
        public function getPluralRuleType( $number ) {
                $index = $this->getPluralRuleIndexNumber( $number );
                $pluralRuleTypes = $this->getPluralRuleTypes();
-               if ( isset( $pluralRuleTypes[$index] ) ) {
-                       return $pluralRuleTypes[$index];
-               } else {
-                       return 'other';
-               }
+               return $pluralRuleTypes[$index] ?? 'other';
        }
 }