r76565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76564‎ | r76565 | r76566 >
Date:06:50, 12 November 2010
Author:aaron
Status:ok
Tags:
Comment:
* Fixed "no matches" msg for /xff checks
* Combined "get account edits" and "get IP edits" into "get edits" option
* Line breaks
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.i18n.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -69,8 +69,10 @@
7070 $checktype = $wgRequest->getVal( 'checktype' );
7171 $period = $wgRequest->getInt( 'period' );
7272 $users = $wgRequest->getArray( 'users' );
73 - $tag = $wgRequest->getBool( 'usetag' ) ? trim( $wgRequest->getVal( 'tag' ) ) : '';
74 - $talkTag = $wgRequest->getBool( 'usettag' ) ? trim( $wgRequest->getVal( 'talktag' ) ) : '';
 73+ $tag = $wgRequest->getBool( 'usetag' ) ?
 74+ trim( $wgRequest->getVal( 'tag' ) ) : '';
 75+ $talkTag = $wgRequest->getBool( 'usettag' ) ?
 76+ trim( $wgRequest->getVal( 'talktag' ) ) : '';
7577
7678 # An IPv4? An IPv6? CIDR included?
7779 if ( IP::isIPAddress( $user ) ) {
@@ -90,6 +92,7 @@
9193 }
9294
9395 $this->doForm( $user, $reason, $checktype, $ip, $xff, $name, $period );
 96+
9497 # Perform one of the various submit operations...
9598 if ( $wgRequest->wasPosted() ) {
9699 if ( $wgRequest->getVal( 'action' ) === 'block' ) {
@@ -98,16 +101,16 @@
99102 $wgOut->addWikiMsg( 'checkuser-noreason' );
100103 } elseif ( $checktype == 'subuserips' ) {
101104 $this->doUserIPsRequest( $name, $reason, $period );
102 - } elseif ( $xff && $checktype == 'subipedits' ) {
 105+ } elseif ( $xff && $checktype == 'subedits' ) {
103106 $this->doIPEditsRequest( $xff, true, $reason, $period );
104 - } elseif ( $checktype == 'subipedits' ) {
 107+ } elseif ( $ip && $checktype == 'subedits' ) {
105108 $this->doIPEditsRequest( $ip, false, $reason, $period );
 109+ } elseif ( $name && $checktype == 'subedits' ) {
 110+ $this->doUserEditsRequest( $user, $reason, $period );
106111 } elseif ( $xff && $checktype == 'subipusers' ) {
107112 $this->doIPUsersRequest( $xff, true, $reason, $period, $tag, $talkTag );
108113 } elseif ( $checktype == 'subipusers' ) {
109114 $this->doIPUsersRequest( $ip, false, $reason, $period, $tag, $talkTag );
110 - } elseif ( $checktype == 'subuseredits' ) {
111 - $this->doUserEditsRequest( $user, $reason, $period );
112115 }
113116 }
114117 # Add CIDR calculation convenience form
@@ -139,18 +142,16 @@
140143 global $wgOut, $wgUser;
141144 $action = $this->getTitle()->escapeLocalUrl();
142145 # Fill in requested type if it makes sense
143 - $encipusers = $encipedits = $encuserips = $encuseredits = 0;
 146+ $encipusers = $encedits = $encuserips = 0;
144147 if ( $checktype == 'subipusers' && ( $ip || $xff ) ) {
145148 $encipusers = 1;
146 - } elseif ( $checktype == 'subipedits' && ( $ip || $xff ) ) {
147 - $encipedits = 1;
148149 } elseif ( $checktype == 'subuserips' && $name ) {
149150 $encuserips = 1;
150 - } elseif ( $checktype == 'subuseredits' && $name ) {
151 - $encuseredits = 1;
 151+ } elseif ( $checktype == 'subedits' ) {
 152+ $encedits = 1;
152153 # Defaults otherwise
153154 } elseif ( $ip || $xff ) {
154 - $encipedits = 1;
 155+ $encedits = 1;
155156 } else {
156157 $encuserips = 1;
157158 }
@@ -173,12 +174,10 @@
174175 $form .= '<td></td><td class="checkuserradios"><table border="0" cellpadding="3"><tr>';
175176 $form .= '<td>' . Xml::radio( 'checktype', 'subuserips', $encuserips, array( 'id' => 'subuserips' ) );
176177 $form .= ' ' . Xml::label( wfMsg( 'checkuser-ips' ), 'subuserips' ) . '</td>';
177 - $form .= '<td>' . Xml::radio( 'checktype', 'subipedits', $encipedits, array( 'id' => 'subipedits' ) );
178 - $form .= ' ' . Xml::label( wfMsg( 'checkuser-edits' ), 'subipedits' ) . '</td>';
 178+ $form .= '<td>' . Xml::radio( 'checktype', 'subedits', $encedits, array( 'id' => 'subedits' ) );
 179+ $form .= ' ' . Xml::label( wfMsg( 'checkuser-edits' ), 'subedits' ) . '</td>';
