* (bug 19721) API action=help should have a way to just list for a specific module

This commit is contained in:
Sam Reed 2010-05-08 11:45:41 +00:00
parent ff70cda61b
commit ff442ae79f
4 changed files with 119 additions and 6 deletions

View file

@ -163,6 +163,7 @@ in a negative namespace (which is invalid).
* (bug 22868) don't list infinite block expiry date as "now" in API logevents
* (bug 22290) prop=revisions now outputs "comment" field even when comment
is empty, for consistency with list=recentchanges
* (bug 19721) API action=help should have a way to just list for a specific module
=== Languages updated in 1.17 ===

View file

@ -40,10 +40,67 @@ class ApiHelp extends ApiBase {
}
/**
* Stub module for displaying help when no parameters are given
* Module for displaying help
*/
public function execute() {
$this->dieUsage( '', 'help' );
// Get parameters
$params = $this->extractRequestParams();
if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
$this->dieUsage( '', 'help' );
}
$this->getMain()->setHelp();
$result = $this->getResult();
$queryObj = new ApiQuery( $this->getMain(), 'query' );
$r = array();
if ( is_array( $params['modules'] ) ) {
$modArr = $this->getMain()->getModules();
foreach ( $params['modules'] as $m ) {
if ( !isset( $modArr[$m] ) ) {
$r[] = array( 'name' => $m, 'missing' => '' );
continue;
}
$module = new $modArr[$m]( $this->getMain(), $m );
$r[] = $this->buildModuleHelp( $module, 'action' );
}
}
if ( is_array( $params['querymodules'] ) ) {
$qmodArr = $queryObj->getModules();
foreach ( $params['querymodules'] as $qm ) {
if ( !isset( $qmodArr[$qm] ) ) {
$r[] = array( 'name' => $qm, 'missing' => '' );
continue;
}
$module = new $qmodArr[$qm]( $this, $qm );
$type = $queryObj->getModuleType( $qm );
if ( $type === null ) {
$r[] = array( 'name' => $qm, 'missing' => '' );
continue;
}
$r[] = $this->buildModuleHelp( $module, $type );
}
}
$result->setIndexedTagName( $r, 'module' );
$result->addValue( null, $this->getModuleName(), $r );
}
private function buildModuleHelp( $module, $type ) {
$msg = ApiMain::makeHelpMsgHeader( $module, $type );
$msg2 = $module->makeHelpMsg();
if ( $msg2 !== false ) {
$msg .= $msg2;
}
return $msg;
}
public function shouldCheckMaxlag() {
@ -53,10 +110,39 @@ class ApiHelp extends ApiBase {
public function isReadMode() {
return false;
}
public function getAllowedParams() {
return array(
'modules' => array(
ApiBase::PARAM_ISMULTI => true
),
'querymodules' => array(
ApiBase::PARAM_ISMULTI => true
),
);
}
public function getParamDescription() {
return array(
'modules' => 'List of module names (value of the action= parameter)',
'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
);
}
public function getDescription() {
return array(
'Display this help screen.'
'Display this help screen. Or the help screen for the specified module'
);
}
protected function getExamples() {
return array(
'Whole help page:',
' api.php?action=help',
'Module help page:',
' api.php?action=help&modules=protect',
'Query modules help page:',
' api.php?action=help&querymodules=categorymembers',
);
}

View file

@ -674,13 +674,19 @@ class ApiMain extends ApiBase {
'or file a bug report at http://bugzilla.wikimedia.org/'
);
}
/**
* Sets whether the pretty-printer should format *bold* and $italics$
*/
public function setHelp( $help = true ) {
$this->mPrinter->setHelp( $help );
}
/**
* Override the parent to generate help messages for all available modules.
*/
public function makeHelpMsg() {
global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
$this->mPrinter->setHelp();
$this->setHelp();
// Get help text from cache if present
$key = wfMemcKey( 'apihelp', $this->getModuleName(),
SpecialVersion::getVersion( 'nodb' ) .
@ -699,7 +705,7 @@ class ApiMain extends ApiBase {
}
public function reallyMakeHelpMsg() {
$this->mPrinter->setHelp();
$this->setHelp();
// Use parent to make default message for the main module
$msg = parent::makeHelpMsg();
@ -737,7 +743,6 @@ class ApiMain extends ApiBase {
$msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n";
return $msg;
}

View file

@ -171,6 +171,27 @@ class ApiQuery extends ApiBase {
function getModules() {
return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
}
/**
* Get whether the specified module is a prop, list or a meta query module
* @param $moduleName string Name of the module to find type for
* @return mixed string or null
*/
function getModuleType( $moduleName ) {
if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
return 'prop';
}
if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
return 'list';
}
if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
return 'meta';
}
return null;
}
public function getCustomPrinter() {
// If &exportnowrap is set, use the raw formatter