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 'submodules' => $request->getCheck( 'submodules' ),
46 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
47 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
48 ];
49
50 // These are for linking from wikitext, since url parameters are a pain
51 // to do.
52 while ( true ) {
53 if ( str_starts_with( $par, 'sub/' ) ) {
54 $par = substr( $par, 4 );
55 $options['submodules'] = 1;
56 continue;
57 }
58
59 if ( str_starts_with( $par, 'rsub/' ) ) {
60 $par = substr( $par, 5 );
61 $options['recursivesubmodules'] = 1;
62 continue;
63 }
64
65 $moduleName = $par;
66 break;
67 }
68 if ( !isset( $moduleName ) ) {
69 throw new LogicException( 'Module name should have been found' );
70 }
71
72 if ( !$this->including() ) {
73 unset( $options['nolead'], $options['title'] );
74 $options['modules'] = $moduleName;
75 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
76 $this->getOutput()->redirect( $link );
77 return;
78 }
79
80 $main = new ApiMain( $this->getContext(), false );
81 try {
82 $module = $main->getModuleFromPath( $moduleName );
83 } catch ( ApiUsageException ) {
84 $this->getOutput()->addHTML( Html::errorBox(
85 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
86 ) );
87 return;
88 }
89
90 ApiHelp::getHelp( $this->getContext(), $module, $options );
91 }
92
94 public function isIncludable() {
95 return true;
96 }
97}
98
100class_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:37
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:67
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.
__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