예제 #1
0
 public function execute()
 {
     global $wgContLang;
     $params = $this->extractRequestParams();
     $this->requireMaxOneParameter($params, 'users', 'ip');
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_user = isset($prop['user']);
     $fld_userid = isset($prop['userid']);
     $fld_by = isset($prop['by']);
     $fld_byid = isset($prop['byid']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $fld_flags = isset($prop['flags']);
     $result = $this->getResult();
     $this->addTables('ipblocks');
     $this->addFields('ipb_auto');
     $this->addFieldsIf('ipb_id', $fld_id);
     $this->addFieldsIf(array('ipb_address', 'ipb_user'), $fld_user || $fld_userid);
     $this->addFieldsIf('ipb_by_text', $fld_by);
     $this->addFieldsIf('ipb_by', $fld_byid);
     $this->addFieldsIf('ipb_timestamp', $fld_timestamp);
     $this->addFieldsIf('ipb_expiry', $fld_expiry);
     $this->addFieldsIf('ipb_reason', $fld_reason);
     $this->addFieldsIf(array('ipb_range_start', 'ipb_range_end'), $fld_range);
     $this->addFieldsIf(array('ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk'), $fld_flags);
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addTimestampWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
     $db = $this->getDB();
     if (isset($params['ids'])) {
         $this->addWhereFld('ipb_id', $params['ids']);
     }
     if (isset($params['users'])) {
         foreach ((array) $params['users'] as $u) {
             $this->prepareUsername($u);
         }
         $this->addWhereFld('ipb_address', $this->usernames);
         $this->addWhereFld('ipb_auto', 0);
     }
     if (isset($params['ip'])) {
         list($ip, $range) = IP::parseCIDR($params['ip']);
         if ($ip && $range) {
             // We got a CIDR range
             if ($range < 16) {
                 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
             }
             $lower = wfBaseConvert($ip, 10, 16, 8, false);
             $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
         } else {
             $lower = $upper = IP::toHex($params['ip']);
         }
         $prefix = substr($lower, 0, 4);
         # Fairly hard to make a malicious SQL statement out of hex characters,
         # but it is good practice to add quotes
         $lower = $db->addQuotes($lower);
         $upper = $db->addQuotes($upper);
         $this->addWhere(array('ipb_range_start' . $db->buildLike($prefix, $db->anyString()), 'ipb_range_start <= ' . $lower, 'ipb_range_end >= ' . $upper, 'ipb_auto' => 0));
     }
     if (!is_null($params['show'])) {
         $show = array_flip($params['show']);
         /* Check for conflicting parameters. */
         if (isset($show['account']) && isset($show['!account']) || isset($show['ip']) && isset($show['!ip']) || isset($show['range']) && isset($show['!range']) || isset($show['temp']) && isset($show['!temp'])) {
             $this->dieUsageMsg('show');
         }
         $this->addWhereIf('ipb_user = 0', isset($show['!account']));
         $this->addWhereIf('ipb_user != 0', isset($show['account']));
         $this->addWhereIf('ipb_user != 0 OR ipb_range_end > ipb_range_start', isset($show['!ip']));
         $this->addWhereIf('ipb_user = 0 AND ipb_range_end = ipb_range_start', isset($show['ip']));
         $this->addWhereIf('ipb_expiry =  ' . $db->addQuotes($db->getInfinity()), isset($show['!temp']));
         $this->addWhereIf('ipb_expiry != ' . $db->addQuotes($db->getInfinity()), isset($show['temp']));
         $this->addWhereIf("ipb_range_end = ipb_range_start", isset($show['!range']));
         $this->addWhereIf("ipb_range_end > ipb_range_start", isset($show['range']));
     }
     if (!$this->getUser()->isAllowed('hideuser')) {
         $this->addWhereFld('ipb_deleted', 0);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
             break;
         }
         $block = array();
         if ($fld_id) {
             $block['id'] = $row->ipb_id;
         }
         if ($fld_user && !$row->ipb_auto) {
             $block['user'] = $row->ipb_address;
         }
         if ($fld_userid && !$row->ipb_auto) {
             $block['userid'] = $row->ipb_user;
         }
         if ($fld_by) {
             $block['by'] = $row->ipb_by_text;
         }
         if ($fld_byid) {
             $block['byid'] = $row->ipb_by;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
         }
         if ($fld_expiry) {
             $block['expiry'] = $wgContLang->formatExpiry($row->ipb_expiry, TS_ISO_8601);
         }
         if ($fld_reason) {
             $block['reason'] = $row->ipb_reason;
         }
         if ($fld_range && !$row->ipb_auto) {
             $block['rangestart'] = IP::hexToQuad($row->ipb_range_start);
             $block['rangeend'] = IP::hexToQuad($row->ipb_range_end);
         }
         if ($fld_flags) {
             // For clarity, these flags use the same names as their action=block counterparts
             if ($row->ipb_auto) {
                 $block['automatic'] = '';
             }
             if ($row->ipb_anon_only) {
                 $block['anononly'] = '';
             }
             if ($row->ipb_create_account) {
                 $block['nocreate'] = '';
             }
             if ($row->ipb_enable_autoblock) {
                 $block['autoblock'] = '';
             }
             if ($row->ipb_block_email) {
                 $block['noemail'] = '';
             }
             if ($row->ipb_deleted) {
                 $block['hidden'] = '';
             }
             if ($row->ipb_allow_usertalk) {
                 $block['allowusertalk'] = '';
             }
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $block);
         if (!$fit) {
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
             break;
         }
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'block');
 }
