<commit_before><?php

class ShortListController extends Page_Controller
{
    private static $allowed_actions = array(
        'renderList',
        'addOrRemove'
    );

    private static $url_handlers = array(
        'add'       => 'addOrRemove',
        'remove'    => 'addOrRemove',
        '$URL!'     => 'renderList',
    );

    public function init()
    {
        parent::init();

        Session::start();

        if ($this->request->getVar('page')) {
            $this->currentPage = $this->request->getVar('page');
        }
    }

    /**
     * When landing on the homepage, if there is a shortlist for the current
     * user, redirect to the correct URL. Otherwise, 404.
     * */
    public function index($request)
    {

        if (($shortlist = $this->getSessionShortList())) {
            return $this->redirect(Config::inst()->get('ShortList', 'URLSegment') . $shortlist->URL);
        } else {
            $this->initList();
        }

        // render with empty template.
        return $this->renderWith(array('Page', 'ShortList_empty'));
    }

    /**
     * Get the absolute URL of this controller.
     * */
    public function Link($action = null)
    {
        $shortlist = $this->getSessionShortList();
        $url = Config::inst()->get('ShortList', 'URLSegment');

        if ($shortlist) {
            $url .= $shortlist->URL;
        }

        return $url;
    }

    /**
     * Create a new list if necessary. If a bot, do nothing!
     * */
    public function initList()
    {
        if (!ShortList::isBrowser()) {
            return $this->httpError(404);
        }

        $shortlist = $this->getSessionShortList();

        if (!$shortlist || !$shortlist->exists()) {
            $shortlist = new ShortList();
            $shortlist->write();
        }
    }

    public function renderList($request)
    {
        $shortlist = DataObject::get_one('ShortList', $filter = array('URL' => $request->param('URL')));

        if (is_null(session_id()) ||
            !$request->param('URL') ||
            !$shortlist ||
            !$shortlist->exists() ||
            !ShortList::isBrowser()
        ) {
            return $this->httpError(404);
        }

        return $this->customise(array(
            'ShortlistURL' => $shortlist && $shortlist->exists() ? $shortlist->Link() : false,
            'ShortlistCount' => $shortlist && $shortlist->exists() ? $shortlist->ShortListItems()->Count() : 0
        ))->renderWith(
            array('ShortList', 'Page')
        );
    }

    /**
     * Add an item to the shortlist.
     *
     * @param ID id of the object to add.
     * @param type classname of the item to remove
     * @param session session id.
     *
     * */
    public function addToShortList($ID = false, $type = null, $session = false)
    {
        if (!$ID || is_null($type) || !$session) {
            return false;
        }

        $shortlist = $this->getSessionShortList();

        if (!$shortlist || !$shortlist->exists()) {
            $shortlist = new ShortList();
            $shortlist->write();
        }

        // check whether the itme is already in the list
        // before attempting to add it.
        $existing = $shortlist->ShortListItems()->filterAny(
            array('ItemID' => $ID, 'ItemType' => $type)
        );

        if ($existing->count() == 1) {
            return true;
        }

        $shortlistItem = new ShortListItem();
        $shortlistItem->ShortListID = $shortlist->ID;
        $shortlistItem->ItemID = $ID;
        $shortlistItem->ItemType = $type;

        $shortlist->ShortListItems()->add($shortlistItem);
        $shortlist->write();

        return true;
    }

    public function addOrRemove($request)
    {
        if (is_null(session_id()) ||
            !$request->getVar('id') ||
            !$request->getVar('type') ||
            !$request->getVar('s') ||
            $request->getVar('s') != session_id() ||
            !ShortList::isBrowser()
        ) {
            return $this->httpError(404);
        }
<commit_msg>update to travis testing<commit_after><?php

class ShortListController extends Page_Controller
{
    private static $allowed_actions = array(
        'renderList',
        'addOrRemove'
    );

    private static $url_handlers = array(
        'add'       => 'addOrRemove',
        'remove'    => 'addOrRemove',
        '$URL!'     => 'renderList',
    );

    public function init()
    {
        parent::init();

        Session::start();

        if ($this->request->getVar('page')) {
            $this->currentPage = $this->request->getVar('page');
        }
    }

    /**
     * When landing on the homepage, if there is a shortlist for the current
     * user, redirect to the correct URL. Otherwise, 404.
     * */
    public function index($request)
    {

        if (($shortlist = $this->getSessionShortList())) {
            return $this->redirect(Config::inst()->get('ShortList', 'URLSegment') . $shortlist->URL);
        } else {
            $this->initList();
        }

        // render with empty template.
        return $this->renderWith(array('Page', 'ShortList_empty'));
    }

    /**
     * Get the absolute URL of this controller.
     * */
    public function Link($action = null)
    {
        $shortlist = $this->getSessionShortList();
        $url = Config::inst()->get('ShortList', 'URLSegment');

        if ($shortlist) {
            $url .= $shortlist->URL;
        }

        return $url;
    }

    /**
     * Create a new list if necessary. If a bot, do nothing!
     * */
    public function initList()
    {
        if (!ShortList::isBrowser()) {
            return $this->httpError(404);
        }

        $shortlist = $this->getSessionShortList();

        if (!$shortlist || !$shortlist->exists()) {
            $shortlist = new ShortList();
            $shortlist->write();
        }
    }

    public function renderList($request)
    {
        $shortlist = DataObject::get_one('ShortList', $filter = array('URL' => $request->param('URL')));

        if (is_null(session_id()) ||
            !$request->param('URL') ||
            !$shortlist ||
            !$shortlist->exists() ||
            !ShortList::isBrowser()
        ) {
            return $this->httpError(404);
        }

        return $this->customise(array(
            'ShortlistURL' => $shortlist && $shortlist->exists() ? $shortlist->Link() : false,
            'ShortlistCount' => $shortlist && $shortlist->exists() ? $shortlist->ShortListItems()->Count() : 0
        ))->renderWith(
            array('ShortList', 'Page')
        );
    }

    /**
     * Add an item to the shortlist.
     *
     * @param ID id of the object to add.
     * @param type classname of the item to remove
     * @param session session id.
     *
     * */
    public function addToShortList($ID = false, $type = null, $session = false)
    {
        if (!$ID || is_null($type) || !$session) {
            return false;
        }

        $shortlist = $this->getSessionShortList();

        if (!$shortlist || !$shortlist->exists()) {
            $shortlist = new ShortList();
            $shortlist->write();
        }

        // check whether the itme is already in the list
        // before attempting to add it.
        /*
$existing = $shortlist->ShortListItems()->filterAny(
            array('ItemID' => $ID, 'ItemType' => $type)
        );

        if ($existing->count() == 1) {
            return true;
        }
*/

        $shortlistItem = new ShortListItem();
        $shortlistItem->ShortListID = $shortlist->ID;
        $shortlistItem->ItemID = $ID;
        $shortlistItem->ItemType = $type;

        $shortlist->ShortListItems()->add($shortlistItem);
        $shortlist->write();

        return true;
    }

    public function addOrRemove($request)
    {
        if (is_null(session_id()) ||
            !$request->getVar('id') ||
            !$request->getVar('type') ||
            !$request->getVar('s') ||
            $request->getVar('s') != session_id() ||
            !ShortList::isBrowser()
        ) {
            return $this->httpError(404);
        }

{'fraction_non_alphanumeric': 0.15885896962990287, 'fraction_numerical': 0.0034427640477068732, 'mean_word_length': 1.9175035868005739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 113, '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': '962821', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2314, 'n_words': 503}