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
// 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
* @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();
* @since 1.23
* @param Status $status
* @return array Array of code and error string
+ * @throws MWException
*/
public function getErrorFromStatus( $status ) {
if ( $status->isGood() ) {
*/
public function getFinalDescription() {
$desc = $this->getDescription();
- wfRunHooks( 'APIGetDescription', array( &$this, &$desc ) );
+ Hooks::run( 'APIGetDescription', array( &$this, &$desc ) );
$desc = self::escapeWikiText( $desc );
if ( is_array( $desc ) ) {
$desc = join( "\n", $desc );
}
$msgs = array( $msg );
- wfRunHooks( 'APIGetDescriptionMessages', array( $this, &$msgs ) );
+ Hooks::run( 'APIGetDescriptionMessages', array( $this, &$msgs ) );
return $msgs;
}
) + ( isset( $params['token'] ) ? $params['token'] : array() );
}
- wfRunHooks( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
+ Hooks::run( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
return $params;
}
* @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();
- wfRunHooks( 'APIGetParamDescription', array( &$this, &$desc ) );
+ Hooks::run( 'APIGetParamDescription', array( &$this, &$desc ) );
if ( !$desc ) {
$desc = array();
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 {
}
}
- wfRunHooks( 'APIGetParamDescriptionMessages', array( $this, &$msgs ) );
+ Hooks::run( 'APIGetParamDescriptionMessages', array( $this, &$msgs ) );
return $msgs;
}
* 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
ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileOut()' );
}
$this->mTimeIn = microtime( true );
- wfProfileIn( $this->getModuleProfileName() );
+ $this->profile = Profiler::instance()->scopedProfileIn( $this->getModuleProfileName() );
}
/**
$this->mModuleTime += microtime( true ) - $this->mTimeIn;
$this->mTimeIn = 0;
- wfProfileOut( $this->getModuleProfileName() );
+ Profiler::instance()->scopedProfileOut( $this->profile );
}
/**
ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileDBOut()' );
}
$this->mDBTimeIn = microtime( true );
- wfProfileIn( $this->getModuleProfileName( true ) );
+
+ $this->dbProfile = Profiler::instance()->scopedProfileIn( $this->getModuleProfileName( true ) );
}
/**
$this->mDBTime += $time;
$this->getMain()->mDBTime += $time;
- wfProfileOut( $this->getModuleProfileName( true ) );
+ Profiler::instance()->scopedProfileOut( $this->dbProfile );
}
/**