/** ** takes a page test, and runs it and tests it for problems in the output. ** Returns: False on finding a problem, or True on no problems being found. */ function runWikiTest(pageTest $test, &$testname, $can_overwrite = false) { // by default don't overwrite a previous test of the same name. while (!$can_overwrite && file_exists(DIRECTORY . "/" . $testname . DATA_FILE)) { $testname .= "-" . mt_rand(0, 9); } $filename = DIRECTORY . "/" . $testname . DATA_FILE; // Store the time before and after, to find slow pages. $before = microtime(true); // Get MediaWiki to give us the output of this test. $wiki_preview = wikiTestOutput($test); $after = microtime(true); // if we received no response, then that's interesting. if ($wiki_preview == "") { print "\nNo response received for: {$filename}"; return false; } // save output HTML to file. $html_file = DIRECTORY . "/" . $testname . HTML_FILE; saveFile($wiki_preview, $html_file); // if there were PHP errors in the output, then that's interesting too. if (strpos($wiki_preview, "<b>Warning</b>: ") !== false || strpos($wiki_preview, "<b>Fatal error</b>: ") !== false || strpos($wiki_preview, "<b>Notice</b>: ") !== false || strpos($wiki_preview, "<b>Error</b>: ") !== false || strpos($wiki_preview, "<b>Strict Standards:</b>") !== false) { $error = substr($wiki_preview, strpos($wiki_preview, "</b>:") + 7, 50); // Avoid probable PHP bug with bad session ids; http://bugs.php.net/bug.php?id=38224 if ($error != "Unknown: The session id contains illegal character") { print "\nPHP error/warning/notice in HTML output: {$html_file} ; {$error}"; return false; } } // if there was a MediaWiki Backtrace message in the output, then that's also interesting. if (strpos($wiki_preview, "Backtrace:") !== false) { print "\nInternal MediaWiki error in HTML output: {$html_file}"; return false; } // if there was a Parser error comment in the output, then that's potentially interesting. if (strpos($wiki_preview, "!-- ERR") !== false) { print "\nParser Error comment in HTML output: {$html_file}"; return false; } // if a database error was logged, then that's definitely interesting. if (dbErrorLogged()) { print "\nDatabase Error logged for: {$filename}"; return false; } // validate result $valid = true; if (VALIDATE_ON_WEB) { list($valid, $validator_output) = validateHTML($wiki_preview); if (!$valid) { print "\nW3C web validation failed - view details with: html2text " . DIRECTORY . "/" . $testname . ".validator_output.html"; } } // Get tidy to check the page, unless we already know it produces non-XHTML output. if ($test->tidyValidate()) { $valid = tidyCheckFile($testname . HTML_FILE) && $valid; } // if it took more than 2 seconds to render, then it may be interesting too. (Possible DoS attack?) if ($after - $before >= 2) { print "\nParticularly slow to render (" . round($after - $before, 2) . " seconds): {$filename}"; return false; } if ($valid) { // Remove temp HTML file if test was valid: unlink($html_file); } elseif (VALIDATE_ON_WEB) { saveFile($validator_output, DIRECTORY . "/" . $testname . ".validator_output.html"); } return $valid; }
/** ** @desc: takes a wiki markup string, and tests it for security or validation problems. */ function testWikiMarkup($raw_markup, $testname) { // don't overwrite a previous test of the same name. while (file_exists(DIRECTORY . "/" . $testname . ".raw_markup.txt")) { $testname .= "-" . mt_rand(0, 9); } // upload to MediaWiki install. $wiki_preview = wikiPreview($raw_markup); // save output files saveFile($raw_markup, $testname . ".raw_markup.txt"); saveFile($wiki_preview, $testname . ".wiki_preview.html"); // validate result $valid = true; if (VALIDATE_ON_WEB) { list($valid, $validator_output) = validateHTML($wiki_preview); } $valid = $valid && checkOpenCloseTags($wiki_preview, $testname . ".wiki_preview.html"); $valid = $valid && tidyCheckFile($testname . ".wiki_preview.html"); if ($valid) { // Remove valid tests: unlink(DIRECTORY . "/" . $testname . ".raw_markup.txt"); unlink(DIRECTORY . "/" . $testname . ".wiki_preview.html"); } elseif (VALIDATE_ON_WEB) { saveFile($validator_output, $testname . ".validator_output.html"); } }
function printDetailed($xmlString) { $xmlString = validateHTML($xmlString); $pos = stripos($xmlString, "</table>"); $xmlString = substr($xmlString, 0, $pos - 6) . "</table>"; $xml = new SimpleXMLElement($xmlString); $i = 0; $evaluation = array(); foreach ($xml->tr as $tr) { if ($i >= 3) { $j = 0; $stats = array(); foreach ($tr->td as $td) { if ($j == 1) { $title = $td; } // appends the statistics into an array if ($j > 1) { if ($j == 2) { $mean = $td; } else { if ($j == 3) { $dev = $td; } else { array_push($stats, $td); } } } $j++; } array_push($evaluation, array('title' => $title, 'mean' => $mean, 'dev' => $dev, 'stats' => $stats)); } $i++; } $i = 1; foreach ($evaluation as $evalu) { print "<p>"; print "<div class='evalTitle full dgold'>{$i}) {$evalu['title']}</div>"; print "<div class='left half gold'>1 - Strongly Disagree</div><div class='left half gold'>7 - Strongly Agree</div>"; print "<div class='clear'></div>"; print "<div class='left half gold'>Mean = {$evalu['mean']}</div><div class='left half gold'>Standard Deviation = {$evalu['dev']}</div>"; print "<div class='clear'></div>"; $data1 = implode(',', $evalu['stats']); foreach ($evalu['stats'] as &$val) { if ($val == 0.0) { $val = 0; } //$val = (int)$val; //if($val != 0) $val .= "%"; } $data2 = implode('|', $evalu['stats']); $img_url = "http://chart.apis.google.com/chart?cht=bvg&chd=t:{$data1}&chco=99873D&chls=2.0,0.0,0.0&chs=316x185&chg=12.5,25,3,3,0,0" . "&chxt=x,y,x&chxl=0:|1|2|3|4|5|6|7|NA|1:|0|25|50|75|100|2:|{$data2}&chf=bg,s,F1E6B8&chbh=21,15,15"; print "<img src='{$img_url}' alt=''/>"; print "</p>"; $i++; } }
$valid = false; $startTag = "<html>"; $endTag = "</html>"; if (strpos($html, $startTag) === 0) { $endPos = strlen($html) - strlen($endTag); if (strpos($html, $endTag) == $endPos) { $valid = true; } else { $valid = false; } } else { $valid = false; } return $valid; } $validatedHTML = validateHTML($htmlContent); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Oplossing Functions: Deel 2</title> <link rel="stylesheet" href="http://web-backend.local/css/global.css"> <link rel="stylesheet" href="http://web-backend.local/css/facade.css"> <link rel="stylesheet" href="http://web-backend.local/css/directory.css"> </head> <body> <?php if ($validatedHTML) { echo "<p> html string is valid </p>";