예제 #2
0
파일: Block.php 프로젝트: whysasse/kmwiki
 /**
  * Insert a block into the block table. Will fail if there is a conflicting
  * block (same name and options) already in the database.
  *
  * @param DatabaseBase $dbw If you have one available
  * @return bool|array False on failure, assoc array on success:
  *	('id' => block ID, 'autoIds' => array of autoblock IDs)
  */
 public function insert($dbw = null)
 {
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     if ($dbw === null) {
         $dbw = wfGetDB(DB_MASTER);
     }
     # Don't collide with expired blocks
     Block::purgeExpired();
     $row = $this->getDatabaseArray();
     $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq");
     $dbw->insert('ipblocks', $row, __METHOD__, array('IGNORE'));
     $affected = $dbw->affectedRows();
     $this->mId = $dbw->insertId();
     if ($affected) {
         $auto_ipd_ids = $this->doRetroactiveAutoblock();
         return array('id' => $this->mId, 'autoIds' => $auto_ipd_ids);
     }
     return false;
 }
예제 #3
0
 public function execute()
 {
     global $wgContLang;
     $db = $this->getDB();
     $params = $this->extractRequestParams();
     $this->requireMaxOneParameter($params, 'users', 'ip');
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_user = isset($prop['user']);
     $fld_userid = isset($prop['userid']);
     $fld_by = isset($prop['by']);
     $fld_byid = isset($prop['byid']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $fld_flags = isset($prop['flags']);
     $result = $this->getResult();
     $this->addTables('ipblocks');
     $this->addFields(array('ipb_auto', 'ipb_id', 'ipb_timestamp'));
     $this->addFieldsIf(array('ipb_address', 'ipb_user'), $fld_user || $fld_userid);
     $this->addFieldsIf('ipb_by_text', $fld_by);
     $this->addFieldsIf('ipb_by', $fld_byid);
     $this->addFieldsIf('ipb_expiry', $fld_expiry);
     $this->addFieldsIf('ipb_reason', $fld_reason);
     $this->addFieldsIf(array('ipb_range_start', 'ipb_range_end'), $fld_range);
     $this->addFieldsIf(array('ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk'), $fld_flags);
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addTimestampWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
     // Include in ORDER BY for uniqueness
     $this->addWhereRange('ipb_id', $params['dir'], null, null);
     if (!is_null($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 2);
         $op = $params['dir'] == 'newer' ? '>' : '<';
         $continueTimestamp = $db->addQuotes($db->timestamp($cont[0]));
         $continueId = (int) $cont[1];
         $this->dieContinueUsageIf($continueId != $cont[1]);
         $this->addWhere("ipb_timestamp {$op} {$continueTimestamp} OR " . "(ipb_timestamp = {$continueTimestamp} AND " . "ipb_id {$op}= {$continueId})");
     }
     if (isset($params['ids'])) {
         $this->addWhereFld('ipb_id', $params['ids']);
     }
     if (isset($params['users'])) {
         $usernames = array();
         foreach ((array) $params['users'] as $u) {
             $usernames[] = $this->prepareUsername($u);
         }
         $this->addWhereFld('ipb_address', $usernames);
         $this->addWhereFld('ipb_auto', 0);
     }
     if (isset($params['ip'])) {
         $blockCIDRLimit = $this->getConfig()->get('BlockCIDRLimit');
         if (IP::isIPv4($params['ip'])) {
             $type = 'IPv4';
             $cidrLimit = $blockCIDRLimit['IPv4'];
             $prefixLen = 0;
         } elseif (IP::isIPv6($params['ip'])) {
             $type = 'IPv6';
             $cidrLimit = $blockCIDRLimit['IPv6'];
             $prefixLen = 3;
             // IP::toHex output is prefixed with "v6-"
         } else {
             $this->dieUsage('IP parameter is not valid', 'param_ip');
         }
         # Check range validity, if it's a CIDR
         list($ip, $range) = IP::parseCIDR($params['ip']);
         if ($ip !== false && $range !== false && $range < $cidrLimit) {
             $this->dieUsage("{$type} CIDR ranges broader than /{$cidrLimit} are not accepted", 'cidrtoobroad');
         }
         # Let IP::parseRange handle calculating $upper, instead of duplicating the logic here.
         list($lower, $upper) = IP::parseRange($params['ip']);
         # Extract the common prefix to any rangeblock affecting this IP/CIDR
         $prefix = substr($lower, 0, $prefixLen + floor($cidrLimit / 4));
         # Fairly hard to make a malicious SQL statement out of hex characters,
         # but it is good practice to add quotes
         $lower = $db->addQuotes($lower);
         $upper = $db->addQuotes($upper);
         $this->addWhere(array('ipb_range_start' . $db->buildLike($prefix, $db->anyString()), 'ipb_range_start <= ' . $lower, 'ipb_range_end >= ' . $upper, 'ipb_auto' => 0));
     }
     if (!is_null($params['show'])) {
         $show = array_flip($params['show']);
         /* Check for conflicting parameters. */
         if (isset($show['account']) && isset($show['!account']) || isset($show['ip']) && isset($show['!ip']) || isset($show['range']) && isset($show['!range']) || isset($show['temp']) && isset($show['!temp'])) {
             $this->dieUsageMsg('show');
         }
         $this->addWhereIf('ipb_user = 0', isset($show['!account']));
         $this->addWhereIf('ipb_user != 0', isset($show['account']));
         $this->addWhereIf('ipb_user != 0 OR ipb_range_end > ipb_range_start', isset($show['!ip']));
         $this->addWhereIf('ipb_user = 0 AND ipb_range_end = ipb_range_start', isset($show['ip']));
         $this->addWhereIf('ipb_expiry = ' . $db->addQuotes($db->getInfinity()), isset($show['!temp']));
         $this->addWhereIf('ipb_expiry != ' . $db->addQuotes($db->getInfinity()), isset($show['temp']));
         $this->addWhereIf('ipb_range_end = ipb_range_start', isset($show['!range']));
         $this->addWhereIf('ipb_range_end > ipb_range_start', isset($show['range']));
     }
     if (!$this->getUser()->isAllowed('hideuser')) {
         $this->addWhereFld('ipb_deleted', 0);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('continue', "{$row->ipb_timestamp}|{$row->ipb_id}");
             break;
         }
         $block = array(ApiResult::META_TYPE => 'assoc');
         if ($fld_id) {
             $block['id'] = (int) $row->ipb_id;
         }
         if ($fld_user && !$row->ipb_auto) {
             $block['user'] = $row->ipb_address;
         }
         if ($fld_userid && !$row->ipb_auto) {
             $block['userid'] = (int) $row->ipb_user;
         }
         if ($fld_by) {
             $block['by'] = $row->ipb_by_text;
         }
         if ($fld_byid) {
             $block['byid'] = (int) $row->ipb_by;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
         }
         if ($fld_expiry) {
             $block['expiry'] = $wgContLang->formatExpiry($row->ipb_expiry, TS_ISO_8601);
         }
         if ($fld_reason) {
             $block['reason'] = $row->ipb_reason;
         }
         if ($fld_range && !$row->ipb_auto) {
             $block['rangestart'] = IP::formatHex($row->ipb_range_start);
             $block['rangeend'] = IP::formatHex($row->ipb_range_end);
         }
         if ($fld_flags) {
             // For clarity, these flags use the same names as their action=block counterparts
             $block['automatic'] = (bool) $row->ipb_auto;
             $block['anononly'] = (bool) $row->ipb_anon_only;
             $block['nocreate'] = (bool) $row->ipb_create_account;
             $block['autoblock'] = (bool) $row->ipb_enable_autoblock;
             $block['noemail'] = (bool) $row->ipb_block_email;
             $block['hidden'] = (bool) $row->ipb_deleted;
             $block['allowusertalk'] = (bool) $row->ipb_allow_usertalk;
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $block);
         if (!$fit) {
             $this->setContinueEnumParameter('continue', "{$row->ipb_timestamp}|{$row->ipb_id}");
             break;
         }
     }
     $result->addIndexedTagName(array('query', $this->getModuleName()), 'block');
 }
 function showList()
 {
     # Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     # Is the user allowed to see hidden blocks?
     if (!$this->getUser()->isAllowed('hideuser')) {
         $conds['ipb_deleted'] = 0;
     }
     if ($this->target !== '') {
         list($target, $type) = Block::parseTarget($this->target);
         switch ($type) {
             case Block::TYPE_ID:
             case Block::TYPE_AUTO:
                 $conds['ipb_id'] = $target;
                 break;
             case Block::TYPE_IP:
             case Block::TYPE_RANGE:
                 list($start, $end) = IP::parseRange($target);
                 $dbr = wfGetDB(DB_SLAVE);
                 $conds[] = $dbr->makeList(array('ipb_address' => $target, Block::getRangeCond($start, $end)), LIST_OR);
                 $conds['ipb_auto'] = 0;
                 break;
             case Block::TYPE_USER:
                 $conds['ipb_address'] = (string) $this->target;
                 $conds['ipb_auto'] = 0;
                 break;
         }
     }
     # Apply filters
     if (in_array('userblocks', $this->options)) {
         $conds['ipb_user'] = 0;
     }
     if (in_array('tempblocks', $this->options)) {
         $conds['ipb_expiry'] = 'infinity';
     }
     if (in_array('addressblocks', $this->options)) {
         $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
     }
     if (in_array('rangeblocks', $this->options)) {
         $conds[] = "ipb_range_end = ipb_range_start";
     }
     # Check for other blocks, i.e. global/tor blocks
     $otherBlockLink = array();
     wfRunHooks('OtherBlockLogLink', array(&$otherBlockLink, $this->target));
     $out = $this->getOutput();
     # Show additional header for the local block only when other blocks exists.
     # Not necessary in a standard installation without such extensions enabled
     if (count($otherBlockLink)) {
         $out->addHTML(Html::element('h2', array(), $this->msg('ipblocklist-localblock')->text()) . "\n");
     }
     $pager = new BlockListPager($this, $conds);
     if ($pager->getNumRows()) {
         $out->addHTML($pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar());
     } elseif ($this->target) {
         $out->addWikiMsg('ipblocklist-no-results');
     } else {
         $out->addWikiMsg('ipblocklist-empty');
     }
     if (count($otherBlockLink)) {
         $out->addHTML(Html::rawElement('h2', array(), $this->msg('ipblocklist-otherblocks', count($otherBlockLink))->parse()) . "\n");
         $list = '';
         foreach ($otherBlockLink as $link) {
             $list .= Html::rawElement('li', array(), $link) . "\n";
         }
         $out->addHTML(Html::rawElement('ul', array('class' => 'mw-ipblocklist-otherblocks'), $list) . "\n");
     }
 }
