This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of Peachy MediaWiki Bot API |
||
5 | * |
||
6 | * Peachy is free software: you can redistribute it and/or modify |
||
7 | * it under the terms of the GNU General Public License as published by |
||
8 | * the Free Software Foundation, either version 3 of the License, or |
||
9 | * (at your option) any later version. |
||
10 | * |
||
11 | * This program is distributed in the hope that it will be useful, |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | * GNU General Public License for more details. |
||
15 | * |
||
16 | * You should have received a copy of the GNU General Public License |
||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | */ |
||
19 | |||
20 | class FlaggedRevs { |
||
21 | |||
22 | private $wiki; |
||
23 | |||
24 | /** |
||
25 | * @param Wiki $wikiClass |
||
26 | * @throws DependencyError |
||
27 | */ |
||
28 | function __construct( Wiki &$wikiClass ) { |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
__construct .
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with ![]() |
|||
29 | |||
30 | if( !array_key_exists( 'FlaggedRevs', $wikiClass->get_extensions() ) ) { |
||
31 | throw new DependencyError( "FlaggedRevs", "http://www.mediawiki.org/wiki/Extension:FlaggedRevs" ); |
||
0 ignored issues
–
show
'http://www.mediawiki.or.../Extension:FlaggedRevs' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
32 | } |
||
33 | |||
34 | $this->wiki = $wikiClass; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param $revid |
||
39 | * @param null $reason |
||
40 | * @param int $status |
||
41 | * @return bool |
||
42 | * @throws AssertFailure |
||
43 | * @throws BadEntryError |
||
44 | * @throws HookError |
||
45 | * @throws LoggedOut |
||
46 | * @throws MWAPIError |
||
47 | */ |
||
48 | public function review( $revid, $reason = null, $status = 1 ) { |
||
49 | |||
50 | if( !in_array( 'review', $this->wiki->get_userrights() ) ) { |
||
51 | pecho( "User is not allowed to review revisions", PECHO_FATAL ); |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | $tokens = $this->wiki->get_tokens(); |
||
56 | |||
57 | if( $tokens['edit'] == '+\\' ) { |
||
58 | pecho( "User has logged out.\n\n", PECHO_FATAL ); |
||
59 | return false; |
||
60 | } |
||
61 | |||
62 | if( mb_strlen( $reason, '8bit' ) > 255 ) { |
||
0 ignored issues
–
show
The call to
mb_strlen() has too many arguments starting with '8bit' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
63 | pecho( "Comment is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL ); |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | pecho( "Reviewing $revid...\n\n", PECHO_NOTICE ); |
||
68 | |||
69 | $editarray = array( |
||
70 | 'flag_accuracy' => $status, |
||
71 | 'action' => 'review', |
||
72 | 'token' => $tokens['edit'], |
||
73 | 'revid' => $revid |
||
74 | ); |
||
75 | |||
76 | if( !empty( $reason ) ) $editArray['comment'] = $reason; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$editArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $editArray = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
77 | |||
78 | if( $this->wiki->get_maxlag() ) { |
||
79 | $editarray['maxlag'] = $this->wiki->get_maxlag(); |
||
80 | } |
||
81 | |||
82 | Hooks::runHook( 'StartReview', array( &$editarray ) ); |
||
83 | |||
84 | $result = $this->wiki->apiQuery( $editarray, true ); |
||
85 | |||
86 | if( isset( $result['review'] ) ) { |
||
87 | if( isset( $result['review']['revid'] ) ) { |
||
88 | return true; |
||
89 | } else { |
||
90 | pecho( "Review error...\n\n" . print_r( $result['review'], true ) . "\n\n", PECHO_FATAL ); |
||
91 | return false; |
||
92 | } |
||
93 | } else { |
||
94 | pecho( "Review error...\n\n" . print_r( $result, true ), PECHO_FATAL ); |
||
95 | return false; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param $title |
||
101 | * @param string $level |
||
102 | * @param null $reason |
||
103 | * @param bool|false $autoreview |
||
104 | * @param bool|false $watch |
||
105 | * @return bool |
||
106 | * @throws AssertFailure |
||
107 | * @throws BadEntryError |
||
108 | * @throws HookError |
||
109 | * @throws LoggedOut |
||
110 | * @throws MWAPIError |
||
111 | */ |
||
112 | public function stabilize( $title, $level = 'none', $reason = null, $autoreview = false, $watch = false ) { |
||
0 ignored issues
–
show
|
|||
113 | |||
114 | if( !in_array( 'stablesettings', $this->wiki->get_userrights() ) ) { |
||
115 | pecho( "User is not allowed to change the stabilization settings", PECHO_FATAL ); |
||
116 | return false; |
||
117 | } |
||
118 | |||
119 | $tokens = $this->wiki->get_tokens(); |
||
120 | |||
121 | if( $tokens['edit'] == '+\\' ) { |
||
122 | pecho( "User has logged out.\n\n", PECHO_FATAL ); |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | if( mb_strlen( $reason, '8bit' ) > 255 ) { |
||
0 ignored issues
–
show
The call to
mb_strlen() has too many arguments starting with '8bit' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
127 | pecho( "Comment is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL ); |
||
128 | return false; |
||
129 | } |
||
130 | |||
131 | pecho( "Stabilizing title...\n\n", PECHO_NOTICE ); |
||
132 | |||
133 | $editarray = array( |
||
134 | 'action' => 'review', |
||
135 | 'title' => $title, |
||
136 | 'token' => $tokens['edit'], |
||
137 | 'protectlevel' => $level |
||
138 | ); |
||
139 | |||
140 | if( $watch ) $editArray['watch'] = 'yes'; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$editArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $editArray = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
141 | if( !empty( $reason ) ) $editArray['reason'] = $reason; |
||
0 ignored issues
–
show
The variable
$editArray does not seem to be defined for all execution paths leading up to this point.
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: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
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
![]() |
|||
142 | |||
143 | if( $this->wiki->get_maxlag() ) { |
||
144 | $editarray['maxlag'] = $this->wiki->get_maxlag(); |
||
145 | } |
||
146 | |||
147 | Hooks::runHook( 'StartStabilize', array( &$editarray ) ); |
||
148 | |||
149 | $result = $this->wiki->apiQuery( $editarray, true ); |
||
150 | |||
151 | if( isset( $result['stabilize'] ) ) { |
||
152 | if( isset( $result['stabilize']['title'] ) ) { |
||
153 | return true; |
||
154 | } else { |
||
155 | pecho( "Stabilization error...\n\n" . print_r( $result['stabilize'], true ) . "\n\n", PECHO_FATAL ); |
||
156 | return false; |
||
157 | } |
||
158 | } else { |
||
159 | pecho( "Stabilization error...\n\n" . print_r( $result, true ), PECHO_FATAL ); |
||
160 | return false; |
||
161 | } |
||
162 | |||
163 | } |
||
164 | |||
165 | public function flagconfig() { } |
||
166 | |||
167 | public function reviewedpages() { } |
||
168 | |||
169 | public function unreviewedpages() { } |
||
170 | |||
171 | public function oldreviewedpages() { } |
||
172 | |||
173 | } |
||
174 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.