<commit_before><?php
/**
 * G_BrowseboxController
 * This controller receives paging requests from AJAX.
 * @author <NAME> | grrr.nl
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Db
 * @lastmodified $Date: $
 */
class G_BrowseboxController extends Garp_Controller_Action {
	/**
	 * Central entry point.
	 * @return Void
	 */
	public function indexAction() {
		$request = $this->getRequest();
		if (!$request->getParam('id') || !$request->getParam('chunk')) {
			throw new Exception('Not enough parameters: "id" and "chunk" are required.');
		}
		$bb = $this->_initBrowsebox($request);
		$this->view->bb = $bb;
		$this->_helper->layout->setLayout('blank');
	}
	
	
	/**
	 * Fetch a Browsebox object configured based on parameters found in the request.
	 * @param Zend_Controller_Request_Abstract $request The current request
	 * @return Garp_Browsebox
	 */
	protected function _initBrowsebox(Zend_Controller_Request_Abstract $request) {
		$bb = Garp_Browsebox::factory($request->getParam('id'));

		if ($request->getParam('conditions')) {
			$options = unserialize(base64_decode($request->getParam('conditions')));
			if (!empty($options['filters'])) {
				$conditions = base64_decode($options['filters']);
				$conditions = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_SEPARATOR, $conditions);
				foreach ($conditions as $condition) {
					$parts = explode(':', $condition);
					if (count($parts) < 2) {
						continue;
					}
					$filterId = $parts[0];
					$params   = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_PROP_SEPARATOR, $parts[1]);
					$bb->setFilter($filterId, $params);
				}
			}

			unset($options['filters']);
			foreach ($options as $key => $value) {
				$bb->setOption($key, $value);
			}
		}
		
		$bb->init($request->getParam('chunk'));
		return $bb;
	}
}<commit_msg>Never allow negative chunk values<commit_after><?php
/**
 * G_BrowseboxController
 * This controller receives paging requests from AJAX.
 * @author <NAME> | grrr.nl
 * @modifiedby $LastChangedBy: $
 * @version $Revision: $
 * @package Garp
 * @subpackage Db
 * @lastmodified $Date: $
 */
class G_BrowseboxController extends Garp_Controller_Action {
	/**
	 * Central entry point.
	 * @return Void
	 */
	public function indexAction() {
		$request = $this->getRequest();
		if (!$request->getParam('id') || !$request->getParam('chunk')) {
			throw new Exception('Not enough parameters: "id" and "chunk" are required.');
		}
		$bb = $this->_initBrowsebox($request);
		$this->view->bb = $bb;
		$this->_helper->layout->setLayout('blank');
	}
	
	
	/**
	 * Fetch a Browsebox object configured based on parameters found in the request.
	 * @param Zend_Controller_Request_Abstract $request The current request
	 * @return Garp_Browsebox
	 */
	protected function _initBrowsebox(Zend_Controller_Request_Abstract $request) {
		$bb = Garp_Browsebox::factory($request->getParam('id'));

		if ($request->getParam('conditions')) {
			$options = unserialize(base64_decode($request->getParam('conditions')));
			if (!empty($options['filters'])) {
				$conditions = base64_decode($options['filters']);
				$conditions = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_SEPARATOR, $conditions);
				foreach ($conditions as $condition) {
					$parts = explode(':', $condition);
					if (count($parts) < 2) {
						continue;
					}
					$filterId = $parts[0];
					$params   = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_PROP_SEPARATOR, $parts[1]);
					$bb->setFilter($filterId, $params);
				}
			}

			unset($options['filters']);
			foreach ($options as $key => $value) {
				$bb->setOption($key, $value);
			}
		}
		
		$chunk = $request->getParam('chunk');
		if ($chunk < 1) {
			$chunk = 1;
		}
		$bb->init($chunk);
		return $bb;
	}
}
{'fraction_non_alphanumeric': 0.1643580181140117, 'fraction_numerical': 0.004262120404901438, 'mean_word_length': 4.333806818181818, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889653', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1214, 'n_words': 251}