Index: branches/apiedit/phase3/CHANGED |
— | — | @@ -54,13 +54,16 @@ |
55 | 55 | * action=block module that wraps around IPBlockForm::doBlock() (r25548) |
56 | 56 | |
57 | 57 | api/ApiUnblock.php (NEW) |
58 | | -* action=unblock module that wraps around IPUnblockForm::doUnblock() (r25633) |
| 58 | +* action=unblock module that wraps around IPUnblockForm::doUnblock() (r25633)i |
59 | 59 | |
| 60 | +api/ApiQueryBlocks.php (NEW) |
| 61 | +* action=query&list=blocks module that lists blocks from the ipblocks table (r25735) |
| 62 | + |
60 | 63 | AutoLoader.php |
61 | | -* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiQueryDeletedRevs (r23668), ApiUndelete (r23687), ApiProtect (r23588), ApiBlock (r25548) |
| 64 | +* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiQueryDeletedRevs (r23668), ApiUndelete (r23687), ApiProtect (r23588), ApiBlock (r25548), ApiQueryBlocks (r25735) |
62 | 65 | |
63 | 66 | api/ApiMain.php |
64 | 67 | * Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiUndelete (r23687), ApiProtect (r23588), ApiBlock (r25548) |
65 | 68 | |
66 | 69 | api/ApiQuery.php |
67 | | -* Added entry for ApiQueryDeletedRevs (r23668) |
| 70 | +* Added entries for ApiQueryDeletedRevs (r23668), ApiQueryBlocks (r25735) |
Index: branches/apiedit/phase3/includes/api/ApiQuery.php |
— | — | @@ -62,6 +62,7 @@ |
63 | 63 | 'alllinks' => 'ApiQueryAllLinks', |
64 | 64 | 'allusers' => 'ApiQueryAllUsers', |
65 | 65 | 'backlinks' => 'ApiQueryBacklinks', |
| 66 | + 'blocks' => 'ApiQueryBlocks', |
66 | 67 | 'categorymembers' => 'ApiQueryCategoryMembers', |
67 | 68 | 'deletedrevs' => 'ApiQueryDeletedrevs', |
68 | 69 | 'embeddedin' => 'ApiQueryBacklinks', |
Index: branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php |
— | — | @@ -114,12 +114,12 @@ |
115 | 115 | if($count++ == $params['limit']) |
116 | 116 | { |
117 | 117 | // We've had enough |
118 | | - $this->setContinueEnumParameter('start', $row->ar_timestamp); |
| 118 | + $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp)); |
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | 122 | $rev = array(); |
123 | | - $rev['timestamp'] = $row->ar_timestamp; |
| 123 | + $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp); |
124 | 124 | if($fld_revid) |
125 | 125 | $rev['revid'] = $row->ar_rev_id; |
126 | 126 | if($fld_user) |
Index: branches/apiedit/phase3/includes/api/ApiQueryBlocks.php |
— | — | @@ -0,0 +1,246 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Sep 10, 2007 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright (C) 2007 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 | +if (!defined('MEDIAWIKI')) { |
| 28 | + // Eclipse helper - will be ignored in production |
| 29 | + require_once ('ApiQueryBase.php'); |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Query module to enumerate all available pages. |
| 34 | + * |
| 35 | + * @addtogroup API |
| 36 | + */ |
| 37 | +class ApiQueryBlocks extends ApiQueryBase { |
| 38 | + |
| 39 | + public function __construct($query, $moduleName) { |
| 40 | + parent :: __construct($query, $moduleName, 'bk'); |
| 41 | + } |
| 42 | + |
| 43 | + public function execute() { |
| 44 | + $this->run(); |
| 45 | + } |
| 46 | + |
| 47 | + private function run() { |
| 48 | + global $wgUser; |
| 49 | + |
| 50 | + $params = $this->extractRequestParams(); |
| 51 | + $prop = array_flip($params['prop']); |
| 52 | + $fld_id = isset($prop['id']); |
| 53 | + $fld_user = isset($prop['user']); |
| 54 | + $fld_by = isset($prop['by']); |
| 55 | + $fld_timestamp = isset($prop['timestamp']); |
| 56 | + $fld_expiry = isset($prop['expiry']); |
| 57 | + $fld_reason = isset($prop['reason']); |
| 58 | + $fld_range = isset($prop['range']); |
| 59 | + $fld_flags = isset($prop['flags']); |
| 60 | + |
| 61 | + $result = $this->getResult(); |
| 62 | + $pageSet = $this->getPageSet(); |
| 63 | + $titles = $pageSet->getTitles(); |
| 64 | + $data = array(); |
| 65 | + |
| 66 | + $this->addTables('ipblocks'); |
| 67 | + if($fld_id) |
| 68 | + $this->addFields('ipb_id'); |
| 69 | + if($fld_user) |
| 70 | + $this->addFields(array('ipb_address', 'ipb_user')); |
| 71 | + if($fld_by) |
| 72 | + { |
| 73 | + $this->addTables('user'); |
| 74 | + $this->addFields(array('ipb_by', 'user_name')); |
| 75 | + $this->addWhere('user_id = ipb_by'); |
| 76 | + } |
| 77 | + if($fld_timestamp) |
| 78 | + $this->addFields('ipb_timestamp'); |
| 79 | + if($fld_expiry) |
| 80 | + $this->addFields('ipb_expiry'); |
| 81 | + if($fld_reason) |
| 82 | + $this->addFields('ipb_reason'); |
| 83 | + if($fld_range) |
| 84 | + $this->addFields(array('ipb_range_start', 'ipb_range_end')); |
| 85 | + if($fld_flags) |
| 86 | + $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted')); |
| 87 | + |
| 88 | + $this->addOption('LIMIT', $params['limit'] + 1); |
| 89 | + $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']); |
| 90 | + if(isset($params['ids'])) |
| 91 | + $this->addWhere(array('ipb_id' => $params['ids'])); |
| 92 | + if(isset($params['users'])) |
| 93 | + $this->addWhere(array('ipb_address' => $params['users'])); |
| 94 | + if(!$wgUser->isAllowed('oversight')) |
| 95 | + $this->addWhere(array('ipb_deleted' => 0)); |
| 96 | + |
| 97 | + // Purge expired entries on one in every 10 queries |
| 98 | + if(!mt_rand(0, 10)) |
| 99 | + Block::purgeExpired(); |
| 100 | + |
| 101 | + $res = $this->select(__METHOD__); |
| 102 | + $db = wfGetDB(); |
| 103 | + |
| 104 | + $count = 0; |
| 105 | + while($row = $db->fetchObject($res)) |
| 106 | + { |
| 107 | + if($count++ == $params['limit']) |
| 108 | + { |
| 109 | + // We've had enough |
| 110 | + $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp)); |
| 111 | + break; |
| 112 | + } |
| 113 | + $block = array(); |
| 114 | + if($fld_id) |
| 115 | + $block['id'] = $row->ipb_id; |
| 116 | + if($fld_user) |
| 117 | + { |
| 118 | + $block['user'] = $row->ipb_address; |
| 119 | + $block['userid'] = $row->ipb_user; |
| 120 | + } |
| 121 | + if($fld_by) |
| 122 | + { |
| 123 | + $block['by'] = $row->user_name; |
| 124 | + $block['byuserid'] = $row->ipb_by; |
| 125 | + } |
| 126 | + if($fld_timestamp) |
| 127 | + $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); |
| 128 | + if($fld_expiry) |
| 129 | + { |
| 130 | + if($row->ipb_expiry == Block::infinity()) |
| 131 | + $block['expiry'] = 'infinity'; |
| 132 | + else |
| 133 | + $block['expiry'] = wfTimestamp(TS_ISO_8601, $row->ipb_expiry); |
| 134 | + } |
| 135 | + if($fld_reason) |
| 136 | + $block['reason'] = $row->ipb_reason; |
| 137 | + if($fld_range) |
| 138 | + { |
| 139 | + $block['range_start'] = $this->convertHexIP($row->ipb_range_start); |
| 140 | + $block['range_end'] = $this->convertHexIP($row->ipb_range_end); |
| 141 | + } |
| 142 | + if($fld_flags) |
| 143 | + { |
| 144 | + // For clarity, these flags use the same names as their action=block counterparts |
| 145 | + if($row->ipb_auto) |
| 146 | + $block['automatic'] = ''; |
| 147 | + if($row->ipb_anon_only) |
| 148 | + $block['anononly'] = ''; |
| 149 | + if($row->ipb_create_account) |
| 150 | + $block['nocreate'] = ''; |
| 151 | + if($row->ipb_enable_autoblock) |
| 152 | + $block['autoblock'] = ''; |
| 153 | + if($row->ipb_block_email) |
| 154 | + $block['noemail'] = ''; |
| 155 | + if($row->ipb_deleted) |
| 156 | + $block['hidden'] = ''; |
| 157 | + } |
| 158 | + $data[] = $block; |
| 159 | + } |
| 160 | + $result->setIndexedTagName($data, 'block'); |
| 161 | + $result->addValue('query', $this->getModuleName(), $data); |
| 162 | + } |
| 163 | + |
| 164 | + protected function convertHexIP($ip) |
| 165 | + { |
| 166 | + // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format |
| 167 | + $dec = wfBaseConvert($ip, 16, 10); |
| 168 | + $parts[0] = (int)($dec / (256*256*256)); |
| 169 | + $dec %= 256*256*256; |
| 170 | + $parts[1] = (int)($dec / (256*256)); |
| 171 | + $dec %= 256*256; |
| 172 | + $parts[2] = (int)($dec / 256); |
| 173 | + $parts[3] = $dec % 256; |
| 174 | + return implode('.', $parts); |
| 175 | + } |
| 176 | + |
| 177 | + protected function getAllowedParams() { |
| 178 | + return array ( |
| 179 | + 'start' => array( |
| 180 | + ApiBase :: PARAM_TYPE => 'timestamp' |
| 181 | + ), |
| 182 | + 'end' => array( |
| 183 | + ApiBase :: PARAM_TYPE => 'timestamp', |
| 184 | + ), |
| 185 | + 'dir' => array( |
| 186 | + ApiBase :: PARAM_TYPE => array( |
| 187 | + 'newer', |
| 188 | + 'older' |
| 189 | + ), |
| 190 | + ApiBase :: PARAM_DFLT => 'older' |
| 191 | + ), |
| 192 | + 'ids' => array( |
| 193 | + ApiBase :: PARAM_TYPE => 'integer', |
| 194 | + ApiBase :: PARAM_ISMULTI => true |
| 195 | + ), |
| 196 | + 'users' => array( |
| 197 | + ApiBase :: PARAM_ISMULTI => true |
| 198 | + ), |
| 199 | + 'limit' => array( |
| 200 | + ApiBase :: PARAM_DFLT => 10, |
| 201 | + ApiBase :: PARAM_TYPE => 'limit', |
| 202 | + ApiBase :: PARAM_MIN => 1, |
| 203 | + ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
| 204 | + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 205 | + ), |
| 206 | + 'prop' => array( |
| 207 | + ApiBase :: PARAM_DFLT => 'id|user|by|timestamp|expiry|reason|flags', |
| 208 | + ApiBase :: PARAM_TYPE => array( |
| 209 | + 'id', |
| 210 | + 'user', |
| 211 | + 'by', |
| 212 | + 'timestamp', |
| 213 | + 'expiry', |
| 214 | + 'reason', |
| 215 | + 'range', |
| 216 | + 'flags' |
| 217 | + ), |
| 218 | + ApiBase :: PARAM_ISMULTI => true |
| 219 | + ) |
| 220 | + ); |
| 221 | + } |
| 222 | + |
| 223 | + protected function getParamDescription() { |
| 224 | + return array ( |
| 225 | + 'start' => 'The timestamp to start enumerating from', |
| 226 | + 'end' => 'The timestamp to stop enumerating at', |
| 227 | + 'dir' => 'The direction in which to enumerate', |
| 228 | + 'ids' => 'Pipe-separated list of block IDs to list (optional)', |
| 229 | + 'users' => 'Pipe-separated list of users to search for (optional)', |
| 230 | + 'limit' => 'The maximum amount of blocks to list', |
| 231 | + 'prop' => 'Which properties to get', |
| 232 | + ); |
| 233 | + } |
| 234 | + |
| 235 | + protected function getDescription() { |
| 236 | + return 'List all blocked users and IP addresses.'; |
| 237 | + } |
| 238 | + |
| 239 | + protected function getExamples() { |
| 240 | + return array ( |
| 241 | + ); |
| 242 | + } |
| 243 | + |
| 244 | + public function getVersion() { |
| 245 | + return __CLASS__ . ': $Id$'; |
| 246 | + } |
| 247 | +} |
Property changes on: branches/apiedit/phase3/includes/api/ApiQueryBlocks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 248 | + native |
Index: branches/apiedit/phase3/includes/api/ApiUndelete.php |
— | — | @@ -58,6 +58,13 @@ |
59 | 59 | $titleObj = Title::newFromText($params['title']); |
60 | 60 | if(!$titleObj) |
61 | 61 | $this->dieUsage("Bad title {$params['title']}", 'invalidtitle'); |
| 62 | + |
| 63 | + // Convert timestamps |
| 64 | + if(!is_array($params['timestamps'])) |
| 65 | + $params['timestamps'] = array($params['timestamps']); |
| 66 | + foreach($params['timestamps'] as $i => $ts) |
| 67 | + $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts); |
| 68 | + |
62 | 69 | $pa = new PageArchive($titleObj); |
63 | 70 | $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']); |
64 | 71 | if(!is_array($retval)) |
Index: branches/apiedit/phase3/includes/AutoLoader.php |
— | — | @@ -320,6 +320,7 @@ |
321 | 321 | 'ApiQueryBase' => 'includes/api/ApiQueryBase.php', |
322 | 322 | 'ApiQueryGeneratorBase' => 'includes/api/ApiQueryBase.php', |
323 | 323 | 'ApiQueryBacklinks' => 'includes/api/ApiQueryBacklinks.php', |
| 324 | + 'ApiQueryBlocks' => 'includes/api/ApiQueryBlocks.php', |
324 | 325 | 'ApiQueryCategories' => 'includes/api/ApiQueryCategories.php', |
325 | 326 | 'ApiQueryCategoryMembers' => 'includes/api/ApiQueryCategoryMembers.php', |
326 | 327 | 'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php', |