1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Implements Special:ApiHelp |
4
|
|
|
* |
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along |
16
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
17
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
19
|
|
|
* |
20
|
|
|
* @file |
21
|
|
|
* @ingroup SpecialPage |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Special page to redirect to API help pages, for situations where linking to |
26
|
|
|
* the api.php endpoint is not wanted. |
27
|
|
|
* |
28
|
|
|
* @ingroup SpecialPage |
29
|
|
|
*/ |
30
|
|
|
class SpecialApiHelp extends UnlistedSpecialPage { |
31
|
|
|
public function __construct() { |
32
|
|
|
parent::__construct( 'ApiHelp' ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function execute( $par ) { |
36
|
|
|
if ( empty( $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 ( substr( $par, 0, 4 ) === 'sub/' ) { |
54
|
|
|
$par = substr( $par, 4 ); |
55
|
|
|
$options['submodules'] = 1; |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ( substr( $par, 0, 5 ) === 'rsub/' ) { |
60
|
|
|
$par = substr( $par, 5 ); |
61
|
|
|
$options['recursivesubmodules'] = 1; |
62
|
|
|
continue; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$moduleName = $par; |
66
|
|
|
break; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ( !$this->including() ) { |
70
|
|
|
unset( $options['nolead'], $options['title'] ); |
71
|
|
|
$options['modules'] = $moduleName; |
|
|
|
|
72
|
|
|
$link = wfAppendQuery( wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ), $options ); |
|
|
|
|
73
|
|
|
$this->getOutput()->redirect( $link ); |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$main = new ApiMain( $this->getContext(), false ); |
78
|
|
|
try { |
79
|
|
|
$module = $main->getModuleFromPath( $moduleName ); |
80
|
|
|
} catch ( UsageException $ex ) { |
81
|
|
|
$this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ], |
82
|
|
|
$this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse() |
83
|
|
|
) ); |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
ApiHelp::getHelp( $this->getContext(), $module, $options ); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function isIncludable() { |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: