Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specials / SpecialApiHelp.php
blob0c4f55d52f59ee10274dcc59cce850c28b5a3f63
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\Specials;
23 use LogicException;
24 use MediaWiki\Api\ApiHelp;
25 use MediaWiki\Api\ApiMain;
26 use MediaWiki\Api\ApiUsageException;
27 use MediaWiki\Html\Html;
28 use MediaWiki\SpecialPage\UnlistedSpecialPage;
29 use MediaWiki\Utils\UrlUtils;
31 /**
32 * Redirect to help pages served by api.php.
34 * For situations where linking to full api.php URLs is not wanted
35 * or not possible, e.g. in edit summaries.
37 * @ingroup SpecialPage
39 class SpecialApiHelp extends UnlistedSpecialPage {
41 private UrlUtils $urlUtils;
43 /**
44 * @param UrlUtils $urlUtils
46 public function __construct(
47 UrlUtils $urlUtils
48 ) {
49 parent::__construct( 'ApiHelp' );
50 $this->urlUtils = $urlUtils;
53 public function execute( $par ) {
54 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
55 if ( !$par ) {
56 $par = 'main';
59 // These come from transclusions
60 $request = $this->getRequest();
61 $options = [
62 'action' => 'help',
63 'nolead' => true,
64 'submodules' => $request->getCheck( 'submodules' ),
65 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
66 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
69 // These are for linking from wikitext, since url parameters are a pain
70 // to do.
71 while ( true ) {
72 if ( str_starts_with( $par, 'sub/' ) ) {
73 $par = substr( $par, 4 );
74 $options['submodules'] = 1;
75 continue;
78 if ( str_starts_with( $par, 'rsub/' ) ) {
79 $par = substr( $par, 5 );
80 $options['recursivesubmodules'] = 1;
81 continue;
84 $moduleName = $par;
85 break;
87 if ( !isset( $moduleName ) ) {
88 throw new LogicException( 'Module name should have been found' );
91 if ( !$this->including() ) {
92 unset( $options['nolead'], $options['title'] );
93 $options['modules'] = $moduleName;
94 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
95 $this->getOutput()->redirect( $link );
96 return;
99 $main = new ApiMain( $this->getContext(), false );
100 try {
101 $module = $main->getModuleFromPath( $moduleName );
102 } catch ( ApiUsageException $ex ) {
103 $this->getOutput()->addHTML( Html::errorBox(
104 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
105 ) );
106 return;
109 ApiHelp::getHelp( $this->getContext(), $module, $options );
112 public function isIncludable() {
113 return true;
117 /** @deprecated class alias since 1.41 */
118 class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );