[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/api/ -> ApiHelp.php (source)

   1  <?php
   2  /**
   3   *
   4   *
   5   * Created on Sep 6, 2006
   6   *
   7   * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
   8   *
   9   * This program is free software; you can redistribute it and/or modify
  10   * it under the terms of the GNU General Public License as published by
  11   * the Free Software Foundation; either version 2 of the License, or
  12   * (at your option) any later version.
  13   *
  14   * This program is distributed in the hope that it will be useful,
  15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17   * GNU General Public License for more details.
  18   *
  19   * You should have received a copy of the GNU General Public License along
  20   * with this program; if not, write to the Free Software Foundation, Inc.,
  21   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22   * http://www.gnu.org/copyleft/gpl.html
  23   *
  24   * @file
  25   */
  26  
  27  /**
  28   * This is a simple class to handle action=help
  29   *
  30   * @ingroup API
  31   */
  32  class ApiHelp extends ApiBase {
  33      /**
  34       * Module for displaying help
  35       */
  36  	public function execute() {
  37          // Get parameters
  38          $params = $this->extractRequestParams();
  39  
  40          if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
  41              $this->dieUsage( '', 'help' );
  42          }
  43  
  44          $this->getMain()->setHelp();
  45          $result = $this->getResult();
  46  
  47          if ( is_array( $params['modules'] ) ) {
  48              $modules = $params['modules'];
  49          } else {
  50              $modules = array();
  51          }
  52  
  53          if ( is_array( $params['querymodules'] ) ) {
  54              $this->logFeatureUsage( 'action=help&querymodules' );
  55              $queryModules = $params['querymodules'];
  56              foreach ( $queryModules as $m ) {
  57                  $modules[] = 'query+' . $m;
  58              }
  59          } else {
  60              $queryModules = array();
  61          }
  62  
  63          $r = array();
  64          foreach ( $modules as $m ) {
  65              // sub-modules could be given in the form of "name[+name[+name...]]"
  66              $subNames = explode( '+', $m );
  67              if ( count( $subNames ) === 1 ) {
  68                  // In case the '+' was typed into URL, it resolves as a space
  69                  $subNames = explode( ' ', $m );
  70              }
  71  
  72              $module = $this->getMain();
  73              $subNamesCount = count( $subNames );
  74              for ( $i = 0; $i < $subNamesCount; $i++ ) {
  75                  $subs = $module->getModuleManager();
  76                  if ( $subs === null ) {
  77                      $module = null;
  78                  } else {
  79                      $module = $subs->getModule( $subNames[$i] );
  80                  }
  81  
  82                  if ( $module === null ) {
  83                      if ( count( $subNames ) === 2
  84                          && $i === 1
  85                          && $subNames[0] === 'query'
  86                          && in_array( $subNames[1], $queryModules )
  87                      ) {
  88                          // Legacy: This is one of the renamed 'querymodule=...' parameters,
  89                          // do not use '+' notation in the output, use submodule's name instead.
  90                          $name = $subNames[1];
  91                      } else {
  92                          $name = implode( '+', array_slice( $subNames, 0, $i + 1 ) );
  93                      }
  94                      $r[] = array( 'name' => $name, 'missing' => '' );
  95                      break;
  96                  } else {
  97                      $type = $subs->getModuleGroup( $subNames[$i] );
  98                  }
  99              }
 100  
 101              if ( $module !== null ) {
 102                  $r[] = $this->buildModuleHelp( $module, $type );
 103              }
 104          }
 105  
 106          $result->setIndexedTagName( $r, 'module' );
 107          $result->addValue( null, $this->getModuleName(), $r );
 108      }
 109  
 110      /**
 111       * @param ApiBase $module
 112       * @param string $type What type of request is this? e.g. action, query, list, prop, meta, format
 113       * @return string
 114       */
 115  	private function buildModuleHelp( $module, $type ) {
 116          $msg = ApiMain::makeHelpMsgHeader( $module, $type );
 117  
 118          $msg2 = $module->makeHelpMsg();
 119          if ( $msg2 !== false ) {
 120              $msg .= $msg2;
 121          }
 122  
 123          return $msg;
 124      }
 125  
 126  	public function shouldCheckMaxlag() {
 127          return false;
 128      }
 129  
 130  	public function isReadMode() {
 131          return false;
 132      }
 133  
 134  	public function getAllowedParams() {
 135          return array(
 136              'modules' => array(
 137                  ApiBase::PARAM_ISMULTI => true
 138              ),
 139              'querymodules' => array(
 140                  ApiBase::PARAM_ISMULTI => true,
 141                  ApiBase::PARAM_DEPRECATED => true
 142              ),
 143          );
 144      }
 145  
 146  	public function getParamDescription() {
 147          return array(
 148              'modules' => 'List of module names (value of the action= parameter). ' .
 149                  'Can specify submodules with a \'+\'',
 150              'querymodules' => 'Use modules=query+value instead. List of query ' .
 151                  'module names (value of prop=, meta= or list= parameter)',
 152          );
 153      }
 154  
 155  	public function getDescription() {
 156          return 'Display this help screen. Or the help screen for the specified module.';
 157      }
 158  
 159  	public function getExamples() {
 160          return array(
 161              'api.php?action=help' => 'Whole help page',
 162              'api.php?action=help&modules=protect' => 'Module (action) help page',
 163              'api.php?action=help&modules=query+categorymembers'
 164                  => 'Help for the query/categorymembers module',
 165              'api.php?action=help&modules=login|query+info'
 166                  => 'Help for the login and query/info modules',
 167          );
 168      }
 169  
 170  	public function getHelpUrls() {
 171          return array(
 172              'https://www.mediawiki.org/wiki/API:Main_page',
 173              'https://www.mediawiki.org/wiki/API:FAQ',
 174              'https://www.mediawiki.org/wiki/API:Quick_start_guide',
 175          );
 176      }
 177  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1