MediaWiki master
SpecialApiHelp.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use LogicException;
16
26
27 public function __construct(
28 private readonly UrlUtils $urlUtils
29 ) {
30 parent::__construct( 'ApiHelp' );
31 }
32
34 public function execute( $par ) {
35 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
36 if ( !$par ) {
37 $par = 'main';
38 }
39
40 // These come from transclusions
41 $request = $this->getRequest();
42 $options = [
43 'action' => 'help',
44 'nolead' => true,
45 'toc' => false,
46 'submodules' => $request->getCheck( 'submodules' ),
47 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
48 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
49 ];
50
51 // These are for linking from wikitext, since url parameters are a pain
52 // to do.
53 while ( true ) {
54 if ( str_starts_with( $par, 'sub/' ) ) {
55 $par = substr( $par, 4 );
56 $options['submodules'] = 1;
57 continue;
58 }
59
60 if ( str_starts_with( $par, 'rsub/' ) ) {
61 $par = substr( $par, 5 );
62 $options['recursivesubmodules'] = 1;
63 continue;
64 }
65
66 $moduleName = $par;
67 break;
68 }
69 if ( !isset( $moduleName ) ) {
70 throw new LogicException( 'Module name should have been found' );
71 }
72
73 if ( !$this->including() ) {
74 unset( $options['nolead'], $options['title'] );
75 $options['modules'] = $moduleName;
76 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
77 $this->getOutput()->redirect( $link );
78 return;
79 }
80
81 $main = new ApiMain( $this->getContext(), false );
82 try {
83 $module = $main->getModuleFromPath( $moduleName );
84 } catch ( ApiUsageException ) {
85 $this->getOutput()->addHTML( Html::errorBox(
86 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
87 ) );
88 return;
89 }
90
91 ApiHelp::getHelp( $this->getContext(), $module, $options );
92 }
93
98 public function isIncludable() {
99 return true;
100 }
101}
102
103// @codeCoverageIgnoreStart
105class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );
106// @codeCoverageIgnoreEnd
const PROTO_CURRENT
Definition Defines.php:222
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:39
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition ApiHelp.php:135
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:66
Exception used to abort API execution with an error.
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
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.
__construct(private readonly UrlUtils $urlUtils)
execute( $par)
Default execute method Checks user permissions.This must be overridden by subclasses; it will be made...
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.to override bool
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16