r23792 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23791‎ | r23792 | r23793 >
Date:16:01, 6 July 2007
Author:brion
Status:old
Tags:
Comment:
Revert the previous-user field, as previously discussed this will be useless as we plan to remove that cookie
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.i18n.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)
  • /trunk/extensions/CheckUser/archives/patch-cuc_cookie_user.sql (deleted) (history)
  • /trunk/extensions/CheckUser/cu_changes.pg.sql (modified) (history)
  • /trunk/extensions/CheckUser/cu_changes.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -120,19 +120,6 @@
121121 # Output form
122122 $wgOut->addHTML( $form );
123123 }
124 -
125 - /**
126 - * As we use the same small set of messages in various methods and that
127 - * they are called often, we call them once and save them in $this->message
128 - */
129 - function preCacheMessages() {
130 - // Precache various messages
131 - if( !isset( $this->message ) ) {
132 - foreach( explode(' ', 'diff hist minoreditletter newpageletter blocklink checkuser-pagelogs' ) as $msg ) {
133 - $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
134 - }
135 - }
136 - }
137124
138125 /**
139126 * @param string $ip
@@ -194,11 +181,24 @@
195182 }
196183
197184 /**
 185+ * As we use the same small set of messages in various methods and that
 186+ * they are called often, we call them once and save them in $this->message
 187+ */
 188+ function preCacheMessages() {
 189+ // Precache various messages
 190+ if( !isset( $this->message ) ) {
 191+ foreach( explode(' ', 'diff hist minoreditletter newpageletter blocklink log' ) as $msg ) {
 192+ $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
 193+ }
 194+ }
 195+ }
 196+
 197+ /**
198198 * @param $row
199199 * @return a streamlined recent changes line with IP data
200200 */
201201 function CUChangesLine( $row ) {
202 - global $wgLang, $wgCURecordCookieData;
 202+ global $wgLang;
203203
204204 # Add date headers
205205 $date = $wgLang->date( $row->cuc_timestamp, true, true );
@@ -226,27 +226,21 @@
227227 $line .= $this->skin->commentBlock( $row->cuc_comment );
228228
229229 $cuTitle = SpecialPage::getTitleFor( 'CheckUser' );
230 - $line .= '<br/>&nbsp;&nbsp;&nbsp;<small>';
231 - # IP address
232 - $line .= ' <strong>' . wfMsgHtml('checkuser-ip') . '</strong> ' .
233 - $this->skin->makeKnownLinkObj( $cuTitle, htmlspecialchars($row->cuc_ip),
234 - "user=" . urlencode($row->cuc_ip) );
235 - # XFF chain
 230+ $line .= '<br/>&nbsp; &nbsp; &nbsp; &nbsp; <small>';
 231+ # IP
 232+ $line .= ' <strong>IP</strong>: '.$this->skin->makeKnownLinkObj( $cuTitle,
 233+ htmlspecialchars( $row->cuc_ip ),
 234+ "user=" . urlencode( $row->cuc_ip ) );
 235+ # XFF
236236 if( $row->cuc_xff !=null ) {
237237 # Flag our trusted proxies
238 - list($client,$trusted) = wfGetClientIPfromXFF($row->cuc_xff,$row->cuc_ip);
 238+ list($client,$trusted) = efGetClientIPfromXFF($row->cuc_xff,$row->cuc_ip);
239239 $c = $trusted ? '#F0FFF0' : '#FFFFCC';
240 - $line .= '</span>&nbsp;&nbsp;&nbsp;<span style="background-color: '.$c.'">' .
241 - '<strong>' . wfMsgHtml('checkuser-xff') . '</strong> ';
 240+ $line .= '</span>&nbsp;&nbsp;&nbsp;<span style="background-color: '.$c.'"><strong>XFF</strong>: ';
242241 $line .= $this->skin->makeKnownLinkObj( $cuTitle,
243242 htmlspecialchars( $row->cuc_xff ),
244243 "user=" . urlencode( $client ) . "/xff" )."</span>";
245244 }
246 - # Previous username
247 - if( $wgCURecordCookieData && $row->cuc_cookie_user !=null ) {
248 - $line .= '&nbsp;&nbsp;&nbsp;<strong>' . wfMsgHtml('checkuser-prev-name') . '</strong> ' .
249 - $this->skin->userLink( -1, $row->cuc_cookie_user );
250 - }
251245 $line .= "</small></li>\n";
252246
253247 return $line;
@@ -258,22 +252,19 @@
259253 */
260254 function getLinkFromRow( $row ) {
261255 if( $row->cuc_type == RC_LOG && $row->cuc_namespace == NS_SPECIAL ) {
262 - // Log items (old format) and events to logs
 256+ //Log items (old format) and events to logs
263257 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $row->cuc_title );
264258 $logname = LogPage::logName( $logtype );
265259 $title = Title::makeTitle( $row->cuc_namespace, $row->cuc_title );
266260 $links = '(' . $this->skin->makeKnownLinkObj( $title, $logname ) . ')';
267261 } elseif( $row->cuc_type == RC_LOG ) {
268 - // Log items
 262+ //Log items
269263 $specialTitle = SpecialPage::getTitleFor( 'Log' );
270264 $title = Title::makeTitle( $row->cuc_namespace, $row->cuc_title );
271 - $links = '(' . $this->skin->makeKnownLinkObj( $specialTitle, $this->message['checkuser-pagelogs'],
 265+ $links = '(' . $this->skin->makeKnownLinkObj( $specialTitle, $this->message['log'],
272266 wfArrayToCGI( array('page' => $title->getPrefixedText() ) ) ) . ')';
273 - } elseif( $row->cuc_type == CU_ALT_LOGIN ) {
274 - // Login events
275 - $links = '(' . wfMsg('checkuser-login') . ')';
276267 } elseif( !is_null( $row->cuc_this_oldid ) ) {
277 - // Everything else
 268+ //Everything else
278269 $title = Title::makeTitle( $row->cuc_namespace, $row->cuc_title );
279270 #new pages
280271 if( $row->cuc_type == RC_NEW ) {
@@ -404,9 +395,9 @@
405396 # XFF string, link to /xff search
406397 if( $set[1] ) {
407398 # Flag our trusted proxies
408 - list($client,$trusted) = wfGetClientIPfromXFF($set[1],$set[0]);
 399+ list($client,$trusted) = efGetClientIPfromXFF($set[1],$set[0]);
409400 $c = $trusted ? '#F0FFF0' : '#FFFFCC';
410 - $s .= '&nbsp;&nbsp;&nbsp;<span style="background-color: '.$c.'"><strong>'.wfMsgHtml('checkuser-ip').'</strong> ';
 401+ $s .= '&nbsp;&nbsp;&nbsp;<span style="background-color: '.$c.'"><strong>XFF</strong>: ';
411402 $s .= $sk->makeKnownLinkObj( $wgTitle,
412403 htmlspecialchars( $set[1] ),
413404 "user=" . urlencode( $client ) . "/xff" )."</span>";
Index: trunk/extensions/CheckUser/CheckUser.i18n.php
@@ -31,11 +31,6 @@
3232 'checkuser-log-fail' => 'Unable to add log entry',
3333 'checkuser-nolog' => 'No log file found.',
3434 'checkuser-blocked' => 'Blocked',
35 - 'checkuser-login' => 'Logged in, but had a valid session for another account',
36 - 'checkuser-xff' => 'XFF:', # only translate this message to other languages if you have to change it
37 - 'checkuser-ip' => 'IP:', # only translate this message to other languages if you have to change it
38 - 'checkuser-prev-name' => 'Previous session:',
39 - 'checkuser-pagelogs' => 'page logs',
4035 );
4136 $wgCheckUserMessages['ar'] = array(
4237 'checkuser' => 'افحص مستخدم',
@@ -86,9 +81,6 @@
8782 'checkuser-log-fail' => 'Logbuch-Eintrag kann nicht hinzugefügt werden.',
8883 'checkuser-nolog' => 'Kein Logbuch vorhanden.',
8984 'checkuser-blocked' => 'gesperrt',
90 - 'checkuser-login' => 'Angemeldet, aber es war eine gültige Session für einen anderen Benutzernamen vorhanden.',
91 - 'checkuser-prev-name' => 'Vorhergehende Session:',
92 - 'checkuser-pagelogs' => 'Seiten-Lögbücher',
9385 );
9486 $wgCheckUserMessages['fi'] = array(
9587 'checkuser-summary' => 'Tämän työkalun avulla voidaan tutkia tuoreet muutokset ja paljastaa käyttäjien IP-osoitteet tai noutaa IP-osoitteiden muokkaukset ja käyttäjätiedot.
@@ -169,11 +161,6 @@
170162 'checkuser-log-fail' => 'לא ניתן היה להוסיף פריט ליומן',
171163 'checkuser-nolog' => 'לא נמצא קובץ יומן.',
172164 'checkuser-blocked' => 'חסום',
173 - 'checkuser-login' => 'מחובר, אבל בעל חיבור תקין לחשבון אחר',
174 - 'checkuser-xff' => 'XFF:',
175 - 'checkuser-ip' => 'IP:',
176 - 'checkuser-prev-name' => 'חיבור קודם:',
177 - 'checkuser-pagelogs' => 'יומני דף',
178165 );
179166 $wgCheckUserMessages['id'] = array(
180167 'checkuser-summary' => 'Peralatan ini memindai perubahan terbaru untuk mendapatkan IP yang digunakan oleh seorang pengguna atau menunjukkan data suntingan/pengguna untuk suatu IP.
@@ -481,11 +468,6 @@
482469 'checkuser-log-fail' => '唔能夠加入日誌項目',
483470 'checkuser-nolog' => '搵唔到日誌檔。',
484471 'checkuser-blocked' => '已經封鎖',
485 - 'checkuser-login' => '登入咗,但對另一個戶口係需要一個有效嘅過程',
486 - 'checkuser-xff' => 'XFF:',
487 - 'checkuser-ip' => 'IP:',
488 - 'checkuser-prev-name' => '之前嘅過程:',
489 - 'checkuser-pagelogs' => '頁面日誌',
490472 );
491473 $wgCheckUserMessages['zh-hans'] = array(
492474 'checkuser-summary' => '本工具会从{{int:recentchanges}}中查询使用者使用过的IP位址,或是一个IP位址发送出来的任何编辑记录。本工具支持IPv4及IPv6的位址。由于技术上的限制,本工具只能查询最近5000笔的记录。请确定你的行为符合守则。',
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -6,9 +6,6 @@
77 exit(1);
88 }
99
10 -# RC_MOVE not used in this table, so no overlap
11 -define( 'CU_ALT_LOGIN', 2);
12 -
1310 # Internationalisation file
1411 require_once( 'CheckUser.i18n.php' );
1512
@@ -26,18 +23,11 @@
2724
2825 # How long to keep CU data?
2926 $wgCUDMaxAge = 3 * 30 * 24 * 3600;
30 -# If set to true, usernames from leftover sessions for IP edits will be stored.
31 -# It will also be stored during login if the old session data for the usre is
32 -# for a different account. (Note that user renames can cause this).
33 -# If you have an older version of checkuser without the cuc_cookie_user column,
34 -# run patch-cuc_cookie_user.sql before enabling this
35 -$wgCURecordCookieData = false;
3627
3728 #Recent changes data hook
3829 global $wgHooks;
3930 $wgHooks['RecentChange_save'][] = 'efUpdateCheckUserData';
4031 $wgHooks['ParserTestTables'][] = 'efCheckUserParserTestTables';
41 -$wgHooks['LoginAuthenticateAudit'][] = 'efCheckUserRecordLogin';
4232 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efCheckUserSchemaUpdates';
4333
4434 /**
@@ -45,7 +35,7 @@
4636 * Saves user data into the cu_changes table
4737 */
4838 function efUpdateCheckUserData( $rc ) {
49 - global $wgUser, $wgCURecordCookieData;
 39+ global $wgUser;
5040 // Extract params
5141 extract( $rc->mAttribs );
5242 // Get IP
@@ -87,10 +77,6 @@
8878 'cuc_xff_hex' => ($xff_ip && !$isSquidOnly) ? IP::toHex( $xff_ip ) : null,
8979 'cuc_agent' => $agent
9080 );
91 - // Fetch and add user cookie data
92 - if( $wgCURecordCookieData && $wgUser->isAnon() ) {
93 - $rcRow['cuc_cookie_user'] = efGetUsernameFromCookie();
94 - }
9581
9682 $dbw = wfGetDB( DB_MASTER );
9783 $dbw->insert( 'cu_changes', $rcRow, __METHOD__ );
@@ -111,56 +97,6 @@
11298 return true;
11399 }
114100
115 -function efCheckUserRecordLogin( &$user, &$mPassword, &$retval ) {
116 - global $wgCURecordCookieData, $wgUser;
117 - // $wgCURecordCookieData must be enabled
118 - // Also, we only care for valid login attempts
119 - if( !$wgCURecordCookieData || $retval != LoginForm::SUCCESS )
120 - return true;
121 - // Do not record re-logins
122 - if( $wgUser->getName() != $user->getName() )
123 - return true;
124 - // Get IP
125 - $ip = wfGetIP();
126 - // Get XFF header
127 - $xff = wfGetForwardedFor();
128 - list($xff_ip,$trusted) = efGetClientIPfromXFF( $xff );
129 - // Our squid XFFs can flood this up sometimes
130 - $isSquidOnly = efXFFChainIsSquid( $xff );
131 - // Get agent
132 - $agent = wfGetAgent();
133 - // Get cookie data
134 - $cuc_cookie_name = efGetUsernameFromCookie();
135 - if( $cuc_cookie_name == $user->getName() )
136 - return true; // Nothing special...
137 -
138 - $rcRow = array(
139 - 'cuc_namespace' => NS_USER,
140 - 'cuc_title' => $user->getName(),
141 - 'cuc_minor' => 0,
142 - 'cuc_user' => $user->getId(),
143 - 'cuc_user_text' => $user->getName(),
144 - 'cuc_actiontext' => '',
145 - 'cuc_comment' => '',
146 - 'cuc_page_id' => 0,
147 - 'cuc_this_oldid' => 0,
148 - 'cuc_last_oldid' => 0,
149 - 'cuc_type' => CU_ALT_LOGIN,
150 - 'cuc_timestamp' => wfTimestampNow(),
151 - 'cuc_ip' => $ip,
152 - 'cuc_ip_hex' => $ip ? IP::toHex( $ip ) : null,
153 - 'cuc_xff' => !$isSquidOnly ? $xff : '',
154 - 'cuc_xff_hex' => ($xff_ip && !$isSquidOnly) ? IP::toHex( $xff_ip ) : null,
155 - 'cuc_agent' => $agent,
156 - 'cuc_cookie_user' => efGetUsernameFromCookie()
157 - );
158 -
159 - $dbw = wfGetDB( DB_MASTER );
160 - $dbw->insert( 'cu_changes', $rcRow, __METHOD__ );
161 -
162 - return true;
163 -}
164 -
165101 /**
166102 * Locates the client IP within a given XFF string
167103 * @param string $xff
@@ -197,11 +133,6 @@
198134 return array( $client, $trusted );
199135 }
200136
201 -/**
202 - * Determines if an XFF string is just local squid IPs
203 - * @param string $xff
204 - * @return bool
205 - */
206137 function efXFFChainIsSquid( $xff ) {
207138 global $wgSquidServers, $wgSquidServersNoPurge;
208139
@@ -227,41 +158,6 @@
228159 return $squidOnly;
229160 }
230161
231 -/**
232 - * Gets the username from client cookie
233 - * If the token is invalid for this user, this will return false
234 - * @return string
235 - */
236 -function efGetUsernameFromCookie() {
237 - global $wgCookiePrefix;
238 -
239 - // Try to get name from session
240 - if( isset( $_SESSION['wsUserName'] ) ) {
241 - $name = $_SESSION['wsUserName'];
242 - // Try cookie
243 - } else if( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
244 - $name = $_COOKIE["{$wgCookiePrefix}UserName"];
245 - } else {
246 - return false;
247 - }
248 - // Load the supposed user
249 - $u = User::newFromName( $name );
250 - $u->load();
251 - // Validate the token
252 - if( isset( $_SESSION['wsToken'] ) ) {
253 - $passwordCorrect = $_SESSION['wsToken'] == $u->mToken;
254 - } else if( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
255 - $passwordCorrect = $u->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
256 - } else {
257 - return false;
258 - }
259 - // User must have proper credentials
260 - if( !$passwordCorrect )
261 - return false;
262 -
263 - return $name;
264 -}
265 -
266162 function efCheckUserSchemaUpdates() {
267163 global $wgDBtype, $wgExtNewFields, $wgExtNewIndexes;
268164
@@ -270,13 +166,8 @@
271167
272168 # FIXME: do postgres index changes!
273169 if ($wgDBtype == 'mysql') {
274 - $wgExtNewFields[] = array('cu_changes',
275 - 'cuc_cookie_user', dirname(__FILE__) . '/archives/patch-cuc_cookie_user.sql');
276170 $wgExtNewIndexes[] = array('cu_changes',
277171 'cuc_user_time', dirname(__FILE__) . '/archives/patch-cu_changes_indexes.sql');
278 - } else {
279 - $wgExtNewFields[] = array('cu_changes',
280 - 'cuc_cookie_user', dirname(__FILE__) . 'TEXT');
281172 }
282173 return true;
283174 }
@@ -294,3 +185,5 @@
295186 require( dirname(__FILE__) . '/../ExtensionFunctions.php' );
296187 }
297188 extAddSpecialPage( dirname(__FILE__) . '/CheckUser_body.php', 'CheckUser', 'CheckUser' );
 189+
 190+
Index: trunk/extensions/CheckUser/cu_changes.pg.sql
@@ -7,25 +7,24 @@
88
99 CREATE SEQUENCE cu_changes_cu_id_seq;
1010 CREATE TABLE cu_changes (
11 - cuc_id INTEGER NOT NULL DEFAULT nextval('cu_changes_cu_id_seq'),
12 - cuc_namespace SMALLINT NOT NULL DEFAULT 0,
13 - cuc_title TEXT NOT NULL DEFAULT '',
14 - cuc_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
15 - cuc_user_text TEXT NOT NULL,
16 - cuc_actiontext TEXT NOT NULL DEFAULT '',
17 - cuc_comment TEXT NOT NULL DEFAULT '',
18 - cuc_minor CHAR NOT NULL DEFAULT '0',
19 - cuc_page_id INTEGER NULL REFERENCES page(page_id) ON DELETE SET NULL,
20 - cuc_this_oldid INTEGER NOT NULL DEFAULT 0,
21 - cuc_last_oldid INTEGER NOT NULL default 0,
22 - cuc_type SMALLINT NOT NULL default '0',
23 - cuc_timestamp TIMESTAMPTZ,
24 - cuc_ip CIDR,
25 - cuc_ip_hex TEXT,
26 - cuc_xff TEXT,
27 - cuc_xff_hex TEXT,
28 - cuc_agent TEXT,
29 - cuc_cookie_user TEXT
 11+ cuc_id INTEGER NOT NULL DEFAULT nextval('cu_changes_cu_id_seq'),
 12+ cuc_namespace SMALLINT NOT NULL DEFAULT 0,
 13+ cuc_title TEXT NOT NULL DEFAULT '',
 14+ cuc_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
 15+ cuc_user_text TEXT NOT NULL,
 16+ cuc_actiontext TEXT NOT NULL DEFAULT '',
 17+ cuc_comment TEXT NOT NULL DEFAULT '',
 18+ cuc_minor CHAR NOT NULL DEFAULT '0',
 19+ cuc_page_id INTEGER NULL REFERENCES page(page_id) ON DELETE SET NULL,
 20+ cuc_this_oldid INTEGER NOT NULL DEFAULT 0,
 21+ cuc_last_oldid INTEGER NOT NULL default 0,
 22+ cuc_type SMALLINT NOT NULL default '0',
 23+ cuc_timestamp TIMESTAMPTZ,
 24+ cuc_ip CIDR,
 25+ cuc_ip_hex TEXT,
 26+ cuc_xff TEXT,
 27+ cuc_xff_hex TEXT,
 28+ cuc_agent TEXT
3029 );
3130
3231 CREATE INDEX cu_changes_index ON cu_changes(cuc_user, cuc_ip_hex, cuc_xff_hex, cuc_timestamp);
Index: trunk/extensions/CheckUser/archives/patch-cuc_cookie_user.sql
@@ -1,6 +0,0 @@
2 -
3 -ALTER TABLE /*$wgDBprefix*/cu_changes
4 - ADD cuc_cookie_user VARCHAR(255) BINARY default NULL;
Index: trunk/extensions/CheckUser/cu_changes.sql
@@ -51,9 +51,6 @@
5252 -- User agent
5353 cuc_agent VARCHAR(255) BINARY default NULL,
5454
55 - -- Last username from session/cookie data
56 - cuc_cookie_user VARCHAR(255) BINARY default NULL,
57 -
5855 PRIMARY KEY cuc_id (cuc_id),
5956 INDEX cuc_ip_hex_time (cuc_ip_hex,cuc_timestamp),
6057 INDEX cuc_user_time (cuc_user,cuc_timestamp),

Status & tagging log