Index: trunk/extensions/CongressLookup/CongressLookup.php |
— | — | @@ -41,8 +41,9 @@ |
42 | 42 | 'descriptionmsg' => 'congresslookup-desc', |
43 | 43 | ); |
44 | 44 | |
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 |
47 | 48 | |
48 | 49 | $dir = dirname( __FILE__ ) . '/'; |
49 | 50 | |
Index: trunk/extensions/CongressLookup/SpecialCongressLookup.php |
— | — | @@ -5,9 +5,7 @@ |
6 | 6 | * to the user. |
7 | 7 | */ |
8 | 8 | 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; |
12 | 10 | |
13 | 11 | public function __construct() { |
14 | 12 | // Register special page |
— | — | @@ -18,39 +16,61 @@ |
19 | 17 | * Handle different types of page requests |
20 | 18 | */ |
21 | 19 | public function execute( $sub ) { |
22 | | - global $wgRequest, $wgOut, $wgCongressLookupMaxAge; |
| 20 | + global $wgRequest, $wgOut; |
23 | 21 | |
24 | 22 | // Pull in query string parameters |
25 | | - $zip = $wgRequest->getVal( 'zip' ); |
| 23 | + $this->zip = $wgRequest->getVal( 'zip' ); |
26 | 24 | |
27 | 25 | // Setup |
28 | | - $wgOut->setSquidMaxage( $wgCongressLookupMaxAge ); |
29 | | - $this->setHeaders(); |
| 26 | + $wgOut->disable(); |
| 27 | + $this->sendHeaders(); |
30 | 28 | |
31 | | - if ( $zip ) { |
32 | | - //$zip = $this->trimZip( $zip ); |
33 | | - $this->showMatches( $zip ); |
34 | | - } |
| 29 | + $this->buildPage(); |
| 30 | + |
35 | 31 | } |
36 | 32 | |
37 | 33 | /** |
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 |
40 | 44 | * @return true |
41 | 45 | */ |
42 | | - private function showMatches( $zip ) { |
43 | | - global $wgOut; |
| 46 | + private function buildPage() { |
| 47 | + $htmlOut = ''; |
44 | 48 | |
| 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() { |
45 | 63 | $myRepresentative = array(); |
46 | 64 | $mySenators = array(); |
47 | | - $myRepresentative = CongressLookupDB::getRepresentative( $zip ); |
48 | | - $mySenators = CongressLookupDB::getSenators( $zip ); |
| 65 | + $myRepresentative = CongressLookupDB::getRepresentative( $this->zip ); |
| 66 | + $mySenators = CongressLookupDB::getSenators( $this->zip ); |
49 | 67 | |
| 68 | + $congressTable = ''; |
| 69 | + |
50 | 70 | //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>'; |
53 | 73 | |
54 | | - // TODO: stuffz. |
| 74 | + return $congressTable; |
55 | 75 | } |
56 | 76 | |
57 | 77 | } |