X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=3a31b2aeebc6ab4ff10771da1d31155f887d5691;hb=a985acd573f19b7fd36d9d4c18783401e710c3e9;hp=9cb895d3acfdb7cbed1cb28526686d94e93155de;hpb=68644e2d340fc8ed1b43f47a0c4fd65cc62e6c7e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 9cb895d3ac..3a31b2aeeb 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -66,13 +66,11 @@ abstract class ApiBase extends ContextSource { const PARAM_RANGE_ENFORCE = 9; /// @since 1.25 // Specify an alternative i18n message for this help parameter. - // Value can be a string key, an array giving key and parameters, or a - // Message object. + // Value is $msg for ApiBase::makeMessage() const PARAM_HELP_MSG = 10; /// @since 1.25 // Specify additional i18n messages to append to the normal message. Value - // is an array of any of strings giving the message key, arrays giving key and - // parameters, or Message objects. + // is an array of $msg for ApiBase::makeMessage() const PARAM_HELP_MSG_APPEND = 11; /// @since 1.25 // Specify additional information tags for the parameter. Value is an array @@ -82,9 +80,14 @@ abstract class ApiBase extends ContextSource { // comma-joined list of values, $3 = module prefix. const PARAM_HELP_MSG_INFO = 12; /// @since 1.25 - // When PARAM_DFLT is an array, this may be an array mapping those values + // When PARAM_TYPE is an array, this may be an array mapping those values // to page titles which will be linked in the help. const PARAM_VALUE_LINKS = 13; + /// @since 1.25 + // When PARAM_TYPE is an array, this is an array mapping those values to + // $msg for ApiBase::makeMessage(). Any value not having a mapping will use + // apihelp-{$path}-paramvalue-{$param}-{$value} is used. + const PARAM_HELP_MSG_PER_VALUE = 14; const LIMIT_BIG1 = 500; // Fast query, std user limit const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit @@ -1042,6 +1045,7 @@ abstract class ApiBase extends ContextSource { * @param string $token Supplied token * @param array $params All supplied parameters for the module * @return bool + * @throws MWException */ final public function validateToken( $token, array $params ) { $tokenType = $this->needsToken(); @@ -1291,6 +1295,7 @@ abstract class ApiBase extends ContextSource { * @since 1.23 * @param Status $status * @return array Array of code and error string + * @throws MWException */ public function getErrorFromStatus( $status ) { if ( $status->isGood() ) { @@ -2018,6 +2023,10 @@ abstract class ApiBase extends ContextSource { * @return array Keys are parameter names, values are arrays of Message objects */ public function getFinalParamDescription() { + $prefix = $this->getModulePrefix(); + $name = $this->getModuleName(); + $path = $this->getModulePath(); + $desc = $this->getParamDescription(); Hooks::run( 'APIGetParamDescription', array( &$this, &$desc ) ); @@ -2048,35 +2057,61 @@ abstract class ApiBase extends ContextSource { if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) { $msg = $settings[ApiBase::PARAM_HELP_MSG]; } else { - $msg = $this->msg( "apihelp-{$this->getModulePath()}-param-{$param}" ); + $msg = $this->msg( "apihelp-{$path}-param-{$param}" ); if ( !$msg->exists() ) { $msg = $this->msg( 'api-help-fallback-parameter', $d ); } } - $msg = ApiBase::makeMessage( $msg, $this->getContext(), array( - $this->getModulePrefix(), - $param, - $this->getModuleName(), - $this->getModulePath(), - ) ); + $msg = ApiBase::makeMessage( $msg, $this->getContext(), + array( $prefix, $param, $name, $path ) ); if ( !$msg ) { $this->dieDebug( __METHOD__, 'Value in ApiBase::PARAM_HELP_MSG is not valid' ); } $msgs[$param] = array( $msg ); + if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { + if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { + $this->dieDebug( __METHOD__, + 'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' ); + } + if ( !is_array( $settings[ApiBase::PARAM_TYPE] ) ) { + $this->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]; + foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) { + if ( isset( $valueMsgs[$value] ) ) { + $msg = $valueMsgs[$value]; + } else { + $msg = "apihelp-{$path}-paramvalue-{$param}-{$value}"; + } + $m = ApiBase::makeMessage( $msg, $this->getContext(), + array( $prefix, $param, $name, $path, $value ) ); + if ( $m ) { + $m = new ApiHelpParamValueMessage( + $value, + array( $m->getKey(), 'api-help-param-no-description' ), + $m->getParams() + ); + $msgs[$param][] = $m->setContext( $this->getContext() ); + } else { + $this->dieDebug( __METHOD__, + "Value in ApiBase::PARAM_HELP_MSG_PER_VALUE for $value is not valid" ); + } + } + } + if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { $this->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(), array( - $this->getModulePrefix(), - $param, - $this->getModuleName(), - $this->getModulePath(), - ) ); + $m = ApiBase::makeMessage( $m, $this->getContext(), + array( $prefix, $param, $name, $path ) ); if ( $m ) { $msgs[$param][] = $m; } else { @@ -2146,6 +2181,10 @@ abstract class ApiBase extends ContextSource { * Profiling: total module execution time */ private $mTimeIn = 0, $mModuleTime = 0; + /** @var ScopedCallback */ + private $profile; + /** @var ScopedCallback */ + private $dbProfile; /** * Get the name of the module as shown in the profiler log @@ -2170,7 +2209,7 @@ abstract class ApiBase extends ContextSource { ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileOut()' ); } $this->mTimeIn = microtime( true ); - wfProfileIn( $this->getModuleProfileName() ); + $this->profile = Profiler::instance()->scopedProfileIn( $this->getModuleProfileName() ); } /** @@ -2189,7 +2228,7 @@ abstract class ApiBase extends ContextSource { $this->mModuleTime += microtime( true ) - $this->mTimeIn; $this->mTimeIn = 0; - wfProfileOut( $this->getModuleProfileName() ); + Profiler::instance()->scopedProfileOut( $this->profile ); } /** @@ -2236,7 +2275,8 @@ abstract class ApiBase extends ContextSource { ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileDBOut()' ); } $this->mDBTimeIn = microtime( true ); - wfProfileIn( $this->getModuleProfileName( true ) ); + + $this->dbProfile = Profiler::instance()->scopedProfileIn( $this->getModuleProfileName( true ) ); } /** @@ -2256,7 +2296,7 @@ abstract class ApiBase extends ContextSource { $this->mDBTime += $time; $this->getMain()->mDBTime += $time; - wfProfileOut( $this->getModuleProfileName( true ) ); + Profiler::instance()->scopedProfileOut( $this->dbProfile ); } /**