Debian Codegraph @

includes/specials/SpecialApiHelp.php

raw symbols SCIP
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Api\ApiHelp;
24 use MediaWiki\Api\ApiMain;
25 use MediaWiki\Api\ApiUsageException;
26 use MediaWiki\Html\Html;
27 use MediaWiki\SpecialPage\UnlistedSpecialPage;
28 use MediaWiki\Utils\UrlUtils;
29
30 /**
31 * Redirect to help pages served by api.php.
32 *
33 * For situations where linking to full api.php URLs is not wanted
34 * or not possible, e.g. in edit summaries.
35 *
36 * @ingroup SpecialPage
37 */
38 class SpecialApiHelp extends UnlistedSpecialPage {
39
40 private UrlUtils $urlUtils;
41
42 /**
43 * @param UrlUtils $urlUtils
44 */
45 public function __construct(
46 UrlUtils $urlUtils
47 ) {
48 parent::__construct( 'ApiHelp' );
49 $this->urlUtils = $urlUtils;
50 }
51
52 public function execute( $par ) {
53 if ( !$par ) {
54 $par = 'main';
55 }
56
57 // These come from transclusions
58 $request = $this->getRequest();
59 $options = [
60 'action' => 'help',
61 'nolead' => true,
62 'submodules' => $request->getCheck( 'submodules' ),
63 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
64 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
65 ];
66
67 // These are for linking from wikitext, since url parameters are a pain
68 // to do.
69 while ( true ) {
70 if ( str_starts_with( $par, 'sub/' ) ) {
71 $par = substr( $par, 4 );
72 $options['submodules'] = 1;
73 continue;
74 }
75
76 if ( str_starts_with( $par, 'rsub/' ) ) {
77 $par = substr( $par, 5 );
78 $options['recursivesubmodules'] = 1;
79 continue;
80 }
81
82 $moduleName = $par;
83 break;
84 }
85
86 if ( !$this->including() ) {
87 unset( $options['nolead'], $options['title'] );
88 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
89 $options['modules'] = $moduleName;
90 $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options );
91 $this->getOutput()->redirect( $link );
92 return;
93 }
94
95 $main = new ApiMain( $this->getContext(), false );
96 try {
97 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable,PhanPossiblyUndeclaredVariable False positive
98 $module = $main->getModuleFromPath( $moduleName );
99 } catch ( ApiUsageException $ex ) {
100 $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
101 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable False positive
102 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
103 ) );
104 return;
105 }
106
107 ApiHelp::getHelp( $this->getContext(), $module, $options );
108 }
109
110 public function isIncludable() {
111 return true;
112 }
113 }
114
115 /** @deprecated class alias since 1.41 */
116 class_alias( SpecialApiHelp::class, 'SpecialApiHelp' );