예제 #5
0
 /**
  * Insert a block into the block table. Will fail if there is a conflicting
  * block (same name and options) already in the database.
  *
  * @param IDatabase $dbw If you have one available
  * @return bool|array False on failure, assoc array on success:
  *	('id' => block ID, 'autoIds' => array of autoblock IDs)
  */
 public function insert($dbw = null)
 {
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     if ($dbw === null) {
         $dbw = wfGetDB(DB_MASTER);
     }
     # Periodic purge via commit hooks
     if (mt_rand(0, 9) == 0) {
         Block::purgeExpired();
     }
     $row = $this->getDatabaseArray();
     $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq");
     $dbw->insert('ipblocks', $row, __METHOD__, array('IGNORE'));
     $affected = $dbw->affectedRows();
     $this->mId = $dbw->insertId();
     # Don't collide with expired blocks.
     # Do this after trying to insert to avoid locking.
     if (!$affected) {
         # T96428: The ipb_address index uses a prefix on a field, so
         # use a standard SELECT + DELETE to avoid annoying gap locks.
         $ids = $dbw->selectFieldValues('ipblocks', 'ipb_id', array('ipb_address' => $row['ipb_address'], 'ipb_user' => $row['ipb_user'], 'ipb_expiry < ' . $dbw->addQuotes($dbw->timestamp())), __METHOD__);
         if ($ids) {
             $dbw->delete('ipblocks', array('ipb_id' => $ids), __METHOD__);
             $dbw->insert('ipblocks', $row, __METHOD__, array('IGNORE'));
             $affected = $dbw->affectedRows();
             $this->mId = $dbw->insertId();
         }
     }
     if ($affected) {
         $auto_ipd_ids = $this->doRetroactiveAutoblock();
         return array('id' => $this->mId, 'autoIds' => $auto_ipd_ids);
     }
     return false;
 }
