MediaWiki master
SpecialApiHelp.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
23use LogicException;
30
40
41 private UrlUtils $urlUtils;
42
43 public function __construct(
44 UrlUtils $urlUtils
45 ) {
46 parent::__construct( 'ApiHelp' );
47 $this->urlUtils = $urlUtils;
48 }
49
50 public function execute( $par ) {
51 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
52 if ( !$par ) {
53 $par = 'main';
54 }
55
56 // These come from transclusions
57 $request = $this->getRequest();
58 $options = [
59 'action' => 'help',
60 'nolead' => true,
61 'submodules' => $request->getCheck( 'submodules' ),
62 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
63 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
64 ];
65
66 // These are for linking from wikitext, since url parameters are a pain
67 // to do.
68 while ( true ) {
69 if ( str_starts_with( $par, 'sub/' ) ) {
70 $par = substr( $par, 4 );
71 $options['submodules'] = 1;
72 continue;
73 }
74
75 if ( str_starts_with( $par, 'rsub/' ) ) {
76 $par = substr( $par, 5 );
77 $options['recursivesubmodules'] = 1;
78 continue;
79 }
80
81 $moduleName = $par;
82 break;
83 }
84 if ( !isset( $moduleName ) ) {
85 throw new LogicException( 'Module name should have been found' );
86 }
87
88 if ( !$this->including() ) {
89 unset( $options['nolead'], $options['title'] );
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 $module = $main->getModuleFromPath( $moduleName );
99 } catch ( ApiUsageException $ex ) {
100 $this->getOutput()->addHTML( Html::errorBox(
101 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
102 ) );
103 return;
104 }
105
106 ApiHelp::getHelp( $this->getContext(), $module, $options );
107 }
108
109 public function isIncludable() {
110 return true;
111 }
112}
113
115class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );
const PROTO_CURRENT
Definition Defines.php:215
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:143
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