MediaWiki
REL1_19
|
00001 <?php 00032 class ApiHelp extends ApiBase { 00033 00034 public function __construct( $main, $action ) { 00035 parent::__construct( $main, $action ); 00036 } 00037 00041 public function execute() { 00042 // Get parameters 00043 $params = $this->extractRequestParams(); 00044 00045 if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) { 00046 $this->dieUsage( '', 'help' ); 00047 } 00048 00049 $this->getMain()->setHelp(); 00050 00051 $result = $this->getResult(); 00052 $queryObj = new ApiQuery( $this->getMain(), 'query' ); 00053 $r = array(); 00054 if ( is_array( $params['modules'] ) ) { 00055 $modArr = $this->getMain()->getModules(); 00056 00057 foreach ( $params['modules'] as $m ) { 00058 if ( !isset( $modArr[$m] ) ) { 00059 $r[] = array( 'name' => $m, 'missing' => '' ); 00060 continue; 00061 } 00062 $module = new $modArr[$m]( $this->getMain(), $m ); 00063 00064 $r[] = $this->buildModuleHelp( $module, 'action' ); 00065 } 00066 } 00067 00068 if ( is_array( $params['querymodules'] ) ) { 00069 $qmodArr = $queryObj->getModules(); 00070 00071 foreach ( $params['querymodules'] as $qm ) { 00072 if ( !isset( $qmodArr[$qm] ) ) { 00073 $r[] = array( 'name' => $qm, 'missing' => '' ); 00074 continue; 00075 } 00076 $module = new $qmodArr[$qm]( $this, $qm ); 00077 $type = $queryObj->getModuleType( $qm ); 00078 00079 if ( $type === null ) { 00080 $r[] = array( 'name' => $qm, 'missing' => '' ); 00081 continue; 00082 } 00083 00084 $r[] = $this->buildModuleHelp( $module, $type ); 00085 } 00086 } 00087 $result->setIndexedTagName( $r, 'module' ); 00088 $result->addValue( null, $this->getModuleName(), $r ); 00089 } 00090 00096 private function buildModuleHelp( $module, $type ) { 00097 $msg = ApiMain::makeHelpMsgHeader( $module, $type ); 00098 00099 $msg2 = $module->makeHelpMsg(); 00100 if ( $msg2 !== false ) { 00101 $msg .= $msg2; 00102 } 00103 00104 return $msg; 00105 } 00106 00107 public function shouldCheckMaxlag() { 00108 return false; 00109 } 00110 00111 public function isReadMode() { 00112 return false; 00113 } 00114 00115 public function getAllowedParams() { 00116 return array( 00117 'modules' => array( 00118 ApiBase::PARAM_ISMULTI => true 00119 ), 00120 'querymodules' => array( 00121 ApiBase::PARAM_ISMULTI => true 00122 ), 00123 ); 00124 } 00125 00126 public function getParamDescription() { 00127 return array( 00128 'modules' => 'List of module names (value of the action= parameter)', 00129 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)', 00130 ); 00131 } 00132 00133 public function getDescription() { 00134 return 'Display this help screen. Or the help screen for the specified module'; 00135 } 00136 00137 public function getExamples() { 00138 return array( 00139 'api.php?action=help' => 'Whole help page', 00140 'api.php?action=help&modules=protect' => 'Module (action) help page', 00141 'api.php?action=help&querymodules=categorymembers' => 'Query (list) modules help page', 00142 'api.php?action=help&querymodules=info' => 'Query (prop) modules help page', 00143 'api.php?action=help&querymodules=siteinfo' => 'Query (meta) modules help page', 00144 ); 00145 } 00146 00147 public function getHelpUrls() { 00148 return array( 00149 'https://www.mediawiki.org/wiki/API:Main_page', 00150 'https://www.mediawiki.org/wiki/API:FAQ', 00151 'https://www.mediawiki.org/wiki/API:Quick_start_guide', 00152 ); 00153 } 00154 00155 public function getVersion() { 00156 return __CLASS__ . ': $Id$'; 00157 } 00158 }