예제 #6
0
 function showList($msg)
 {
     global $wgOut;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ("" != $msg) {
         $wgOut->setSubtitle($msg);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     if ($this->ip == '') {
         // No extra conditions
     } elseif (substr($this->ip, 0, 1) == '#') {
         $conds['ipb_id'] = substr($this->ip, 1);
     } elseif (IP::toUnsigned($this->ip) !== false) {
         $conds['ipb_address'] = $this->ip;
         $conds['ipb_auto'] = 0;
     } elseif (preg_match("/^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\/(\\d{1,2})\$/", $this->ip, $matches)) {
         $conds['ipb_address'] = Block::normaliseRange($this->ip);
         $conds['ipb_auto'] = 0;
     } else {
         $user = User::newFromName($this->ip);
         if ($user && ($id = $user->getID()) != 0) {
             $conds['ipb_user'] = $id;
         } else {
             // Uh...?
             $conds['ipb_address'] = $this->ip;
             $conds['ipb_auto'] = 0;
         }
     }
     $pager = new IPBlocklistPager($this, $conds);
     $s = $pager->getNavigationBar() . $this->searchForm();
     if ($pager->getNumRows()) {
         $s .= "<ul>" . $pager->getBody() . "</ul>";
     } else {
         $s .= '<p>' . wfMsgHTML('ipblocklistempty') . '</p>';
     }
     $s .= $pager->getNavigationBar();
     $wgOut->addHTML($s);
 }
예제 #7
0
 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     if (isset($params['users']) && isset($params['ip'])) {
         $this->dieUsage('bkusers and bkip cannot be used together', 'usersandip');
     }
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_user = isset($prop['user']);
     $fld_by = isset($prop['by']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $fld_flags = isset($prop['flags']);
     $result = $this->getResult();
     $pageSet = $this->getPageSet();
     $titles = $pageSet->getTitles();
     $data = array();
     $this->addTables('ipblocks');
     if ($fld_id) {
         $this->addFields('ipb_id');
     }
     if ($fld_user) {
         $this->addFields(array('ipb_address', 'ipb_user', 'ipb_auto'));
     }
     if ($fld_by) {
         $this->addTables('user');
         $this->addFields(array('ipb_by', 'user_name'));
         $this->addWhere('user_id = ipb_by');
     }
     if ($fld_timestamp) {
         $this->addFields('ipb_timestamp');
     }
     if ($fld_expiry) {
         $this->addFields('ipb_expiry');
     }
     if ($fld_reason) {
         $this->addFields('ipb_reason');
     }
     if ($fld_range) {
         $this->addFields(array('ipb_range_start', 'ipb_range_end'));
     }
     if ($fld_flags) {
         $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk'));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
     if (isset($params['ids'])) {
         $this->addWhereFld('ipb_id', $params['ids']);
     }
     if (isset($params['users'])) {
         foreach ((array) $params['users'] as $u) {
             $this->prepareUsername($u);
         }
         $this->addWhereFld('ipb_address', $this->usernames);
     }
     if (isset($params['ip'])) {
         list($ip, $range) = IP::parseCIDR($params['ip']);
         if ($ip && $range) {
             # We got a CIDR range
             if ($range < 16) {
                 $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
             }
             $lower = wfBaseConvert($ip, 10, 16, 8, false);
             $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
         } else {
             $lower = $upper = IP::toHex($params['ip']);
         }
         $prefix = substr($lower, 0, 4);
         $this->addWhere(array("ipb_range_start LIKE '{$prefix}%'", "ipb_range_start <= '{$lower}'", "ipb_range_end >= '{$upper}'"));
     }
     if (!$wgUser->isAllowed('suppress')) {
         $this->addWhereFld('ipb_deleted', 0);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     while ($row = $res->fetchObject()) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
             break;
         }
         $block = array();
         if ($fld_id) {
             $block['id'] = $row->ipb_id;
         }
         if ($fld_user && !$row->ipb_auto) {
             $block['user'] = $row->ipb_address;
         }
         if ($fld_by) {
             $block['by'] = $row->user_name;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
         }
         if ($fld_expiry) {
             $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601);
         }
         if ($fld_reason) {
             $block['reason'] = $row->ipb_reason;
         }
         if ($fld_range) {
             $block['rangestart'] = IP::hexToQuad($row->ipb_range_start);
             $block['rangeend'] = IP::hexToQuad($row->ipb_range_end);
         }
         if ($fld_flags) {
             // For clarity, these flags use the same names as their action=block counterparts
             if ($row->ipb_auto) {
                 $block['automatic'] = '';
             }
             if ($row->ipb_anon_only) {
                 $block['anononly'] = '';
             }
             if ($row->ipb_create_account) {
                 $block['nocreate'] = '';
             }
             if ($row->ipb_enable_autoblock) {
                 $block['autoblock'] = '';
             }
             if ($row->ipb_block_email) {
                 $block['noemail'] = '';
             }
             if ($row->ipb_deleted) {
                 $block['hidden'] = '';
             }
             if ($row->ipb_allow_usertalk) {
                 $block['allowusertalk'] = '';
             }
         }
         $data[] = $block;
     }
     $result->setIndexedTagName($data, 'block');
     $result->addValue('query', $this->getModuleName(), $data);
 }
