r49033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49032‎ | r49033 | r49034 >
Date:12:19, 30 March 2009
Author:catrope
Status:ok
Tags:
Comment:
AbuseFilter API modules:
* Use the 'new' way of adding results (adding them one at a time and stopping when addValue() returns false)
* Use intval() on results that are really integers
* Use an implicit join in ApiAbuseLog
* Use dieUsageMsg() for an invalid title
* Move some things up and down in ApiAbuseLog so related things are grouped together
Modified paths:
  • /trunk/extensions/AbuseFilter/ApiQueryAbuseFilters.php (modified) (history)
  • /trunk/extensions/AbuseFilter/ApiQueryAbuseLog.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/ApiQueryAbuseFilters.php
@@ -56,7 +56,6 @@
5757 $fld_private = isset($prop['private']);
5858
5959 $result = $this->getResult();
60 - $data = array();
6160
6261 $this->addTables('abuse_filter');
6362
@@ -109,7 +108,7 @@
110109 }
111110 $entry = array();
112111 if($fld_id)
113 - $entry['id'] = $row->af_id;
 112+ $entry['id'] = intval($row->af_id);
114113 if($fld_desc)
115114 $entry['description'] = $row->af_public_comments;
116115 if($fld_pattern && (!$row->af_hidden || $showhidden))
@@ -117,7 +116,7 @@
118117 if($fld_actions)
119118 $entry['actions'] = $row->af_actions;
120119 if($fld_hits)
121 - $entry['hits'] = $row->af_hit_count;
 120+ $entry['hits'] = intval($row->af_hit_count);
122121 if($fld_comments && (!$row->af_hidden || $showhidden))
123122 $entry['comments'] = $row->af_comments;
124123 if($fld_user)
@@ -132,11 +131,15 @@
133132 if($row->af_deleted)
134133 $entry['deleted'] = '';
135134 }
136 - if ($entry)
137 - $data[] = $entry;
 135+ if ($entry) {
 136+ $fit = $result->addValue(array('query', $this->getModuleName()), null, $entry);
 137+ if(!$fit) {
 138+ $this->setContinueEnumParameter('startid', $row->af_id);
 139+ break;
 140+ }
 141+ }
138142 }
139 - $result->setIndexedTagName($data, 'filter');
140 - $result->addValue('query', $this->getModuleName(), $data);
 143+ $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'filter');
141144 }
142145
143146 public function getAllowedParams() {
Index: trunk/extensions/AbuseFilter/ApiQueryAbuseLog.php
@@ -48,27 +48,21 @@
4949 $fld_filter = isset($prop['filter']);
5050 $fld_user = isset($prop['user']);
5151 $fld_ip = isset($prop['ip']);
52 - if($fld_ip && !$wgUser->isAllowed('abusefilter-private'))
53 - $this->dieUsage('You don\'t have permission to view IP addresses', 'permissiondenied');
5452 $fld_title = isset($prop['title']);
5553 $fld_action = isset($prop['action']);
5654 $fld_details = isset($prop['details']);
 55+ $fld_result = isset($prop['result']);
 56+ $fld_timestamp = isset($prop['timestamp']);
 57+
 58+ if($fld_ip && !$wgUser->isAllowed('abusefilter-private'))
 59+ $this->dieUsage('You don\'t have permission to view IP addresses', 'permissiondenied');
5760 if($fld_details && !$wgUser->isAllowed('abusefilter-log-detail'))
5861 $this->dieUsage('You don\'t have permission to view detailed abuse log entries', 'permissiondenied');
59 - $fld_result = isset($prop['result']);
60 - $fld_timestamp = isset($prop['timestamp']);
6162
6263 $result = $this->getResult();
63 - $data = array();
6464
6565 $this->addTables('abuse_filter_log');
66 - if($fld_filter) {
67 - $this->addTables('abuse_filter');
68 - $this->addFields('af_public_comments');
69 - $this->addJoinConds(array('abuse_filter' =>
70 - array('JOIN', 'afl_filter=af_id'))
71 - );
72 - }
 66+ $this->addFields('afl_timestamp');
7367 $this->addFieldsIf(array('afl_id', 'afl_filter'), $fld_ids);
7468 $this->addFieldsIf('afl_user_text', $fld_user);
7569 $this->addFieldsIf('afl_ip', $fld_ip);
@@ -76,7 +70,11 @@
7771 $this->addFieldsIf('afl_action', $fld_action);
7872 $this->addFieldsIf('afl_var_dump', $fld_details);
7973 $this->addFieldsIf('afl_actions', $fld_result);
80 - $this->addFields('afl_timestamp');
 74+ if($fld_filter) {
 75+ $this->addTables('abuse_filter');
 76+ $this->addFields('af_public_comments');
 77+ $this->addWhere('afl_filter=af_id');
 78+ }
8179
8280 $this->addOption('LIMIT', $params['limit'] + 1);
8381
@@ -89,7 +87,7 @@
9088 if (!is_null($title)) {
9189 $titleObj = Title :: newFromText($title);
9290 if (is_null($titleObj))
93 - $this->dieUsage("Bad title value '$title'", 'param_title');
 91+ $this->dieUsageMsg(array('invalidtitle', $title));
9492 $this->addWhereFld('afl_namespace', $titleObj->getNamespace());
9593 $this->addWhereFld('afl_title', $titleObj->getDBkey());
9694 }
@@ -106,8 +104,8 @@
107105 }
108106 $entry = array();
109107 if($fld_ids) {
110 - $entry['id'] = $row->afl_id;
111 - $entry['filter_id'] = $row->afl_filter;
 108+ $entry['id'] = intval($row->afl_id);
 109+ $entry['filter_id'] = intval($row->afl_filter);
112110 }
113111 if($fld_filter)
114112 $entry['filter'] = $row->af_public_comments;
@@ -133,11 +131,15 @@
134132 $entry['details'] = array_change_key_case($vars, CASE_LOWER);
135133 }
136134 }
137 - if ($entry)
138 - $data[] = $entry;
 135+ if ($entry) {
 136+ $fit = $result->addValue(array('query', $this->getModuleName()), null, $entry);
 137+ if(!$fit) {
 138+ $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->afl_timestamp));
 139+ break;
 140+ }
 141+ }
139142 }
140 - $result->setIndexedTagName($data, 'item');
141 - $result->addValue('query', $this->getModuleName(), $data);
 143+ $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'item');
142144 }
143145
144146 public function getAllowedParams() {
@@ -146,7 +148,7 @@
147149 ApiBase :: PARAM_TYPE => 'timestamp'
148150 ),
149151 'end' => array(
150 - ApiBase :: PARAM_TYPE => 'timestamp',
 152+ ApiBase :: PARAM_TYPE => 'timestamp'
151153 ),
152154 'dir' => array(
153155 ApiBase :: PARAM_TYPE => array(

Status & tagging log