MediaWiki  master
SpecialApiHelp.php
Go to the documentation of this file.
1 <?php
31  public function __construct() {
32  parent::__construct( 'ApiHelp' );
33  }
34 
35  public function execute( $par ) {
36  if ( empty( $par ) ) {
37  $par = 'main';
38  }
39 
40  // These come from transclusions
41  $request = $this->getRequest();
42  $options = [
43  'action' => 'help',
44  'nolead' => true,
45  'submodules' => $request->getCheck( 'submodules' ),
46  'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
47  'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
48  ];
49 
50  // These are for linking from wikitext, since url parameters are a pain
51  // to do.
52  while ( true ) {
53  if ( substr( $par, 0, 4 ) === 'sub/' ) {
54  $par = substr( $par, 4 );
55  $options['submodules'] = 1;
56  continue;
57  }
58 
59  if ( substr( $par, 0, 5 ) === 'rsub/' ) {
60  $par = substr( $par, 5 );
61  $options['recursivesubmodules'] = 1;
62  continue;
63  }
64 
65  $moduleName = $par;
66  break;
67  }
68 
69  if ( !$this->including() ) {
70  unset( $options['nolead'], $options['title'] );
71  $options['modules'] = $moduleName;
72  $link = wfAppendQuery( wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ), $options );
73  $this->getOutput()->redirect( $link );
74  return;
75  }
76 
77  $main = new ApiMain( $this->getContext(), false );
78  try {
79  $module = $main->getModuleFromPath( $moduleName );
80  } catch ( ApiUsageException $ex ) {
81  $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
82  $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
83  ) );
84  return;
85  }
86 
87  ApiHelp::getHelp( $this->getContext(), $module, $options );
88  }
89 
90  public function isIncludable() {
91  return true;
92  }
93 }
Shortcut to construct a special page which is unlisted by default.
getContext()
Gets the context this SpecialPage is executed in.
including( $x=null)
Whether the special page is being evaluated via transclusion.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Exception used to abort API execution with an error.
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
const PROTO_CURRENT
Definition: Defines.php:202
getOutput()
Get the OutputPage being used for this instance.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:42
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition: ApiHelp.php:112
Special page to redirect to API help pages, for situations where linking to the api.php endpoint is not wanted.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.