X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=80aeff5478a009c4ebc74ba95b9beaec3fd94f0f;hp=bc3def841f40a0248f33204d7e2014df9f3f6450;hb=1d7a1bf8bddf0908e4f572c82268733f63126a13;hpb=925fe0df015458a330d320c9f1a0014d32ff8866 diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index bc3def841f..80aeff5478 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -204,6 +204,19 @@ abstract class ApiBase extends ContextSource { */ const PARAM_DEPRECATED_VALUES = 20; + /** + * (integer) Maximum number of values, for normal users. Must be used with PARAM_ISMULTI. + * @since 1.30 + */ + const PARAM_ISMULTI_LIMIT1 = 21; + + /** + * (integer) Maximum number of values, for users with the apihighimits right. + * Must be used with PARAM_ISMULTI. + * @since 1.30 + */ + const PARAM_ISMULTI_LIMIT2 = 22; + /**@}*/ const ALL_DEFAULT_STRING = '*'; @@ -548,7 +561,7 @@ abstract class ApiBase extends ContextSource { // Main module has this method overridden // Safety - avoid infinite loop: if ( $this->isMain() ) { - ApiBase::dieDebug( __METHOD__, 'base method was called on main module.' ); + self::dieDebug( __METHOD__, 'base method was called on main module.' ); } return $this->getMain()->lacksSameOriginSecurity(); @@ -620,7 +633,7 @@ abstract class ApiBase extends ContextSource { // Main module has getResult() method overridden // Safety - avoid infinite loop: if ( $this->isMain() ) { - ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' ); + self::dieDebug( __METHOD__, 'base method was called on main module. ' ); } return $this->getMain()->getResult(); @@ -634,7 +647,7 @@ abstract class ApiBase extends ContextSource { // Main module has getErrorFormatter() method overridden // Safety - avoid infinite loop: if ( $this->isMain() ) { - ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' ); + self::dieDebug( __METHOD__, 'base method was called on main module. ' ); } return $this->getMain()->getErrorFormatter(); @@ -660,7 +673,7 @@ abstract class ApiBase extends ContextSource { // Main module has getContinuationManager() method overridden // Safety - avoid infinite loop: if ( $this->isMain() ) { - ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' ); + self::dieDebug( __METHOD__, 'base method was called on main module. ' ); } return $this->getMain()->getContinuationManager(); @@ -668,13 +681,13 @@ abstract class ApiBase extends ContextSource { /** * Set the continuation manager - * @param ApiContinuationManager|null + * @param ApiContinuationManager|null $manager */ public function setContinuationManager( $manager ) { // Main module has setContinuationManager() method overridden // Safety - avoid infinite loop: if ( $this->isMain() ) { - ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' ); + self::dieDebug( __METHOD__, 'base method was called on main module. ' ); } $this->getMain()->setContinuationManager( $manager ); @@ -1024,6 +1037,12 @@ abstract class ApiBase extends ContextSource { $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; @@ -1059,7 +1078,7 @@ abstract class ApiBase extends ContextSource { if ( $type == 'boolean' ) { if ( isset( $default ) && $default !== false ) { // Having a default value of anything other than 'false' is not allowed - ApiBase::dieDebug( + self::dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'. " . 'Boolean parameters must default to false.' @@ -1070,13 +1089,13 @@ abstract class ApiBase extends ContextSource { } elseif ( $type == 'upload' ) { if ( isset( $default ) ) { // Having a default value is not allowed - ApiBase::dieDebug( + self::dieDebug( __METHOD__, "File upload param $encParamName's default is set to " . "'$default'. File upload parameters may not have a default." ); } if ( $multi ) { - ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); + self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); } $value = $this->getMain()->getUpload( $encParamName ); if ( !$value->exists() ) { @@ -1138,7 +1157,7 @@ abstract class ApiBase extends ContextSource { $allSpecifier = ( is_string( $allowAll ) ? $allowAll : self::ALL_DEFAULT_STRING ); if ( $allowAll && $multi && is_array( $type ) && in_array( $allSpecifier, $type, true ) ) { - ApiBase::dieDebug( + self::dieDebug( __METHOD__, "For param $encParamName, PARAM_ALL collides with a possible value" ); } @@ -1148,7 +1167,9 @@ abstract class ApiBase extends ContextSource { $value, $multi, is_array( $type ) ? $type : null, - $allowAll ? $allSpecifier : null + $allowAll ? $allSpecifier : null, + $multiLimit1, + $multiLimit2 ); } @@ -1194,13 +1215,13 @@ abstract class ApiBase extends ContextSource { if ( !isset( $paramSettings[self::PARAM_MAX] ) || !isset( $paramSettings[self::PARAM_MAX2] ) ) { - ApiBase::dieDebug( + self::dieDebug( __METHOD__, "MAX1 or MAX2 are not defined for the limit $encParamName" ); } if ( $multi ) { - ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); + self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); } $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0; if ( $value == 'max' ) { @@ -1221,7 +1242,7 @@ abstract class ApiBase extends ContextSource { break; case 'boolean': if ( $multi ) { - ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); + self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); } break; case 'timestamp': @@ -1255,7 +1276,7 @@ abstract class ApiBase extends ContextSource { } break; default: - ApiBase::dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" ); + self::dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" ); } } @@ -1350,21 +1371,25 @@ abstract class ApiBase extends ContextSource { * null, all values are accepted. * @param string|null $allSpecifier String to use to specify all allowed values, or null * if this behavior should not be allowed + * @param int|null $limit1 Maximum number of values, for normal users. + * @param int|null $limit2 Maximum number of values, for users with the apihighlimits right. * @return string|string[] (allowMultiple ? an_array_of_values : a_single_value) */ protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues, - $allSpecifier = null + $allSpecifier = null, $limit1 = null, $limit2 = null ) { if ( ( trim( $value ) === '' || trim( $value ) === "\x1f" ) && $allowMultiple ) { return []; } + $limit1 = $limit1 ?: self::LIMIT_SML1; + $limit2 = $limit2 ?: self::LIMIT_SML2; // This is a bit awkward, but we want to avoid calling canApiHighLimits() // because it unstubs $wgUser - $valuesList = $this->explodeMultiValue( $value, self::LIMIT_SML2 + 1 ); - $sizeLimit = count( $valuesList ) > self::LIMIT_SML1 && $this->mMainModule->canApiHighLimits() - ? self::LIMIT_SML2 - : self::LIMIT_SML1; + $valuesList = $this->explodeMultiValue( $value, $limit2 + 1 ); + $sizeLimit = count( $valuesList ) > $limit1 && $this->mMainModule->canApiHighLimits() + ? $limit2 + : $limit1; if ( $allowMultiple && is_array( $allowedValues ) && $allSpecifier && count( $valuesList ) === 1 && $valuesList[0] === $allSpecifier @@ -1432,7 +1457,7 @@ abstract class ApiBase extends ContextSource { * Validate the value against the minimum and user/bot maximum limits. * Prints usage info on failure. * @param string $paramName Parameter name - * @param int $value Parameter value + * @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 @@ -1599,7 +1624,7 @@ abstract class ApiBase extends ContextSource { /** * Truncate an array to a certain length. - * @param array $arr Array to truncate + * @param array &$arr Array to truncate * @param int $limit Maximum length * @return bool True if the array was truncated, false otherwise */ @@ -2077,19 +2102,19 @@ abstract class ApiBase extends ContextSource { * @return Message */ public function getFinalSummary() { - $msg = ApiBase::makeMessage( $this->getSummaryMessage(), $this->getContext(), [ + $msg = self::makeMessage( $this->getSummaryMessage(), $this->getContext(), [ $this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), ] ); if ( !$msg->exists() ) { wfDeprecated( 'API help "description" messages', '1.30' ); - $msg = ApiBase::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [ + $msg = self::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [ $this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), ] ); - $msg = ApiBase::makeMessage( 'rawmessage', $this->getContext(), [ + $msg = self::makeMessage( 'rawmessage', $this->getContext(), [ preg_replace( '/\n.*/s', '', $msg->text() ) ] ); } @@ -2116,12 +2141,12 @@ abstract class ApiBase extends ContextSource { $desc = (string)$desc; } - $summary = ApiBase::makeMessage( $this->getSummaryMessage(), $this->getContext(), [ + $summary = self::makeMessage( $this->getSummaryMessage(), $this->getContext(), [ $this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), ] ); - $extendedDescription = ApiBase::makeMessage( + $extendedDescription = self::makeMessage( $this->getExtendedDescription(), $this->getContext(), [ $this->getModulePrefix(), $this->getModuleName(), @@ -2133,7 +2158,7 @@ abstract class ApiBase extends ContextSource { $msgs = [ $summary, $extendedDescription ]; } else { wfDeprecated( 'API help "description" messages', '1.30' ); - $description = ApiBase::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [ + $description = self::makeMessage( $this->getDescriptionMessage(), $this->getContext(), [ $this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), @@ -2165,10 +2190,10 @@ abstract class ApiBase extends ContextSource { if ( $this->needsToken() ) { $params['token'] = [ - ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true, - ApiBase::PARAM_SENSITIVE => true, - ApiBase::PARAM_HELP_MSG => [ + self::PARAM_TYPE => 'string', + self::PARAM_REQUIRED => true, + self::PARAM_SENSITIVE => true, + self::PARAM_HELP_MSG => [ 'api-help-param-token', $this->needsToken(), ], @@ -2205,7 +2230,7 @@ abstract class ApiBase extends ContextSource { } $desc = self::escapeWikiText( $desc ); - $params = $this->getFinalParams( ApiBase::GET_VALUES_FOR_HELP ); + $params = $this->getFinalParams( self::GET_VALUES_FOR_HELP ); $msgs = []; foreach ( $params as $param => $settings ) { if ( !is_array( $settings ) ) { @@ -2224,15 +2249,15 @@ abstract class ApiBase extends ContextSource { $d = implode( ' ', $d ); } - if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) { - $msg = $settings[ApiBase::PARAM_HELP_MSG]; + if ( isset( $settings[self::PARAM_HELP_MSG] ) ) { + $msg = $settings[self::PARAM_HELP_MSG]; } else { $msg = $this->msg( "apihelp-{$path}-param-{$param}" ); if ( !$msg->exists() ) { $msg = $this->msg( 'api-help-fallback-parameter', $d ); } } - $msg = ApiBase::makeMessage( $msg, $this->getContext(), + $msg = self::makeMessage( $msg, $this->getContext(), [ $prefix, $param, $name, $path ] ); if ( !$msg ) { self::dieDebug( __METHOD__, @@ -2240,11 +2265,11 @@ abstract class ApiBase extends ContextSource { } $msgs[$param] = [ $msg ]; - if ( isset( $settings[ApiBase::PARAM_TYPE] ) && - $settings[ApiBase::PARAM_TYPE] === 'submodule' + if ( isset( $settings[self::PARAM_TYPE] ) && + $settings[self::PARAM_TYPE] === 'submodule' ) { - if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) { - $map = $settings[ApiBase::PARAM_SUBMODULE_MAP]; + if ( isset( $settings[self::PARAM_SUBMODULE_MAP] ) ) { + $map = $settings[self::PARAM_SUBMODULE_MAP]; } else { $prefix = $this->isMain() ? '' : ( $this->getModulePath() . '+' ); $map = []; @@ -2282,29 +2307,29 @@ abstract class ApiBase extends ContextSource { $arr[] = $m->setContext( $this->getContext() ); } $msgs[$param] = array_merge( $msgs[$param], $submodules, $deprecatedSubmodules ); - } elseif ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { - if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { + } elseif ( isset( $settings[self::PARAM_HELP_MSG_PER_VALUE] ) ) { + if ( !is_array( $settings[self::PARAM_HELP_MSG_PER_VALUE] ) ) { self::dieDebug( __METHOD__, 'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' ); } - if ( !is_array( $settings[ApiBase::PARAM_TYPE] ) ) { + if ( !is_array( $settings[self::PARAM_TYPE] ) ) { self::dieDebug( __METHOD__, 'ApiBase::PARAM_HELP_MSG_PER_VALUE may only be used when ' . 'ApiBase::PARAM_TYPE is an array' ); } - $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE]; - $deprecatedValues = isset( $settings[ApiBase::PARAM_DEPRECATED_VALUES] ) - ? $settings[ApiBase::PARAM_DEPRECATED_VALUES] + $valueMsgs = $settings[self::PARAM_HELP_MSG_PER_VALUE]; + $deprecatedValues = isset( $settings[self::PARAM_DEPRECATED_VALUES] ) + ? $settings[self::PARAM_DEPRECATED_VALUES] : []; - foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) { + foreach ( $settings[self::PARAM_TYPE] as $value ) { if ( isset( $valueMsgs[$value] ) ) { $msg = $valueMsgs[$value]; } else { $msg = "apihelp-{$path}-paramvalue-{$param}-{$value}"; } - $m = ApiBase::makeMessage( $msg, $this->getContext(), + $m = self::makeMessage( $msg, $this->getContext(), [ $prefix, $param, $name, $path, $value ] ); if ( $m ) { $m = new ApiHelpParamValueMessage( @@ -2321,13 +2346,13 @@ abstract class ApiBase extends ContextSource { } } - if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { - if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { + if ( isset( $settings[self::PARAM_HELP_MSG_APPEND] ) ) { + if ( !is_array( $settings[self::PARAM_HELP_MSG_APPEND] ) ) { self::dieDebug( __METHOD__, 'Value for ApiBase::PARAM_HELP_MSG_APPEND is not an array' ); } - foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $m ) { - $m = ApiBase::makeMessage( $m, $this->getContext(), + foreach ( $settings[self::PARAM_HELP_MSG_APPEND] as $m ) { + $m = self::makeMessage( $m, $this->getContext(), [ $prefix, $param, $name, $path ] ); if ( $m ) { $msgs[$param][] = $m; @@ -2614,6 +2639,7 @@ abstract class ApiBase extends ContextSource { * @param string $warning Warning message */ public function setWarning( $warning ) { + wfDeprecated( __METHOD__, '1.29' ); $msg = new ApiRawMessage( $warning, 'warning' ); $this->getErrorFormatter()->addWarning( $this->getModulePath(), $msg ); } @@ -2632,6 +2658,7 @@ abstract class ApiBase extends ContextSource { * @throws ApiUsageException always */ public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithError( new RawMessage( '$1', [ $description ] ), $errorCode, @@ -2651,6 +2678,7 @@ abstract class ApiBase extends ContextSource { * @throws MWException */ public function getErrorFromStatus( $status, &$extraData = null ) { + wfDeprecated( __METHOD__, '1.29' ); if ( $status->isGood() ) { throw new MWException( 'Successful status passed to ApiBase::dieStatus' ); } @@ -2857,9 +2885,10 @@ abstract class ApiBase extends ContextSource { * Return the error message related to a certain array * @deprecated since 1.29 * @param array|string|MessageSpecifier $error Element of a getUserPermissionsErrors()-style array - * @return [ 'code' => code, 'info' => info ] + * @return array [ 'code' => code, 'info' => info ] */ public function parseMsg( $error ) { + wfDeprecated( __METHOD__, '1.29' ); // Check whether someone passed the whole array, instead of one element as // documented. This breaks if it's actually an array of fallback keys, but // that's long-standing misbehavior introduced in r87627 to incorrectly @@ -2889,6 +2918,7 @@ abstract class ApiBase extends ContextSource { * @throws ApiUsageException always */ public function dieUsageMsg( $error ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithError( $this->parseMsgInternal( $error ) ); } @@ -2901,6 +2931,7 @@ abstract class ApiBase extends ContextSource { * @since 1.21 */ public function dieUsageMsgOrDebug( $error ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithErrorOrDebug( $this->parseMsgInternal( $error ) ); }