MediaWiki
REL1_22
|
00001 <?php 00032 class ApiHelp extends ApiBase { 00033 00037 public function execute() { 00038 // Get parameters 00039 $params = $this->extractRequestParams(); 00040 00041 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) { 00042 $this->dieUsage( '', 'help' ); 00043 } 00044 00045 $this->getMain()->setHelp(); 00046 $result = $this->getResult(); 00047 00048 if ( is_array( $params['modules'] ) ) { 00049 $modules = $params['modules']; 00050 } else { 00051 $modules = array(); 00052 } 00053 00054 if ( is_array( $params['querymodules'] ) ) { 00055 $queryModules = $params['querymodules']; 00056 foreach ( $queryModules as $m ) { 00057 $modules[] = 'query+' . $m; 00058 } 00059 } else { 00060 $queryModules = array(); 00061 } 00062 00063 $r = array(); 00064 foreach ( $modules as $m ) { 00065 // sub-modules could be given in the form of "name[+name[+name...]]" 00066 $subNames = explode( '+', $m ); 00067 if ( count( $subNames ) === 1 ) { 00068 // In case the '+' was typed into URL, it resolves as a space 00069 $subNames = explode( ' ', $m ); 00070 } 00071 $module = $this->getMain(); 00072 for ( $i = 0; $i < count( $subNames ); $i++ ) { 00073 $subs = $module->getModuleManager(); 00074 if ( $subs === null ) { 00075 $module = null; 00076 } else { 00077 $module = $subs->getModule( $subNames[$i] ); 00078 } 00079 if ( $module === null ) { 00080 if ( count( $subNames ) === 2 00081 && $i === 1 00082 && $subNames[0] === 'query' 00083 && in_array( $subNames[1], $queryModules ) 00084 ) { 00085 // Legacy: This is one of the renamed 'querymodule=...' parameters, 00086 // do not use '+' notation in the output, use submodule's name instead. 00087 $name = $subNames[1]; 00088 } else { 00089 $name = implode( '+', array_slice( $subNames, 0, $i + 1 ) ); 00090 } 00091 $r[] = array( 'name' => $name, 'missing' => '' ); 00092 break; 00093 } else { 00094 $type = $subs->getModuleGroup( $subNames[$i] ); 00095 } 00096 } 00097 if ( $module !== null ) { 00098 $r[] = $this->buildModuleHelp( $module, $type ); 00099 } 00100 } 00101 00102 $result->setIndexedTagName( $r, 'module' ); 00103 $result->addValue( null, $this->getModuleName(), $r ); 00104 } 00105 00111 private function buildModuleHelp( $module, $type ) { 00112 $msg = ApiMain::makeHelpMsgHeader( $module, $type ); 00113 00114 $msg2 = $module->makeHelpMsg(); 00115 if ( $msg2 !== false ) { 00116 $msg .= $msg2; 00117 } 00118 00119 return $msg; 00120 } 00121 00122 public function shouldCheckMaxlag() { 00123 return false; 00124 } 00125 00126 public function isReadMode() { 00127 return false; 00128 } 00129 00130 public function getAllowedParams() { 00131 return array( 00132 'modules' => array( 00133 ApiBase::PARAM_ISMULTI => true 00134 ), 00135 'querymodules' => array( 00136 ApiBase::PARAM_ISMULTI => true, 00137 ApiBase::PARAM_DEPRECATED => true 00138 ), 00139 ); 00140 } 00141 00142 public function getParamDescription() { 00143 return array( 00144 'modules' => 'List of module names (value of the action= parameter). Can specify submodules with a \'+\'', 00145 'querymodules' => 'Use modules=query+value instead. List of query module names (value of prop=, meta= or list= parameter)', 00146 ); 00147 } 00148 00149 public function getDescription() { 00150 return 'Display this help screen. Or the help screen for the specified module'; 00151 } 00152 00153 public function getExamples() { 00154 return array( 00155 'api.php?action=help' => 'Whole help page', 00156 'api.php?action=help&modules=protect' => 'Module (action) help page', 00157 'api.php?action=help&modules=query+categorymembers' => 'Help for the query/categorymembers module', 00158 'api.php?action=help&modules=login|query+info' => 'Help for the login and query/info modules', 00159 ); 00160 } 00161 00162 public function getHelpUrls() { 00163 return array( 00164 'https://www.mediawiki.org/wiki/API:Main_page', 00165 'https://www.mediawiki.org/wiki/API:FAQ', 00166 'https://www.mediawiki.org/wiki/API:Quick_start_guide', 00167 ); 00168 } 00169 }