예제 #8
0
 /**
  * Insert a block into the block table.
  *@return Whether or not the insertion was successful.
  */
 function insert()
 {
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     $dbw = wfGetDB(DB_MASTER);
     # Unset ipb_anon_only for user blocks, makes no sense
     if ($this->mUser) {
         $this->mAnonOnly = 0;
     }
     # Unset ipb_enable_autoblock for IP blocks, makes no sense
     if (!$this->mUser) {
         $this->mEnableAutoblock = 0;
         $this->mBlockEmail = 0;
         //Same goes for email...
     }
     # Don't collide with expired blocks
     Block::purgeExpired();
     $ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_val');
     $dbw->insert('ipblocks', array('ipb_id' => $ipb_id, 'ipb_address' => $this->mAddress, 'ipb_user' => $this->mUser, 'ipb_by' => $this->mBy, 'ipb_reason' => $this->mReason, 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), 'ipb_auto' => $this->mAuto, 'ipb_anon_only' => $this->mAnonOnly, 'ipb_create_account' => $this->mCreateAccount, 'ipb_enable_autoblock' => $this->mEnableAutoblock, 'ipb_expiry' => self::encodeExpiry($this->mExpiry, $dbw), 'ipb_range_start' => $this->mRangeStart, 'ipb_range_end' => $this->mRangeEnd, 'ipb_deleted' => $this->mHideName, 'ipb_block_email' => $this->mBlockEmail), 'Block::insert', array('IGNORE'));
     $affected = $dbw->affectedRows();
     $dbw->commit();
     if ($affected) {
         $this->doRetroactiveAutoblock();
     }
     return $affected;
 }
