Jump to content

User:RFC posting script/source

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Harej (talk | contribs) at 18:54, 28 January 2009 (enough of that). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Template:Beerware

postingscript.php

<?php
$connect = mysql_connect('sql', $sqluser, $sqlpass);
if (!$connect)
	die("Error: database connection failed.");
mysql_select_db($database);


ini_set("display_errors", 1);
error_reporting(E_ALL ^ E_NOTICE);
include("./botclasses.php");

$user = mysql_real_escape_string($_GET['user']);
$category = mysql_real_escape_string($_GET['category']);
$page = mysql_real_escape_string($_GET['page']);
$section = mysql_real_escape_string($_GET['section']);
$reason =mysql_real_escape_string( $_GET['reason']);
$id = md5(time());

if (isset($_GET['submit'])) {
	if (($_GET['user'] != "") && ($_GET['category'] != "") && ($_GET['page'] != "") && ($_GET['section'] != "") && ($_GET['reason'] != "")) {
		$rfctype = "";
		switch ($category) {
			case "Biographies":
				$rfctype = "RFCbio";
				break;
			case "Economy, trade, and companies":
				$rfctype = "RFCecon";
				break;
			case "History and geography":
				$rfctype = "RFChist";
				break;
			case "Language and linguistics":
				$rfctype = "RFClang";
				break;
			case "Maths, science, and technology":
				$rfctype = "RFCsci";
				break;
			case "Art, architecture, literature and media":
				$rfctype = "RFCart";
				break;
			case "Politics":
				$rfctype = "RFCpol";
				break;
			case "Religion and philosophy":
				$rfctype = "RFCreli";
				break;
			case "Society, sports, law, and sex":
				$rfctype = "RFCsoc";
				break;
			case "Wikipedia style, referencing, layout and WikiProjects":
				$rfctype = "RFCstyle";
				break;
			case "Wikipedia policies, guidelines and proposals":
				$rfctype = "RFCpolicy";
				break;
		}
		$query = "INSERT INTO `u_messedrocker_reqs`.`rfcposter` (`id`, `section`, `reason`, `page`, `user`, `rfctype`) VALUES ('$id', '$section', '$reason', '$page', '$user', '$rfctype')";
		$query = mysql_query($query);
		
		$subject = "Confirm your RFC request";
  		$msg = "Please confirm that you entered an RFC request for the page $page by visiting this URL: http://toolserver.org/~messedrocker/confirm.php?id=$id\n\nIf you did not enter an RFC request, please disregard this e-mail.";
		$objwiki = new wikipedia();
		$objwiki->login($botuser, $botpass);
  		$objwiki->email($user,$subject,$msg);
  		  		
  		echo "You have been sent an e-mail to confirm your request. Please enter or click on the URL in the e-mail.";
	}
	else {
		echo "You did not fill out every field. Go back and try again.";
	}
}
else {
	echo "<form id=\"form1\" name=\"form1\" method=\"get\" action=\"postingscript.php\">\n";
	echo "<strong>Your username:</strong>\n";
	echo "<label>\n";
	echo "<input name=\"user\" type=\"text\" id=\"user\" size=\"50\" />\n";
	echo "</label>\n";
	echo "<em>Do not prefix with \"User:\"<br />\n";
	echo "</em>This tool will only work if you are <strong>registered</strong> and you have a <strong>confirmed e-mail address</strong> registered via <a href='http://en.wikipedia.org/wiki/Special:Preferences'>Special:Preferences</a>!<br />\n";
	echo "<br />\n";
	echo "<strong>Page for RFC discussion: </strong>\n";
	echo "<label>\n";
	echo "<input name=\"page\" type=\"text\" id=\"page\" value=\"Talk:\" size=\"43\" />\n";
	echo "</label>\n";
	echo "<em>Do not forget \"Talk:\" if you are posting to a talk page. Only write the page title, not the full URL.<br />\n";
	echo "</em><strong>RFC category:\n";
	echo "<select name=\"category\" id=\"category\">\n";
	echo "<option selected=\"selected\">Biographies</option>\n";
	echo "<option value='Economy, trade, and companies'>Economy, trade, and companies</option>\n";
	echo "<option value='History and geography'>History and geography</option>\n";
	echo "<option value='Language and linguistics'>Language and linguistics</option>\n";
	echo "<option value='Maths, science, and technology'>Maths, science, and technology</option>\n";
	echo "<option value='Art, architecture, literature and media'>Art, architecture, literature and media</option>\n";
	echo "<option value='Politics'>Politics</option>\n";
	echo "<option value='Religion and philosophy'>Religion and philosophy</option>\n";
	echo "<option value='Society, sports, law, and sex'>Society, sports, law, and sex</option>\n";
	echo "<option value='Wikipedia style, referencing, layout and WikiProjects'>Wikipedia style, referencing, layout and WikiProjects</option>\n";
	echo "<option value='Wikipedia policies, guidelines and proposals'>Wikipedia policies, guidelines, and proposals</option>\n";
	echo "</select>\n";
	echo "</strong><br />\n";
	echo "<strong>Name of RFC: \n";
	echo "<label> \n";
	echo "<input name=\"section\" type=\"text\" id=\"section\" size=\"56\" />\n";
	echo "</label>\n";
	echo "</strong> <em>This is the name of the new discussion section that will be created<br />\n";
	echo "</em><strong>Description:</strong> <em>Keep it short and to the point. One paragraph only; you can elaborate once the RFC is posted.</em><br />\n";
	echo "<input type=\"text\" size=\"80\" name=\"reason\" id=\"reason\" cols=\"70\" rows=\"7\"></textarea>\n";
	echo "<label></label>\n";
	echo "</strong><br />\n";
	echo "<br />\n";
	echo "<label>\n";
	echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit\" />\n";
	echo "</label>\n";
	echo "<br />\n";
	echo "</form>\n";
}
?>

confirm.php

<?php
ini_set("display_errors", 1);
error_reporting(E_ALL ^ E_NOTICE);
include("./botclasses.php");

$sqlpass = "PDp#_dMewp\$AUjNt";
$connect = mysql_connect('sql', $sqluser, $sqlpass);
if (!$connect)
	die("Error: database connection failed.");
mysql_select_db($database);


if (isset($_GET['id'])) {
	$id = mysql_real_escape_string($_GET['id']);
	$query = "SELECT * FROM rfcposter WHERE id = '" . $id . "';";
	$query = mysql_query($query);
	if (!$query)
		die("Error: Query failed " . mysql_error());
	$row = mysql_fetch_assoc($query);
	
	$page = $row['page'];
	$user = $row['user'];
	$section = $row['section'];
	$reason = $row['reason'];
	$rfctype = $row['rfctype'];
	
	$rfc = '{{'.$rfctype.' | section='.$section.' !! reason='.$reason.' !! time=~~~~~ }}'."\n";
	
	$objwiki = new wikipedia();
	$objwiki->login($botuser, $botpass);
	$origpage = $objwiki->getpage($page);
	$newpage = $origpage . "\n\n==" . $section . "==\n" . $rfc . "\n\n" . $reason . " &mdash;[[User:$user|" . $user . "]] <small>(via [[User:RFC posting script|posting script]])</small> ~~~~~";
	$objwiki->edit($page,$newpage,"Adding RFC on behalf of $user",false,true);
	
	$query = "DELETE FROM rfcposter WHERE id = '$id'";
	$query = mysql_query($query);
	
	echo "Your RFC has been posted at <a href='http://en.wikipedia.org/wiki/$page'>$page</a>";
}
else {
	echo "id not entered.";
}
?>