MediaWiki master
SpecialApiHelp.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
29
39
40 private UrlUtils $urlUtils;
41
45 public function __construct(
46 UrlUtils $urlUtils
47 ) {
48 parent::__construct( 'ApiHelp' );
49 $this->urlUtils = $urlUtils;
50 }
51
52 public function execute( $par ) {
53 if ( !$par ) {
54 $par = 'main';
55 }
56
57 // These come from transclusions
58 $request = $this->getRequest();
59 $options = [
60 'action' => 'help',
61 'nolead' => true,
62 'submodules' => $request->getCheck( 'submodules' ),
63 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
64 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
65 ];
66
67 // These are for linking from wikitext, since url parameters are a pain
68 // to do.
69 while ( true ) {
70 if ( str_starts_with( $par, 'sub/' ) ) {
71 $par = substr( $par, 4 );
72 $options['submodules'] = 1;
73 continue;
74 }
75
76 if ( str_starts_with( $par, 'rsub/' ) ) {
77 $par = substr( $par, 5 );
78 $options['recursivesubmodules'] = 1;
79 continue;
80 }
81
82 $moduleName = $par;
83 break;
84 }
85
86 if ( !$this->including() ) {
87 unset( $options['nolead'], $options['title'] );
88 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
89 $options['modules'] = $moduleName;
90 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
91 $this->getOutput()->redirect( $link );
92 return;
93 }
94
95 $main = new ApiMain( $this->getContext(), false );
96 try {
97 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable,PhanPossiblyUndeclaredVariable False positive
98 $module = $main->getModuleFromPath( $moduleName );
99 } catch ( ApiUsageException $ex ) {
100 $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
101 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
102 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
103 ) );
104 return;
105 }
106
107 ApiHelp::getHelp( $this->getContext(), $module, $options );
108 }
109
110 public function isIncludable() {
111 return true;
112 }
113}
114
116class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );
const PROTO_CURRENT
Definition Defines.php:209
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:52
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition ApiHelp.php:148
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:78
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.
Redirect to help pages served by api.php.
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