<commit_before><?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
/* Setup the mediawiki classes. */
require_once dirname(__FILE__) . '/../config.inc.php';
require_once dirname(__FILE__) . '/../botclasses.php';

$link = mysqli_connect($hotarticlesdb['host'], $hotarticlesdb['user'], $hotarticlesdb['pass'], $hotarticlesdb['dbname']);

$wikipedia = new wikipedia();

/* Log in to wikipedia. */
$wikipedia->login($enwiki['user'],$enwiki['pass']);

$error = '';
if (isset($_POST['source'])) {
	$_POST['source'] = str_replace("_", " ", $_POST['source']);
	$count = $wikipedia->categorypagecount('Category:'.$_POST['source']);
	if ($count > $maxArticles) {
		$error = "Error: Category ".$_POST['source']." is too large.<br/>";
	} else {
		$_POST['source'] = trim(mysqli_real_escape_string($_POST['source']));
		$query = "SELECT * FROM hotarticles where source = '$_POST[source]' LIMIT 1";
		$sourceresult = mysqli_query($link, $query);
		if (@mysqli_num_rows($sourceresult) == 1) {
			$error = "Error: Category is already subscribed. Please enter a new one.";
		} else {
			$_POST['target_page'] = trim(mysqli_real_escape_string($_POST['target_page']));
			$_POST['article_number'] = mysqli_real_escape_string($_POST['article_number']);
			$_POST['span_days'] = mysqli_real_escape_string($_POST['span_days']);
			$_POST['orange'] = mysqli_real_escape_string($_POST['orange']);
			$_POST['red'] = mysqli_real_escape_string($_POST['red']);
			$query = "INSERT INTO hotarticles (method, source, article_number, span_days, target_page, orange, red) VALUES ('category', '$_POST[source]', '$_POST[article_number]', '$_POST[span_days]', '$_POST[target_page]', '$_POST[orange]', '$_POST[red]')";
			$result = mysqli_query($link, $query);
			if (!$result) {
				$error = "Database error: ".mysqli_error();
			} else {
				Header("Location:configure.php");
			}
		}
	}
}

include ("header.inc.php");

print("<h2>Add a Hot Article Subscription</h2>");
print("<p><i>Note: Currently subscriptions are limited to categories with ".$maxArticles." or fewer pages.</i></p>");
if ($error) {
	print ("<p class=\"error\">".$error."</p>\n");
}
?>
<form name="form1" method="post">
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td>Category Name:
				<a class="tt" href="#">
				<img height="12" width="12" border="0" src="images/help_icon.gif"/>
				<span class="tooltip">
					<span class="top"></span>
					<span class="middle">Without 'Category:' prefix. For example, "WikiProject Tulips articles"</span>
					<span class="bottom"></span>
				</span>
				</a><commit_msg>Setting some sane limits on add page<commit_after><?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
/* Setup the mediawiki classes. */
require_once dirname(__FILE__) . '/../config.inc.php';
require_once dirname(__FILE__) . '/../botclasses.php';

$link = mysqli_connect($hotarticlesdb['host'], $hotarticlesdb['user'], $hotarticlesdb['pass'], $hotarticlesdb['dbname']);

$wikipedia = new wikipedia();

/* Log in to wikipedia. */
$wikipedia->login($enwiki['user'],$enwiki['pass']);

$error = '';
if (isset($_POST['source'])) {
	$_POST['source'] = str_replace("_", " ", $_POST['source']);
	$count = $wikipedia->categorypagecount('Category:'.$_POST['source']);
	if ($count > $maxArticles) {
		$error = "Error: Category ".$_POST['source']." is too large.<br/>";
	} else {
		$_POST['source'] = trim(mysqli_real_escape_string($_POST['source']));
		$query = "SELECT * FROM hotarticles where source = '$_POST[source]' LIMIT 1";
		$sourceresult = mysqli_query($link, $query);
		if (@mysqli_num_rows($sourceresult) == 1) {
			$error = "Error: Category is already subscribed. Please enter a new one.";
		} else {
			$_POST['target_page'] = trim(mysqli_real_escape_string($_POST['target_page']));
			$_POST['article_number'] = mysqli_real_escape_string($_POST['article_number']);
			$_POST['span_days'] = mysqli_real_escape_string($_POST['span_days']);
			$_POST['orange'] = mysqli_real_escape_string($_POST['orange']);
			$_POST['red'] = mysqli_real_escape_string($_POST['red']);
			if ( $_POST['span_days'] <= 30 && $_POST['article_number'] <= 100 ) {
				$query = "INSERT INTO hotarticles (method, source, article_number, span_days, target_page, orange, red) VALUES ('category', '$_POST[source]', '$_POST[article_number]', '$_POST[span_days]', '$_POST[target_page]', '$_POST[orange]', '$_POST[red]')";
				$result = mysqli_query($link, $query);
				if (!$result) {
					$error = "Database error: ".mysqli_error();
				} else {
					Header("Location:configure.php");
				}
			} else {
				$error = "Form input not valid. Please try again.";
			}
			
		}
	}
}

include ("header.inc.php");

print("<h2>Add a Hot Article Subscription</h2>");
print("<p><i>Note: Currently subscriptions are limited to categories with ".$maxArticles." or fewer pages.</i></p>");
if ($error) {
	print ("<p class=\"error\">".$error."</p>\n");
}
?>
<form name="form1" method="post">
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td>Category Name:
				<a class="tt" href="#">
				<img height="12" width="12" border="0" src="images/help_icon.gif"/>
				<span class="tooltip">
					<span class="top"></span>
					<span class="middle">Without 'Category:' prefix. For example, "WikiProject Tulips articles"</span>
					<span class="bottom"></span>
				</span>
				</a>
{'fraction_non_alphanumeric': 0.21197897108524222, 'fraction_numerical': 0.006196019526849418, 'mean_word_length': 5.488428745432399, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, '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': '1187029', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1770, 'n_words': 367}