Merge "Fix the bug for dates between 1912 and 1941 in Thai language"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 02a635a..be4eeef 100644 (file)
@@ -1100,7 +1100,7 @@ abstract class ApiBase extends ContextSource {
         * Return true if we're to watch the page, false if not, null if no change.
         * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
         * @param Title $titleObj The page under consideration
-        * @param string $userOption The user option to consider when $watchlist=preferences.
+        * @param string|null $userOption The user option to consider when $watchlist=preferences.
         *    If not set will use watchdefault always and watchcreations if $titleObj doesn't exist.
         * @return bool
         */
@@ -1156,36 +1156,16 @@ abstract class ApiBase extends ContextSource {
                        ];
                }
 
-               $default = isset( $paramSettings[self::PARAM_DFLT] )
-                       ? $paramSettings[self::PARAM_DFLT]
-                       : null;
-               $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
-                       ? $paramSettings[self::PARAM_ISMULTI]
-                       : false;
-               $multiLimit1 = isset( $paramSettings[self::PARAM_ISMULTI_LIMIT1] )
-                       ? $paramSettings[self::PARAM_ISMULTI_LIMIT1]
-                       : null;
-               $multiLimit2 = isset( $paramSettings[self::PARAM_ISMULTI_LIMIT2] )
-                       ? $paramSettings[self::PARAM_ISMULTI_LIMIT2]
-                       : null;
-               $type = isset( $paramSettings[self::PARAM_TYPE] )
-                       ? $paramSettings[self::PARAM_TYPE]
-                       : null;
-               $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] )
-                       ? $paramSettings[self::PARAM_ALLOW_DUPLICATES]
-                       : false;
-               $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] )
-                       ? $paramSettings[self::PARAM_DEPRECATED]
-                       : false;
-               $deprecatedValues = isset( $paramSettings[self::PARAM_DEPRECATED_VALUES] )
-                       ? $paramSettings[self::PARAM_DEPRECATED_VALUES]
-                       : [];
-               $required = isset( $paramSettings[self::PARAM_REQUIRED] )
-                       ? $paramSettings[self::PARAM_REQUIRED]
-                       : false;
-               $allowAll = isset( $paramSettings[self::PARAM_ALL] )
-                       ? $paramSettings[self::PARAM_ALL]
-                       : false;
+               $default = $paramSettings[self::PARAM_DFLT] ?? null;
+               $multi = $paramSettings[self::PARAM_ISMULTI] ?? false;
+               $multiLimit1 = $paramSettings[self::PARAM_ISMULTI_LIMIT1] ?? null;
+               $multiLimit2 = $paramSettings[self::PARAM_ISMULTI_LIMIT2] ?? null;
+               $type = $paramSettings[self::PARAM_TYPE] ?? null;
+               $dupes = $paramSettings[self::PARAM_ALLOW_DUPLICATES] ?? false;
+               $deprecated = $paramSettings[self::PARAM_DEPRECATED] ?? false;
+               $deprecatedValues = $paramSettings[self::PARAM_DEPRECATED_VALUES] ?? [];
+               $required = $paramSettings[self::PARAM_REQUIRED] ?? false;
+               $allowAll = $paramSettings[self::PARAM_ALL] ?? false;
 
                // When type is not given, and no choices, the type is the same as $default
                if ( !isset( $type ) ) {
@@ -1313,10 +1293,9 @@ abstract class ApiBase extends ContextSource {
                                                }
                                                break;
                                        case 'integer': // Force everything using intval() and optionally validate limits
-                                               $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null;
-                                               $max = isset( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null;
-                                               $enforceLimits = isset( $paramSettings[self::PARAM_RANGE_ENFORCE] )
-                                                       ? $paramSettings[self::PARAM_RANGE_ENFORCE] : false;
+                                               $min = $paramSettings[self::PARAM_MIN] ?? null;
+                                               $max = $paramSettings[self::PARAM_MAX] ?? null;
+                                               $enforceLimits = $paramSettings[self::PARAM_RANGE_ENFORCE] ?? false;
 
                                                if ( is_array( $value ) ) {
                                                        $value = array_map( 'intval', $value );
@@ -1348,7 +1327,7 @@ abstract class ApiBase extends ContextSource {
                                                if ( $multi ) {
                                                        self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
                                                }
-                                               $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0;
+                                               $min = $paramSettings[self::PARAM_MIN] ?? 0;
                                                if ( $value == 'max' ) {
                                                        $value = $this->getMain()->canApiHighLimits()
                                                                ? $paramSettings[self::PARAM_MAX2]
@@ -1595,7 +1574,7 @@ abstract class ApiBase extends ContextSource {
         * @param int &$value Parameter value
         * @param int|null $min Minimum value
         * @param int|null $max Maximum value for users
-        * @param int $botMax Maximum value for sysops/bots
+        * @param int|null $botMax Maximum value for sysops/bots
         * @param bool $enforceLimits Whether to enforce (die) if value is outside limits
         */
        protected function validateLimit( $paramName, &$value, $min, $max, $botMax = null,
@@ -1765,7 +1744,7 @@ abstract class ApiBase extends ContextSource {
         * Set a watch (or unwatch) based the based on a watchlist parameter.
         * @param string $watch Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
         * @param Title $titleObj The article's title to change
-        * @param string $userOption The user option to consider when $watch=preferences
+        * @param string|null $userOption The user option to consider when $watch=preferences
         */
        protected function setWatch( $watch, $titleObj, $userOption = null ) {
                $value = $this->getWatchlistValue( $watch, $titleObj, $userOption );
@@ -1833,14 +1812,14 @@ abstract class ApiBase extends ContextSource {
         * @since 1.25
         * @param string|array|Message $msg
         * @param IContextSource $context
-        * @param array $params
+        * @param array|null $params
         * @return Message|null
         */
        public static function makeMessage( $msg, IContextSource $context, array $params = null ) {
                if ( is_string( $msg ) ) {
                        $msg = wfMessage( $msg );
                } elseif ( is_array( $msg ) ) {
-                       $msg = call_user_func_array( 'wfMessage', $msg );
+                       $msg = wfMessage( ...$msg );
                }
                if ( !$msg instanceof Message ) {
                        return null;
@@ -1887,7 +1866,7 @@ abstract class ApiBase extends ContextSource {
                                        [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                ) );
                        } else {
-                               call_user_func_array( [ $status, 'fatal' ], (array)$error );
+                               $status->fatal( ...(array)$error );
                        }
                }
                return $status;
@@ -2066,10 +2045,7 @@ abstract class ApiBase extends ContextSource {
                if ( !$status->getErrorsByType( 'error' ) ) {
                        $newStatus = Status::newGood();
                        foreach ( $status->getErrorsByType( 'warning' ) as $err ) {
-                               call_user_func_array(
-                                       [ $newStatus, 'fatal' ],
-                                       array_merge( [ $err['message'] ], $err['params'] )
-                               );
+                               $newStatus->fatal( $err['message'], ...$err['params'] );
                        }
                        if ( !$newStatus->getErrorsByType( 'error' ) ) {
                                $newStatus->fatal( 'unknownerror-nocode' );
@@ -2106,7 +2082,7 @@ abstract class ApiBase extends ContextSource {
                        $user = $this->getUser();
                }
                $rights = (array)$rights;
-               if ( !call_user_func_array( [ $user, 'isAllowedAny' ], $rights ) ) {
+               if ( !$user->isAllowedAny( ...$rights ) ) {
                        $this->dieWithError( [ 'apierror-permissiondenied', $this->msg( "action-{$rights[0]}" ) ] );
                }
        }
@@ -2335,7 +2311,7 @@ abstract class ApiBase extends ContextSource {
                                        'api-help-param-token',
                                        $this->needsToken(),
                                ],
-                       ] + ( isset( $params['token'] ) ? $params['token'] : [] );
+                       ] + ( $params['token'] ?? [] );
                }
 
                // Avoid PHP 7.1 warning of passing $this by reference
@@ -2375,7 +2351,7 @@ abstract class ApiBase extends ContextSource {
                                $settings = [];
                        }
 
-                       $d = isset( $desc[$param] ) ? $desc[$param] : '';
+                       $d = $desc[$param] ?? '';
                        if ( is_array( $d ) ) {
                                // Special handling for prop parameters
                                $d = array_map( function ( $line ) {
@@ -2457,9 +2433,7 @@ abstract class ApiBase extends ContextSource {
                                }
 
                                $valueMsgs = $settings[self::PARAM_HELP_MSG_PER_VALUE];
-                               $deprecatedValues = isset( $settings[self::PARAM_DEPRECATED_VALUES] )
-                                       ? $settings[self::PARAM_DEPRECATED_VALUES]
-                                       : [];
+                               $deprecatedValues = $settings[self::PARAM_DEPRECATED_VALUES] ?? [];
 
                                foreach ( $settings[self::PARAM_TYPE] as $value ) {
                                        if ( isset( $valueMsgs[$value] ) ) {
@@ -2701,16 +2675,14 @@ abstract class ApiBase extends ContextSource {
         * @deprecated since 1.25
         */
        public function profileIn() {
-               // No wfDeprecated() yet because extensions call this and might need to
-               // keep doing so for BC.
+               wfDeprecated( __METHOD__, '1.25' );
        }
 
        /**
         * @deprecated since 1.25
         */
        public function profileOut() {
-               // No wfDeprecated() yet because extensions call this and might need to
-               // keep doing so for BC.
+               wfDeprecated( __METHOD__, '1.25' );
        }
 
        /**
@@ -2811,7 +2783,7 @@ abstract class ApiBase extends ContextSource {
                if ( !$msg instanceof IApiMessage ) {
                        $key = $msg->getKey();
                        $params = $msg->getParams();
-                       array_unshift( $params, isset( self::$messageMap[$key] ) ? self::$messageMap[$key] : $key );
+                       array_unshift( $params, self::$messageMap[$key] ?? $key );
                        $msg = ApiMessage::create( $params );
                }