<commit_before><?php
/**
 * $Id$
 *
  * @author <NAME>, 2007-2008 <<EMAIL>>
 */

/**
 * XXX
 */
function URLadd($_key, $_val = '', $_extra = '')    //FIXME: is this function even required???
{
    $curr_url = 'http://localhost'.$_SERVER['REQUEST_URI'];

    $arr = parse_url($curr_url);

    $wiki_link = false;
    $pos = strpos($_key, ':');
    if ($pos !== false) $wiki_link = substr($_key, $pos+1);

    if ($_val) {
        $keyval = $_key.'='.$_val;
    } else {
        $keyval = $_key;
    }

    if (empty($arr['query'])) return $arr['path'].'?'.$keyval.$_extra;

    $args = explode('&', $arr['query']);

    $out_args = '';

    for ($i=0; $i<count($args); $i++) {        //fixme: use foreach

        $vals = explode('=', $args[$i]);

        //Skip it here, $keyval will be added later
        if ($vals[0] == $_key) continue;

        //Wiki:Style links
        if ($wiki_link && strpos($vals[0], ':')) {
            if (substr($vals[0], strpos($vals[0], ':')+1) == $wiki_link) {
                $out_args .= $keyval.'&amp;';    //Replaces wiki link with current wiki link
                $keyval = '';
                continue;
            }
        }

        if (isset($vals[1])) {
            $out_args .= $vals[0].'='.urlencode($vals[1]).'&amp;';
        } else {
            $out_args .= $vals[0].'&amp;';
        }
    }

    if ($out_args && !$keyval && !$_extra) $out_args = substr($out_args, 0, -strlen('&amp;'));

    if ($out_args) {
        return $arr['path'].'?'.$out_args.$keyval.$_extra;
    } else {
        return $arr['path'].'?'.$keyval.$_extra;
    }
}

/**
 * Helper function used to create "are you sure?" pages
 *
 * Example use:
 *
 * if (confirmed('Are you sure you want to delete this rule?', 'id', $_GET['id'])) {
 *        deleteItem($_GET['id']);
 * }
 *
 * Wiki-style link example use:
 *
 * if (confirmed('Are you sure you want to delete this blog?', 'BlogDelete:'.$_id)) {
 *        deleteBlog($_GET['BlogDelete:'.$_id]);
 * }
 */
function confirmed($text, $_var, $_id = 0)
{
    global $project;    //path to design includes
    global $h, $db, $config, $time_start;

    if (!$_var || !is_numeric($_id) || isset($_GET['confirmed'])) return true;

    require_once($project.'design_head.php');

    echo $text.'<br/><br/>';
    if ($_id) {
        //Normal links
        echo '<a href="'.URLadd('confirmed&amp;'.$_var, $_id).'">Yes, I am sure</a><br/><br/>';
    } else {
        //Wiki-style links
        //fixme: use URLadd() here
        echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$_var.'&amp;confirmed">Yes, I am sure</a><br/><br/>';
    }
    echo '<a href="javascript:history.go(-1);">No, wrong button</a><br/>';

    require_once($project.'design_foot.php');
    die;
}

/**
 * Looks for formatted wiki section commands, like: Wiki:Page, WikiEdit:Page, WikiHistory:Page, WikiFiles:Page
 * used by class.Wiki.php, class.Blogs.php for special url creation to allow these modules to be embedded in other pages
 */
function fetchSpecialParams($allowed_tabs)
{
    $paramName = '';
    $current_tab = '';

    foreach($_GET as $key => $val) {
        $arr = explode(':', $key);
        if (empty($arr[1]) || !in_array($arr[0], $allowed_tabs)) continue;
        $arr[1] = trim($arr[1]);
        return $arr;
    }

    return false;
}

?>
<commit_msg>made confirmed() sort-of work with core_dev trunk again, needs more work<commit_after><?php
/**
 * $Id$
 *
  * @author <NAME>, 2007-2008 <<EMAIL>>
 */

/**
 * XXX
 */
function URLadd($_key, $_val = '', $_extra = '')    //FIXME: is this function even required???
{
    $curr_url = 'http://localhost'.$_SERVER['REQUEST_URI'];

    $arr = parse_url($curr_url);

    $wiki_link = false;
    $pos = strpos($_key, ':');
    if ($pos !== false) $wiki_link = substr($_key, $pos+1);

    if ($_val) {
        $keyval = $_key.'='.$_val;
    } else {
        $keyval = $_key;
    }

    if (empty($arr['query'])) return $arr['path'].'?'.$keyval.$_extra;

    $args = explode('&', $arr['query']);

    $out_args = '';

    for ($i=0; $i<count($args); $i++) {        //fixme: use foreach

        $vals = explode('=', $args[$i]);

        //Skip it here, $keyval will be added later
        if ($vals[0] == $_key) continue;

        //Wiki:Style links
        if ($wiki_link && strpos($vals[0], ':')) {
            if (substr($vals[0], strpos($vals[0], ':')+1) == $wiki_link) {
                $out_args .= $keyval.'&amp;';    //Replaces wiki link with current wiki link
                $keyval = '';
                continue;
            }
        }

        if (isset($vals[1])) {
            $out_args .= $vals[0].'='.urlencode($vals[1]).'&amp;';
        } else {
            $out_args .= $vals[0].'&amp;';
        }
    }

    if ($out_args && !$keyval && !$_extra) $out_args = substr($out_args, 0, -strlen('&amp;'));

    if ($out_args) {
        return $arr['path'].'?'.$out_args.$keyval.$_extra;
    } else {
        return $arr['path'].'?'.$keyval.$_extra;
    }
}

/**
 * Helper function used to create "are you sure?" pages
 *
 * Example use:
 *
 * if (confirmed('Are you sure you want to delete this rule?', 'id', $_GET['id'])) {
 *        deleteItem($_GET['id']);
 * }
 *
 * Wiki-style link example use:
 *
 * if (confirmed('Are you sure you want to delete this blog?', 'BlogDelete:'.$_id)) {
 *        deleteBlog($_GET['BlogDelete:'.$_id]);
 * }
 */
function confirmed($text, $_var, $_id = 0)
{
    if (!$_var || !is_numeric($_id) || isset($_GET['confirmed'])) return true;

    echo $text.'<br/><br/>';
    if ($_id) {
        //Normal links
        echo '<a href="'.URLadd('confirmed&amp;'.$_var, $_id).'">Yes, I am sure</a><br/><br/>';
    } else {
        //Wiki-style links
        //fixme: use URLadd() here
        echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$_var.'&amp;confirmed">Yes, I am sure</a><br/><br/>';
    }
    echo '<a href="javascript:history.go(-1);">No, wrong button</a><br/>';

    die;
}

/**
 * Looks for formatted wiki section commands, like: Wiki:Page, WikiEdit:Page, WikiHistory:Page, WikiFiles:Page
 * used by class.Wiki.php, class.Blogs.php for special url creation to allow these modules to be embedded in other pages
 */
function fetchSpecialParams($allowed_tabs)
{
    $paramName = '';
    $current_tab = '';

    foreach($_GET as $key => $val) {
        $arr = explode(':', $key);
        if (empty($arr[1]) || !in_array($arr[0], $allowed_tabs)) continue;
        $arr[1] = trim($arr[1]);
        return $arr;
    }

    return false;
}

?>

{'fraction_non_alphanumeric': 0.21683397683397684, 'fraction_numerical': 0.008030888030888032, 'mean_word_length': 2.558241758241758, 'pattern_counts': {'":': 0, '<': 39, '<?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': '1446600', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2203, 'n_words': 513}