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