예제 #9
0
파일: Block.php 프로젝트: paladox/mediawiki
 /**
  * Insert a block into the block table. Will fail if there is a conflicting
  * block (same name and options) already in the database.
  *
  * @param IDatabase $dbw If you have one available
  * @return bool|array False on failure, assoc array on success:
  *	('id' => block ID, 'autoIds' => array of autoblock IDs)
  */
 public function insert($dbw = null)
 {
     global $wgBlockDisablesLogin;
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     if ($dbw === null) {
         $dbw = wfGetDB(DB_MASTER);
     }
     # Periodic purge via commit hooks
     if (mt_rand(0, 9) == 0) {
         Block::purgeExpired();
     }
     $row = $this->getDatabaseArray();
     $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq");
     $dbw->insert('ipblocks', $row, __METHOD__, ['IGNORE']);
     $affected = $dbw->affectedRows();
     $this->mId = $dbw->insertId();
     # Don't collide with expired blocks.
     # Do this after trying to insert to avoid locking.
     if (!$affected) {
         # T96428: The ipb_address index uses a prefix on a field, so
         # use a standard SELECT + DELETE to avoid annoying gap locks.
         $ids = $dbw->selectFieldValues('ipblocks', 'ipb_id', ['ipb_address' => $row['ipb_address'], 'ipb_user' => $row['ipb_user'], 'ipb_expiry < ' . $dbw->addQuotes($dbw->timestamp())], __METHOD__);
         if ($ids) {
             $dbw->delete('ipblocks', ['ipb_id' => $ids], __METHOD__);
             $dbw->insert('ipblocks', $row, __METHOD__, ['IGNORE']);
             $affected = $dbw->affectedRows();
             $this->mId = $dbw->insertId();
         }
     }
     if ($affected) {
         $auto_ipd_ids = $this->doRetroactiveAutoblock();
         if ($wgBlockDisablesLogin && $this->target instanceof User) {
             // Change user login token to force them to be logged out.
             $this->target->setToken();
             $this->target->saveSettings();
         }
         return ['id' => $this->mId, 'autoIds' => $auto_ipd_ids];
     }
     return false;
 }
 private function run()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_user = isset($prop['user']);
     $fld_by = isset($prop['by']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_expiry = isset($prop['expiry']);
     $fld_reason = isset($prop['reason']);
     $fld_range = isset($prop['range']);
     $fld_flags = isset($prop['flags']);
     $result = $this->getResult();
     $pageSet = $this->getPageSet();
     $titles = $pageSet->getTitles();
     $data = array();
     $this->addTables('ipblocks');
     if ($fld_id) {
         $this->addFields('ipb_id');
     }
     if ($fld_user) {
         $this->addFields(array('ipb_address', 'ipb_user'));
     }
     if ($fld_by) {
         $this->addTables('user');
         $this->addFields(array('ipb_by', 'user_name'));
         $this->addWhere('user_id = ipb_by');
     }
     if ($fld_timestamp) {
         $this->addFields('ipb_timestamp');
     }
     if ($fld_expiry) {
         $this->addFields('ipb_expiry');
     }
     if ($fld_reason) {
         $this->addFields('ipb_reason');
     }
     if ($fld_range) {
         $this->addFields(array('ipb_range_start', 'ipb_range_end'));
     }
     if ($fld_flags) {
         $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted'));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
     if (isset($params['ids'])) {
         $this->addWhere(array('ipb_id' => $params['ids']));
     }
     if (isset($params['users'])) {
         $this->addWhere(array('ipb_address' => $params['users']));
     }
     if (!$wgUser->isAllowed('oversight')) {
         $this->addWhere(array('ipb_deleted' => 0));
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $res = $this->select(__METHOD__);
     $db = wfGetDB();
     $count = 0;
     while ($row = $db->fetchObject($res)) {
         if ($count++ == $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
             break;
         }
         $block = array();
         if ($fld_id) {
             $block['id'] = $row->ipb_id;
         }
         if ($fld_user && !$row->ipb_auto) {
             $block['user'] = $row->ipb_address;
         }
         if ($fld_by) {
             $block['by'] = $row->user_name;
         }
         if ($fld_timestamp) {
             $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
         }
         if ($fld_expiry) {
             $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601);
         }
         if ($fld_reason) {
             $block['reason'] = $row->ipb_reason;
         }
         if ($fld_range) {
             $block['rangestart'] = $this->convertHexIP($row->ipb_range_start);
             $block['rangeend'] = $this->convertHexIP($row->ipb_range_end);
         }
         if ($fld_flags) {
             // For clarity, these flags use the same names as their action=block counterparts
             if ($row->ipb_auto) {
                 $block['automatic'] = '';
             }
             if ($row->ipb_anon_only) {
                 $block['anononly'] = '';
             }
             if ($row->ipb_create_account) {
                 $block['nocreate'] = '';
             }
             if ($row->ipb_enable_autoblock) {
                 $block['autoblock'] = '';
             }
             if ($row->ipb_block_email) {
                 $block['noemail'] = '';
             }
             if ($row->ipb_deleted) {
                 $block['hidden'] = '';
             }
         }
         $data[] = $block;
     }
     $result->setIndexedTagName($data, 'block');
     $result->addValue('query', $this->getModuleName(), $data);
 }
 function showList($msg)
 {
     global $wgOut, $wgUser;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ("" != $msg) {
         $wgOut->setSubtitle($msg);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     $matches = array();
     // Is user allowed to see all the blocks?
     if (!$wgUser->isAllowed('oversight')) {
         $conds['ipb_deleted'] = 0;
     }
     if ($this->ip == '') {
         // No extra conditions
     } elseif (substr($this->ip, 0, 1) == '#') {
         $conds['ipb_id'] = substr($this->ip, 1);
     } elseif (IP::toUnsigned($this->ip) !== false) {
         $conds['ipb_address'] = $this->ip;
         $conds['ipb_auto'] = 0;
     } elseif (preg_match('/^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\/(\\d{1,2})$/', $this->ip, $matches)) {
         $conds['ipb_address'] = Block::normaliseRange($this->ip);
         $conds['ipb_auto'] = 0;
     } else {
         $user = User::newFromName($this->ip);
         if ($user && ($id = $user->getID()) != 0) {
             $conds['ipb_user'] = $id;
         } else {
             // Uh...?
             $conds['ipb_address'] = $this->ip;
             $conds['ipb_auto'] = 0;
         }
     }
     $pager = new IPBlocklistPager($this, $conds);
     if ($pager->getNumRows()) {
         $wgOut->addHTML($this->searchForm() . $pager->getNavigationBar() . Xml::tags('ul', null, $pager->getBody()) . $pager->getNavigationBar());
     } elseif ($this->ip != '') {
         $wgOut->addHTML($this->searchForm());
         $wgOut->addWikiText(wfMsg('ipblocklist-no-results'));
     } else {
         $wgOut->addWikiText(wfMsg('ipblocklist-empty'));
     }
 }
예제 #12
0
 function insert()
 {
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     $dbw =& wfGetDB(DB_MASTER);
     $dbw->begin();
     # Unset ipb_anon_only for user blocks, makes no sense
     if ($this->mUser) {
         $this->mAnonOnly = 0;
     }
     # Don't collide with expired blocks
     Block::purgeExpired();
     $ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_val');
     $dbw->insert('ipblocks', array('ipb_id' => $ipb_id, 'ipb_address' => $this->mAddress, 'ipb_user' => $this->mUser, 'ipb_by' => $this->mBy, 'ipb_reason' => $this->mReason, 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), 'ipb_auto' => $this->mAuto, 'ipb_anon_only' => $this->mAnonOnly, 'ipb_create_account' => $this->mCreateAccount, 'ipb_expiry' => self::encodeExpiry($this->mExpiry, $dbw), 'ipb_range_start' => $this->mRangeStart, 'ipb_range_end' => $this->mRangeEnd), 'Block::insert', array('IGNORE'));
     $affected = $dbw->affectedRows();
     $dbw->commit();
     return $affected;
 }
예제 #13
0
파일: Block.php 프로젝트: ruizrube/spdef
 /**
  * Insert a block into the block table. Will fail if there is a conflicting
  * block (same name and options) already in the database.
  *
  * @return Boolean: whether or not the insertion was successful.
  */
 public function insert()
 {
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     $dbw = wfGetDB(DB_MASTER);
     $this->validateBlockParams();
     $this->initialiseRange();
     # Don't collide with expired blocks
     Block::purgeExpired();
     $ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_val');
     $dbw->insert('ipblocks', array('ipb_id' => $ipb_id, 'ipb_address' => $this->mAddress, 'ipb_user' => $this->mUser, 'ipb_by' => $this->mBy, 'ipb_by_text' => $this->mByName, 'ipb_reason' => $this->mReason, 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), 'ipb_auto' => $this->mAuto, 'ipb_anon_only' => $this->mAnonOnly, 'ipb_create_account' => $this->mCreateAccount, 'ipb_enable_autoblock' => $this->mEnableAutoblock, 'ipb_expiry' => self::encodeExpiry($this->mExpiry, $dbw), 'ipb_range_start' => $this->mRangeStart, 'ipb_range_end' => $this->mRangeEnd, 'ipb_deleted' => $this->mHideName, 'ipb_block_email' => $this->mBlockEmail, 'ipb_allow_usertalk' => $this->mAllowUsertalk), 'Block::insert', array('IGNORE'));
     $affected = $dbw->affectedRows();
     if ($affected) {
         $this->doRetroactiveAutoblock();
     }
     return (bool) $affected;
 }