179180 $form .= '<td>' . Xml::radio( 'checktype', 'subipusers', $encipusers, array( 'id' => 'subipusers' ) );
180181 $form .= ' ' . Xml::label( wfMsg( 'checkuser-users' ), 'subipusers' ) . '</td>';
181 - $form .= '<td>' . Xml::radio( 'checktype', 'subuseredits', $encuseredits, array( 'id' => 'subuseredits' ) );
182 - $form .= ' ' . Xml::label( wfMsg( 'checkuser-account' ), 'subuseredits' ) . '</td>';
183182 $form .= '</tr></table></td>';
184183 $form .= '</tr><tr>';
185184 $form .= '<td>' . wfMsgHtml( 'checkuser-reason' ) . '</td>';
@@ -259,41 +258,43 @@
260259 }
261260 }
262261
263 - protected function noMatchesMessage( $userName ) {
 262+ // Give a "no matches found for X" message.
 263+ // If $checkLast, then mention the last edit by this user or IP.
 264+ protected function noMatchesMessage( $userName, $checkLast = true ) {
264265 global $wgLang;
265 - $dbr = wfGetDB( DB_SLAVE );
266 - $user_id = User::idFromName( $userName );
267 - if ( $user_id ) {
268 - $revEdit = $dbr->selectField( 'revision',
269 - 'rev_timestamp',
270 - array( 'rev_user' => $user_id ),
271 - __METHOD__,
272 - array( 'ORDER BY' => 'rev_timestamp DESC' )
273 - );
274 - } else {
275 - $revEdit = $dbr->selectField( 'revision',
276 - 'rev_timestamp',
277 - array( 'rev_user_text' => $userName ),
278 - __METHOD__,
279 - array( 'ORDER BY' => 'rev_timestamp DESC' )
280 - );
 266+ if ( $checkLast ) {
 267+ $dbr = wfGetDB( DB_SLAVE );
 268+ $user_id = User::idFromName( $userName );
 269+ if ( $user_id ) {
 270+ $revEdit = $dbr->selectField( 'revision',
 271+ 'rev_timestamp',
 272+ array( 'rev_user' => $user_id ),
 273+ __METHOD__,
 274+ array( 'ORDER BY' => 'rev_timestamp DESC' )
 275+ );
 276+ $logEdit = $dbr->selectField( 'logging',
 277+ 'log_timestamp',
 278+ array( 'log_user' => $user_id ),
 279+ __METHOD__,
 280+ array( 'ORDER BY' => 'log_timestamp DESC' )
 281+ );
 282+ } else {
 283+ $revEdit = $dbr->selectField( 'revision',
 284+ 'rev_timestamp',
 285+ array( 'rev_user_text' => $userName ),
 286+ __METHOD__,
 287+ array( 'ORDER BY' => 'rev_timestamp DESC' )
 288+ );
 289+ $logEdit = false; // no log_user_text index
 290+ }
 291+ $lastEdit = max( $revEdit, $logEdit );
 292+ if ( $lastEdit ) {
 293+ $lastEditDate = $wgLang->date( wfTimestamp( TS_MW, $lastEdit ), true );
 294+ $lastEditTime = $wgLang->time( wfTimestamp( TS_MW, $lastEdit ), true );
 295+ // FIXME: don't pass around parsed messages
 296+ return wfMsgExt( 'checkuser-nomatch-edits', 'parse', $lastEditDate, $lastEditTime );
 297+ }
281298 }
282 - $logEdit = 0;
283 - if ( $user_id ) {
284 - $logEdit = $dbr->selectField( 'logging',
285 - 'log_timestamp',
286 - array( 'log_user' => $user_id ),
287 - __METHOD__,
288 - array( 'ORDER BY' => 'log_timestamp DESC' )
289 - );
290 - }
291 - $lastEdit = max( $revEdit, $logEdit );
292 - if ( $lastEdit ) {
293 - $lastEditDate = $wgLang->date( wfTimestamp( TS_MW, $lastEdit ), true );
294 - $lastEditTime = $wgLang->time( wfTimestamp( TS_MW, $lastEdit ), true );
295 - // FIXME: don't pass around parsed messages
296 - return wfMsgExt( 'checkuser-nomatch-edits', 'parse', $lastEditDate, $lastEditTime );
297 - }
298299 return wfMsgExt( 'checkuser-nomatch', 'parse' );
299300 }
300301
@@ -538,7 +539,7 @@
539540 $wgOut->addHTML( $s );
540541 return;
541542 } elseif ( isset( $rangecount ) && !$rangecount ) {
542 - $s = $this->noMatchesMessage( $ip ) . "\n";
 543+ $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
543544 $wgOut->addHTML( $s );
544545 return;
545546 }
@@ -550,7 +551,7 @@
551552 $ret = $dbr->query( $sql, __METHOD__ );
552553
553554 if ( !$dbr->numRows( $ret ) ) {
554 - $s = $this->noMatchesMessage( $ip ) . "\n";
 555+ $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
555556 } else {
556557 # Cache common messages
557558 $this->preCacheMessages();
@@ -799,7 +800,7 @@
800801 $wgOut->addHTML( $s );
801802 return;
802803 } elseif ( isset( $rangecount ) && !$rangecount ) {
803 - $s = $this->noMatchesMessage( $ip ) . "\n";
 804+ $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
804805 $wgOut->addHTML( $s );
805806 return;
806807 }
@@ -814,7 +815,7 @@
815816
816817 $users_first = $users_last = $users_edits = $users_ids = array();
817818 if ( !$dbr->numRows( $ret ) ) {
818 - $s = $this->noMatchesMessage( $ip ) . "\n";
 819+ $s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
819820 } else {
820821 global $wgAuth;
821822 while ( ( $row = $dbr->fetchObject( $ret ) ) != false ) {
Index: trunk/extensions/CheckUser/CheckUser.i18n.php
@@ -32,9 +32,8 @@
3333 'checkuser-query' => 'Query recent changes',
3434 'checkuser-target' => 'IP address or username:',
3535 'checkuser-users' => 'Get users',
36 - 'checkuser-edits' => 'Get edits from IP address',
 36+ 'checkuser-edits' => 'Get edits',
3737 'checkuser-ips' => 'Get IP addresses',
38 - 'checkuser-account' => 'Get account edits',
3938 'checkuser-search' => 'Search',
4039 'checkuser-period' => 'Duration:',
4140 'checkuser-week-1' => 'last week',

Status & tagging log