MediaWiki master
SpecialApiHelp.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use LogicException;
16
26
27 private UrlUtils $urlUtils;
28
29 public function __construct(
30 UrlUtils $urlUtils
31 ) {
32 parent::__construct( 'ApiHelp' );
33 $this->urlUtils = $urlUtils;
34 }
35
37 public function execute( $par ) {
38 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
39 if ( !$par ) {
40 $par = 'main';
41 }
42
43 // These come from transclusions
44 $request = $this->getRequest();
45 $options = [
46 'action' => 'help',
47 'nolead' => true,
48 'submodules' => $request->getCheck( 'submodules' ),
49 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
50 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
51 ];
52
53 // These are for linking from wikitext, since url parameters are a pain
54 // to do.
55 while ( true ) {
56 if ( str_starts_with( $par, 'sub/' ) ) {
57 $par = substr( $par, 4 );
58 $options['submodules'] = 1;
59 continue;
60 }
61
62 if ( str_starts_with( $par, 'rsub/' ) ) {
63 $par = substr( $par, 5 );
64 $options['recursivesubmodules'] = 1;
65 continue;
66 }
67
68 $moduleName = $par;
69 break;
70 }
71 if ( !isset( $moduleName ) ) {
72 throw new LogicException( 'Module name should have been found' );
73 }
74
75 if ( !$this->including() ) {
76 unset( $options['nolead'], $options['title'] );
77 $options['modules'] = $moduleName;
78 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
79 $this->getOutput()->redirect( $link );
80 return;
81 }
82
83 $main = new ApiMain( $this->getContext(), false );
84 try {
85 $module = $main->getModuleFromPath( $moduleName );
86 } catch ( ApiUsageException ) {
87 $this->getOutput()->addHTML( Html::errorBox(
88 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
89 ) );
90 return;
91 }
92
93 ApiHelp::getHelp( $this->getContext(), $module, $options );
94 }
95
97 public function isIncludable() {
98 return true;
99 }
100}
101
103class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );
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:35
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition ApiHelp.php:126
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:43
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.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