http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100186
Revision: 100186
Author: johnduhart
Date: 2011-10-18 23:41:53 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
Followup r100165, fixing formatting per CR
Modified Paths:
--------------
trunk/extensions/CheckUser/CheckUser.hooks.php
trunk/extensions/CheckUser/CheckUser.php
trunk/extensions/CheckUser/CheckUser_body.php
trunk/extensions/CheckUser/api/ApiQueryCheckUser.php
trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php
trunk/extensions/CheckUser/maintenance/purgeOldData.php
Modified: trunk/extensions/CheckUser/CheckUser.hooks.php
===================================================================
--- trunk/extensions/CheckUser/CheckUser.hooks.php 2011-10-18 23:41:29 UTC
(rev 100185)
+++ trunk/extensions/CheckUser/CheckUser.hooks.php 2011-10-18 23:41:53 UTC
(rev 100186)
@@ -6,7 +6,7 @@
*/
public static function updateCheckUserData( RecentChange $rc ) {
global $wgRequest, $wgCUDMaxAge;
-
+
// Extract params
extract( $rc->mAttribs );
// Get IP
@@ -28,7 +28,7 @@
} else {
$actionText = '';
}
-
+
$dbw = wfGetDB( DB_MASTER );
$cuc_id = $dbw->nextSequenceValue( 'cu_changes_cu_id_seq' );
$rcRow = array(
@@ -61,17 +61,17 @@
$encCutoff = $dbw->addQuotes( $dbw->timestamp( time() -
$wgCUDMaxAge ) );
$dbw->delete( 'cu_changes', array( "cuc_timestamp <
$encCutoff" ), __METHOD__ );
}
-
+
return true;
}
-
+
/**
* Hook function to store password reset
* Saves user data into the cu_changes table
*/
public static function updateCUPasswordResetData( User $user, $ip,
$account ) {
global $wgRequest;
-
+
// Get XFF header
$xff = $wgRequest->getHeader( 'X-Forwarded-For' );
list( $xff_ip, $isSquidOnly ) = self::getClientIPfromXFF( $xff
);
@@ -99,10 +99,10 @@
'cuc_agent' => $agent
);
$dbw->insert( 'cu_changes', $rcRow, __METHOD__ );
-
+
return true;
}
-
+
/**
* Hook function to store email data
* Saves user data into the cu_changes table
@@ -144,10 +144,10 @@
'cuc_agent' => $agent
);
$dbw->insert( 'cu_changes', $rcRow, __METHOD__ );
-
+
return true;
}
-
+
/**
* Hook function to store autocreation data from the auth plugin
* Saves user data into the cu_changes table
@@ -159,7 +159,7 @@
public static function updateAutoCreateData( User $user ) {
return self::logUserAccountCreation( $user,
'checkuser-autocreate-action' );
}
-
+
/**
* @param $user User
* @param $actiontext string
@@ -167,7 +167,7 @@
*/
public static function logUserAccountCreation( User $user, $actiontext
) {
global $wgRequest;
-
+
// Get IP
$ip = wfGetIP();
// Get XFF header
@@ -198,10 +198,10 @@
'cuc_agent' => $agent
);
$dbw->insert( 'cu_changes', $rcRow, __METHOD__ );
-
+
return true;
}
-
+
/**
* Hook function to store registration data
* Saves user data into the cu_changes table
@@ -213,7 +213,7 @@
public static function addNewAccount( User $user, $byEmail ) {
return self::logUserAccountCreation( $user,
'checkuser-create-action' );
}
-
+
/**
* Locates the client IP within a given XFF string
* @param string $xff
@@ -287,7 +287,7 @@
create_cu_log( $db );
}
}
-
+
/**
* Tell the parser test engine to create a stub cu_changes table,
* or temporary pages won't save correctly during the test run.
@@ -296,7 +296,7 @@
$tables[] = 'cu_changes';
return true;
}
-
+
/**
* Add a link to Special:CheckUser on Special:Contributions/<username>
for
* privileged users.
Modified: trunk/extensions/CheckUser/CheckUser.php
===================================================================
--- trunk/extensions/CheckUser/CheckUser.php 2011-10-18 23:41:29 UTC (rev
100185)
+++ trunk/extensions/CheckUser/CheckUser.php 2011-10-18 23:41:53 UTC (rev
100186)
@@ -82,8 +82,8 @@
$wgSpecialPages['CheckUser'] = 'CheckUser';
$wgSpecialPageGroups['CheckUser'] = 'users';
-$wgAutoloadClasses['CheckUser'] = dirname( __FILE__ ) . '/CheckUser_body.php';
-$wgAutoloadClasses['CheckUserHooks'] = dirname( __FILE__ ) .
'/CheckUser.hooks.php';
+$wgAutoloadClasses['CheckUser'] = $dir . '/CheckUser_body.php';
+$wgAutoloadClasses['CheckUserHooks'] = $dir . '/CheckUser.hooks.php';
// API modules
$wgAutoloadClasses['ApiQueryCheckUser'] = "$dir/api/ApiQueryCheckUser.php";
Modified: trunk/extensions/CheckUser/CheckUser_body.php
===================================================================
--- trunk/extensions/CheckUser/CheckUser_body.php 2011-10-18 23:41:29 UTC
(rev 100185)
+++ trunk/extensions/CheckUser/CheckUser_body.php 2011-10-18 23:41:53 UTC
(rev 100186)
@@ -176,7 +176,7 @@
$form .= ' ' . $this->getPeriodMenu( $period ) . '</td>';
$form .= '</tr><tr>';
$form .= '<td></td>';
- $form .= Xml::openElement('td', array( 'class' =>
'checkuserradios' ) );
+ $form .= Xml::openElement( 'td', array( 'class' =>
'checkuserradios' ) );
$form .= Xml::openElement( 'table', array( 'style' =>
'border:0' ) );
$form .= '<tr>';
$form .= '<td>' .
@@ -278,18 +278,18 @@
$counter = $blockSize = 0;
$safeUsers = array();
$log = new LogPage( 'block' );
- foreach( $users as $name ) {
+ foreach ( $users as $name ) {
# Enforce limits
$counter++;
$blockSize++;
# Lets not go *too* fast
- if( $blockSize >= 20 ) {
+ if ( $blockSize >= 20 ) {
$blockSize = 0;
wfWaitForSlaves( 5 );
}
$u = User::newFromName( $name, false );
// If user doesn't exist, it ought to be an IP then
- if( is_null( $u ) || ( !$u->getId() &&
!IP::isIPAddress( $u->getName() ) ) ) {
+ if ( is_null( $u ) || ( !$u->getId() &&
!IP::isIPAddress( $u->getName() ) ) ) {
continue;
}
$userTitle = $u->getUserPage();
@@ -314,12 +314,12 @@
$block->prevents( 'editownusertalk', false );
$oldblock = Block::newFromTarget( $u->getName() );
- if( !$oldblock ) {
+ if ( !$oldblock ) {
$block->insert();
# Prepare log parameters
$logParams = array();
$logParams[] = $expirestr;
- if( $anonOnly ) {
+ if ( $anonOnly ) {
$logParams[] = 'anononly';
}
$logParams[] = 'nocreate';
@@ -327,10 +327,10 @@
$log->addEntry( 'block', $userTitle, $reason,
$logParams );
}
# Tag userpage! (check length to avoid mistakes)
- if( strlen( $tag ) > 2 ) {
+ if ( strlen( $tag ) > 2 ) {
$userpage->doEdit( $tag, $reason, EDIT_MINOR );
}
- if( strlen( $talkTag ) > 2 ) {
+ if ( strlen( $talkTag ) > 2 ) {
$usertalk->doEdit( $talkTag, $reason,
EDIT_MINOR );
}
}
@@ -648,9 +648,9 @@
$ret = $dbr->select(
'cu_changes',
array(
- 'cuc_namespace','cuc_title', 'cuc_user',
'cuc_user_text', 'cuc_comment', 'cuc_actiontext',
+ 'cuc_namespace', 'cuc_title', 'cuc_user',
'cuc_user_text', 'cuc_comment', 'cuc_actiontext',
'cuc_timestamp', 'cuc_minor', 'cuc_page_id',
'cuc_type', 'cuc_this_oldid',
- 'cuc_last_oldid', 'cuc_ip',
'cuc_xff','cuc_agent'
+ 'cuc_last_oldid', 'cuc_ip', 'cuc_xff',
'cuc_agent'
),
array( $ip_conds, $time_conds ),
__METHOD__,
@@ -956,7 +956,7 @@
$s = $this->noMatchesMessage( $ip, !$xfor ) . "\n";
} else {
global $wgAuth;
- foreach( $ret as $row ) {
+ foreach ( $ret as $row ) {
if ( !array_key_exists( $row->cuc_user_text,
$users_edits ) ) {
$users_last[$row->cuc_user_text] =
$row->cuc_timestamp;
$users_edits[$row->cuc_user_text] = 0;
Modified: trunk/extensions/CheckUser/api/ApiQueryCheckUser.php
===================================================================
--- trunk/extensions/CheckUser/api/ApiQueryCheckUser.php 2011-10-18
23:41:29 UTC (rev 100185)
+++ trunk/extensions/CheckUser/api/ApiQueryCheckUser.php 2011-10-18
23:41:53 UTC (rev 100186)
@@ -1,271 +1,279 @@
<?php
+
/**
* CheckUser API Query Module
*/
-
class ApiQueryCheckUser extends ApiQueryBase {
- public function __construct( $query, $moduleName ) {
- parent::__construct( $query, $moduleName, 'cu' );
- }
-
- public function execute() {
- global $wgUser, $wgCheckUserForceSummary;
-
- $db = $this->getDB( DB_SLAVE );
- $params = $this->extractRequestParams();
-
- if( !$wgUser->isAllowed( 'checkuser' ) ) {
- $this->dieUsage( 'You need the checkuser right', 'permissionerror'
);
- }
-
- if( $wgCheckUserForceSummary && is_null($params['reason']) ) {
- $this->dieUsage( 'You need define reason for check', 'missingdata'
);
- }
-
- $limit = $params['limit'];
- $target = $params['target'];
- $reason = wfMsgForContent( 'checkuser-reason-api' ) . ' ' .
$params['reason'];
- $time = wfTimestamp( TS_MW, strtotime('now') - (
strtotime($params['timecond'] ? $params['timecond'] : '2 weeks') -
strtotime('now')));
- if( !$time ) {
- $this->dieUsage( 'You need use correct time limit (like "2
weeks")', 'invalidtime' );
- }
-
- $this->addTables( 'cu_changes' );
- $this->addOption( 'LIMIT', $limit + 1 );
- $this->addOption( 'ORDER BY', 'cuc_timestamp DESC' );
- $this->addWhere( "cuc_timestamp > $time" );
-
- switch($params['request']) {
- case 'userips':
- $user_id = User::idFromName( $target );
- if( !$user_id ) {
- $this->dieUsage( 'Target user does not exist',
'nosuchuser' );
- }
-
- $this->addFields( array('cuc_timestamp', 'cuc_ip', 'cuc_xff')
);
- $this->addWhere( "cuc_user_text = '$target'" );
- $res = $this->select( __METHOD__ );
- $result = $this->getResult();
-
- $ips = array();
- foreach( $res as $row ) {
- $timestamp = $row->cuc_timestamp;
- $ip = strval($row->cuc_ip);
- $xff = $row->cuc_xff;
-
- if( !isset( $ips[$ip] ) ) {
- $ips[$ip]['end'] = $timestamp;
- $ips[$ip]['editcount'] = 1;
- } else {
- $ips[$ip]['start'] = $timestamp;
- $ips[$ip]['editcount']++;
- }
- }
-
- $count = 0;
- foreach( array_keys($ips) as $ip ) {
- $ips[$count] = $ips[$ip];
- $ips[$count]['address'] = $ip;
- unset($ips[$ip]);
- $count++;
- }
-
- CheckUser::addLogEntry('userips', 'user', $target, $reason,
$user_id);
- $result->addValue( array( 'query', $this->getModuleName() ),
'userips', $ips );
- $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName(), 'userips' ), 'ip' );
- break;
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'cu' );
+ }
- case 'edits':
- if( IP::isIPAddress($target) && isset($params['xff']) ) {
- $cond = CheckUser::getIpConds($db, $target, true);
- if( !$cond ) {
- $this->dieUsage( 'IP or range is invalid', 'invalidip'
);
- }
- $this->addWhere( "$cond" );
- $log_type = array('ipedits-xff', 'ip');
- } elseif ( IP::isIPAddress($target) ) {
- $cond = CheckUser::getIpConds($db, $target);
- if( !$cond ) {
- $this->dieUsage( 'IP or range is invalid', 'invalidip'
);
- }
- $this->addWhere( "$cond" );
- $log_type = array('ipedits', 'ip');
- } else {
- $user_id = User::idFromName( $target );
- if( !$user_id ) {
- $this->dieUsage( 'Target user is not exists',
'nosuchuser' );
- }
- $this->addWhere( "cuc_user_text = '$target'" );
- $log_type = array('useredits', 'user');
- }
-
- $this->addFields( array('cuc_namespace', 'cuc_title',
'cuc_user_text', 'cuc_actiontext', 'cuc_comment', 'cuc_minor', 'cuc_timestamp',
'cuc_ip', 'cuc_xff', 'cuc_agent') );
-
- $res = $this->select( __METHOD__ );
- $result = $this->getResult();
-
- $edits = array();
- $count = 0;
- foreach( $res as $row ) {
- $edits[$count]['timestamp'] = $row->cuc_timestamp;
- $edits[$count]['ns'] = $row->cuc_namespace;
- $edits[$count]['title'] = $row->cuc_title;
- $edits[$count]['user'] = $row->cuc_user_text;
- if( $row->cuc_actiontext ) {
- $edits[$count]['summary'] = $row->cuc_actiontext;
- } elseif( $row->cuc_comment ) {
- $edits[$count]['summary'] = $row->cuc_comment;
- }
- if( $row->cuc_minor ) {
- $edits[$count]['minor'] = 'm';
- }
- $edits[$count]['ip'] = $row->cuc_ip;
- if( $row->cuc_xff ) {
- $edits[$count]['xff'] = $row->cuc_xff;
- }
- $edits[$count]['agent'] = $row->cuc_agent;
- $count++;
- }
-
- CheckUser::addLogEntry($log_type[0], $log_type[1], $target,
$reason, $user_id ? $user_id : '0');
- $result->addValue( array( 'query', $this->getModuleName() ),
'edits', $edits );
- $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName(), 'edits' ), 'action' );
- break;
+ public function execute() {
+ global $wgUser, $wgCheckUserForceSummary;
- case 'ipusers':
- if( IP::isIPAddress($target) && isset($params['xff']) ) {
- $cond = CheckUser::getIpConds($db, $target, true);
- $this->addWhere( $cond );
- } elseif ( IP::isIPAddress($target) ) {
- $cond = CheckUser::getIpConds($db, $target);
- $this->addWhere( $cond );
- $log_type = 'ipusers';
- } else {
- $this->dieUsage( 'IP or range is invalid', 'invalidip' );
- }
-
- $this->addFields( array('cuc_user_text', 'cuc_timestamp',
'cuc_ip', 'cuc_agent') );
-
- $res = $this->select( __METHOD__ );
- $result = $this->getResult();
-
- $users = array();
- foreach( $res as $row ) {
- $user = $row->cuc_user_text;
- $ip = $row->cuc_ip;
- $agent = $row->cuc_agent;
-
- if( !isset($users[$user]) ) {
- $users[$user]['end'] = $row->cuc_timestamp;
- $users[$user]['editcount'] = 1;
- $users[$user]['ips'][] = $ip;
- $users[$user]['agents'][] = $agent;
- } else {
- $users[$user]['start'] = $row->cuc_timestamp;
- $users[$user]['editcount']++;
- if( !in_array( $ip, $users[$user]['ips'] ) )
$users[$user]['ips'][] = $ip;
- if( !in_array( $agent, $users[$user]['agents'] ) )
$users[$user]['agents'][] = $agent;
- }
- }
-
- $count = 0;
- foreach( array_keys($users) as $user ) {
- $users[$count] = $users[$user];
- $users[$count]['name'] = $user;
- unset($users[$user]);
-
- $result->setIndexedTagName( $users[$count]['ips'], 'ip' );
- $result->setIndexedTagName( $users[$count]['agents'],
'agent' );
-
- $count++;
- }
-
- CheckUser::addLogEntry($log_type, 'ip', $target, $reason);
- $result->addValue( array( 'query', $this->getModuleName() ),
'ipusers', $users );
- $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName(), 'ipusers' ), 'user' );
- break;
-
- default:
- $this->dieUsage( 'Invalid request mode', 'invalidmode' );
- }
- }
-
- public function mustBePosted() {
- return true;
- }
-
- public function isWriteMode() {
- return true;
- }
+ $db = $this->getDB( DB_SLAVE );
+ $params = $this->extractRequestParams();
- public function getAllowedParams() {
- return array(
- 'request' => array(
- ApiBase::PARAM_REQUIRED => false,
- ApiBase::PARAM_TYPE => array(
- 'userips',
- 'edits',
- 'ipusers'
- )
- ),
- 'target' => array(
- ApiBase::PARAM_REQUIRED => false
- ),
- 'reason' => null,
- 'limit' => array(
- ApiBase::PARAM_DFLT => 1000,
- ApiBase::PARAM_TYPE => 'limit',
- ApiBase::PARAM_MIN => 1,
- ApiBase::PARAM_MAX => 5000,
- ApiBase::PARAM_MAX2 => 5000
- ),
- 'timecond' => null
- );
- }
+ if ( !$wgUser->isAllowed( 'checkuser' ) ) {
+ $this->dieUsage( 'You need the checkuser right',
'permissionerror' );
+ }
- public function getParamDescription() {
- return array(
- 'request' => array(
- 'Type of CheckUser request',
- ' userips - get IP of target user',
- ' edits - get changes from target IP or range',
- ' ipusers - get users from target IP or range',
- ),
- 'target' => "Username or IP-address/range to perform check",
- 'reason' => 'Reason to check',
- 'limit' => 'Limit of rows',
- 'timecond' => 'Time limit of user data (like "2 weeks")'
- );
- }
+ if ( $wgCheckUserForceSummary && is_null( $params['reason'] ) )
{
+ $this->dieUsage( 'You need define reason for check',
'missingdata' );
+ }
- public function getDescription() {
- return 'Allows check which IPs are used by a given username and which
usernames are used by a given IP';
- }
+ $limit = $params['limit'];
+ $target = $params['target'];
+ $reason = wfMsgForContent( 'checkuser-reason-api' ) . ' ' .
$params['reason'];
+ $time = wfTimestamp( TS_MW,
+ strtotime( 'now' ) - ( strtotime( $params['timecond'] ?
$params['timecond'] : '2 weeks' ) - strtotime( 'now'
+ ) )
+ );
+ if ( !$time ) {
+ $this->dieUsage( 'You need use correct time limit (like
"2 weeks")', 'invalidtime' );
+ }
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(),
- array(
- array( 'nosuchuser' ),
- array( 'invalidip' ),
- array( 'permissionerror' ),
- array( 'invalidmode' ),
- array( 'missingdata' )
- )
- );
- }
+ $this->addTables( 'cu_changes' );
+ $this->addOption( 'LIMIT', $limit + 1 );
+ $this->addOption( 'ORDER BY', 'cuc_timestamp DESC' );
+ $this->addWhere( "cuc_timestamp > $time" );
- public function getExamples() {
- return array(
-
'api.php?action=query&list=checkuser&curequest=userips&cutarget=Jimbo_Wales',
-
'api.php?action=query&list=checkuser&curequest=edits&cutarget=127.0.0.1/16/xff&cureason=Some_check'
- );
- }
+ switch ( $params['request'] ) {
+ case 'userips':
+ $user_id = User::idFromName( $target );
+ if ( !$user_id ) {
+ $this->dieUsage( 'Target user does not
exist', 'nosuchuser' );
+ }
- public function getHelpUrls() {
- return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API';
- }
+ $this->addFields( array( 'cuc_timestamp',
'cuc_ip', 'cuc_xff' ) );
+ $this->addWhere( "cuc_user_text = '$target'" );
+ $res = $this->select( __METHOD__ );
+ $result = $this->getResult();
- public function getVersion() {
- return __CLASS__ . ': $Id$';
- }
+ $ips = array();
+ foreach ( $res as $row ) {
+ $timestamp = $row->cuc_timestamp;
+ $ip = strval( $row->cuc_ip );
+ $xff = $row->cuc_xff;
+
+ if ( !isset( $ips[$ip] ) ) {
+ $ips[$ip]['end'] = $timestamp;
+ $ips[$ip]['editcount'] = 1;
+ } else {
+ $ips[$ip]['start'] = $timestamp;
+ $ips[$ip]['editcount']++;
+ }
+ }
+
+ $count = 0;
+ foreach ( array_keys( $ips ) as $ip ) {
+ $ips[$count] = $ips[$ip];
+ $ips[$count]['address'] = $ip;
+ unset( $ips[$ip] );
+ $count++;
+ }
+
+ CheckUser::addLogEntry( 'userips', 'user',
$target, $reason, $user_id );
+ $result->addValue( array( 'query',
$this->getModuleName() ), 'userips', $ips );
+ $result->setIndexedTagName_internal( array(
'query', $this->getModuleName(), 'userips' ), 'ip' );
+ break;
+
+ case 'edits':
+ if ( IP::isIPAddress( $target ) && isset(
$params['xff'] ) ) {
+ $cond = CheckUser::getIpConds( $db,
$target, true );
+ if ( !$cond ) {
+ $this->dieUsage( 'IP or range
is invalid', 'invalidip' );
+ }
+ $this->addWhere( "$cond" );
+ $log_type = array( 'ipedits-xff', 'ip'
);
+ } elseif ( IP::isIPAddress( $target ) ) {
+ $cond = CheckUser::getIpConds( $db,
$target );
+ if ( !$cond ) {
+ $this->dieUsage( 'IP or range
is invalid', 'invalidip' );
+ }
+ $this->addWhere( "$cond" );
+ $log_type = array( 'ipedits', 'ip' );
+ } else {
+ $user_id = User::idFromName( $target );
+ if ( !$user_id ) {
+ $this->dieUsage( 'Target user
is not exists', 'nosuchuser' );
+ }
+ $this->addWhere( "cuc_user_text =
'$target'" );
+ $log_type = array( 'useredits', 'user'
);
+ }
+
+ $this->addFields( array( 'cuc_namespace',
'cuc_title', 'cuc_user_text', 'cuc_actiontext', 'cuc_comment', 'cuc_minor',
'cuc_timestamp', 'cuc_ip', 'cuc_xff', 'cuc_agent' )
+ );
+
+ $res = $this->select( __METHOD__ );
+ $result = $this->getResult();
+
+ $edits = array();
+ $count = 0;
+ foreach ( $res as $row ) {
+ $edits[$count]['timestamp'] =
$row->cuc_timestamp;
+ $edits[$count]['ns'] =
$row->cuc_namespace;
+ $edits[$count]['title'] =
$row->cuc_title;
+ $edits[$count]['user'] =
$row->cuc_user_text;
+ if ( $row->cuc_actiontext ) {
+ $edits[$count]['summary'] =
$row->cuc_actiontext;
+ } elseif ( $row->cuc_comment ) {
+ $edits[$count]['summary'] =
$row->cuc_comment;
+ }
+ if ( $row->cuc_minor ) {
+ $edits[$count]['minor'] = 'm';
+ }
+ $edits[$count]['ip'] = $row->cuc_ip;
+ if ( $row->cuc_xff ) {
+ $edits[$count]['xff'] =
$row->cuc_xff;
+ }
+ $edits[$count]['agent'] =
$row->cuc_agent;
+ $count++;
+ }
+
+ CheckUser::addLogEntry( $log_type[0],
$log_type[1], $target, $reason, $user_id ? $user_id : '0' );
+ $result->addValue( array( 'query',
$this->getModuleName() ), 'edits', $edits );
+ $result->setIndexedTagName_internal( array(
'query', $this->getModuleName(), 'edits' ), 'action' );
+ break;
+
+ case 'ipusers':
+ if ( IP::isIPAddress( $target ) && isset(
$params['xff'] ) ) {
+ $cond = CheckUser::getIpConds( $db,
$target, true );
+ $this->addWhere( $cond );
+ } elseif ( IP::isIPAddress( $target ) ) {
+ $cond = CheckUser::getIpConds( $db,
$target );
+ $this->addWhere( $cond );
+ $log_type = 'ipusers';
+ } else {
+ $this->dieUsage( 'IP or range is
invalid', 'invalidip' );
+ }
+
+ $this->addFields( array( 'cuc_user_text',
'cuc_timestamp', 'cuc_ip', 'cuc_agent' ) );
+
+ $res = $this->select( __METHOD__ );
+ $result = $this->getResult();
+
+ $users = array();
+ foreach ( $res as $row ) {
+ $user = $row->cuc_user_text;
+ $ip = $row->cuc_ip;
+ $agent = $row->cuc_agent;
+
+ if ( !isset( $users[$user] ) ) {
+ $users[$user]['end'] =
$row->cuc_timestamp;
+ $users[$user]['editcount'] = 1;
+ $users[$user]['ips'][] = $ip;
+ $users[$user]['agents'][] =
$agent;
+ } else {
+ $users[$user]['start'] =
$row->cuc_timestamp;
+ $users[$user]['editcount']++;
+ if ( !in_array( $ip,
$users[$user]['ips'] ) ) {
+ $users[$user]['ips'][]
= $ip;
+ }
+ if ( !in_array( $agent,
$users[$user]['agents'] ) ) {
+
$users[$user]['agents'][] = $agent;
+ }
+ }
+ }
+
+ $count = 0;
+ foreach ( array_keys( $users ) as $user ) {
+ $users[$count] = $users[$user];
+ $users[$count]['name'] = $user;
+ unset( $users[$user] );
+
+ $result->setIndexedTagName(
$users[$count]['ips'], 'ip' );
+ $result->setIndexedTagName(
$users[$count]['agents'], 'agent' );
+
+ $count++;
+ }
+
+ CheckUser::addLogEntry( $log_type, 'ip',
$target, $reason );
+ $result->addValue( array( 'query',
$this->getModuleName() ), 'ipusers', $users );
+ $result->setIndexedTagName_internal( array(
'query', $this->getModuleName(), 'ipusers' ), 'user' );
+ break;
+
+ default:
+ $this->dieUsage( 'Invalid request mode',
'invalidmode' );
+ }
+ }
+
+ public function mustBePosted() {
+ return true;
+ }
+
+ public function isWriteMode() {
+ return true;
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'request' => array(
+ ApiBase::PARAM_REQUIRED => false,
+ ApiBase::PARAM_TYPE => array(
+ 'userips',
+ 'edits',
+ 'ipusers'
+ )
+ ),
+ 'target' => array(
+ ApiBase::PARAM_REQUIRED => false
+ ),
+ 'reason' => null,
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 1000,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => 5000,
+ ApiBase::PARAM_MAX2 => 5000
+ ),
+ 'timecond' => null
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'request' => array(
+ 'Type of CheckUser request',
+ ' userips - get IP of target user',
+ ' edits - get changes from target IP or
range',
+ ' ipusers - get users from target IP or range',
+ ),
+ 'target' => "Username or IP-address/range to perform
check",
+ 'reason' => 'Reason to check',
+ 'limit' => 'Limit of rows',
+ 'timecond' => 'Time limit of user data (like "2
weeks")',
+ );
+ }
+
+ public function getDescription() {
+ return 'Allows check which IPs are used by a given username and
which usernames are used by a given IP';
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(),
+ array(
+ array( 'nosuchuser' ),
+ array( 'invalidip' ),
+ array( 'permissionerror' ),
+ array( 'invalidmode' ),
+ array( 'missingdata' ),
+ )
+ );
+ }
+
+ public function getExamples() {
+ return array(
+
'api.php?action=query&list=checkuser&curequest=userips&cutarget=Jimbo_Wales',
+
'api.php?action=query&list=checkuser&curequest=edits&cutarget=127.0.0.1/16/xff&cureason=Some_check',
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API';
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
}
\ No newline at end of file
Modified: trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php
===================================================================
--- trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php 2011-10-18
23:41:29 UTC (rev 100185)
+++ trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php 2011-10-18
23:41:53 UTC (rev 100186)
@@ -1,117 +1,121 @@
<?php
+
/**
* CheckUser API Query Module
*/
+class ApiQueryCheckUserLog extends ApiQueryBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'cul' );
+ }
-class ApiQueryCheckUserLog extends ApiQueryBase {
- public function __construct( $query, $moduleName ) {
- parent::__construct( $query, $moduleName, 'cul' );
- }
-
- public function execute() {
- global $wgUser;
-
- $params = $this->extractRequestParams();
-
- if( !$wgUser->isAllowed( 'checkuser-log' ) ) {
- $this->dieUsage( 'You need the checkuser-log right',
'permissionerror' );
- }
-
- $user = $params['user'];
- $limit = $params['limit'];
- $target = $params['target'];
- $from = $params['from'];
- $to = $params['to'];
-
- $this->addTables( 'cu_log' );
- $this->addOption( 'LIMIT', $limit + 1 );
- $this->addOption( 'ORDER BY', 'cul_timestamp DESC' );
-
- $this->addFields( array('cul_timestamp', 'cul_user_text',
'cul_reason', 'cul_type', 'cul_target_text') );
-
- if( isset($user) ) $this->addWhere( "cul_user_text = '$user'" );
- if( isset($target) ) $this->addWhere( "cul_target_text = '$target'" );
- if( isset($from) && isset($to) ) {
- $this->addWhere( "cul_timestamp BETWEEN '$from' AND '$to'" );
- unset($from, $to);
- } elseif ( isset($from) ) {
- $this->addWhere( "cul_timestamp < $from" );
- } elseif ( isset($to) ) {
- $this->addWhere( "cul_timestamp > $to" );
- }
-
- $res = $this->select( __METHOD__ );
- $result = $this->getResult();
-
- $count = 0;
- $log = array();
- foreach( $res as $row ) {
- $log[$count]['timestamp'] = $row->cul_timestamp;
- $log[$count]['checkuser'] = $row->cul_user_text;
- $log[$count]['type'] = $row->cul_type;
- $log[$count]['reason'] = $row->cul_reason;
- $log[$count]['target'] = $row->cul_target_text;
- $count++;
- }
-
- $result->addValue( array( 'query', $this->getModuleName() ),
'entries', $log );
- $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName(), 'entries' ), 'entry' );
- }
-
- public function getAllowedParams() {
- return array(
- 'user' => null,
- 'target' => null,
- 'limit' => array(
+ public function execute() {
+ global $wgUser;
+
+ $params = $this->extractRequestParams();
+
+ if ( !$wgUser->isAllowed( 'checkuser-log' ) ) {
+ $this->dieUsage( 'You need the checkuser-log right',
'permissionerror' );
+ }
+
+ $user = $params['user'];
+ $limit = $params['limit'];
+ $target = $params['target'];
+ $from = $params['from'];
+ $to = $params['to'];
+
+ $this->addTables( 'cu_log' );
+ $this->addOption( 'LIMIT', $limit + 1 );
+ $this->addOption( 'ORDER BY', 'cul_timestamp DESC' );
+
+ $this->addFields( array( 'cul_timestamp', 'cul_user_text',
'cul_reason', 'cul_type', 'cul_target_text' ) );
+
+ if ( isset( $user ) ) {
+ $this->addWhere( "cul_user_text = '$user'" );
+ }
+ if ( isset( $target ) ) {
+ $this->addWhere( "cul_target_text = '$target'" );
+ }
+ if ( isset( $from ) && isset( $to ) ) {
+ $this->addWhere( "cul_timestamp BETWEEN '$from' AND
'$to'" );
+ unset( $from, $to );
+ } elseif ( isset( $from ) ) {
+ $this->addWhere( "cul_timestamp < $from" );
+ } elseif ( isset( $to ) ) {
+ $this->addWhere( "cul_timestamp > $to" );
+ }
+
+ $res = $this->select( __METHOD__ );
+ $result = $this->getResult();
+
+ $count = 0;
+ $log = array();
+ foreach ( $res as $row ) {
+ $log[$count]['timestamp'] = $row->cul_timestamp;
+ $log[$count]['checkuser'] = $row->cul_user_text;
+ $log[$count]['type'] = $row->cul_type;
+ $log[$count]['reason'] = $row->cul_reason;
+ $log[$count]['target'] = $row->cul_target_text;
+ $count++;
+ }
+
+ $result->addValue( array( 'query', $this->getModuleName() ),
'entries', $log );
+ $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName(), 'entries' ), 'entry' );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'user' => null,
+ 'target' => null,
+ 'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
- ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
),
- 'from' => array(
- ApiBase::PARAM_TYPE => 'timestamp'
+ 'from' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
),
- 'to' => array(
- ApiBase::PARAM_TYPE => 'timestamp'
+ 'to' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
),
- );
- }
+ );
+ }
- public function getParamDescription() {
- return array(
- 'user' => 'Username of CheckUser',
- 'target' => "Checked user or IP-address/range",
- 'limit' => 'Limit of rows',
- 'from' => 'The timestamp to start enumerating from',
- 'to' => 'The timestamp to end enumerating'
- );
- }
+ public function getParamDescription() {
+ return array(
+ 'user' => 'Username of CheckUser',
+ 'target' => "Checked user or IP-address/range",
+ 'limit' => 'Limit of rows',
+ 'from' => 'The timestamp to start enumerating from',
+ 'to' => 'The timestamp to end enumerating',
+ );
+ }
- public function getDescription() {
- return 'Allows get entries of CheckUser log';
- }
+ public function getDescription() {
+ return 'Allows get entries of CheckUser log';
+ }
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(),
- array(
- array( 'permissionerror' )
- )
- );
- }
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(),
+ array(
+ array( 'permissionerror' ),
+ ),
+ );
+ }
- public function getExamples() {
- return array(
-
'api.php?action=query&list=checkuserlog&culuser=WikiSysop&limit=25',
-
'api.php?action=query&list=checkuserlog&cultarget=127.0.0.1&culfrom=20111015230000'
- );
- }
+ public function getExamples() {
+ return array(
+
'api.php?action=query&list=checkuserlog&culuser=WikiSysop&limit=25',
+
'api.php?action=query&list=checkuserlog&cultarget=127.0.0.1&culfrom=20111015230000',
+ );
+ }
- public function getHelpUrls() {
- return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API';
- }
+ public function getHelpUrls() {
+ return 'http://www.mediawiki.org/wiki/Extension:CheckUser#API';
+ }
- public function getVersion() {
- return __CLASS__ . ': $Id$';
- }
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
}
\ No newline at end of file
Modified: trunk/extensions/CheckUser/maintenance/purgeOldData.php
===================================================================
--- trunk/extensions/CheckUser/maintenance/purgeOldData.php 2011-10-18
23:41:29 UTC (rev 100185)
+++ trunk/extensions/CheckUser/maintenance/purgeOldData.php 2011-10-18
23:41:53 UTC (rev 100186)
@@ -2,7 +2,7 @@
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
- $IP = dirname(__FILE__).'/../../..';
+ $IP = dirname( __FILE__ ) . '/../../..';
}
require_once( "$IP/maintenance/Maintenance.php" );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs