MediaWiki master
SpecialApiHelp.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
26use ApiHelp;
27use ApiMain;
32
40
41 private UrlUtils $urlUtils;
42
46 public function __construct(
47 UrlUtils $urlUtils
48 ) {
49 parent::__construct( 'ApiHelp' );
50 $this->urlUtils = $urlUtils;
51 }
52
53 public function execute( $par ) {
54 if ( !$par ) {
55 $par = 'main';
56 }
57
58 // These come from transclusions
59 $request = $this->getRequest();
60 $options = [
61 'action' => 'help',
62 'nolead' => true,
63 'submodules' => $request->getCheck( 'submodules' ),
64 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
65 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
66 ];
67
68 // These are for linking from wikitext, since url parameters are a pain
69 // to do.
70 while ( true ) {
71 if ( str_starts_with( $par, 'sub/' ) ) {
72 $par = substr( $par, 4 );
73 $options['submodules'] = 1;
74 continue;
75 }
76
77 if ( str_starts_with( $par, 'rsub/' ) ) {
78 $par = substr( $par, 5 );
79 $options['recursivesubmodules'] = 1;
80 continue;
81 }
82
83 $moduleName = $par;
84 break;
85 }
86
87 if ( !$this->including() ) {
88 unset( $options['nolead'], $options['title'] );
89 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
90 $options['modules'] = $moduleName;
91 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
92 $this->getOutput()->redirect( $link );
93 return;
94 }
95
96 $main = new ApiMain( $this->getContext(), false );
97 try {
98 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable,PhanPossiblyUndeclaredVariable False positive
99 $module = $main->getModuleFromPath( $moduleName );
100 } catch ( ApiUsageException $ex ) {
101 $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
102 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
103 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
104 ) );
105 return;
106 }
107
108 ApiHelp::getHelp( $this->getContext(), $module, $options );
109 }
110
111 public function isIncludable() {
112 return true;
113 }
114}
115
117class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );
const PROTO_CURRENT
Definition Defines.php:207
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
Class to output help for an API module.
Definition ApiHelp.php:46
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition ApiHelp.php:142
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:65
Exception used to abort API execution with an error.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
getPageTitle( $subpage=false)
Get a self-referential title object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
including( $x=null)
Whether the special page is being evaluated via transclusion.
Shortcut to construct a special page which is unlisted by default.
Special page to redirect to API help pages, for situations where linking to the api....
execute( $par)
Default execute method Checks user permissions.
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...