Index: trunk/extensions/GlobalBlocking/ApiGlobalBlocks.php |
— | — | @@ -1,230 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/* |
5 | | - * Created on Nov 1, 2008 |
6 | | - * |
7 | | - * GlobalBlocking extension |
8 | | - * |
9 | | - * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl |
10 | | - * |
11 | | - * This program is free software; you can redistribute it and/or modify |
12 | | - * it under the terms of the GNU General Public License as published by |
13 | | - * the Free Software Foundation; either version 2 of the License, or |
14 | | - * (at your option) any later version. |
15 | | - * |
16 | | - * This program is distributed in the hope that it will be useful, |
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | | - * GNU General Public License for more details. |
20 | | - * |
21 | | - * You should have received a copy of the GNU General Public License along |
22 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
23 | | - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
24 | | - * http://www.gnu.org/copyleft/gpl.html |
25 | | - */ |
26 | | - |
27 | | -/** |
28 | | - * Query module to enumerate all available pages. |
29 | | - * |
30 | | - * @ingroup API |
31 | | - * @ingroup Extensions |
32 | | - */ |
33 | | -class ApiQueryGlobalBlocks extends ApiQueryBase { |
34 | | - |
35 | | - public function __construct($query, $moduleName) { |
36 | | - parent :: __construct($query, $moduleName, 'bg'); |
37 | | - } |
38 | | - |
39 | | - public function execute() { |
40 | | - global $wgUser; |
41 | | - $params = $this->extractRequestParams(); |
42 | | - |
43 | | - $prop = array_flip($params['prop']); |
44 | | - $fld_id = isset($prop['id']); |
45 | | - $fld_address = isset($prop['address']); |
46 | | - $fld_by = isset($prop['by']); |
47 | | - $fld_timestamp = isset($prop['timestamp']); |
48 | | - $fld_expiry = isset($prop['expiry']); |
49 | | - $fld_reason = isset($prop['reason']); |
50 | | - $fld_range = isset($prop['range']); |
51 | | - |
52 | | - $result = $this->getResult(); |
53 | | - $pageSet = $this->getPageSet(); |
54 | | - $titles = $pageSet->getTitles(); |
55 | | - $data = array(); |
56 | | - |
57 | | - $this->addTables('globalblocks'); |
58 | | - if($fld_id) |
59 | | - $this->addFields('gb_id'); |
60 | | - if($fld_address) |
61 | | - $this->addFields(array('gb_address', 'gb_anon_only')); |
62 | | - if($fld_by) |
63 | | - $this->addFields(array('gb_by', 'gb_by_wiki')); |
64 | | - if($fld_timestamp) |
65 | | - $this->addFields('gb_timestamp'); |
66 | | - if($fld_expiry) |
67 | | - $this->addFields('gb_expiry'); |
68 | | - if($fld_reason) |
69 | | - $this->addFields('gb_reason'); |
70 | | - if($fld_range) |
71 | | - $this->addFields(array('gb_range_start', 'gb_range_end')); |
72 | | - |
73 | | - $this->addOption('LIMIT', $params['limit'] + 1); |
74 | | - $this->addWhereRange('gb_timestamp', $params['dir'], $params['start'], $params['end']); |
75 | | - if(isset($params['ids'])) |
76 | | - $this->addWhereFld('gb_id', $params['ids']); |
77 | | - if(isset($params['addresses'])) |
78 | | - $this->addWhereFld('gb_address', $params['addresses']); |
79 | | - if(isset($params['ip'])) |
80 | | - { |
81 | | - list($ip, $range) = IP::parseCIDR($params['ip']); |
82 | | - if($ip && $range) |
83 | | - { |
84 | | - # We got a CIDR range |
85 | | - if($range < 16) |
86 | | - $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad'); |
87 | | - $lower = wfBaseConvert($ip, 10, 16, 8, false); |
88 | | - $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false); |
89 | | - } |
90 | | - else |
91 | | - $lower = $upper = IP::toHex($params['ip']); |
92 | | - $prefix = substr($lower, 0, 4); |
93 | | - $this->addWhere(array( |
94 | | - "gb_range_start LIKE '$prefix%'", |
95 | | - "gb_range_start <= '$lower'", |
96 | | - "gb_range_end >= '$upper'" |
97 | | - )); |
98 | | - } |
99 | | - |
100 | | - $res = $this->select(__METHOD__); |
101 | | - |
102 | | - $count = 0; |
103 | | - while($row = $res->fetchObject()) |
104 | | - { |
105 | | - if(++$count > $params['limit']) |
106 | | - { |
107 | | - // We've had enough |
108 | | - $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp)); |
109 | | - break; |
110 | | - } |
111 | | - $block = array(); |
112 | | - if($fld_id) |
113 | | - $block['id'] = $row->gb_id; |
114 | | - if($fld_address) |
115 | | - { |
116 | | - $block['address'] = $row->gb_address; |
117 | | - if($row->gb_anon_only) |
118 | | - $block['anononly'] = ''; |
119 | | - } |
120 | | - if($fld_by) |
121 | | - { |
122 | | - $block['by'] = $row->gb_by; |
123 | | - $block['bywiki'] = $row->gb_by_wiki; |
124 | | - } |
125 | | - if($fld_timestamp) |
126 | | - $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->gb_timestamp); |
127 | | - if($fld_expiry) |
128 | | - $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601); |
129 | | - if($fld_reason) |
130 | | - $block['reason'] = $row->gb_reason; |
131 | | - if($fld_range) |
132 | | - { |
133 | | - $block['rangestart'] = self::convertHexIP($row->gb_range_start); |
134 | | - $block['rangeend'] = self::convertHexIP($row->gb_range_end); |
135 | | - } |
136 | | - $data[] = $block; |
137 | | - } |
138 | | - $result->setIndexedTagName($data, 'block'); |
139 | | - $result->addValue('query', $this->getModuleName(), $data); |
140 | | - } |
141 | | - |
142 | | - protected static function convertHexIP($ip) |
143 | | - { |
144 | | - // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format |
145 | | - $dec = wfBaseConvert($ip, 16, 10); |
146 | | - $parts[3] = $dec % 256; |
147 | | - $dec /= 256; |
148 | | - $parts[2] = $dec % 256; |
149 | | - $dec /= 256; |
150 | | - $parts[1] = $dec % 256; |
151 | | - $parts[0] = $dec / 256; |
152 | | - } |
153 | | - |
154 | | - public function getAllowedParams() { |
155 | | - return array ( |
156 | | - 'start' => array( |
157 | | - ApiBase :: PARAM_TYPE => 'timestamp' |
158 | | - ), |
159 | | - 'end' => array( |
160 | | - ApiBase :: PARAM_TYPE => 'timestamp', |
161 | | - ), |
162 | | - 'dir' => array( |
163 | | - ApiBase :: PARAM_TYPE => array( |
164 | | - 'newer', |
165 | | - 'older' |
166 | | - ), |
167 | | - ApiBase :: PARAM_DFLT => 'older' |
168 | | - ), |
169 | | - 'ids' => array( |
170 | | - ApiBase :: PARAM_TYPE => 'integer', |
171 | | - ApiBase :: PARAM_ISMULTI => true |
172 | | - ), |
173 | | - 'addresses' => array( |
174 | | - ApiBase :: PARAM_ISMULTI => true |
175 | | - ), |
176 | | - 'ip' => null, |
177 | | - 'limit' => array( |
178 | | - ApiBase :: PARAM_DFLT => 10, |
179 | | - ApiBase :: PARAM_TYPE => 'limit', |
180 | | - ApiBase :: PARAM_MIN => 1, |
181 | | - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
182 | | - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
183 | | - ), |
184 | | - 'prop' => array( |
185 | | - ApiBase :: PARAM_DFLT => 'id|address|by|timestamp|expiry|reason', |
186 | | - ApiBase :: PARAM_TYPE => array( |
187 | | - 'id', |
188 | | - 'address', |
189 | | - 'by', |
190 | | - 'timestamp', |
191 | | - 'expiry', |
192 | | - 'reason', |
193 | | - 'range', |
194 | | - ), |
195 | | - ApiBase :: PARAM_ISMULTI => true |
196 | | - ) |
197 | | - ); |
198 | | - } |
199 | | - |
200 | | - protected function getDB() { |
201 | | - return GlobalBlocking::getGlobalBlockingSlave(); |
202 | | - } |
203 | | - |
204 | | - public function getParamDescription() { |
205 | | - return array ( |
206 | | - 'start' => 'The timestamp to start enumerating from', |
207 | | - 'end' => 'The timestamp to stop enumerating at', |
208 | | - 'dir' => 'The direction in which to enumerate', |
209 | | - 'ids' => 'Pipe-separated list of block IDs to list (optional)', |
210 | | - 'addresses' => 'Pipe-separated list of addresses to search for (optional)', |
211 | | - 'ip' => array( 'Get all blocks applying to this IP or CIDR range, including range blocks.', |
212 | | - 'Cannot be used together with bkusers. CIDR ranges broader than /16 are not accepted.'), |
213 | | - 'limit' => 'The maximum amount of blocks to list', |
214 | | - 'prop' => 'Which properties to get', |
215 | | - ); |
216 | | - } |
217 | | - |
218 | | - public function getDescription() { |
219 | | - return 'List all globally blocked IP addresses.'; |
220 | | - } |
221 | | - |
222 | | - protected function getExamples() { |
223 | | - return array ( 'api.php?action=query&list=globalblocks', |
224 | | - 'api.php?action=query&list=globalblocks&bgip=217.121.114.116' |
225 | | - ); |
226 | | - } |
227 | | - |
228 | | - public function getVersion() { |
229 | | - return __CLASS__ . ': $Id$'; |
230 | | - } |
231 | | -} |
Index: trunk/extensions/GlobalBlocking/GlobalBlocking.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | $wgSpecialPages['GlobalBlockStatus'] = 'SpecialGlobalBlockStatus'; |
39 | 39 | $wgAutoloadClasses['SpecialRemoveGlobalBlock'] = "$dir/SpecialRemoveGlobalBlock.php"; |
40 | 40 | $wgSpecialPages['RemoveGlobalBlock'] = 'SpecialRemoveGlobalBlock'; |
41 | | -$wgAutoloadClasses['ApiQueryGlobalBlocks'] = "$dir/ApiGlobalBlocks.php"; |
| 41 | +$wgAutoloadClasses['ApiQueryGlobalBlocks'] = "$dir/ApiQueryGlobalBlocks.php"; |
42 | 42 | $wgAPIListModules['globalblocks'] = 'ApiQueryGlobalBlocks'; |
43 | 43 | |
44 | 44 | ## Add global block log |
Index: trunk/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php |
— | — | @@ -0,0 +1,230 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Nov 1, 2008 |
| 6 | + * |
| 7 | + * GlobalBlocking extension |
| 8 | + * |
| 9 | + * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + */ |
| 26 | + |
| 27 | +/** |
| 28 | + * Query module to enumerate all available pages. |
| 29 | + * |
| 30 | + * @ingroup API |
| 31 | + * @ingroup Extensions |
| 32 | + */ |
| 33 | +class ApiQueryGlobalBlocks extends ApiQueryBase { |
| 34 | + |
| 35 | + public function __construct($query, $moduleName) { |
| 36 | + parent :: __construct($query, $moduleName, 'bg'); |
| 37 | + } |
| 38 | + |
| 39 | + public function execute() { |
| 40 | + global $wgUser; |
| 41 | + $params = $this->extractRequestParams(); |
| 42 | + |
| 43 | + $prop = array_flip($params['prop']); |
| 44 | + $fld_id = isset($prop['id']); |
| 45 | + $fld_address = isset($prop['address']); |
| 46 | + $fld_by = isset($prop['by']); |
| 47 | + $fld_timestamp = isset($prop['timestamp']); |
| 48 | + $fld_expiry = isset($prop['expiry']); |
| 49 | + $fld_reason = isset($prop['reason']); |
| 50 | + $fld_range = isset($prop['range']); |
| 51 | + |
| 52 | + $result = $this->getResult(); |
| 53 | + $pageSet = $this->getPageSet(); |
| 54 | + $titles = $pageSet->getTitles(); |
| 55 | + $data = array(); |
| 56 | + |
| 57 | + $this->addTables('globalblocks'); |
| 58 | + if($fld_id) |
| 59 | + $this->addFields('gb_id'); |
| 60 | + if($fld_address) |
| 61 | + $this->addFields(array('gb_address', 'gb_anon_only')); |
| 62 | + if($fld_by) |
| 63 | + $this->addFields(array('gb_by', 'gb_by_wiki')); |
| 64 | + if($fld_timestamp) |
| 65 | + $this->addFields('gb_timestamp'); |
| 66 | + if($fld_expiry) |
| 67 | + $this->addFields('gb_expiry'); |
| 68 | + if($fld_reason) |
| 69 | + $this->addFields('gb_reason'); |
| 70 | + if($fld_range) |
| 71 | + $this->addFields(array('gb_range_start', 'gb_range_end')); |
| 72 | + |
| 73 | + $this->addOption('LIMIT', $params['limit'] + 1); |
| 74 | + $this->addWhereRange('gb_timestamp', $params['dir'], $params['start'], $params['end']); |
| 75 | + if(isset($params['ids'])) |
| 76 | + $this->addWhereFld('gb_id', $params['ids']); |
| 77 | + if(isset($params['addresses'])) |
| 78 | + $this->addWhereFld('gb_address', $params['addresses']); |
| 79 | + if(isset($params['ip'])) |
| 80 | + { |
| 81 | + list($ip, $range) = IP::parseCIDR($params['ip']); |
| 82 | + if($ip && $range) |
| 83 | + { |
| 84 | + # We got a CIDR range |
| 85 | + if($range < 16) |
| 86 | + $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad'); |
| 87 | + $lower = wfBaseConvert($ip, 10, 16, 8, false); |
| 88 | + $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false); |
| 89 | + } |
| 90 | + else |
| 91 | + $lower = $upper = IP::toHex($params['ip']); |
| 92 | + $prefix = substr($lower, 0, 4); |
| 93 | + $this->addWhere(array( |
| 94 | + "gb_range_start LIKE '$prefix%'", |
| 95 | + "gb_range_start <= '$lower'", |
| 96 | + "gb_range_end >= '$upper'" |
| 97 | + )); |
| 98 | + } |
| 99 | + |
| 100 | + $res = $this->select(__METHOD__); |
| 101 | + |
| 102 | + $count = 0; |
| 103 | + while($row = $res->fetchObject()) |
| 104 | + { |
| 105 | + if(++$count > $params['limit']) |
| 106 | + { |
| 107 | + // We've had enough |
| 108 | + $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp)); |
| 109 | + break; |
| 110 | + } |
| 111 | + $block = array(); |
| 112 | + if($fld_id) |
| 113 | + $block['id'] = $row->gb_id; |
| 114 | + if($fld_address) |
| 115 | + { |
| 116 | + $block['address'] = $row->gb_address; |
| 117 | + if($row->gb_anon_only) |
| 118 | + $block['anononly'] = ''; |
| 119 | + } |
| 120 | + if($fld_by) |
| 121 | + { |
| 122 | + $block['by'] = $row->gb_by; |
| 123 | + $block['bywiki'] = $row->gb_by_wiki; |
| 124 | + } |
| 125 | + if($fld_timestamp) |
| 126 | + $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->gb_timestamp); |
| 127 | + if($fld_expiry) |
| 128 | + $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601); |
| 129 | + if($fld_reason) |
| 130 | + $block['reason'] = $row->gb_reason; |
| 131 | + if($fld_range) |
| 132 | + { |
| 133 | + $block['rangestart'] = self::convertHexIP($row->gb_range_start); |
| 134 | + $block['rangeend'] = self::convertHexIP($row->gb_range_end); |
| 135 | + } |
| 136 | + $data[] = $block; |
| 137 | + } |
| 138 | + $result->setIndexedTagName($data, 'block'); |
| 139 | + $result->addValue('query', $this->getModuleName(), $data); |
| 140 | + } |
| 141 | + |
| 142 | + protected static function convertHexIP($ip) |
| 143 | + { |
| 144 | + // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format |
| 145 | + $dec = wfBaseConvert($ip, 16, 10); |
| 146 | + $parts[3] = $dec % 256; |
| 147 | + $dec /= 256; |
| 148 | + $parts[2] = $dec % 256; |
| 149 | + $dec /= 256; |
| 150 | + $parts[1] = $dec % 256; |
| 151 | + $parts[0] = $dec / 256; |
| 152 | + } |
| 153 | + |
| 154 | + public function getAllowedParams() { |
| 155 | + return array ( |
| 156 | + 'start' => array( |
| 157 | + ApiBase :: PARAM_TYPE => 'timestamp' |
| 158 | + ), |
| 159 | + 'end' => array( |
| 160 | + ApiBase :: PARAM_TYPE => 'timestamp', |
| 161 | + ), |
| 162 | + 'dir' => array( |
| 163 | + ApiBase :: PARAM_TYPE => array( |
| 164 | + 'newer', |
| 165 | + 'older' |
| 166 | + ), |
| 167 | + ApiBase :: PARAM_DFLT => 'older' |
| 168 | + ), |
| 169 | + 'ids' => array( |
| 170 | + ApiBase :: PARAM_TYPE => 'integer', |
| 171 | + ApiBase :: PARAM_ISMULTI => true |
| 172 | + ), |
| 173 | + 'addresses' => array( |
| 174 | + ApiBase :: PARAM_ISMULTI => true |
| 175 | + ), |
| 176 | + 'ip' => null, |
| 177 | + 'limit' => array( |
| 178 | + ApiBase :: PARAM_DFLT => 10, |
| 179 | + ApiBase :: PARAM_TYPE => 'limit', |
| 180 | + ApiBase :: PARAM_MIN => 1, |
| 181 | + ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
| 182 | + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 183 | + ), |
| 184 | + 'prop' => array( |
| 185 | + ApiBase :: PARAM_DFLT => 'id|address|by|timestamp|expiry|reason', |
| 186 | + ApiBase :: PARAM_TYPE => array( |
| 187 | + 'id', |
| 188 | + 'address', |
| 189 | + 'by', |
| 190 | + 'timestamp', |
| 191 | + 'expiry', |
| 192 | + 'reason', |
| 193 | + 'range', |
| 194 | + ), |
| 195 | + ApiBase :: PARAM_ISMULTI => true |
| 196 | + ) |
| 197 | + ); |
| 198 | + } |
| 199 | + |
| 200 | + protected function getDB() { |
| 201 | + return GlobalBlocking::getGlobalBlockingSlave(); |
| 202 | + } |
| 203 | + |
| 204 | + public function getParamDescription() { |
| 205 | + return array ( |
| 206 | + 'start' => 'The timestamp to start enumerating from', |
| 207 | + 'end' => 'The timestamp to stop enumerating at', |
| 208 | + 'dir' => 'The direction in which to enumerate', |
| 209 | + 'ids' => 'Pipe-separated list of block IDs to list (optional)', |
| 210 | + 'addresses' => 'Pipe-separated list of addresses to search for (optional)', |
| 211 | + 'ip' => array( 'Get all blocks applying to this IP or CIDR range, including range blocks.', |
| 212 | + 'Cannot be used together with bkusers. CIDR ranges broader than /16 are not accepted.'), |
| 213 | + 'limit' => 'The maximum amount of blocks to list', |
| 214 | + 'prop' => 'Which properties to get', |
| 215 | + ); |
| 216 | + } |
| 217 | + |
| 218 | + public function getDescription() { |
| 219 | + return 'List all globally blocked IP addresses.'; |
| 220 | + } |
| 221 | + |
| 222 | + protected function getExamples() { |
| 223 | + return array ( 'api.php?action=query&list=globalblocks', |
| 224 | + 'api.php?action=query&list=globalblocks&bgip=217.121.114.116' |
| 225 | + ); |
| 226 | + } |
| 227 | + |
| 228 | + public function getVersion() { |
| 229 | + return __CLASS__ . ': $Id$'; |
| 230 | + } |
| 231 | +} |
Property changes on: trunk/extensions/GlobalBlocking/ApiQueryGlobalBlocks.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
Added: svn:eol-style |
1 | 232 | + native |
Added: svn:keywords |
2 | 233 | + Id |