Index: trunk/extensions/CheckUser/CheckUser_body.php |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | $form .= ' ' . $this->getPeriodMenu( $period ) . '</td>'; |
178 | 178 | $form .= '</tr><tr>'; |
179 | 179 | $form .= '<td></td>'; |
180 | | - $form .= Xml::openElement('td', array( 'class' => 'checkuserradios' ) ); |
| 180 | + $form .= Xml::openElement( 'td', array( 'class' => 'checkuserradios' ) ); |
181 | 181 | $form .= Xml::openElement( 'table', array( 'style' => 'border:0' ) ); |
182 | 182 | $form .= '<tr>'; |
183 | 183 | $form .= '<td>' . |
— | — | @@ -278,18 +278,18 @@ |
279 | 279 | $counter = $blockSize = 0; |
280 | 280 | $safeUsers = array(); |
281 | 281 | $log = new LogPage( 'block' ); |
282 | | - foreach( $users as $name ) { |
| 282 | + foreach ( $users as $name ) { |
283 | 283 | # Enforce limits |
284 | 284 | $counter++; |
285 | 285 | $blockSize++; |
286 | 286 | # Lets not go *too* fast |
287 | | - if( $blockSize >= 20 ) { |
| 287 | + if ( $blockSize >= 20 ) { |
288 | 288 | $blockSize = 0; |
289 | 289 | wfWaitForSlaves( 5 ); |
290 | 290 | } |
291 | 291 | $u = User::newFromName( $name, false ); |
292 | 292 | // If user doesn't exist, it ought to be an IP then |
293 | | - if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) { |
| 293 | + if ( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) { |
294 | 294 | continue; |
295 | 295 | } |
296 | 296 | $userTitle = $u->getUserPage(); |
— | — | @@ -314,12 +314,12 @@ |
315 | 315 | $block->prevents( 'editownusertalk', false ); |
316 | 316 | |
317 | 317 | $oldblock = Block::newFromTarget( $u->getName() ); |
318 | | - if( !$oldblock ) { |
| 318 | + if ( !$oldblock ) { |
319 | 319 | $block->insert(); |
320 | 320 | # Prepare log parameters |
321 | 321 | $logParams = array(); |
322 | 322 | $logParams[] = $expirestr; |
323 | | - if( $anonOnly ) { |
| 323 | + if ( $anonOnly ) { |
324 | 324 | $logParams[] = 'anononly'; |
325 | 325 | } |
326 | 326 | $logParams[] = 'nocreate'; |
— | — | @@ -327,10 +327,10 @@ |
328 | 328 | $log->addEntry( 'block', $userTitle, $reason, $logParams ); |
329 | 329 | } |
330 | 330 | # Tag userpage! (check length to avoid mistakes) |
331 | | - if( strlen( $tag ) > 2 ) { |
| 331 | + if ( strlen( $tag ) > 2 ) { |
332 | 332 | $userpage->doEdit( $tag, $reason, EDIT_MINOR ); |
333 | 333 | } |
334 | | - if( strlen( $talkTag ) > 2 ) { |
| 334 | + if ( strlen( $talkTag ) > 2 ) { |
335 | 335 | $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR ); |
336 | 336 | } |
337 | 337 | } |
— | — | @@ -648,9 +648,9 @@ |
649 | 649 | $ret = $dbr->select( |
650 | 650 | 'cu_changes', |
651 | 651 | array( |
652 | | - 'cuc_namespace','cuc_title', 'cuc_user', 'cuc_user_text', 'cuc_comment', 'cuc_actiontext', |
| 652 | + 'cuc_namespace', 'cuc_title', 'cuc_user', 'cuc_user_text', 'cuc_comment', 'cuc_actiontext', |
653 | 653 | 'cuc_timestamp', 'cuc_minor', 'cuc_page_id', 'cuc_type', 'cuc_this_oldid', |
654 | | - 'cuc_last_oldid', 'cuc_ip', 'cuc_xff','cuc_agent' |
| 654 | + 'cuc_last_oldid', 'cuc_ip', 'cuc_xff', 'cuc_agent' |
655 | 655 | ), |
656 | 656 | array( $ip_conds, $time_conds ), |
657 | 657 | __METHOD__, |
— | — | @@ -956,7 +956,7 @@ |
957 | 957 | $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n"; |
958 | 958 | } else { |
959 | 959 | global $wgAuth; |
960 | | - foreach( $ret as $row ) { |
| 960 | + foreach ( $ret as $row ) { |
961 | 961 | if ( !array_key_exists( $row->cuc_user_text, $users_edits ) ) { |
962 | 962 | $users_last[$row->cuc_user_text] = $row->cuc_timestamp; |
963 | 963 | $users_edits[$row->cuc_user_text] = 0; |
Index: trunk/extensions/CheckUser/maintenance/purgeOldData.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
4 | 4 | $IP = getenv( 'MW_INSTALL_PATH' ); |
5 | 5 | } else { |
6 | | - $IP = dirname(__FILE__).'/../../..'; |
| 6 | + $IP = dirname( __FILE__ ) . '/../../..'; |
7 | 7 | } |
8 | 8 | require_once( "$IP/maintenance/Maintenance.php" ); |
9 | 9 | |
Index: trunk/extensions/CheckUser/CheckUser.hooks.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | */ |
8 | 8 | public static function updateCheckUserData( RecentChange $rc ) { |
9 | 9 | global $wgRequest, $wgCUDMaxAge; |
10 | | - |
| 10 | + |
11 | 11 | // Extract params |
12 | 12 | extract( $rc->mAttribs ); |
13 | 13 | // Get IP |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | } else { |
30 | 30 | $actionText = ''; |
31 | 31 | } |
32 | | - |
| 32 | + |
33 | 33 | $dbw = wfGetDB( DB_MASTER ); |
34 | 34 | $cuc_id = $dbw->nextSequenceValue( 'cu_changes_cu_id_seq' ); |
35 | 35 | $rcRow = array( |
— | — | @@ -61,17 +61,17 @@ |
62 | 62 | $encCutoff = $dbw->addQuotes( $dbw->timestamp( time() - $wgCUDMaxAge ) ); |
63 | 63 | $dbw->delete( 'cu_changes', array( "cuc_timestamp < $encCutoff" ), __METHOD__ ); |
64 | 64 | } |
65 | | - |
| 65 | + |
66 | 66 | return true; |
67 | 67 | } |
68 | | - |
| 68 | + |
69 | 69 | /** |
70 | 70 | * Hook function to store password reset |
71 | 71 | * Saves user data into the cu_changes table |
72 | 72 | */ |
73 | 73 | public static function updateCUPasswordResetData( User $user, $ip, $account ) { |
74 | 74 | global $wgRequest; |
75 | | - |
| 75 | + |
76 | 76 | // Get XFF header |
77 | 77 | $xff = $wgRequest->getHeader( 'X-Forwarded-For' ); |
78 | 78 | list( $xff_ip, $isSquidOnly ) = self::getClientIPfromXFF( $xff ); |
— | — | @@ -99,10 +99,10 @@ |
100 | 100 | 'cuc_agent' => $agent |
101 | 101 | ); |
102 | 102 | $dbw->insert( 'cu_changes', $rcRow, __METHOD__ ); |
103 | | - |
| 103 | + |
104 | 104 | return true; |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | /** |
108 | 108 | * Hook function to store email data |
109 | 109 | * Saves user data into the cu_changes table |
— | — | @@ -144,10 +144,10 @@ |
145 | 145 | 'cuc_agent' => $agent |
146 | 146 | ); |
147 | 147 | $dbw->insert( 'cu_changes', $rcRow, __METHOD__ ); |
148 | | - |
| 148 | + |
149 | 149 | return true; |
150 | 150 | } |
151 | | - |
| 151 | + |
152 | 152 | /** |
153 | 153 | * Hook function to store autocreation data from the auth plugin |
154 | 154 | * Saves user data into the cu_changes table |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | public static function updateAutoCreateData( User $user ) { |
161 | 161 | return self::logUserAccountCreation( $user, 'checkuser-autocreate-action' ); |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | /** |
165 | 165 | * @param $user User |
166 | 166 | * @param $actiontext string |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | */ |
169 | 169 | public static function logUserAccountCreation( User $user, $actiontext ) { |
170 | 170 | global $wgRequest; |
171 | | - |
| 171 | + |
172 | 172 | // Get IP |
173 | 173 | $ip = wfGetIP(); |
174 | 174 | // Get XFF header |
— | — | @@ -198,10 +198,10 @@ |
199 | 199 | 'cuc_agent' => $agent |
200 | 200 | ); |
201 | 201 | $dbw->insert( 'cu_changes', $rcRow, __METHOD__ ); |
202 | | - |
| 202 | + |
203 | 203 | return true; |
204 | 204 | } |
205 | | - |
| 205 | + |
206 | 206 | /** |
207 | 207 | * Hook function to store registration data |
208 | 208 | * Saves user data into the cu_changes table |
— | — | @@ -213,7 +213,7 @@ |
214 | 214 | public static function addNewAccount( User $user, $byEmail ) { |
215 | 215 | return self::logUserAccountCreation( $user, 'checkuser-create-action' ); |
216 | 216 | } |
217 | | - |
| 217 | + |
218 | 218 | /** |
219 | 219 | * Locates the client IP within a given XFF string |
220 | 220 | * @param string $xff |
— | — | @@ -287,7 +287,7 @@ |
288 | 288 | create_cu_log( $db ); |
289 | 289 | } |
290 | 290 | } |
291 | | - |
| 291 | + |
292 | 292 | /** |
293 | 293 | * Tell the parser test engine to create a stub cu_changes table, |
294 | 294 | * or temporary pages won't save correctly during the test run. |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | $tables[] = 'cu_changes'; |
298 | 298 | return true; |
299 | 299 | } |
300 | | - |
| 300 | + |
301 | 301 | /** |
302 | 302 | * Add a link to Special:CheckUser on Special:Contributions/<username> for |
303 | 303 | * privileged users. |
Index: trunk/extensions/CheckUser/CheckUser.php |
— | — | @@ -82,8 +82,8 @@ |
83 | 83 | $wgSpecialPages['CheckUser'] = 'CheckUser'; |
84 | 84 | $wgSpecialPageGroups['CheckUser'] = 'users'; |
85 | 85 | |
86 | | -$wgAutoloadClasses['CheckUser'] = dirname( __FILE__ ) . '/CheckUser_body.php'; |
87 | | -$wgAutoloadClasses['CheckUserHooks'] = dirname( __FILE__ ) . '/CheckUser.hooks.php'; |
| 86 | +$wgAutoloadClasses['CheckUser'] = $dir . '/CheckUser_body.php'; |
| 87 | +$wgAutoloadClasses['CheckUserHooks'] = $dir . '/CheckUser.hooks.php'; |
88 | 88 | |
89 | 89 | // API modules |
90 | 90 | $wgAutoloadClasses['ApiQueryCheckUser'] = "$dir/api/ApiQueryCheckUser.php"; |
Index: trunk/extensions/CheckUser/api/ApiQueryCheckUser.php |
— | — | @@ -1,271 +1,279 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * CheckUser API Query Module |
5 | 6 | */ |
6 | | - |
7 | 7 | class ApiQueryCheckUser extends ApiQueryBase { |
8 | | - public function __construct( $query, $moduleName ) { |
9 | | - parent::__construct( $query, $moduleName, 'cu' ); |
10 | | - } |
11 | | - |
12 | | - public function execute() { |
13 | | - global $wgUser, $wgCheckUserForceSummary; |
14 | | - |
15 | | - $db = $this->getDB( DB_SLAVE ); |
16 | | - $params = $this->extractRequestParams(); |
17 | | - |
18 | | - if( !$wgUser->isAllowed( 'checkuser' ) ) { |
19 | | - $this->dieUsage( 'You need the checkuser right', 'permissionerror' ); |
20 | | - } |
21 | | - |
22 | | - if( $wgCheckUserForceSummary && is_null($params['reason']) ) { |
23 | | - $this->dieUsage( 'You need define reason for check', 'missingdata' ); |
24 | | - } |
25 | | - |
26 | | - $limit = $params['limit']; |
27 | | - $target = $params['target']; |
28 | | - $reason = wfMsgForContent( 'checkuser-reason-api' ) . ' ' . $params['reason']; |
29 | | - $time = wfTimestamp( TS_MW, strtotime('now') - ( strtotime($params['timecond'] ? $params['timecond'] : '2 weeks') - strtotime('now'))); |
30 | | - if( !$time ) { |
31 | | - $this->dieUsage( 'You need use correct time limit (like "2 weeks")', 'invalidtime' ); |
32 | | - } |
33 | | - |
34 | | - $this->addTables( 'cu_changes' ); |
35 | | - $this->addOption( 'LIMIT', $limit + 1 ); |
36 | | - $this->addOption( 'ORDER BY', 'cuc_timestamp DESC' ); |
37 | | - $this->addWhere( "cuc_timestamp > $time" ); |
38 | | - |
39 | | - switch($params['request']) { |
40 | | - case 'userips': |
41 | | - $user_id = User::idFromName( $target ); |
42 | | - if( !$user_id ) { |
43 | | - $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); |
44 | | - } |
45 | | - |
46 | | - $this->addFields( array('cuc_timestamp', 'cuc_ip', 'cuc_xff') ); |
47 | | - $this->addWhere( "cuc_user_text = '$target'" ); |
48 | | - $res = $this->select( __METHOD__ ); |
49 | | - $result = $this->getResult(); |
50 | | - |
51 | | - $ips = array(); |
52 | | - foreach( $res as $row ) { |
53 | | - $timestamp = $row->cuc_timestamp; |
54 | | - $ip = strval($row->cuc_ip); |
55 | | - $xff = $row->cuc_xff; |
56 | | - |
57 | | - if( !isset( $ips[$ip] ) ) { |
58 | | - $ips[$ip]['end'] = $timestamp; |
59 | | - $ips[$ip]['editcount'] = 1; |
60 | | - } else { |
61 | | - $ips[$ip]['start'] = $timestamp; |
62 | | - $ips[$ip]['editcount']++; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - $count = 0; |
67 | | - foreach( array_keys($ips) as $ip ) { |
68 | | - $ips[$count] = $ips[$ip]; |
69 | | - $ips[$count]['address'] = $ip; |
70 | | - unset($ips[$ip]); |
71 | | - $count++; |
72 | | - } |
73 | | - |
74 | | - CheckUser::addLogEntry('userips', 'user', $target, $reason, $user_id); |
75 | | - $result->addValue( array( 'query', $this->getModuleName() ), 'userips', $ips ); |
76 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'userips' ), 'ip' ); |
77 | | - break; |
| 8 | + public function __construct( $query, $moduleName ) { |
| 9 | + parent::__construct( $query, $moduleName, 'cu' ); |
| 10 | + } |
78 | 11 | |
79 | | - case 'edits': |
80 | | - if( IP::isIPAddress($target) && isset($params['xff']) ) { |
81 | | - $cond = CheckUser::getIpConds($db, $target, true); |
82 | | - if( !$cond ) { |
83 | | - $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
84 | | - } |
85 | | - $this->addWhere( "$cond" ); |
86 | | - $log_type = array('ipedits-xff', 'ip'); |
87 | | - } elseif ( IP::isIPAddress($target) ) { |
88 | | - $cond = CheckUser::getIpConds($db, $target); |
89 | | - if( !$cond ) { |
90 | | - $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
91 | | - } |
92 | | - $this->addWhere( "$cond" ); |
93 | | - $log_type = array('ipedits', 'ip'); |
94 | | - } else { |
95 | | - $user_id = User::idFromName( $target ); |
96 | | - if( !$user_id ) { |
97 | | - $this->dieUsage( 'Target user is not exists', 'nosuchuser' ); |
98 | | - } |
99 | | - $this->addWhere( "cuc_user_text = '$target'" ); |
100 | | - $log_type = array('useredits', 'user'); |
101 | | - } |
102 | | - |
103 | | - $this->addFields( array('cuc_namespace', 'cuc_title', 'cuc_user_text', 'cuc_actiontext', 'cuc_comment', 'cuc_minor', 'cuc_timestamp', 'cuc_ip', 'cuc_xff', 'cuc_agent') ); |
104 | | - |
105 | | - $res = $this->select( __METHOD__ ); |
106 | | - $result = $this->getResult(); |
107 | | - |
108 | | - $edits = array(); |
109 | | - $count = 0; |
110 | | - foreach( $res as $row ) { |
111 | | - $edits[$count]['timestamp'] = $row->cuc_timestamp; |
112 | | - $edits[$count]['ns'] = $row->cuc_namespace; |
113 | | - $edits[$count]['title'] = $row->cuc_title; |
114 | | - $edits[$count]['user'] = $row->cuc_user_text; |
115 | | - if( $row->cuc_actiontext ) { |
116 | | - $edits[$count]['summary'] = $row->cuc_actiontext; |
117 | | - } elseif( $row->cuc_comment ) { |
118 | | - $edits[$count]['summary'] = $row->cuc_comment; |
119 | | - } |
120 | | - if( $row->cuc_minor ) { |
121 | | - $edits[$count]['minor'] = 'm'; |
122 | | - } |
123 | | - $edits[$count]['ip'] = $row->cuc_ip; |
124 | | - if( $row->cuc_xff ) { |
125 | | - $edits[$count]['xff'] = $row->cuc_xff; |
126 | | - } |
127 | | - $edits[$count]['agent'] = $row->cuc_agent; |
128 | | - $count++; |
129 | | - } |
130 | | - |
131 | | - CheckUser::addLogEntry($log_type[0], $log_type[1], $target, $reason, $user_id ? $user_id : '0'); |
132 | | - $result->addValue( array( 'query', $this->getModuleName() ), 'edits', $edits ); |
133 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'edits' ), 'action' ); |
134 | | - break; |
| 12 | + public function execute() { |
| 13 | + global $wgUser, $wgCheckUserForceSummary; |
135 | 14 | |
136 | | - case 'ipusers': |
137 | | - if( IP::isIPAddress($target) && isset($params['xff']) ) { |
138 | | - $cond = CheckUser::getIpConds($db, $target, true); |
139 | | - $this->addWhere( $cond ); |
140 | | - } elseif ( IP::isIPAddress($target) ) { |
141 | | - $cond = CheckUser::getIpConds($db, $target); |
142 | | - $this->addWhere( $cond ); |
143 | | - $log_type = 'ipusers'; |
144 | | - } else { |
145 | | - $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
146 | | - } |
147 | | - |
148 | | - $this->addFields( array('cuc_user_text', 'cuc_timestamp', 'cuc_ip', 'cuc_agent') ); |
149 | | - |
150 | | - $res = $this->select( __METHOD__ ); |
151 | | - $result = $this->getResult(); |
152 | | - |
153 | | - $users = array(); |
154 | | - foreach( $res as $row ) { |
155 | | - $user = $row->cuc_user_text; |
156 | | - $ip = $row->cuc_ip; |
157 | | - $agent = $row->cuc_agent; |
158 | | - |
159 | | - if( !isset($users[$user]) ) { |
160 | | - $users[$user]['end'] = $row->cuc_timestamp; |
161 | | - $users[$user]['editcount'] = 1; |
162 | | - $users[$user]['ips'][] = $ip; |
163 | | - $users[$user]['agents'][] = $agent; |
164 | | - } else { |
165 | | - $users[$user]['start'] = $row->cuc_timestamp; |
166 | | - $users[$user]['editcount']++; |
167 | | - if( !in_array( $ip, $users[$user]['ips'] ) ) $users[$user]['ips'][] = $ip; |
168 | | - if( !in_array( $agent, $users[$user]['agents'] ) ) $users[$user]['agents'][] = $agent; |
169 | | - } |
170 | | - } |
171 | | - |
172 | | - $count = 0; |
173 | | - foreach( array_keys($users) as $user ) { |
174 | | - $users[$count] = $users[$user]; |
175 | | - $users[$count]['name'] = $user; |
176 | | - unset($users[$user]); |
177 | | - |
178 | | - $result->setIndexedTagName( $users[$count]['ips'], 'ip' ); |
179 | | - $result->setIndexedTagName( $users[$count]['agents'], 'agent' ); |
180 | | - |
181 | | - $count++; |
182 | | - } |
183 | | - |
184 | | - CheckUser::addLogEntry($log_type, 'ip', $target, $reason); |
185 | | - $result->addValue( array( 'query', $this->getModuleName() ), 'ipusers', $users ); |
186 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'ipusers' ), 'user' ); |
187 | | - break; |
188 | | - |
189 | | - default: |
190 | | - $this->dieUsage( 'Invalid request mode', 'invalidmode' ); |
191 | | - } |
192 | | - } |
193 | | - |
194 | | - public function mustBePosted() { |
195 | | - return true; |
196 | | - } |
197 | | - |
198 | | - public function isWriteMode() { |
199 | | - return true; |
200 | | - } |
| 15 | + $db = $this->getDB( DB_SLAVE ); |
| 16 | + $params = $this->extractRequestParams(); |
201 | 17 | |
202 | | - public function getAllowedParams() { |
203 | | - return array( |
204 | | - 'request' => array( |
205 | | - ApiBase::PARAM_REQUIRED => false, |
206 | | - ApiBase::PARAM_TYPE => array( |
207 | | - 'userips', |
208 | | - 'edits', |
209 | | - 'ipusers' |
210 | | - ) |
211 | | - ), |
212 | | - 'target' => array( |
213 | | - ApiBase::PARAM_REQUIRED => false |
214 | | - ), |
215 | | - 'reason' => null, |
216 | | - 'limit' => array( |
217 | | - ApiBase::PARAM_DFLT => 1000, |
218 | | - ApiBase::PARAM_TYPE => 'limit', |
219 | | - ApiBase::PARAM_MIN => 1, |
220 | | - ApiBase::PARAM_MAX => 5000, |
221 | | - ApiBase::PARAM_MAX2 => 5000 |
222 | | - ), |
223 | | - 'timecond' => null |
224 | | - ); |
225 | | - } |
| 18 | + if ( !$wgUser->isAllowed( 'checkuser' ) ) { |
| 19 | + $this->dieUsage( 'You need the checkuser right', 'permissionerror' ); |
| 20 | + } |
226 | 21 | |
227 | | - public function getParamDescription() { |
228 | | - return array( |
229 | | - 'request' => array( |
230 | | - 'Type of CheckUser request', |
231 | | - ' userips - get IP of target user', |
232 | | - ' edits - get changes from target IP or range', |
233 | | - ' ipusers - get users from target IP or range', |
234 | | - ), |
235 | | - 'target' => "Username or IP-address/range to perform check", |
236 | | - 'reason' => 'Reason to check', |
237 | | - 'limit' => 'Limit of rows', |
238 | | - 'timecond' => 'Time limit of user data (like "2 weeks")' |
239 | | - ); |
240 | | - } |
| 22 | + if ( $wgCheckUserForceSummary && is_null( $params['reason'] ) ) { |
| 23 | + $this->dieUsage( 'You need define reason for check', 'missingdata' ); |
| 24 | + } |
241 | 25 | |
242 | | - public function getDescription() { |
243 | | - return 'Allows check which IPs are used by a given username and which usernames are used by a given IP'; |
244 | | - } |
| 26 | + $limit = $params['limit']; |
| 27 | + $target = $params['target']; |
| 28 | + $reason = wfMsgForContent( 'checkuser-reason-api' ) . ' ' . $params['reason']; |
| 29 | + $time = wfTimestamp( TS_MW, |
| 30 | + strtotime( 'now' ) - ( strtotime( $params['timecond'] ? $params['timecond'] : '2 weeks' ) - strtotime( 'now' |
| 31 | + ) ) |
| 32 | + ); |
| 33 | + if ( !$time ) { |
| 34 | + $this->dieUsage( 'You need use correct time limit (like "2 weeks")', 'invalidtime' ); |
| 35 | + } |
245 | 36 | |
246 | | - public function getPossibleErrors() { |
247 | | - return array_merge( parent::getPossibleErrors(), |
248 | | - array( |
249 | | - array( 'nosuchuser' ), |
250 | | - array( 'invalidip' ), |
251 | | - array( 'permissionerror' ), |
252 | | - array( 'invalidmode' ), |
253 | | - array( 'missingdata' ) |
254 | | - ) |
255 | | - ); |
256 | | - } |
| 37 | + $this->addTables( 'cu_changes' ); |
| 38 | + $this->addOption( 'LIMIT', $limit + 1 ); |
| 39 | + $this->addOption( 'ORDER BY', 'cuc_timestamp DESC' ); |
| 40 | + $this->addWhere( "cuc_timestamp > $time" ); |
257 | 41 | |
258 | | - public function getExamples() { |
259 | | - return array( |
260 | | - 'api.php?action=query&list=checkuser&curequest=userips&cutarget=Jimbo_Wales', |
261 | | - 'api.php?action=query&list=checkuser&curequest=edits&cutarget=127.0.0.1/16/xff&cureason=Some_check' |
262 | | - ); |
263 | | - } |
| 42 | + switch ( $params['request'] ) { |
| 43 | + case 'userips': |
| 44 | + $user_id = User::idFromName( $target ); |
| 45 | + if ( !$user_id ) { |
| 46 | + $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); |
| 47 | + } |
264 | 48 | |
265 | | - public function getHelpUrls() { |
266 | | - return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API'; |
267 | | - } |
| 49 | + $this->addFields( array( 'cuc_timestamp', 'cuc_ip', 'cuc_xff' ) ); |
| 50 | + $this->addWhere( "cuc_user_text = '$target'" ); |
| 51 | + $res = $this->select( __METHOD__ ); |
| 52 | + $result = $this->getResult(); |
268 | 53 | |
269 | | - public function getVersion() { |
270 | | - return __CLASS__ . ': $Id$'; |
271 | | - } |
| 54 | + $ips = array(); |
| 55 | + foreach ( $res as $row ) { |
| 56 | + $timestamp = $row->cuc_timestamp; |
| 57 | + $ip = strval( $row->cuc_ip ); |
| 58 | + $xff = $row->cuc_xff; |
| 59 | + |
| 60 | + if ( !isset( $ips[$ip] ) ) { |
| 61 | + $ips[$ip]['end'] = $timestamp; |
| 62 | + $ips[$ip]['editcount'] = 1; |
| 63 | + } else { |
| 64 | + $ips[$ip]['start'] = $timestamp; |
| 65 | + $ips[$ip]['editcount']++; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + $count = 0; |
| 70 | + foreach ( array_keys( $ips ) as $ip ) { |
| 71 | + $ips[$count] = $ips[$ip]; |
| 72 | + $ips[$count]['address'] = $ip; |
| 73 | + unset( $ips[$ip] ); |
| 74 | + $count++; |
| 75 | + } |
| 76 | + |
| 77 | + CheckUser::addLogEntry( 'userips', 'user', $target, $reason, $user_id ); |
| 78 | + $result->addValue( array( 'query', $this->getModuleName() ), 'userips', $ips ); |
| 79 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'userips' ), 'ip' ); |
| 80 | + break; |
| 81 | + |
| 82 | + case 'edits': |
| 83 | + if ( IP::isIPAddress( $target ) && isset( $params['xff'] ) ) { |
| 84 | + $cond = CheckUser::getIpConds( $db, $target, true ); |
| 85 | + if ( !$cond ) { |
| 86 | + $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
| 87 | + } |
| 88 | + $this->addWhere( "$cond" ); |
| 89 | + $log_type = array( 'ipedits-xff', 'ip' ); |
| 90 | + } elseif ( IP::isIPAddress( $target ) ) { |
| 91 | + $cond = CheckUser::getIpConds( $db, $target ); |
| 92 | + if ( !$cond ) { |
| 93 | + $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
| 94 | + } |
| 95 | + $this->addWhere( "$cond" ); |
| 96 | + $log_type = array( 'ipedits', 'ip' ); |
| 97 | + } else { |
| 98 | + $user_id = User::idFromName( $target ); |
| 99 | + if ( !$user_id ) { |
| 100 | + $this->dieUsage( 'Target user is not exists', 'nosuchuser' ); |
| 101 | + } |
| 102 | + $this->addWhere( "cuc_user_text = '$target'" ); |
| 103 | + $log_type = array( 'useredits', 'user' ); |
| 104 | + } |
| 105 | + |
| 106 | + $this->addFields( array( 'cuc_namespace', 'cuc_title', 'cuc_user_text', 'cuc_actiontext', 'cuc_comment', 'cuc_minor', 'cuc_timestamp', 'cuc_ip', 'cuc_xff', 'cuc_agent' ) |
| 107 | + ); |
| 108 | + |
| 109 | + $res = $this->select( __METHOD__ ); |
| 110 | + $result = $this->getResult(); |
| 111 | + |
| 112 | + $edits = array(); |
| 113 | + $count = 0; |
| 114 | + foreach ( $res as $row ) { |
| 115 | + $edits[$count]['timestamp'] = $row->cuc_timestamp; |
| 116 | + $edits[$count]['ns'] = $row->cuc_namespace; |
| 117 | + $edits[$count]['title'] = $row->cuc_title; |
| 118 | + $edits[$count]['user'] = $row->cuc_user_text; |
| 119 | + if ( $row->cuc_actiontext ) { |
| 120 | + $edits[$count]['summary'] = $row->cuc_actiontext; |
| 121 | + } elseif ( $row->cuc_comment ) { |
| 122 | + $edits[$count]['summary'] = $row->cuc_comment; |
| 123 | + } |
| 124 | + if ( $row->cuc_minor ) { |
| 125 | + $edits[$count]['minor'] = 'm'; |
| 126 | + } |
| 127 | + $edits[$count]['ip'] = $row->cuc_ip; |
| 128 | + if ( $row->cuc_xff ) { |
| 129 | + $edits[$count]['xff'] = $row->cuc_xff; |
| 130 | + } |
| 131 | + $edits[$count]['agent'] = $row->cuc_agent; |
| 132 | + $count++; |
| 133 | + } |
| 134 | + |
| 135 | + CheckUser::addLogEntry( $log_type[0], $log_type[1], $target, $reason, $user_id ? $user_id : '0' ); |
| 136 | + $result->addValue( array( 'query', $this->getModuleName() ), 'edits', $edits ); |
| 137 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'edits' ), 'action' ); |
| 138 | + break; |
| 139 | + |
| 140 | + case 'ipusers': |
| 141 | + if ( IP::isIPAddress( $target ) && isset( $params['xff'] ) ) { |
| 142 | + $cond = CheckUser::getIpConds( $db, $target, true ); |
| 143 | + $this->addWhere( $cond ); |
| 144 | + } elseif ( IP::isIPAddress( $target ) ) { |
| 145 | + $cond = CheckUser::getIpConds( $db, $target ); |
| 146 | + $this->addWhere( $cond ); |
| 147 | + $log_type = 'ipusers'; |
| 148 | + } else { |
| 149 | + $this->dieUsage( 'IP or range is invalid', 'invalidip' ); |
| 150 | + } |
| 151 | + |
| 152 | + $this->addFields( array( 'cuc_user_text', 'cuc_timestamp', 'cuc_ip', 'cuc_agent' ) ); |
| 153 | + |
| 154 | + $res = $this->select( __METHOD__ ); |
| 155 | + $result = $this->getResult(); |
| 156 | + |
| 157 | + $users = array(); |
| 158 | + foreach ( $res as $row ) { |
| 159 | + $user = $row->cuc_user_text; |
| 160 | + $ip = $row->cuc_ip; |
| 161 | + $agent = $row->cuc_agent; |
| 162 | + |
| 163 | + if ( !isset( $users[$user] ) ) { |
| 164 | + $users[$user]['end'] = $row->cuc_timestamp; |
| 165 | + $users[$user]['editcount'] = 1; |
| 166 | + $users[$user]['ips'][] = $ip; |
| 167 | + $users[$user]['agents'][] = $agent; |
| 168 | + } else { |
| 169 | + $users[$user]['start'] = $row->cuc_timestamp; |
| 170 | + $users[$user]['editcount']++; |
| 171 | + if ( !in_array( $ip, $users[$user]['ips'] ) ) { |
| 172 | + $users[$user]['ips'][] = $ip; |
| 173 | + } |
| 174 | + if ( !in_array( $agent, $users[$user]['agents'] ) ) { |
| 175 | + $users[$user]['agents'][] = $agent; |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + $count = 0; |
| 181 | + foreach ( array_keys( $users ) as $user ) { |
| 182 | + $users[$count] = $users[$user]; |
| 183 | + $users[$count]['name'] = $user; |
| 184 | + unset( $users[$user] ); |
| 185 | + |
| 186 | + $result->setIndexedTagName( $users[$count]['ips'], 'ip' ); |
| 187 | + $result->setIndexedTagName( $users[$count]['agents'], 'agent' ); |
| 188 | + |
| 189 | + $count++; |
| 190 | + } |
| 191 | + |
| 192 | + CheckUser::addLogEntry( $log_type, 'ip', $target, $reason ); |
| 193 | + $result->addValue( array( 'query', $this->getModuleName() ), 'ipusers', $users ); |
| 194 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'ipusers' ), 'user' ); |
| 195 | + break; |
| 196 | + |
| 197 | + default: |
| 198 | + $this->dieUsage( 'Invalid request mode', 'invalidmode' ); |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + public function mustBePosted() { |
| 203 | + return true; |
| 204 | + } |
| 205 | + |
| 206 | + public function isWriteMode() { |
| 207 | + return true; |
| 208 | + } |
| 209 | + |
| 210 | + public function getAllowedParams() { |
| 211 | + return array( |
| 212 | + 'request' => array( |
| 213 | + ApiBase::PARAM_REQUIRED => false, |
| 214 | + ApiBase::PARAM_TYPE => array( |
| 215 | + 'userips', |
| 216 | + 'edits', |
| 217 | + 'ipusers' |
| 218 | + ) |
| 219 | + ), |
| 220 | + 'target' => array( |
| 221 | + ApiBase::PARAM_REQUIRED => false |
| 222 | + ), |
| 223 | + 'reason' => null, |
| 224 | + 'limit' => array( |
| 225 | + ApiBase::PARAM_DFLT => 1000, |
| 226 | + ApiBase::PARAM_TYPE => 'limit', |
| 227 | + ApiBase::PARAM_MIN => 1, |
| 228 | + ApiBase::PARAM_MAX => 5000, |
| 229 | + ApiBase::PARAM_MAX2 => 5000 |
| 230 | + ), |
| 231 | + 'timecond' => null |
| 232 | + ); |
| 233 | + } |
| 234 | + |
| 235 | + public function getParamDescription() { |
| 236 | + return array( |
| 237 | + 'request' => array( |
| 238 | + 'Type of CheckUser request', |
| 239 | + ' userips - get IP of target user', |
| 240 | + ' edits - get changes from target IP or range', |
| 241 | + ' ipusers - get users from target IP or range', |
| 242 | + ), |
| 243 | + 'target' => "Username or IP-address/range to perform check", |
| 244 | + 'reason' => 'Reason to check', |
| 245 | + 'limit' => 'Limit of rows', |
| 246 | + 'timecond' => 'Time limit of user data (like "2 weeks")', |
| 247 | + ); |
| 248 | + } |
| 249 | + |
| 250 | + public function getDescription() { |
| 251 | + return 'Allows check which IPs are used by a given username and which usernames are used by a given IP'; |
| 252 | + } |
| 253 | + |
| 254 | + public function getPossibleErrors() { |
| 255 | + return array_merge( parent::getPossibleErrors(), |
| 256 | + array( |
| 257 | + array( 'nosuchuser' ), |
| 258 | + array( 'invalidip' ), |
| 259 | + array( 'permissionerror' ), |
| 260 | + array( 'invalidmode' ), |
| 261 | + array( 'missingdata' ), |
| 262 | + ) |
| 263 | + ); |
| 264 | + } |
| 265 | + |
| 266 | + public function getExamples() { |
| 267 | + return array( |
| 268 | + 'api.php?action=query&list=checkuser&curequest=userips&cutarget=Jimbo_Wales', |
| 269 | + 'api.php?action=query&list=checkuser&curequest=edits&cutarget=127.0.0.1/16/xff&cureason=Some_check', |
| 270 | + ); |
| 271 | + } |
| 272 | + |
| 273 | + public function getHelpUrls() { |
| 274 | + return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API'; |
| 275 | + } |
| 276 | + |
| 277 | + public function getVersion() { |
| 278 | + return __CLASS__ . ': $Id$'; |
| 279 | + } |
272 | 280 | } |
\ No newline at end of file |
Index: trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php |
— | — | @@ -1,117 +1,121 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * CheckUser API Query Module |
5 | 6 | */ |
| 7 | +class ApiQueryCheckUserLog extends ApiQueryBase { |
| 8 | + public function __construct( $query, $moduleName ) { |
| 9 | + parent::__construct( $query, $moduleName, 'cul' ); |
| 10 | + } |
6 | 11 | |
7 | | -class ApiQueryCheckUserLog extends ApiQueryBase { |
8 | | - public function __construct( $query, $moduleName ) { |
9 | | - parent::__construct( $query, $moduleName, 'cul' ); |
10 | | - } |
11 | | - |
12 | | - public function execute() { |
13 | | - global $wgUser; |
14 | | - |
15 | | - $params = $this->extractRequestParams(); |
16 | | - |
17 | | - if( !$wgUser->isAllowed( 'checkuser-log' ) ) { |
18 | | - $this->dieUsage( 'You need the checkuser-log right', 'permissionerror' ); |
19 | | - } |
20 | | - |
21 | | - $user = $params['user']; |
22 | | - $limit = $params['limit']; |
23 | | - $target = $params['target']; |
24 | | - $from = $params['from']; |
25 | | - $to = $params['to']; |
26 | | - |
27 | | - $this->addTables( 'cu_log' ); |
28 | | - $this->addOption( 'LIMIT', $limit + 1 ); |
29 | | - $this->addOption( 'ORDER BY', 'cul_timestamp DESC' ); |
30 | | - |
31 | | - $this->addFields( array('cul_timestamp', 'cul_user_text', 'cul_reason', 'cul_type', 'cul_target_text') ); |
32 | | - |
33 | | - if( isset($user) ) $this->addWhere( "cul_user_text = '$user'" ); |
34 | | - if( isset($target) ) $this->addWhere( "cul_target_text = '$target'" ); |
35 | | - if( isset($from) && isset($to) ) { |
36 | | - $this->addWhere( "cul_timestamp BETWEEN '$from' AND '$to'" ); |
37 | | - unset($from, $to); |
38 | | - } elseif ( isset($from) ) { |
39 | | - $this->addWhere( "cul_timestamp < $from" ); |
40 | | - } elseif ( isset($to) ) { |
41 | | - $this->addWhere( "cul_timestamp > $to" ); |
42 | | - } |
43 | | - |
44 | | - $res = $this->select( __METHOD__ ); |
45 | | - $result = $this->getResult(); |
46 | | - |
47 | | - $count = 0; |
48 | | - $log = array(); |
49 | | - foreach( $res as $row ) { |
50 | | - $log[$count]['timestamp'] = $row->cul_timestamp; |
51 | | - $log[$count]['checkuser'] = $row->cul_user_text; |
52 | | - $log[$count]['type'] = $row->cul_type; |
53 | | - $log[$count]['reason'] = $row->cul_reason; |
54 | | - $log[$count]['target'] = $row->cul_target_text; |
55 | | - $count++; |
56 | | - } |
57 | | - |
58 | | - $result->addValue( array( 'query', $this->getModuleName() ), 'entries', $log ); |
59 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'entries' ), 'entry' ); |
60 | | - } |
61 | | - |
62 | | - public function getAllowedParams() { |
63 | | - return array( |
64 | | - 'user' => null, |
65 | | - 'target' => null, |
66 | | - 'limit' => array( |
| 12 | + public function execute() { |
| 13 | + global $wgUser; |
| 14 | + |
| 15 | + $params = $this->extractRequestParams(); |
| 16 | + |
| 17 | + if ( !$wgUser->isAllowed( 'checkuser-log' ) ) { |
| 18 | + $this->dieUsage( 'You need the checkuser-log right', 'permissionerror' ); |
| 19 | + } |
| 20 | + |
| 21 | + $user = $params['user']; |
| 22 | + $limit = $params['limit']; |
| 23 | + $target = $params['target']; |
| 24 | + $from = $params['from']; |
| 25 | + $to = $params['to']; |
| 26 | + |
| 27 | + $this->addTables( 'cu_log' ); |
| 28 | + $this->addOption( 'LIMIT', $limit + 1 ); |
| 29 | + $this->addOption( 'ORDER BY', 'cul_timestamp DESC' ); |
| 30 | + |
| 31 | + $this->addFields( array( 'cul_timestamp', 'cul_user_text', 'cul_reason', 'cul_type', 'cul_target_text' ) ); |
| 32 | + |
| 33 | + if ( isset( $user ) ) { |
| 34 | + $this->addWhere( "cul_user_text = '$user'" ); |
| 35 | + } |
| 36 | + if ( isset( $target ) ) { |
| 37 | + $this->addWhere( "cul_target_text = '$target'" ); |
| 38 | + } |
| 39 | + if ( isset( $from ) && isset( $to ) ) { |
| 40 | + $this->addWhere( "cul_timestamp BETWEEN '$from' AND '$to'" ); |
| 41 | + unset( $from, $to ); |
| 42 | + } elseif ( isset( $from ) ) { |
| 43 | + $this->addWhere( "cul_timestamp < $from" ); |
| 44 | + } elseif ( isset( $to ) ) { |
| 45 | + $this->addWhere( "cul_timestamp > $to" ); |
| 46 | + } |
| 47 | + |
| 48 | + $res = $this->select( __METHOD__ ); |
| 49 | + $result = $this->getResult(); |
| 50 | + |
| 51 | + $count = 0; |
| 52 | + $log = array(); |
| 53 | + foreach ( $res as $row ) { |
| 54 | + $log[$count]['timestamp'] = $row->cul_timestamp; |
| 55 | + $log[$count]['checkuser'] = $row->cul_user_text; |
| 56 | + $log[$count]['type'] = $row->cul_type; |
| 57 | + $log[$count]['reason'] = $row->cul_reason; |
| 58 | + $log[$count]['target'] = $row->cul_target_text; |
| 59 | + $count++; |
| 60 | + } |
| 61 | + |
| 62 | + $result->addValue( array( 'query', $this->getModuleName() ), 'entries', $log ); |
| 63 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'entries' ), 'entry' ); |
| 64 | + } |
| 65 | + |
| 66 | + public function getAllowedParams() { |
| 67 | + return array( |
| 68 | + 'user' => null, |
| 69 | + 'target' => null, |
| 70 | + 'limit' => array( |
67 | 71 | ApiBase::PARAM_DFLT => 10, |
68 | 72 | ApiBase::PARAM_TYPE => 'limit', |
69 | 73 | ApiBase::PARAM_MIN => 1, |
70 | 74 | ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
71 | | - ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 75 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2, |
72 | 76 | ), |
73 | | - 'from' => array( |
74 | | - ApiBase::PARAM_TYPE => 'timestamp' |
| 77 | + 'from' => array( |
| 78 | + ApiBase::PARAM_TYPE => 'timestamp', |
75 | 79 | ), |
76 | | - 'to' => array( |
77 | | - ApiBase::PARAM_TYPE => 'timestamp' |
| 80 | + 'to' => array( |
| 81 | + ApiBase::PARAM_TYPE => 'timestamp', |
78 | 82 | ), |
79 | | - ); |
80 | | - } |
| 83 | + ); |
| 84 | + } |
81 | 85 | |
82 | | - public function getParamDescription() { |
83 | | - return array( |
84 | | - 'user' => 'Username of CheckUser', |
85 | | - 'target' => "Checked user or IP-address/range", |
86 | | - 'limit' => 'Limit of rows', |
87 | | - 'from' => 'The timestamp to start enumerating from', |
88 | | - 'to' => 'The timestamp to end enumerating' |
89 | | - ); |
90 | | - } |
| 86 | + public function getParamDescription() { |
| 87 | + return array( |
| 88 | + 'user' => 'Username of CheckUser', |
| 89 | + 'target' => "Checked user or IP-address/range", |
| 90 | + 'limit' => 'Limit of rows', |
| 91 | + 'from' => 'The timestamp to start enumerating from', |
| 92 | + 'to' => 'The timestamp to end enumerating', |
| 93 | + ); |
| 94 | + } |
91 | 95 | |
92 | | - public function getDescription() { |
93 | | - return 'Allows get entries of CheckUser log'; |
94 | | - } |
| 96 | + public function getDescription() { |
| 97 | + return 'Allows get entries of CheckUser log'; |
| 98 | + } |
95 | 99 | |
96 | | - public function getPossibleErrors() { |
97 | | - return array_merge( parent::getPossibleErrors(), |
98 | | - array( |
99 | | - array( 'permissionerror' ) |
100 | | - ) |
101 | | - ); |
102 | | - } |
| 100 | + public function getPossibleErrors() { |
| 101 | + return array_merge( parent::getPossibleErrors(), |
| 102 | + array( |
| 103 | + array( 'permissionerror' ), |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
103 | 107 | |
104 | | - public function getExamples() { |
105 | | - return array( |
106 | | - 'api.php?action=query&list=checkuserlog&culuser=WikiSysop&limit=25', |
107 | | - 'api.php?action=query&list=checkuserlog&cultarget=127.0.0.1&culfrom=20111015230000' |
108 | | - ); |
109 | | - } |
| 108 | + public function getExamples() { |
| 109 | + return array( |
| 110 | + 'api.php?action=query&list=checkuserlog&culuser=WikiSysop&limit=25', |
| 111 | + 'api.php?action=query&list=checkuserlog&cultarget=127.0.0.1&culfrom=20111015230000', |
| 112 | + ); |
| 113 | + } |
110 | 114 | |
111 | | - public function getHelpUrls() { |
112 | | - return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API'; |
113 | | - } |
| 115 | + public function getHelpUrls() { |
| 116 | + return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API'; |
| 117 | + } |
114 | 118 | |
115 | | - public function getVersion() { |
116 | | - return __CLASS__ . ': $Id$'; |
117 | | - } |
| 119 | + public function getVersion() { |
| 120 | + return __CLASS__ . ': $Id$'; |
| 121 | + } |
118 | 122 | } |
\ No newline at end of file |