예제 #14
0
 function showList($msg)
 {
     global $wgOut, $wgUser;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ("" != $msg) {
         $wgOut->setSubtitle($msg);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     $matches = array();
     // Is user allowed to see all the blocks?
     if (!$wgUser->isAllowed('suppress')) {
         $conds['ipb_deleted'] = 0;
     }
     if ($this->ip == '') {
         // No extra conditions
     } elseif (substr($this->ip, 0, 1) == '#') {
         $conds['ipb_id'] = substr($this->ip, 1);
         // Single IPs
     } elseif (IP::isIPAddress($this->ip) && strpos($this->ip, '/') === false) {
         if ($iaddr = IP::toHex($this->ip)) {
             # Only scan ranges which start in this /16, this improves search speed
             # Blocks should not cross a /16 boundary.
             $range = substr($iaddr, 0, 4);
             // Fixme -- encapsulate this sort of query-building.
             $dbr = wfGetDB(DB_SLAVE);
             $encIp = $dbr->addQuotes(IP::sanitizeIP($this->ip));
             $encRange = $dbr->addQuotes("{$range}%");
             $encAddr = $dbr->addQuotes($iaddr);
             $conds[] = "(ipb_address = {$encIp}) OR \n\t\t\t\t\t(ipb_range_start LIKE {$encRange} AND\n\t\t\t\t\tipb_range_start <= {$encAddr}\n\t\t\t\t\tAND ipb_range_end >= {$encAddr})";
         } else {
             $conds['ipb_address'] = IP::sanitizeIP($this->ip);
         }
         $conds['ipb_auto'] = 0;
         // IP range
     } elseif (IP::isIPAddress($this->ip)) {
         $conds['ipb_address'] = Block::normaliseRange($this->ip);
         $conds['ipb_auto'] = 0;
     } else {
         $user = User::newFromName($this->ip);
         if ($user && ($id = $user->getId()) != 0) {
             $conds['ipb_user'] = $id;
         } else {
             // Uh...?
             $conds['ipb_address'] = $this->ip;
             $conds['ipb_auto'] = 0;
         }
     }
     // Apply filters
     if ($this->hideuserblocks) {
         $conds['ipb_user'] = 0;
     }
     if ($this->hidetempblocks) {
         $conds['ipb_expiry'] = 'infinity';
     }
     if ($this->hideaddressblocks) {
         $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
     }
     $pager = new IPBlocklistPager($this, $conds);
     if ($pager->getNumRows()) {
         $wgOut->addHTML($this->searchForm() . $pager->getNavigationBar() . Xml::tags('ul', null, $pager->getBody()) . $pager->getNavigationBar());
     } elseif ($this->ip != '') {
         $wgOut->addHTML($this->searchForm());
         $wgOut->addWikiMsg('ipblocklist-no-results');
     } else {
         $wgOut->addHTML($this->searchForm());
         $wgOut->addWikiMsg('ipblocklist-empty');
     }
 }
예제 #15
0
 /**
  * Insert a block into the block table. Will fail if there is a conflicting
  * block (same name and options) already in the database.
  *
  * @param $dbw DatabaseBase if you have one available
  * @return mixed: false on failure, assoc array on success:
  *	('id' => block ID, 'autoIds' => array of autoblock IDs)
  */
 public function insert($dbw = null)
 {
     global $wgBlockDisablesLogin;
     wfDebug("Block::insert; timestamp {$this->mTimestamp}\n");
     if ($dbw === null) {
         $dbw = wfGetDB(DB_MASTER);
     }
     # Don't collide with expired blocks
     Block::purgeExpired();
     $row = $this->getDatabaseArray();
     $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq");
     $dbw->insert('ipblocks', $row, __METHOD__, array('IGNORE'));
     $affected = $dbw->affectedRows();
     $this->mId = $dbw->insertId();
     if ($affected) {
         if ($wgBlockDisablesLogin && $this->target instanceof User) {
             // Change user login token to force them to be logged out.
             $this->target->setToken();
             $this->target->saveSettings();
         }
         $auto_ipd_ids = $this->doRetroactiveAutoblock();
         return array('id' => $this->mId, 'autoIds' => $auto_ipd_ids);
     }
     return false;
 }
예제 #16
0
 function showList($msg)
 {
     global $wgOut, $wgUser;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ($msg != "") {
         $wgOut->setSubtitle($msg);
     }
     // Purge expired entries on one in every 10 queries
     if (!mt_rand(0, 10)) {
         Block::purgeExpired();
     }
     $conds = array();
     $matches = array();
     // Is user allowed to see all the blocks?
     if (!$wgUser->isAllowed('hideuser')) {
         $conds['ipb_deleted'] = 0;
     }
     if ($this->ip == '') {
         // No extra conditions
     } elseif (substr($this->ip, 0, 1) == '#') {
         $conds['ipb_id'] = substr($this->ip, 1);
         // Single IPs
     } elseif (IP::isIPAddress($this->ip) && strpos($this->ip, '/') === false) {
         if ($iaddr = IP::toHex($this->ip)) {
             # Only scan ranges which start in this /16, this improves search speed
             # Blocks should not cross a /16 boundary.
             $range = substr($iaddr, 0, 4);
             // Fixme -- encapsulate this sort of query-building.
             $dbr = wfGetDB(DB_SLAVE);
             $encIp = $dbr->addQuotes(IP::sanitizeIP($this->ip));
             $encAddr = $dbr->addQuotes($iaddr);
             $conds[] = "(ipb_address = {$encIp}) OR \n\t\t\t\t\t(ipb_range_start" . $dbr->buildLike($range, $dbr->anyString()) . " AND\n\t\t\t\t\tipb_range_start <= {$encAddr}\n\t\t\t\t\tAND ipb_range_end >= {$encAddr})";
         } else {
             $conds['ipb_address'] = IP::sanitizeIP($this->ip);
         }
         $conds['ipb_auto'] = 0;
         // IP range
     } elseif (IP::isIPAddress($this->ip)) {
         $conds['ipb_address'] = Block::normaliseRange($this->ip);
         $conds['ipb_auto'] = 0;
     } else {
         $user = User::newFromName($this->ip);
         if ($user && ($id = $user->getId()) != 0) {
             $conds['ipb_user'] = $id;
         } else {
             // Uh...?
             $conds['ipb_address'] = $this->ip;
             $conds['ipb_auto'] = 0;
         }
     }
     // Apply filters
     if ($this->hideuserblocks) {
         $conds['ipb_user'] = 0;
     }
     if ($this->hidetempblocks) {
         $conds['ipb_expiry'] = 'infinity';
     }
     if ($this->hideaddressblocks) {
         $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
     }
     // Search form
     $wgOut->addHTML($this->searchForm());
     // Check for other blocks, i.e. global/tor blocks
     $otherBlockLink = array();
     wfRunHooks('OtherBlockLogLink', array(&$otherBlockLink, $this->ip));
     // Show additional header for the local block only when other blocks exists.
     // Not necessary in a standard installation without such extensions enabled
     if (count($otherBlockLink)) {
         $wgOut->addHTML(Html::rawElement('h2', array(), wfMsg('ipblocklist-localblock')) . "\n");
     }
     $pager = new IPBlocklistPager($this, $conds);
     if ($pager->getNumRows()) {
         $wgOut->addHTML($pager->getNavigationBar() . Xml::tags('ul', null, $pager->getBody()) . $pager->getNavigationBar());
     } elseif ($this->ip != '') {
         $wgOut->addWikiMsg('ipblocklist-no-results');
     } else {
         $wgOut->addWikiMsg('ipblocklist-empty');
     }
     if (count($otherBlockLink)) {
         $wgOut->addHTML(Html::rawElement('h2', array(), wfMsgExt('ipblocklist-otherblocks', 'parseinline', count($otherBlockLink))) . "\n");
         $list = '';
         foreach ($otherBlockLink as $link) {
             $list .= Html::rawElement('li', array(), $link) . "\n";
         }
         $wgOut->addHTML(Html::rawElement('ul', array('class' => 'mw-ipblocklist-otherblocks'), $list) . "\n");
     }
 }