}
/**
- * 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() {
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',
);
}
'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' ) .
}
public function reallyMakeHelpMsg() {
- $this->mPrinter->setHelp();
+ $this->setHelp();
// Use parent to make default message for the main module
$msg = parent::makeHelpMsg();
$msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n";
-
return $msg;
}
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