",
"\"", "'",
">",
"http://","https://","url://","ftp://","file://","irc://","javascript:",
"!",
"\n! ",
"!!",
"||",
".gif",
".png",
".jpg",
".jpeg",
"",
"",
"Image:",
"[[category:",
"{{REVISIONID}}",
"{{SUBPAGENAME}}",
"{{SUBPAGENAMEE}}",
"{{ns:0}}",
"[[:Image",
"[[Special:",
"{{fullurl:}}",
'__TOC__',
"",
"",
""
);
///////////////////// A CLASS THAT GENERATES RANDOM STRINGS OF DATA //////////////////////
class htmler {
var $maxparams = 4;
var $maxtypes = 40;
function randnum($finish,$start=0) {
return mt_rand($start,$finish);
}
function randstring() {
global $ext;
$thestring = "";
for ($i=0; $i<40; $i++) {
$what = $this->randnum(1);
if ($what == 0) { // include some random wiki syntax
$which = $this->randnum(count($ext) - 1);
$thestring .= $ext[$which];
}
else { // include some random text
$char = chr(INCLUDE_BINARY ? $this->randnum(255) : $this->randnum(126,32));
if ($char == "<") $char = ""; // we don't want the '<' character, it stuffs us up.
$length = $this->randnum(8);
$thestring .= str_repeat ($char, $length);
}
}
return $thestring;
}
function makestring() {
global $ints, $other;
$what = $this->randnum(2);
if ($what == 0) {
return $this->randstring();
}
elseif ($what == 1) {
return $ints[$this->randnum(count($ints) - 1)];
}
else {
return $other[$this->randnum(count($other) - 1)];
}
}
function loop() {
global $types, $data;
$string = "";
$i = $this->randnum(count($types) - 1);
$t = $types[$i];
$arr = $data[$t];
$string .= "<" . $types[$i] . " ";
for ($z=0; $z<$this->maxparams; $z++) {
$badparam = $arr[$this->randnum(count($arr) - 1)];
$badstring = $this->makestring();
$string .= $badparam . "=" . $badstring . " ";
}
$string .= ">\n";
return $string;
}
function main() {
$page = "";
for ($k=0; $k<$this->maxtypes; $k++) {
$page .= $this->loop();
}
return $page;
}
}
//////////////////// SAVING OUTPUT /////////////////////////
/**
** @desc: Utility function for saving a file. Currently has no error checking.
*/
function saveFile($string, $name) {
$fp = fopen ( DIRECTORY . "/" . $name, "w");
fwrite($fp, $string);
fclose ($fp);
}
//////////////////// MEDIAWIKI PREVIEW /////////////////////////
/*
** @desc: Asks MediaWiki for a preview of a string. Returns the HTML.
*/
function wikiPreview($text) {
$params = array (
"action" => "submit",
"wpMinoredit" => "1",
"wpPreview" => "Show preview",
"wpSection" => "new",
"wpEdittime" => "",
"wpSummary" => "This is a test",
"wpTextbox1" => $text
);
if( function_exists('curl_init') ) {
$ch = curl_init();
} else {
die("Could not found 'curl_init' function. Is curl extension enabled ?\n");
}
curl_setopt($ch, CURLOPT_POST, 1); // save form using a POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); // load the POST variables
curl_setopt($ch, CURLOPT_URL, WIKI_URL); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
$result=curl_exec ($ch);
// if we encountered an error, then log it, and exit.
if (curl_error($ch)) {
trigger_error("Curl error #: " . curl_errno($ch) . " - " . curl_error ($ch) );
print "Curl error #: " . curl_errno($ch) . " - " . curl_error ($ch) . " - exiting.\n";
exit();
}
curl_close ($ch);
return $result;
}
//////////////////// HTML VALIDATION /////////////////////////
/*
** @desc: Asks the validator whether this is valid HTML, or not.
*/
function validateHTML($text) {
$params = array ("fragment" => $text);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1); // save form using a POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); // load the POST variables
curl_setopt($ch, CURLOPT_URL, VALIDATOR_URL); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
$result=curl_exec ($ch);
// if we encountered an error, then log it, and exit.
if (curl_error($ch)) {
trigger_error("Curl error #: " . curl_errno($ch) . " - " . curl_error ($ch) );
print "Curl error #: " . curl_errno($ch) . " - " . curl_error ($ch) . " - exiting.\n";
exit();
}
curl_close ($ch);
$valid = (strpos($result, "Failed validation") === false ? true : false);
return array($valid, $result);
}
/**
** @desc: checks the string to see if tags are balanced.
*/
function checkOpenCloseTags($string, $filename) {
$valid = true;
$lines = explode("\n", $string);
$num_lines = count($lines);
// print "Num lines: " . $num_lines . "\n";
foreach ($lines as $line_num => $line) {
// skip mediawiki's own unbalanced lines.
if ($line_num == 15) continue;
if ($line == "\t\t