X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiParamInfo.php;h=b74d52866f8c4666737f088c8b999f6732ec22bf;hb=95c85f71b178e75efd0a4444a4f39bbce27e694f;hp=5965a46f5a02960b21683f15f0074df1ae847c04;hpb=fdd8993fe6a9d2bf0bdba83690e4273bb4038ce7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 5965a46f5a..b74d52866f 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -37,8 +37,6 @@ class ApiParamInfo extends ApiBase { } public function execute() { - global $wgContLang; - // Get parameters $params = $this->extractRequestParams(); @@ -131,8 +129,9 @@ class ApiParamInfo extends ApiBase { * @param array $res Result array * @param string $key Result key * @param Message[] $msgs + * @param bool $joinLists */ - protected function formatHelpMessages( array &$res, $key, array $msgs ) { + protected function formatHelpMessages( array &$res, $key, array $msgs, $joinLists = false ) { switch ( $this->helpFormat ) { case 'none': break; @@ -143,6 +142,9 @@ class ApiParamInfo extends ApiBase { $ret[] = $m->setContext( $this->context )->text(); } $res[$key] = join( "\n\n", $ret ); + if ( $joinLists ) { + $res[$key] = preg_replace( '!^(([*#:;])[^\n]*)\n\n(?=\2)!m', "$1\n", $res[$key] ); + } break; case 'html': @@ -150,16 +152,24 @@ class ApiParamInfo extends ApiBase { foreach ( $msgs as $m ) { $ret[] = $m->setContext( $this->context )->parseAsBlock(); } - $res[$key] = join( "\n", $ret ); + $ret = join( "\n", $ret ); + if ( $joinLists ) { + $ret = preg_replace( '!\s*\s*<\1>\s*!', "\n", $ret ); + } + $res[$key] = $ret; break; case 'raw': $res[$key] = array(); foreach ( $msgs as $m ) { - $res[$key][] = array( + $a = array( 'key' => $m->getKey(), 'params' => $m->getParams(), ); + if ( $m instanceof ApiHelpParamValueMessage ) { + $a['forvalue'] = $m->getParamValue(); + } + $res[$key][] = $a; } $this->getResult()->setIndexedTagName( $res[$key], 'msg' ); break; @@ -173,10 +183,11 @@ class ApiParamInfo extends ApiBase { private function getModuleInfo( $module ) { $result = $this->getResult(); $ret = array(); + $path = $module->getModulePath(); $ret['name'] = $module->getModuleName(); $ret['classname'] = get_class( $module ); - $ret['path'] = $module->getModulePath(); + $ret['path'] = $path; if ( !$module->isMain() ) { $ret['group'] = $module->getParent()->getModuleManager()->getModuleGroup( $module->getModuleName() @@ -233,7 +244,7 @@ class ApiParamInfo extends ApiBase { 'name' => $name ); if ( isset( $paramDesc[$name] ) ) { - $this->formatHelpMessages( $item, 'description', $paramDesc[$name] ); + $this->formatHelpMessages( $item, 'description', $paramDesc[$name], true ); } if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) { @@ -314,6 +325,30 @@ class ApiParamInfo extends ApiBase { if ( isset( $settings[ApiBase::PARAM_MIN] ) ) { $item['min'] = $settings[ApiBase::PARAM_MIN]; } + + if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) { + $item['info'] = array(); + foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) { + $tag = array_shift( $i ); + $info = array( + 'name' => $tag, + ); + if ( count( $i ) ) { + $info['values'] = $i; + $result->setIndexedTagName( $info['values'], 'v' ); + } + $this->formatHelpMessages( $info, 'text', array( + $this->context->msg( "apihelp-{$path}-paraminfo-{$tag}" ) + ->numParams( count( $i ) ) + ->params( $this->context->getLanguage()->commaList( $i ) ) + ->params( $module->getModulePrefix() ) + ) ); + $result->setSubelements( $info, 'text' ); + $item['info'][] = $info; + } + $result->setIndexedTagName( $item['info'], 'i' ); + } + $ret['parameters'][] = $item; } $result->setIndexedTagName( $ret['parameters'], 'param' ); @@ -361,26 +396,10 @@ class ApiParamInfo extends ApiBase { ); } - public function getParamDescription() { - return array( - 'modules' => 'List of module names (values of the action= and format= parameters, or "main"). Can specify submodules with a \'+\'', - 'helpformat' => 'Format of help strings', - - 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)', - 'mainmodule' => 'Get information about the main (top-level) module as well', - 'pagesetmodule' => 'Get information about the pageset module ' . - '(providing titles= and friends) as well', - 'formatmodules' => 'List of format module names (value of format= parameter)', - ); - } - - public function getDescription() { - return 'Obtain information about certain API parameters and errors.'; - } - - public function getExamples() { + protected function getExamplesMessages() { return array( - 'api.php?action=paraminfo&modules=parse|phpfm|query+allpages|query+siteinfo' + 'action=paraminfo&modules=parse|phpfm|query+allpages|query+siteinfo' + => 'apihelp-paraminfo-example-1', ); }