本文整理汇总了PHP中ApiBase::makeMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiBase::makeMessage方法的具体用法?PHP ApiBase::makeMessage怎么用?PHP ApiBase::makeMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiBase
的用法示例。
在下文中一共展示了ApiBase::makeMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFinalDescription
public function getFinalDescription()
{
// A bit of a hack to append 'api-help-authmanager-general-usage'
$msgs = parent::getFinalDescription();
$msgs[] = ApiBase::makeMessage('api-help-authmanager-general-usage', $this->getContext(), [$this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), AuthManager::ACTION_LOGIN, self::needsToken()]);
return $msgs;
}
示例2: getHelpInternal
//.........这里部分代码省略.........
case 'text':
// Displaying a type message here would be useless.
$type = null;
break;
}
}
// Add type. Messages for grep: api-help-param-type-limit
// api-help-param-type-integer api-help-param-type-boolean
// api-help-param-type-timestamp api-help-param-type-user
// api-help-param-type-password
if (is_string($type)) {
$msg = $context->msg("api-help-param-type-{$type}");
if (!$msg->isDisabled()) {
$info[] = $msg->params($multi ? 2 : 1)->parse();
}
}
if ($multi) {
$extra = array();
if ($hintPipeSeparated) {
$extra[] = $context->msg('api-help-param-multi-separate')->parse();
}
if ($count > ApiBase::LIMIT_SML1) {
$extra[] = $context->msg('api-help-param-multi-max')->numParams(ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2)->parse();
}
if ($extra) {
$info[] = join(' ', $extra);
}
}
}
// Add default
$default = isset($settings[ApiBase::PARAM_DFLT]) ? $settings[ApiBase::PARAM_DFLT] : null;
if ($default === '') {
$info[] = $context->msg('api-help-param-default-empty')->parse();
} elseif ($default !== null && $default !== false) {
$info[] = $context->msg('api-help-param-default')->params(wfEscapeWikiText($default))->parse();
}
if (!array_filter($description)) {
$description = array(self::wrap($context->msg('api-help-param-no-description'), 'apihelp-empty'));
}
// Add "deprecated" flag
if (!empty($settings[ApiBase::PARAM_DEPRECATED])) {
$help['parameters'] .= Html::openElement('dd', array('class' => 'info'));
$help['parameters'] .= self::wrap($context->msg('api-help-param-deprecated'), 'apihelp-deprecated', 'strong');
$help['parameters'] .= Html::closeElement('dd');
}
if ($description) {
$description = join('', $description);
$description = preg_replace('!\\s*</([oud]l)>\\s*<\\1>\\s*!', "\n", $description);
$help['parameters'] .= Html::rawElement('dd', array('class' => 'description'), $description);
}
foreach ($info as $i) {
$help['parameters'] .= Html::rawElement('dd', array('class' => 'info'), $i);
}
}
if ($dynamicParams !== null) {
$dynamicParams = ApiBase::makeMessage($dynamicParams, $context, array($module->getModulePrefix(), $module->getModuleName(), $module->getModulePath()));
$help['parameters'] .= Html::element('dt', null, '*');
$help['parameters'] .= Html::rawElement('dd', array('class' => 'description'), $dynamicParams->parse());
}
$help['parameters'] .= Html::closeElement('dl');
$help['parameters'] .= Html::closeElement('div');
}
$examples = $module->getExamplesMessages();
if ($examples) {
$help['examples'] .= Html::openElement('div', array('class' => 'apihelp-block apihelp-examples'));
$msg = $context->msg('api-help-examples');
if (!$msg->isDisabled()) {
$help['examples'] .= self::wrap($msg->numParams(count($examples)), 'apihelp-block-head', 'div');
}
$help['examples'] .= Html::openElement('dl');
foreach ($examples as $qs => $msg) {
$msg = ApiBase::makeMessage($msg, $context, array($module->getModulePrefix(), $module->getModuleName(), $module->getModulePath()));
$link = wfAppendQuery(wfScript('api'), $qs);
$help['examples'] .= Html::rawElement('dt', null, $msg->parse());
$help['examples'] .= Html::rawElement('dd', null, Html::element('a', array('href' => $link), "api.php?{$qs}"));
}
$help['examples'] .= Html::closeElement('dl');
$help['examples'] .= Html::closeElement('div');
}
$subtocnumber = $tocnumber;
$subtocnumber[$level + 1] = 0;
$suboptions = array('submodules' => $options['recursivesubmodules'], 'headerlevel' => $level + 1, 'tocnumber' => &$subtocnumber, 'noheader' => false) + $options;
if ($options['submodules'] && $module->getModuleManager()) {
$manager = $module->getModuleManager();
$submodules = array();
foreach ($groups as $group) {
$names = $manager->getNames($group);
sort($names);
foreach ($names as $name) {
$submodules[] = $manager->getModule($name);
}
}
$help['submodules'] .= self::getHelpInternal($context, $submodules, $suboptions, $haveModules);
}
$module->modifyHelp($help, $suboptions, $haveModules);
Hooks::run('APIHelpModifyOutput', array($module, &$help, $suboptions, &$haveModules));
$out .= join("\n", $help);
}
return $out;
}
示例3: getFinalParamDescription
/**
* Get final parameter descriptions, after hooks have had a chance to tweak it as
* needed.
*
* @since 1.25, returns array of Message[] rather than array of string[]
* @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));
if (!$desc) {
$desc = array();
}
$desc = self::escapeWikiText($desc);
$params = $this->getFinalParams(ApiBase::GET_VALUES_FOR_HELP);
$msgs = array();
foreach ($params as $param => $settings) {
if (!is_array($settings)) {
$settings = array();
}
$d = isset($desc[$param]) ? $desc[$param] : '';
if (is_array($d)) {
// Special handling for prop parameters
$d = array_map(function ($line) {
if (preg_match('/^\\s+(\\S+)\\s+-\\s+(.+)$/', $line, $m)) {
$line = "\n;{$m[1]}:{$m[2]}";
}
return $line;
}, $d);
$d = join(' ', $d);
}
if (isset($settings[ApiBase::PARAM_HELP_MSG])) {
$msg = $settings[ApiBase::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(), 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($prefix, $param, $name, $path));
if ($m) {
$msgs[$param][] = $m;
} else {
$this->dieDebug(__METHOD__, 'Value in ApiBase::PARAM_HELP_MSG_APPEND is not valid');
}
}
}
}
Hooks::run('APIGetParamDescriptionMessages', array($this, &$msgs));
return $msgs;
}
示例4: checkMessage
/**
* Test a message
* @param Message $msg
* @param string $what Which message is being checked
*/
private function checkMessage($msg, $what)
{
$msg = ApiBase::makeMessage($msg, self::getMain()->getContext());
$this->assertInstanceOf('Message', $msg, "{$what} message");
$this->assertTrue($msg->exists(), "{$what} message {$msg->getKey()} exists");
}
示例5: getModuleInfo
/**
* @param ApiBase $module
* @return ApiResult
*/
private function getModuleInfo($module)
{
$ret = [];
$path = $module->getModulePath();
$ret['name'] = $module->getModuleName();
$ret['classname'] = get_class($module);
$ret['path'] = $path;
if (!$module->isMain()) {
$ret['group'] = $module->getParent()->getModuleManager()->getModuleGroup($module->getModuleName());
}
$ret['prefix'] = $module->getModulePrefix();
$sourceInfo = $module->getModuleSourceInfo();
if ($sourceInfo) {
$ret['source'] = $sourceInfo['name'];
if (isset($sourceInfo['namemsg'])) {
$ret['sourcename'] = $this->context->msg($sourceInfo['namemsg'])->text();
} else {
$ret['sourcename'] = $ret['source'];
}
$link = SpecialPage::getTitleFor('Version', 'License/' . $sourceInfo['name'])->getFullURL();
if (isset($sourceInfo['license-name'])) {
$ret['licensetag'] = $sourceInfo['license-name'];
$ret['licenselink'] = (string) $link;
} elseif (SpecialVersion::getExtLicenseFileName(dirname($sourceInfo['path']))) {
$ret['licenselink'] = (string) $link;
}
}
$this->formatHelpMessages($ret, 'description', $module->getFinalDescription());
foreach ($module->getHelpFlags() as $flag) {
$ret[$flag] = true;
}
$ret['helpurls'] = (array) $module->getHelpUrls();
if (isset($ret['helpurls'][0]) && $ret['helpurls'][0] === false) {
$ret['helpurls'] = [];
}
ApiResult::setIndexedTagName($ret['helpurls'], 'helpurl');
if ($this->helpFormat !== 'none') {
$ret['examples'] = [];
$examples = $module->getExamplesMessages();
foreach ($examples as $qs => $msg) {
$item = ['query' => $qs];
$msg = ApiBase::makeMessage($msg, $this->context, [$module->getModulePrefix(), $module->getModuleName(), $module->getModulePath()]);
$this->formatHelpMessages($item, 'description', [$msg]);
if (isset($item['description'])) {
if (is_array($item['description'])) {
$item['description'] = $item['description'][0];
} else {
ApiResult::setSubelementsList($item, 'description');
}
}
$ret['examples'][] = $item;
}
ApiResult::setIndexedTagName($ret['examples'], 'example');
}
$ret['parameters'] = [];
$params = $module->getFinalParams(ApiBase::GET_VALUES_FOR_HELP);
$paramDesc = $module->getFinalParamDescription();
foreach ($params as $name => $settings) {
if (!is_array($settings)) {
$settings = [ApiBase::PARAM_DFLT => $settings];
}
$item = ['name' => $name];
if (isset($paramDesc[$name])) {
$this->formatHelpMessages($item, 'description', $paramDesc[$name], true);
}
$item['required'] = !empty($settings[ApiBase::PARAM_REQUIRED]);
if (!empty($settings[ApiBase::PARAM_DEPRECATED])) {
$item['deprecated'] = true;
}
if ($name === 'token' && $module->needsToken()) {
$item['tokentype'] = $module->needsToken();
}
if (!isset($settings[ApiBase::PARAM_TYPE])) {
$dflt = isset($settings[ApiBase::PARAM_DFLT]) ? $settings[ApiBase::PARAM_DFLT] : null;
if (is_bool($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'boolean';
} elseif (is_string($dflt) || is_null($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'string';
} elseif (is_int($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'integer';
}
}
if (isset($settings[ApiBase::PARAM_DFLT])) {
switch ($settings[ApiBase::PARAM_TYPE]) {
case 'boolean':
$item['default'] = (bool) $settings[ApiBase::PARAM_DFLT];
break;
case 'string':
case 'text':
case 'password':
$item['default'] = strval($settings[ApiBase::PARAM_DFLT]);
break;
case 'integer':
case 'limit':
$item['default'] = intval($settings[ApiBase::PARAM_DFLT]);
break;
//.........这里部分代码省略.........
示例6: getModuleInfo
/**
* @param ApiBase $module
* @return ApiResult
*/
private function getModuleInfo($module)
{
$result = $this->getResult();
$ret = array();
$path = $module->getModulePath();
$ret['name'] = $module->getModuleName();
$ret['classname'] = get_class($module);
$ret['path'] = $path;
if (!$module->isMain()) {
$ret['group'] = $module->getParent()->getModuleManager()->getModuleGroup($module->getModuleName());
}
$ret['prefix'] = $module->getModulePrefix();
$this->formatHelpMessages($ret, 'description', $module->getFinalDescription());
foreach ($module->getHelpFlags() as $flag) {
$ret[$flag] = true;
}
$ret['helpurls'] = (array) $module->getHelpUrls();
if (isset($ret['helpurls'][0]) && $ret['helpurls'][0] === false) {
$ret['helpurls'] = array();
}
ApiResult::setIndexedTagName($ret['helpurls'], 'helpurl');
if ($this->helpFormat !== 'none') {
$ret['examples'] = array();
$examples = $module->getExamplesMessages();
foreach ($examples as $qs => $msg) {
$item = array('query' => $qs);
$msg = ApiBase::makeMessage($msg, $this->context, array($module->getModulePrefix(), $module->getModuleName(), $module->getModulePath()));
$this->formatHelpMessages($item, 'description', array($msg));
if (isset($item['description'])) {
if (is_array($item['description'])) {
$item['description'] = $item['description'][0];
} else {
ApiResult::setSubelementsList($item, 'description');
}
}
$ret['examples'][] = $item;
}
ApiResult::setIndexedTagName($ret['examples'], 'example');
}
$ret['parameters'] = array();
$params = $module->getFinalParams(ApiBase::GET_VALUES_FOR_HELP);
$paramDesc = $module->getFinalParamDescription();
foreach ($params as $name => $settings) {
if (!is_array($settings)) {
$settings = array(ApiBase::PARAM_DFLT => $settings);
}
$item = array('name' => $name);
if (isset($paramDesc[$name])) {
$this->formatHelpMessages($item, 'description', $paramDesc[$name], true);
}
$item['required'] = !empty($settings[ApiBase::PARAM_REQUIRED]);
if (!empty($settings[ApiBase::PARAM_DEPRECATED])) {
$item['deprecated'] = true;
}
if ($name === 'token' && $module->needsToken()) {
$item['tokentype'] = $module->needsToken();
}
if (!isset($settings[ApiBase::PARAM_TYPE])) {
$dflt = isset($settings[ApiBase::PARAM_DFLT]) ? $settings[ApiBase::PARAM_DFLT] : null;
if (is_bool($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'boolean';
} elseif (is_string($dflt) || is_null($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'string';
} elseif (is_int($dflt)) {
$settings[ApiBase::PARAM_TYPE] = 'integer';
}
}
if (isset($settings[ApiBase::PARAM_DFLT])) {
switch ($settings[ApiBase::PARAM_TYPE]) {
case 'boolean':
$item['default'] = $settings[ApiBase::PARAM_DFLT] ? 'true' : 'false';
break;
case 'string':
$item['default'] = strval($settings[ApiBase::PARAM_DFLT]);
break;
case 'integer':
$item['default'] = intval($settings[ApiBase::PARAM_DFLT]);
break;
default:
$item['default'] = $settings[ApiBase::PARAM_DFLT];
break;
}
}
$item['multi'] = !empty($settings[ApiBase::PARAM_ISMULTI]);
if ($item['multi']) {
$item['limit'] = $this->getMain()->canApiHighLimits() ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_SML1;
$item['lowlimit'] = ApiBase::LIMIT_SML1;
$item['highlimit'] = ApiBase::LIMIT_SML2;
}
if (!empty($settings[ApiBase::PARAM_ALLOW_DUPLICATES])) {
$item['allowsduplicates'] = true;
}
if (isset($settings[ApiBase::PARAM_TYPE])) {
if ($settings[ApiBase::PARAM_TYPE] === 'submodule') {
$item['type'] = $module->getModuleManager()->getNames($name);
sort($item['type']);
//.........这里部分代码省略.........