So now, with more HTML, my HTMLReporter class is 18.2 kb long... way too big. How do you suggest I break it up? Comments on how to refactor would be nice too. It looks like this:
Code: Select all
<?php
class HTMLReporter
{
var $Plugin;
function HTMLReporter(&$Plugin) {
$this->Plugin =& $Plugin;
$this->_readable = $Plugin->getHTMLReporterReadableHTML();
}
// the META FUNCTIONS
//sets newline according to tabbing conventions and readability flag
var $_readable = true;
var $_tabs = 0;
var $_tabs_per_space = 4;
function _nl($tab = 0) {
if ($this->_readable) {
if (is_int($tab)) {
$this->_tabs += $tab;
if ($this->_tabs < 0) $this->_tabs = 0;
}
$string = "\r\n" .
str_repeat(' ',$this->_tabs * $this->_tabs_per_space);
return $string;
}
}
//increases tab: good for loops
function _t() {
$this->_tabs++;
}
//paragraphs according to doublespace
function _paragraph($string) {
$string = '<p>' . $string . '</p>';
$string = str_replace("\r", '', $string);
$string = str_replace("\n\n", '</p><p>', $string);
$string = str_replace("\n", ' ', $string);
$string = str_replace("\t", ' ', $string);
$string = str_replace("<p></p>", '', $string);
return $string;
}
function setLocation($location) {
header('Location: ' . $this->Plugin->getWebPath() . '/' . $location);
}
function setCookieUsername($username) {
setcookie($this->Plugin->getCookieNameForUsername(),$username,
time()+15552000,$this->Plugin->getWebPath());
}
// the OMNIPRESENT ONES
function paintHeader($title) {
//make configurable
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' .
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo $this->_nl() . '<html>';
echo $this->_nl() . '<head>';
echo $this->_nl(1) . '<title>' . htmlentities($title) . '</title>';
echo $this->_nl() . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
echo $this->_nl() . '<link rel="stylesheet" type="text/css"' .
'href="' . $this->Plugin->getWebPath() . '/css/default.css" />';
echo $this->_nl(-1) . '</head>';
echo $this->_nl() . '<body>';
echo $this->_nl() . '<h1>' . htmlentities($title) . '</h1>';
}
function paintDivision() {
echo $this->_nl() . '<hr class="division" />';
}
function paintFooter() {
//make configurable
echo $this->_nl() . '</body>';
echo $this->_nl() . '</html>';
}
// the NOUNS
function paintImportantServices(&$services) {
if (empty($services)) return;
echo $this->_nl() . '<div id="ImportantServices">';
echo $this->_nl(1) . '<table cellspacing="0">';
echo $this->_nl(1) . '<tr>';
foreach ($services as $key => $value) {
$service =& $services[$key];
echo '<th>';
echo htmlentities($service->getName()) . ' Speed';
echo '</th>';
}
echo '</tr>';
echo $this->_nl() . '<tr>';
foreach ($services as $key => $value) {
$service =& $services[$key];
echo '<td style="color:'.$service->getSpeedColor().';">';
echo htmlentities($service->getSpeedName());
echo '</td>';
}
echo '</tr>';
echo $this->_nl(-1) . '</table>';
echo $this->_nl(-1) . '</div>';
}
function paintLesserServices(&$services) {
if (empty($services)) return;
echo $this->_nl() . '<div id="LesserServices">';
echo $this->_nl(1) . '<table cellspacing="4">';
$this->_t();
foreach ($services as $key => $value) {
$service =& $services[$key];
echo $this->_nl() . '<tr>';
echo '<th>';
echo htmlentities($service->getName()) . ' Speed';
echo '</th>';
echo '<td class="message" style="color:'.htmlentities($service->getSpeedColor()).';">';
echo $service->getSpeedName();
echo '</td>';
echo '</tr>';
}
echo $this->_nl(-1) . '</table>';
echo $this->_nl(-1) . '</div>';
}
function paintSymptoms(&$symptoms) {
echo $this->_nl() . '<div id="Symptoms">';
echo $this->_nl(1) . '<h2>Other Symptoms</h2>';
if (empty($symptoms)) {
echo $this->_nl() . '<div class="ok">None</div>';
} else {
echo $this->_nl() . '<ul>';
$this->_t();
foreach ($symptoms as $key => $symptom) {
echo $this->_nl() . '<li class="message" style="color:' . $symptom->getColor() . ';">';
echo htmlentities($symptom->getName());
echo '</li>';
}
echo $this->_nl(-1) . '</ul>';
}
echo $this->_nl(-1) . '</div>';
}
function paintInformation() {
//make configurable
echo $this->_nl() . '<div id="Information">';
echo $this->_nl(1) . '<h2>Information</h2>';
//use wordwrap here
echo $this->_nl() . "<p>When reporting Wikipedia's status, include a description of what caused you to change the status report at the bottom of the page — people are often wrong about the cause of Wikipedia's technical problems, but tend to accurately report the symptoms.</p>";
echo $this->_nl() . "<p>If no one has reported on Wikipedia for a while, perhaps it has resumed normalcy (people are more likely to check Wikipedia Status when there's a problem than when things are running smoothly).</p>";
echo $this->_nl() . "<p>There may be a difference in the read speed according to the country from where you reach the English Wikipedia. From a country with a nearby squid cache the speed of reading a cached page will be higher than from a country where the request is routed to the servers in Florida.</p>";
echo $this->_nl() . "<p>Please note that even when an edit appears to have failed, and you see a message that the Wikipedia servers are not responding, the edit probably <strong>has been saved</strong>. Checking your recent edits (or the article history) in a second browser window will take some load off the servers caused by editors repeatedly trying to save the same edits, and will also reduce the edit conflicts (with your own previous edit) you may experience.</p>";
echo $this->_nl() . "<p>Please use <a href=\"http://www.google.com/custom?sa=Google+Search&domains=wikiped". "ia.org&sitesearch=wikipedia.org\">Google</a> search and other copies of Wikipedia content if you have problems.</p>";
echo $this->_nl() . "<p>For insight into problems, try visiting the <a href=\"http://wikimedia.org/stats/live/\">Wikimedia Live Stats</a>, the <a href=\"http://zwinger.wikimedia.org/ganglia/\">Wikimedia Grid Report</a>, <a href=\"http://www.livejournal.com/community/wikitech/\">Developers' LiveJournal</a>, <a href=\"http://mail.wikipedia.org/pipermail/wikitech-l/\">Wikitech-l Mailing List</a> and <a href=\"http://wikitech.leuksman.com/view/Server_admin_log\">Server Admin Log</a>. If you're wondering how Wikimedia uses its servers, check out <a href=\"http://meta.wikimedia.org/wiki/Wikimedia_servers\">Wikimedia Servers</a>.</p>";
echo $this->_nl() . "<p>The IRC channel also offers useful information for unannounced outages. Try <a href=\"irc://irc.freenode.net/wikipedia\">#wikipedia</a> or <a href=\"irc://irc.freenode.net/wikimedia-tech\">#wikimedia-tech</a> although the channels may be flooded during large outages. Try <a href=\"http://fennec.homedns.org/stats/wikipedia.html\">Fennec's #wikipedia stats</a> in that case, which displays the most recent channel topics (which usually offer the most information about outages).</p>";
echo $this->_nl(-1) . '</div>';
}
function paintEditLink() {
echo $this->_nl() . '<div id="EditButton">';
echo $this->_nl(1) . '<a href="./?action=edit">Edit status</a>';
echo $this->_nl(-1) . '</div>';
}
function paintComments(&$threads) {
echo $this->_nl() . '<div id="Comments">';
echo $this->_nl(1) . '<h2>Changelog</h2>';
echo $this->_nl(1) . '<ul>';
foreach ($threads as $key => $value) {
$thread =& $threads[$key];
echo $this->_nl() . '<li id="Comment_' . $thread->getID() .
'" class="Thread">';
$this->paintComment($thread);
$comments =& $thread->getChildren();
echo $this->_nl() . '<ul class="container">';
$this->_t();
foreach($comments as $key => $value) {
echo $this->_nl() . '<li>';
$this->paintComment($comments[$key]);
echo $this->_nl(-1) . '</li>';
}
echo $this->_nl(-1) . '</ul>';
echo $this->_nl(-1) . '</li>';
}
echo $this->_nl(-1) . '</ul>';
echo $this->_nl(-1) . '</div>';
}
function paintCommentStart(&$comment) {
echo $this->_nl() . '<div id="Comment_' . $comment->getID() .
'" class="Thread">';
}
function paintComment(&$comment) {
$this->_t();
if (is_a($comment, 'Thread')) {
echo $this->_nl() . '<div class="comment_reply">'.
'<a href="./?action=reply&id='.$comment->getID().'">reply</a></div>';
}
if ($comment->getUsername()) {
if (!$this->Plugin->getWebUserURL()) {
echo $this->_nl() . '<div class="comment_username">' .
htmlentities($comment->getUsername()).'</div>';
} else {
$user_url = str_replace('%s',urlencode($comment->getUsername()),
$this->Plugin->getWebUserURL());
echo $this->_nl() . '<div class="comment_username">' .
'<a href="'.$user_url.'">' .
htmlentities($comment->getUsername()).'</a></div>';
}
} else {
echo $this->_nl() . '<div class="comment_username comment_ipaddress">IP ' .
htmlentities($comment->getIPAddress()).'</div>';
}
echo $this->_nl() . '<div class="comment_time">Posted '.
$comment->getTimeAgo().' on '.
date('F j, Y, g:i a', $comment->getTimestamp()).'</div>';
echo $this->_nl() . '<div class="comment_contents">' .
$this->_paragraph(htmlentities($comment->getContents())) . '</div>';
}
function paintCommentEnd() {
echo $this->_nl(-1) . '</div>';
}
// the FORM ELEMENTS
function paintImportantServicesField($services) {
echo $this->_nl() . '<fieldset id="EditImportantServices">';
$this->_t();
foreach ($services as $key => $value) {
$service =& $services[$key];
echo $this->_nl() . '<div class="label">' .
htmlentities($service->getName()) . ' Speed' . '</div>';
echo $this->_nl() . '<table cellspacing="0">';
$speeds = $service->getSpeeds();
$this->_t();
foreach ($speeds as $key => $value) {
echo $this->_nl() . '<tr';
if ($service->getSpeed() == $key) {
echo ' class="active"';
}
echo '>';
echo '<td><input type="radio" name="Service[' . $service->getID() .
']" value="' . $key . '"';
if ($service->getSpeed() == $key) {
echo ' checked="checked"';
}
echo ' /></td>';
echo '<th class="message" style="color:' . $value['color'] . ';">';
echo $value['name'];
echo '</th>';
echo '</tr>';
}
echo $this->_nl(-1) . '</table>';
}
echo $this->_nl(-1) . '</fieldset>';
}
function paintLesserServicesField($services) {
echo $this->_nl() . '<fieldset id="EditLesserServices">';
echo $this->_nl(1) . '<table>';
$this->_t();
foreach ($services as $key => $value) {
$service =& $services[$key];
echo $this->_nl() . '<tr>';
echo $this->_nl(1) . '<th class="label"><label for="Service_' . $service->getID() . '">';
echo htmlentities($service->getName()) . ' Speed';
echo '</label></th>';
echo $this->_nl() . '<td>';
$speeds = $service->getSpeeds();
echo $this->_nl(1) . '<select id="Service_' . $service->getID() .
'" name="Service[' . $service->getID() . ']">';
$this->_t();
foreach ($speeds as $key => $value) {
echo $this->_nl() . '<option value="' . $key . '"';
if ($service->getSpeed() == $key) {
echo ' selected="selected"';
}
echo '>';
echo $value['name'];
echo '</option>';
}
echo $this->_nl(-1) . '</select>';
echo $this->_nl(-1) . '</td>';
echo $this->_nl(-1) . '</tr>';
}
echo $this->_nl(-1) . '</table>';
echo $this->_nl(-1) . '</fieldset>';
}
function paintSymptomGroupsField($symptomgroups) {
echo $this->_nl() . '<fieldset id="EditSymptoms">';
echo $this->_nl(1) . '<h2>Symptoms</h2>';
echo $this->_nl() . '<ul>';
$this->_t();
foreach ($symptomgroups as $key => $symptomgroup) {
$symptomgroup =& $symptomgroups[$key];
echo $this->_nl() . '<li class="symptomgroup">' . $symptomgroup->getName() . '</li>';
echo $this->_nl() . '<li class="container"><ul>';
$symptoms = $symptomgroup->getSymptoms();
$this->_t();
foreach ($symptoms as $key => $symptom) {
$symptom =& $symptoms[$key];
echo $this->_nl() . '<li>';
echo '<input name="Symptom['.$symptom->getID().']" type="checkbox"';
if ($symptom->isActive()) {
echo ' checked="checked"';
}
echo ' />';
echo '<span class="message" style="color:' . $symptom->getColor() . ';">';
echo htmlentities($symptom->getName());
echo '</span>';
echo '</li>';
}
echo $this->_nl(-1) . '</ul></li>';
}
echo $this->_nl(-1) . '</ul>';
echo $this->_nl(-1) . '</fieldset>';
}
function paintEditFormStart() {
$this->paintFormStart('submit');
}
function paintEditFormEnd() {
$this->paintFormEnd();
}
function paintSubmitButton() {
echo $this->_nl() . '<fieldset id="SubmitButton">';
echo $this->_nl(1) . '<input type="submit" value="Submit" />';
echo $this->_nl() . '<input type="reset" value="Reset" />';
echo $this->_nl(-1) . '</fieldset>';
}
function paintReplyFormStart() {
$this->paintFormStart('submitreply');
}
function paintReplyFormEnd() {
$this->paintFormEnd();
}
function paintFormStart($action) {
echo $this->_nl() . '<form action="./?action='.urlencode($action).'" method="post" ' .
'enctype="multipart/form-data">';
}
function paintFormEnd() {
echo $this->_nl() . '</form>';
}
function paintHiddenFields($fields) {
echo $this->_nl() . '<div class="HiddenField">';
$this->_t();
foreach($fields as $key => $value) {
echo $this->_nl() . '<input type="hidden" name="'.urlencode($key).
'" value="'.urlencode($value).'" />';
}
echo $this->_nl(-1) . '</div>';
}
function paintCommentField($remembered_username = '') {
$remembered_username = htmlentities($remembered_username);
$username_remember_field_checked = $remembered_username ? ' checked="checked"' : '';
echo $this->_nl() . '<fieldset id="CommentField">';
echo $this->_nl(1) . '<h2>Comment</h2>';
echo $this->_nl() .
'<div>'.
'<div id="username_remember">'.
'<label for="username_remember_field">Remember Username?</label>'.
'<input id="username_remember_field" name="username_remember" type="checkbox"'.$username_remember_field_checked.' />'.
'</div>'.
'<input type="text" name="username" id="username" value="' . $remembered_username . '" />' .
'<div class="label">' .
'<label for="username">Wikipedia Username</label>'.
'</div>'.
'</div>';
echo $this->_nl() . '<div><textarea rows="12" cols="80" name="Comment">'
. '</textarea></div>';
echo $this->_nl(-1) . '</fieldset>';
}
// the ERRORS
function paintReplyRequiresCommentID() {
echo $this->_nl() . '<p>Reply requires a comment ID.</p>';
}
function paintBadID() {
echo $this->_nl() . '<p>Bad ID was passed. Valid IDs are numeric.</p>';
}
function paintNullComment() {
echo $this->_nl() . '<p>The comment you requested did not exist.</p>';
}
function paintReplyCannotBeToReply() {
echo $this->_nl() . '<p>Comments cannot reply to replies. Please reply
to the parent post of the thread.</p>';
}
function paintInvalidAction() {
echo $this->_nl() . '<p>This action is not recognized.</p>';
}
}
?>