Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -171,6 +171,27 @@ |
172 | 172 | function getModules() { |
173 | 173 | return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules ); |
174 | 174 | } |
| 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 | + } |
175 | 196 | |
176 | 197 | public function getCustomPrinter() { |
177 | 198 | // If &exportnowrap is set, use the raw formatter |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -674,13 +674,19 @@ |
675 | 675 | 'or file a bug report at http://bugzilla.wikimedia.org/' |
676 | 676 | ); |
677 | 677 | } |
| 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 | + } |
678 | 684 | |
679 | 685 | /** |
680 | 686 | * Override the parent to generate help messages for all available modules. |
681 | 687 | */ |
682 | 688 | public function makeHelpMsg() { |
683 | 689 | global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout; |
684 | | - $this->mPrinter->setHelp(); |
| 690 | + $this->setHelp(); |
685 | 691 | // Get help text from cache if present |
686 | 692 | $key = wfMemcKey( 'apihelp', $this->getModuleName(), |
687 | 693 | SpecialVersion::getVersion( 'nodb' ) . |
— | — | @@ -699,7 +705,7 @@ |
700 | 706 | } |
701 | 707 | |
702 | 708 | public function reallyMakeHelpMsg() { |
703 | | - $this->mPrinter->setHelp(); |
| 709 | + $this->setHelp(); |
704 | 710 | |
705 | 711 | // Use parent to make default message for the main module |
706 | 712 | $msg = parent::makeHelpMsg(); |
— | — | @@ -737,7 +743,6 @@ |
738 | 744 | |
739 | 745 | $msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n"; |
740 | 746 | |
741 | | - |
742 | 747 | return $msg; |
743 | 748 | } |
744 | 749 | |
Index: trunk/phase3/includes/api/ApiHelp.php |
— | — | @@ -40,11 +40,68 @@ |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | | - * Stub module for displaying help when no parameters are given |
| 44 | + * Module for displaying help |
45 | 45 | */ |
46 | 46 | 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 ); |
48 | 94 | } |
| 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 | + } |
49 | 106 | |
50 | 107 | public function shouldCheckMaxlag() { |
51 | 108 | return false; |
— | — | @@ -53,12 +110,41 @@ |
54 | 111 | public function isReadMode() { |
55 | 112 | return false; |
56 | 113 | } |
| 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 | + } |
57 | 125 | |
| 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 | + |
58 | 133 | public function getDescription() { |
59 | 134 | return array( |
60 | | - 'Display this help screen.' |
| 135 | + 'Display this help screen. Or the help screen for the specified module' |
61 | 136 | ); |
62 | 137 | } |
| 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 | + } |
63 | 149 | |
64 | 150 | public function getVersion() { |
65 | 151 | return __CLASS__ . ': $Id$'; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -163,6 +163,7 @@ |
164 | 164 | * (bug 22868) don't list infinite block expiry date as "now" in API logevents |
165 | 165 | * (bug 22290) prop=revisions now outputs "comment" field even when comment |
166 | 166 | is empty, for consistency with list=recentchanges |
| 167 | +* (bug 19721) API action=help should have a way to just list for a specific module |
167 | 168 | |
168 | 169 | === Languages updated in 1.17 === |
169 | 170 | |