r66061 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66060‎ | r66061 | r66062 >
Date:11:45, 8 May 2010
Author:reedy
Status:ok
Tags:
Comment:
* (bug 19721) API action=help should have a way to just list for a specific module
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiHelp.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -171,6 +171,27 @@
172172 function getModules() {
173173 return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
174174 }
 175+
 176+ /**
 177+ * Get whether the specified module is a prop, list or a meta query module
 178+ * @param $moduleName string Name of the module to find type for
 179+ * @return mixed string or null
 180+ */
 181+ function getModuleType( $moduleName ) {
 182+ if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
 183+ return 'prop';
 184+ }
 185+
 186+ if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
 187+ return 'list';
 188+ }
 189+
 190+ if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
 191+ return 'meta';
 192+ }
 193+
 194+ return null;
 195+ }
175196
176197 public function getCustomPrinter() {
177198 // If &exportnowrap is set, use the raw formatter
Index: trunk/phase3/includes/api/ApiMain.php
@@ -674,13 +674,19 @@
675675 'or file a bug report at http://bugzilla.wikimedia.org/'
676676 );
677677 }
 678+ /**
 679+ * Sets whether the pretty-printer should format *bold* and $italics$
 680+ */
 681+ public function setHelp( $help = true ) {
 682+ $this->mPrinter->setHelp( $help );
 683+ }
678684
679685 /**
680686 * Override the parent to generate help messages for all available modules.
681687 */
682688 public function makeHelpMsg() {
683689 global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
684 - $this->mPrinter->setHelp();
 690+ $this->setHelp();
685691 // Get help text from cache if present
686692 $key = wfMemcKey( 'apihelp', $this->getModuleName(),
687693 SpecialVersion::getVersion( 'nodb' ) .
@@ -699,7 +705,7 @@
700706 }
701707
702708 public function reallyMakeHelpMsg() {
703 - $this->mPrinter->setHelp();
 709+ $this->setHelp();
704710
705711 // Use parent to make default message for the main module
706712 $msg = parent::makeHelpMsg();
@@ -737,7 +743,6 @@
738744
739745 $msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n";
740746
741 -
742747 return $msg;
743748 }
744749
Index: trunk/phase3/includes/api/ApiHelp.php
@@ -40,11 +40,68 @@
4141 }
4242
4343 /**
44 - * Stub module for displaying help when no parameters are given
 44+ * Module for displaying help
4545 */
4646 public function execute() {
47 - $this->dieUsage( '', 'help' );
 47+ // Get parameters
 48+ $params = $this->extractRequestParams();
 49+
 50+ if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
 51+ $this->dieUsage( '', 'help' );
 52+ }
 53+
 54+ $this->getMain()->setHelp();
 55+
 56+ $result = $this->getResult();
 57+ $queryObj = new ApiQuery( $this->getMain(), 'query' );
 58+ $r = array();
 59+ if ( is_array( $params['modules'] ) ) {
 60+ $modArr = $this->getMain()->getModules();
 61+
 62+ foreach ( $params['modules'] as $m ) {
 63+ if ( !isset( $modArr[$m] ) ) {
 64+ $r[] = array( 'name' => $m, 'missing' => '' );
 65+ continue;
 66+ }
 67+ $module = new $modArr[$m]( $this->getMain(), $m );
 68+
 69+ $r[] = $this->buildModuleHelp( $module, 'action' );
 70+ }
 71+ }
 72+
 73+ if ( is_array( $params['querymodules'] ) ) {
 74+ $qmodArr = $queryObj->getModules();
 75+
 76+ foreach ( $params['querymodules'] as $qm ) {
 77+ if ( !isset( $qmodArr[$qm] ) ) {
 78+ $r[] = array( 'name' => $qm, 'missing' => '' );
 79+ continue;
 80+ }
 81+ $module = new $qmodArr[$qm]( $this, $qm );
 82+ $type = $queryObj->getModuleType( $qm );
 83+
 84+ if ( $type === null ) {
 85+ $r[] = array( 'name' => $qm, 'missing' => '' );
 86+ continue;
 87+ }
 88+
 89+ $r[] = $this->buildModuleHelp( $module, $type );
 90+ }
 91+ }
 92+ $result->setIndexedTagName( $r, 'module' );
 93+ $result->addValue( null, $this->getModuleName(), $r );
4894 }
 95+
 96+ private function buildModuleHelp( $module, $type ) {
 97+ $msg = ApiMain::makeHelpMsgHeader( $module, $type );
 98+
 99+ $msg2 = $module->makeHelpMsg();
 100+ if ( $msg2 !== false ) {
 101+ $msg .= $msg2;
 102+ }
 103+
 104+ return $msg;
 105+ }
49106
50107 public function shouldCheckMaxlag() {
51108 return false;
@@ -53,12 +110,41 @@
54111 public function isReadMode() {
55112 return false;
56113 }
 114+
 115+ public function getAllowedParams() {
 116+ return array(
 117+ 'modules' => array(
 118+ ApiBase::PARAM_ISMULTI => true
 119+ ),
 120+ 'querymodules' => array(
 121+ ApiBase::PARAM_ISMULTI => true
 122+ ),
 123+ );
 124+ }
57125
 126+ public function getParamDescription() {
 127+ return array(
 128+ 'modules' => 'List of module names (value of the action= parameter)',
 129+ 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
 130+ );
 131+ }
 132+
58133 public function getDescription() {
59134 return array(
60 - 'Display this help screen.'
 135+ 'Display this help screen. Or the help screen for the specified module'
61136 );
62137 }
 138+
 139+ protected function getExamples() {
 140+ return array(
 141+ 'Whole help page:',
 142+ ' api.php?action=help',
 143+ 'Module help page:',
 144+ ' api.php?action=help&modules=protect',
 145+ 'Query modules help page:',
 146+ ' api.php?action=help&querymodules=categorymembers',
 147+ );
 148+ }
63149
64150 public function getVersion() {
65151 return __CLASS__ . ': $Id$';
Index: trunk/phase3/RELEASE-NOTES
@@ -163,6 +163,7 @@
164164 * (bug 22868) don't list infinite block expiry date as "now" in API logevents
165165 * (bug 22290) prop=revisions now outputs "comment" field even when comment
166166 is empty, for consistency with list=recentchanges
 167+* (bug 19721) API action=help should have a way to just list for a specific module
167168
168169 === Languages updated in 1.17 ===
169170

Follow-up revisions

RevisionCommit summaryAuthorDate
r73853Minor followup to r66061, make the examples more explicit/verbose (different ...reedy00:56, 28 September 2010

Status & tagging log