r109102 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109101‎ | r109102 | r109103 >
Date:03:34, 17 January 2012
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
switching to raw HTML page
Modified paths:
  • /trunk/extensions/CongressLookup/CongressLookup.php (modified) (history)
  • /trunk/extensions/CongressLookup/SpecialCongressLookup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/CongressLookup.php
@@ -41,8 +41,9 @@
4242 'descriptionmsg' => 'congresslookup-desc',
4343 );
4444
45 -// Configurrable variable for caching time
46 -$wgCongressLookupMaxAge = 900; // 15 minutes
 45+// Configurable variables for caching the special page
 46+$wgCongressLookupSharedMaxAge = 900; // 15 minutes server-side
 47+$wgCongressLookupMaxAge = 600; // 10 minutes client-side
4748
4849 $dir = dirname( __FILE__ ) . '/';
4950
Index: trunk/extensions/CongressLookup/SpecialCongressLookup.php
@@ -5,9 +5,7 @@
66 * to the user.
77 */
88 class SpecialCongressLookup extends UnlistedSpecialPage {
9 -
10 - protected $sharedMaxAge = 600; // Cache for 10 minutes on the server side
11 - protected $maxAge = 600; // Cache for 10 minutes on the client side
 9+ var $zip;
1210
1311 public function __construct() {
1412 // Register special page
@@ -18,39 +16,61 @@
1917 * Handle different types of page requests
2018 */
2119 public function execute( $sub ) {
22 - global $wgRequest, $wgOut, $wgCongressLookupMaxAge;
 20+ global $wgRequest, $wgOut;
2321
2422 // Pull in query string parameters
25 - $zip = $wgRequest->getVal( 'zip' );
 23+ $this->zip = $wgRequest->getVal( 'zip' );
2624
2725 // Setup
28 - $wgOut->setSquidMaxage( $wgCongressLookupMaxAge );
29 - $this->setHeaders();
 26+ $wgOut->disable();
 27+ $this->sendHeaders();
3028
31 - if ( $zip ) {
32 - //$zip = $this->trimZip( $zip );
33 - $this->showMatches( $zip );
34 - }
 29+ $this->buildPage();
 30+
3531 }
3632
3733 /**
38 - * Given a zip code, output HTML-formatted data for the representatives for that area
39 - * @param $zip string: A zip code
 34+ * Generate the HTTP response headers for the landing page
 35+ */
 36+ private function sendHeaders() {
 37+ global $wgCongressLookupSharedMaxAge, $wgCongressLookupMaxAge;
 38+ header( "Content-type: text/html; charset=utf-8" );
 39+ header( "Cache-Control: public, s-maxage=$wgCongressLookupSharedMaxAge, max-age=$wgCongressLookupMaxAge" );
 40+ }
 41+
 42+ /**
 43+ * Build the HTML for the page
4044 * @return true
4145 */
42 - private function showMatches( $zip ) {
43 - global $wgOut;
 46+ private function buildPage() {
 47+ $htmlOut = '';
4448
 49+ if ( $this->zip ) {
 50+ $htmlOut .= $this->getCongressTable();
 51+ }
 52+
 53+ echo $htmlOut;
 54+
 55+ return true;
 56+ }
 57+
 58+ /**
 59+ * Get an HTML table of data for the user's congressional representatives
 60+ * @return HTML for the table
 61+ */
 62+ private function getCongressTable() {
4563 $myRepresentative = array();
4664 $mySenators = array();
47 - $myRepresentative = CongressLookupDB::getRepresentative( $zip );
48 - $mySenators = CongressLookupDB::getSenators( $zip );
 65+ $myRepresentative = CongressLookupDB::getRepresentative( $this->zip );
 66+ $mySenators = CongressLookupDB::getSenators( $this->zip );
4967
 68+ $congressTable = '';
 69+
5070 //TODO: Change this so it looks like... anything.
51 - $wgOut->addHTML( '<pre>' . print_r( $myRepresentative, true ) . '</pre>' );
52 - $wgOut->addHTML( '<pre>' . print_r( $mySenators, true ) . '</pre>' );
 71+ $congressTable .= '<pre>' . print_r( $myRepresentative, true ) . '</pre>';
 72+ $congressTable .= '<pre>' . print_r( $mySenators, true ) . '</pre>';
5373
54 - // TODO: stuffz.
 74+ return $congressTable;
5575 }
5676
5777 }

Comments

#Comment by NeilK (talk | contribs)   07:21, 17 January 2012

would have been an escaping issue, but is superseded by later changes.

Status & tagging log