r109316 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109315‎ | r109316 | r109317 >
Date:05:58, 18 January 2012
Author:awjrichards
Status:ok
Tags:
Comment:
MFT revs 109299 through 109315
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/CongressLookup (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CongressLookup/SpecialCongressLookup.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CongressLookup/data/cl_house.sql (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CongressLookup/maintenance/checkContacts.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CongressLookup/maintenance/populateCache.php (added) (history)
  • /branches/wmf/1.18wmf1/extensions/CongressLookup/scripts/zip_file_parser.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/CongressLookup/maintenance/checkContacts.php
@@ -44,13 +44,30 @@
4545 }
4646
4747 protected function checkContactLink( $name, $url, &$countOk ) {
48 - $req = MWHttpRequest::factory( $url, array(
49 - 'method' => 'GET',
50 - 'timeout' => 8,
51 - 'sslVerifyHost' => false, // just check if it can be reached
52 - 'sslVerifyCert' => false, // just check if it can be reached
53 - ) );
54 - if ( $req->execute()->isOK() ) {
 48+ global $wgVersion;
 49+
 50+ $ok = false;
 51+ if ( Sanitizer::validateEmail( $url ) ) {
 52+ $ok = true; // assume OK
 53+ } else {
 54+ $bits = wfParseUrl( $url );
 55+ if ( $bits && isset( $bits['scheme'] ) ) {
 56+ if ( $bits['scheme'] == 'mailto' ) {
 57+ $ok = true; // assume OK
 58+ } elseif ( in_array( $bits['scheme'], array( 'http', 'https' ) ) ) {
 59+ $req = MWHttpRequest::factory( $url, array(
 60+ 'method' => 'GET',
 61+ 'timeout' => 8,
 62+ 'sslVerifyHost' => false, // just check if it can be reached
 63+ 'sslVerifyCert' => false, // just check if it can be reached
 64+ ) );
 65+ $req->setUserAgent( "MediaWiki {$wgVersion}, CheckCongressLinks Checker" );
 66+ $ok = $req->execute()->isOK();
 67+ }
 68+ }
 69+ }
 70+
 71+ if ( $ok ) {
5572 ++$countOk;
5673 } else {
5774 $this->output( "Broken: [$name] [$url]\n" );
Index: branches/wmf/1.18wmf1/extensions/CongressLookup/maintenance/populateCache.php
@@ -0,0 +1,142 @@
 2+<?php
 3+/**
 4+ * @ingroup Maintenance
 5+ */
 6+if ( getenv( 'MW_INSTALL_PATH' ) ) {
 7+ $IP = getenv( 'MW_INSTALL_PATH' );
 8+} else {
 9+ $IP = dirname(__FILE__).'/../../..';
 10+}
 11+
 12+require_once( "$IP/maintenance/Maintenance.php" );
 13+
 14+class PopulateCache extends Maintenance {
 15+ public $isOK = 0;
 16+ public $isBad = 0;
 17+ protected $dbr;
 18+
 19+ public function __construct() {
 20+ parent::__construct();
 21+ $this->mDescription = "Prepopulate caches with zipcode queries";
 22+
 23+ $this->addOption( 'url', 'The base URL for zipcode lookup.', true, true );
 24+ $this->addOption( 'limit', 'The amount of values to return during a db query.', false, false );
 25+ $this->addOption( 'cache_warmup', 'If this is used, the script will attempt to hit all of the possible URLs for you to warm up the cache.', false, false );
 26+ $this->addOption( 'path', 'The file path to output all possible zip code URLs. If this option is specified, this script will NOT attempt to hit the URLs for you.', false, false );
 27+
 28+ }
 29+
 30+ public function execute() {
 31+ $this->dbr = wfGetDB( DB_SLAVE );
 32+ $path = $this->getOption( 'path', null );
 33+ if ( $path ) {
 34+ $this->writeUrlsToFile( $path );
 35+ }
 36+ if ( $this->getOption( 'cache_warmup', null )) {
 37+ $this->warmUpCache();
 38+ }
 39+ }
 40+
 41+ public function warmUpCache() {
 42+ $this->output( "Populating caches...\n" );
 43+
 44+ $limit = $this->getOption( 'limit', 1000 );
 45+ $offset = 0;
 46+ $keepGoing = true;
 47+
 48+ while( $keepGoing ) {
 49+ $result = $this->dbr->select(
 50+ 'cl_zip5',
 51+ 'clz5_zip',
 52+ array(),
 53+ __METHOD__,
 54+ array(
 55+ 'LIMIT' => $limit,
 56+ 'OFFSET' => $offset,
 57+ )
 58+ );
 59+
 60+ if ( !$result->numRows() ) {
 61+ $keepGoing = false;
 62+ }
 63+
 64+ foreach ( $result as $row ) {
 65+ $this->hitUrl( $row->clz5_zip );
 66+ }
 67+
 68+ $offset += $limit;
 69+ $this->output( "...Attempted $offset URLs so far.\n" );
 70+ $this->output( "...OK so far: " . $this->isOK . "\n" );
 71+ $this->output( "...Bad so far: " . $this->isBad . "\n" );
 72+ sleep( 1 ); // rate limit
 73+ }
 74+ $this->ouput( "Done!\n" );
 75+ }
 76+
 77+ public function writeUrlsToFile( $path ) {
 78+ $this->output( "Preparing to write URLs to file...\n" );
 79+ $limit = $this->getOption( 'limit', 1000 );
 80+ $offset = 0;
 81+ $keepGoing = true;
 82+ $fh = fopen( $path, 'w' );
 83+
 84+ while( $keepGoing ) {
 85+ $result = $this->dbr->select(
 86+ 'cl_zip5',
 87+ 'clz5_zip',
 88+ array(),
 89+ __METHOD__,
 90+ array(
 91+ 'LIMIT' => $limit,
 92+ 'OFFSET' => $offset,
 93+ )
 94+ );
 95+
 96+ if ( !$result->numRows() ) {
 97+ $keepGoing = false;
 98+ }
 99+
 100+ foreach ( $result as $row ) {
 101+ $url = $this->makeUrl( $row->clz5_zip );
 102+ fwrite( $fh, $url ."\n" );
 103+ }
 104+ $offset += $limit;
 105+ }
 106+ fclose( $fh );
 107+ $this->output( "Done!\n" );
 108+ }
 109+
 110+ public function hitUrl( $zip, $attempt=0 ) {
 111+ $url = $this->makeUrl( $zip );
 112+ //$this->output( "*Trying to hit $url\n" );
 113+ $req = MWHttpRequest::factory( $url, array(
 114+ 'method' => 'GET',
 115+ 'timeout' => 2,
 116+ 'sslVerifyHost' => false, // just check if it can be reached
 117+ 'sslVerifyCert' => false, // just check if it can be reached
 118+ ) );
 119+ if ( $req->execute()->isOK()) {
 120+ $this->isOK++;
 121+ } else {
 122+ sleep( 2 );
 123+ $attempt++;
 124+ if ( $attempt < 3 ) {
 125+ $this->hitUrl( $zip, $attempt );
 126+ } else {
 127+ $this->isBad++;
 128+ }
 129+ }
 130+ }
 131+
 132+ public function makeUrl( $zip ) {
 133+ $zip = intval( $zip );
 134+ if ( $zip < 10000 ) { // make sure there are 5 digits
 135+ $zip = sprintf( "%05d", $zip );
 136+ }
 137+ $url = $this->getOption( 'url' ) . "?zip=" . $zip . "&submit=Look+up";
 138+ return $url;
 139+ }
 140+}
 141+
 142+$maintClass = "PopulateCache";
 143+require_once( DO_MAINTENANCE );
\ No newline at end of file
Property changes on: branches/wmf/1.18wmf1/extensions/CongressLookup/maintenance/populateCache.php
___________________________________________________________________
Added: svn:eol-style
1144 + native
Index: branches/wmf/1.18wmf1/extensions/CongressLookup/SpecialCongressLookup.php
@@ -43,12 +43,11 @@
4444 * @return true
4545 */
4646 private function buildPage() {
 47+ global $wgScriptPath;
4748 $htmlOut = '';
4849
4950 // Output beginning of the page
5051 $htmlOut .= <<<HTML
51 -
52 -
5352 <!DOCTYPE html>
5453 <html lang="en" dir="ltr" class="client-nojs">
5554 <head>
@@ -56,6 +55,54 @@
5756 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5857 <meta http-equiv="Content-Style-Type" content="text/css" />
5958 <meta name="generator" content="MediaWiki 1.18wmf1" />
 59+<script src="//geoiplookup.wikimedia.org/" type="text/javascript"></script>
 60+HTML;
 61+ $htmlOut .= '<script type="text/javascript" src="' . $wgScriptPath . '/load.php?lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=20111213T185322Z"> </script>';
 62+ $htmlOut .= <<<HTML
 63+<script type="text/javascript">
 64+
 65+$(document).ready(function() {
 66+
 67+ var geoHasUsRep = [
 68+ 'US', // USA
 69+ 'PR', // Puerto Rico
 70+ 'VI', // Virgin Islands
 71+ 'MP', // Northern Mariana Islands
 72+ 'AS', // American Samoa
 73+ 'GU' // Guam
 74+ ];
 75+
 76+ // Fake country from get param
 77+ // Parse out GET params from the URL
 78+ var urlParams = {};
 79+ (function () {
 80+ var e,
 81+ a = /\+/g,
 82+ r = /([^&=]+)=?([^&]*)/g,
 83+ d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
 84+ q = window.location.search.substring(1);
 85+
 86+ while (e = r.exec(q)) {
 87+ urlParams[d(e[1])] = d(e[2]);
 88+ }
 89+ })();
 90+
 91+ // Defaults to the US, so if we can't determine location, show form
 92+ var country = 'US';
 93+ if ( urlParams.country ) {
 94+ country = urlParams.country;
 95+ } else if ( window.Geo && window.Geo.country ) {
 96+ country = window.Geo.country;
 97+ }
 98+
 99+ var hasUsRep = ( $.inArray( country, geoHasUsRep ) === 0 );
 100+ if( !hasUsRep ) {
 101+ $("#sopaShareOptions").show();
 102+ $("#sopaZipForm").hide();
 103+ }
 104+
 105+});
 106+</script>
60107 <style type="text/css">
61108 body {
62109 color: #dedede;
@@ -88,7 +135,7 @@
89136 div#instructions {
90137 position: absolute;
91138 top: 67px;
92 - left: 440px;
 139+ left: 480px;
93140 text-align: left;
94141 width: 500px;
95142 padding-bottom: 30px;
@@ -99,7 +146,7 @@
100147 div#contacts {
101148 position: absolute;
102149 top: 50px;
103 - left: 50px;
 150+ left: 80px;
104151 width: 320px;
105152 background-color: #161616;
106153 padding: 5px 20px 20px 20px;
@@ -144,6 +191,19 @@
145192 font-size: 1.2em;
146193 margin-bottom: 0.2em;
147194 }
 195+.sopaSocial {
 196+ float: left;
 197+ text-align: center;
 198+ margin-right: 12px;
 199+ margin-bttom: 3px;
 200+ font-size: small;
 201+}
 202+.sopaActionHead {
 203+ font-weight: bold
 204+}
 205+#sopaShareOptions {
 206+ display: none;
 207+}
148208 </style>
149209 </head>
150210 <body>
@@ -161,7 +221,7 @@
162222 </p>
163223
164224 <p>
165 - In a post SOPA/PIPA world, Wikipedia --and many other useful informational sites-- cannot survive in a world where politicians regulate the Internet based on the influence of big money in Washington. It represents a framework for future restrictions and suppression. Congress says it's trying to protect the rights of copyright owners, but the "cure" that SOPA and PIPA represent is much more destructive than the disease they are trying to fix.
 225+ In a post SOPA/PIPA world, Wikipedia—and many other useful informational sites—cannot survive in a world where politicians regulate the Internet based on the influence of big money in Washington. It represents a framework for future restrictions and suppression. Congress says it's trying to protect the rights of copyright owners, but the "cure" that SOPA and PIPA represent is much more destructive than the disease they are trying to fix.
166226 </p>
167227
168228 <p>
@@ -179,6 +239,7 @@
180240 $htmlOut .= $this->getCongressTables();
181241 } else {
182242 $htmlOut .= $this->getZipForm();
 243+ $htmlOut .= $this->getSocialMedia();
183244 }
184245
185246 // Output end of the page
@@ -188,8 +249,17 @@
189250
190251 return true;
191252 }
192 -
 253+
193254 /**
 255+ * Given twitter handle, return an HTML link to the account. Make sure to use rawElement to wrap this.
 256+ * @param string twitter handle, assumed to be in ascii, without leading at-sign
 257+ * @return string HTML for the link
 258+ */
 259+ private function getTwitterHtml( $handle ) {
 260+ return Html::element( 'a', array( 'target' => '_blank', 'href' => 'http://twitter.com/!#/' . $handle ), '@' . $handle );
 261+ }
 262+
 263+ /**
194264 * Get an HTML table of data for the user's congressional representatives
195265 * @return string HTML for the table
196266 */
@@ -217,13 +287,9 @@
218288 Html::element( 'td', array(), wfMsg( 'congresslookup-phone', $myRepresentative['phone'] ) )
219289 );
220290
221 - $congressTable .= "\n" . Html::rawElement( 'tr', array(),
222 - Html::element( 'td', array(), wfMsg( 'congresslookup-fax', $myRepresentative['fax'] ) )
223 - );
224 -
225291 if ( $myRepresentative['twitter'] ) {
226292 $congressTable .= "\n" . Html::rawElement( 'tr', array(),
227 - Html::element( 'td', array(), wfMsg( 'congresslookup-twitter', $myRepresentative['twitter'] ) )
 293+ Html::rawElement( 'td', array(), wfMsg( 'congresslookup-twitter', self::getTwitterHtml( $myRepresentative['twitter'] ) ) )
228294 );
229295 }
230296
@@ -259,13 +325,15 @@
260326 Html::element( 'td', array(), wfMsg( 'congresslookup-phone', $senator['phone'] ) )
261327 );
262328
 329+ /*
263330 $congressTable .= "\n" . Html::rawElement( 'tr', array(),
264331 Html::element( 'td', array(), wfMsg( 'congresslookup-fax', $senator['fax'] ) )
265332 );
 333+ */
266334
267335 if ( $senator['twitter'] ) {
268336 $congressTable .= "\n" . Html::rawElement( 'tr', array(),
269 - Html::element( 'td', array(), wfMsg( 'congresslookup-twitter', $senator['twitter'] ) )
 337+ Html::rawElement( 'td', array(), wfMsg( 'congresslookup-twitter', self::getTwitterHtml( $senator['twitter'] ) ) )
270338 );
271339 }
272340
@@ -300,8 +368,8 @@
301369 */
302370 private function getZipForm( $isError=false ) {
303371 $htmlOut = <<<HTML
 372+<div id="sopaZipForm" class="sopaActionDiv">
304373 <h4>Contact your representatives</h4>
305 -<div class="sopaActionDiv">
306374 HTML;
307375 if ( $isError ) {
308376 $htmlOut .= Html::element( 'p', array( 'class' => 'error' ), wfMsg( 'congresslookup-zipcode-error' ));
@@ -322,32 +390,56 @@
323391 * @return string HTML for social media links
324392 */
325393 private function getSocialMedia() {
 394+ // Update links here. Currently pointing to example.com
326395 $htmlOut = <<<HTML
327 -<div class="sopaActionDiv">
328 - <div>
329 - <div class="sopaSocial">
330 - <a style="text-decoration: none;" href="https://www.facebook.com/sharer.php?u=http%3A%2F%2Fexample.com%2F">
331 - <img width="33" height="33" src="//upload.wikimedia.org/wikipedia/commons/2/2a/WP_SOPA_sm_icon_facebook_dedede.png">
332 - </a>
333 - <br/>
334 - <a style="text-decoration: none;" href="https://www.facebook.com/sharer.php?u=http%3A%2F%2Fexample.com%2F">Facebook</a>
335 - </div>
336 - <div class="sopaSocial">
337 - <a style="text-decoration: none;" href="https://m.google.com/app/plus/x/?v=compose&content=Google%20Plus%20Post%20Here%20http%3A%2F%2Fexample.com%2F">
338 - <img width="33" height="33" src="//upload.wikimedia.org/wikipedia/commons/0/08/WP_SOPA_sm_icon_gplus_dedede.png">
339 - </a>
340 - <br/>
341 - <a style="text-decoration: none; color:" href="https://m.google.com/app/plus/x/?v=compose&content=Google%20Plus%20Post%20Here%20http%3A%2F%2Fexample.com%2F">Google+</a>
342 - </div>
343 - <div class="sopaSocial">
344 - <a style="text-decoration: none;" href="https://twitter.com/intent/tweet?original_referer=http%3A%2F%2Ftest.wikipedia.org%2Fwiki%2FMain_Page%3Fbanner%3Dblackout&text=Tweet%20here%20%23WikipediaBlackout%20http%3A%2F%2Fexample.com%2F">
345 - <img width="33" height="33" src="//upload.wikimedia.org/wikipedia/commons/4/45/WP_SOPA_sm_icon_twitter_dedede.png">
346 - </a>
347 - <br/>
348 - <a style="text-decoration: none;" href="https://twitter.com/intent/tweet?original_referer=http%3A%2F%2Ftest.wikipedia.org%2Fwiki%2FMain_Page%3Fbanner%3Dblackout&text=Tweet%20here%20%23WikipediaBlackout%20http%3A%2F%2Fexample.com%2F">Twitter</a>
349 - </div>
350 - </div>
351 - <div style="clear: both;"></div>
 396+<div id="sopaShareOptions" class="sopaActionDiv">
 397+<p class="sopaActionHead">Make your voice heard</p>
 398+ <div>
 399+ <div class="sopaSocial">
 400+ <a style="text-decoration: none;"
 401+ href="https://www.facebook.com/sharer.php?u=http://tinyurl.com/7vq4o8g"
 402+ target="wpblackout_Facebook_share"><img width="33"
 403+ height="33"
 404+ src=
 405+ "//upload.wikimedia.org/wikipedia/commons/2/2a/WP_SOPA_sm_icon_facebook_dedede.png"></a><br>
 406+
 407+ <a style="text-decoration: none; color: rgb(222, 222, 222);"
 408+ href="https://www.facebook.com/sharer.php?u=http://tinyurl.com/7vq4o8g"
 409+ target="wpblackout_Facebook_share">Facebook</a>
 410+ </div>
 411+
 412+ <div class="sopaSocial">
 413+ <a style="text-decoration: none;"
 414+ href=
 415+ "https://m.google.com/app/plus/x/?v=compose&amp;content=I%20support%20the%20January%2018th%20Wikipedia%20blackout%20to%20protest%20SOPA%20and%20PIPA.%20Show%20your%20support%20here%20%20http%3A%2F%2Ftinyurl.com%2F7vq4o8g">
 416+ <img width="33"
 417+ height="33"
 418+ src=
 419+ "//upload.wikimedia.org/wikipedia/commons/0/08/WP_SOPA_sm_icon_gplus_dedede.png"></a><br>
 420+
 421+ <a style="text-decoration: none;"
 422+ href=
 423+ "https://m.google.com/app/plus/x/?v=compose&amp;content=I%20support%20the%20January%2018th%20Wikipedia%20blackout%20to%20protest%20SOPA%20and%20PIPA.%20Show%20your%20support%20here%20%20http%3A%2F%2Ftinyurl.com%2F7vq4o8g">
 424+ Google+</a>
 425+ </div>
 426+
 427+ <div class="sopaSocial">
 428+ <a style="text-decoration: none;"
 429+ href=
 430+ "https://twitter.com/intent/tweet?text=I%20support%20%23wikipediablackout!%20Show%20your%20support%20here%20http%3A%2F%2Ftinyurl.com%2F7vq4o8g"
 431+ target="wpblackout_Twitter_share"><img width="33"
 432+ height="33"
 433+ src=
 434+ "//upload.wikimedia.org/wikipedia/commons/4/45/WP_SOPA_sm_icon_twitter_dedede.png"></a><br>
 435+
 436+ <a style="text-decoration: none; color: rgb(222, 222, 222);"
 437+ href=
 438+ "https://twitter.com/intent/tweet?text=I%20support%20%23wikipediablackout!%20Show%20your%20support%20here%20http%3A%2F%2Ftinyurl.com%2F7vq4o8g"
 439+ target="wpblackout_Twitter_share">Twitter</a>
 440+ </div>
 441+ </div>
 442+
 443+ <div style="clear: both;"></div>
352444 </div>
353445 HTML;
354446 return $htmlOut;
Index: branches/wmf/1.18wmf1/extensions/CongressLookup/scripts/zip_file_parser.php
@@ -20,15 +20,60 @@
2121 $skip_up_to = $_SERVER['argv'][1];
2222 }
2323 $function = 'fillOutNulls';
24 - if ( !empty( $_SERVER['argv'][1] ) && $_SERVER['argv'][1] === 'findSplits' ){
25 - $function = 'findSplits';
 24+ if ( !empty( $_SERVER['argv'][1] ) && !is_numeric( $_SERVER['argv'][1] ) ){
 25+ $function = $_SERVER['argv'][1];
2626 }
2727
2828 switch ( $function ){
 29+ case 'associate':
 30+ //it should go zip, state, district for the next three params.
 31+
 32+ if ( !empty( $_SERVER['argv'][2] ) ){
 33+ $zip = $_SERVER['argv'][2];
 34+ } else {
 35+ die( "Missing parameter 2: 5-digit zip code." );
 36+ }
 37+ if ( !empty( $_SERVER['argv'][3] ) ){
 38+ $state = $_SERVER['argv'][3];
 39+ } else {
 40+ die( "Missing parameter 3: state code." );
 41+ }
 42+ if ( !empty( $_SERVER['argv'][4] ) ){
 43+ $district = $_SERVER['argv'][4];
 44+ } else {
 45+ die( "Missing parameter 4: district code." );
 46+ }
 47+
 48+ $this->associate_zip5_reps( $zip, $state, $district );
 49+
 50+ break;
 51+ case 'disassociate':
 52+ //it should go zip, state, district for the next three params.
 53+
 54+ if ( !empty( $_SERVER['argv'][2] ) ){
 55+ $zip = $_SERVER['argv'][2];
 56+ } else {
 57+ die( "Missing parameter 2: 5-digit zip code." );
 58+ }
 59+ if ( !empty( $_SERVER['argv'][3] ) ){
 60+ $state = $_SERVER['argv'][3];
 61+ } else {
 62+ die( "Missing parameter 3: state code." );
 63+ }
 64+ if ( !empty( $_SERVER['argv'][4] ) ){
 65+ $district = $_SERVER['argv'][4];
 66+ } else {
 67+ die( "Missing parameter 4: district code." );
 68+ }
 69+
 70+ $this->disassociate_zip5_reps( $zip, $state, $district );
 71+
 72+ break;
2973 case 'fillOutNulls':
3074 $this->fill_out_nulls( $skip_up_to );
3175 break;
3276 case 'findSplits':
 77+ default:
3378 $this->find_split_zipcodes( $skip_up_to );
3479 break;
3580 }
@@ -121,7 +166,7 @@
122167 if ( is_array($reps) && count( $reps ) > 0 ){
123168 foreach ( $reps as $rep_id ){
124169 echo "$zip Rep ID: $rep_id\n";
125 - $this->insert_rep( $zip, $rep_id );
 170+ $this->update_rep( $zip, $rep_id );
126171 }
127172 } else {
128173 echo "We got no reps in a really odd way.\n";
@@ -188,7 +233,44 @@
189234
190235 }
191236
192 - function insert_rep( $zip, $rep_id ){
 237+ function associate_zip5_reps( $zip, $state, $district ){
 238+ //first, retrieve the state and district rep.
 239+ $reps = $this->get_rep_ids( $state, $district );
 240+ if ( count( $reps ) !== 1 ){
 241+ if ( empty($reps) ){
 242+ die("No rep found in $state $district");
 243+ } else {
 244+ die("Something very funky happened just then...");
 245+ }
 246+ }
 247+
 248+ $rep = $reps[0];
 249+ $this->insert_rep( $zip, $reps[0] );
 250+
 251+ //if it's not already in there, it should put it in there.
 252+ //if it is already in there, do nothing.
 253+ }
 254+
 255+ function disassociate_zip5_reps( $zip, $state, $district ){
 256+ //first, retrieve the state and district rep.
 257+ $reps = $this->get_rep_ids( $state, $district );
 258+ if ( count( $reps ) !== 1 ){
 259+ if ( empty($reps) ){
 260+ die("No rep found in $state $district");
 261+ } else {
 262+ die("Something very funky happened just then...");
 263+ }
 264+ }
 265+
 266+ $rep = $reps[0];
 267+ $this->remove_rep( $zip, $reps[0] );
 268+
 269+ //if it's not already in there, it should put it in there.
 270+ //if it is already in there, do nothing.
 271+ }
 272+
 273+
 274+ function update_rep( $zip, $rep_id ){
193275 $dbr = wfGetDB( DB_SLAVE );
194276 $dbr->update( 'cl_zip5',
195277 array(
@@ -201,6 +283,46 @@
202284 echo "Updated $zip to include rep id $rep_id\n";
203285 }
204286
 287+
 288+ function remove_rep( $zip, $rep_id ){
 289+ $dbr = wfGetDB( DB_SLAVE );
 290+
 291+ $dbr->delete( 'cl_zip5',
 292+ array(
 293+ 'clz5_rep_id' => $rep_id,
 294+ 'clz5_zip' => $zip,
 295+ )
 296+ );
 297+ echo "Removed $rep_id from $zip\n";
 298+ }
 299+
 300+ function insert_rep( $zip, $rep_id ){
 301+ $dbr = wfGetDB( DB_SLAVE );
 302+
 303+ $rowCheck = $dbr->selectRow( 'cl_zip5',
 304+ array(
 305+ 'clz5_rep_id',
 306+ 'clz5_zip',
 307+ ),
 308+ array(
 309+ 'clz5_rep_id' => $rep_id,
 310+ 'clz5_zip' => $zip,
 311+ )
 312+ );
 313+
 314+ if ( $rowCheck ){
 315+ echo "Rep id $rep_id already found in $zip.";
 316+ } else {
 317+ $dbr->insert( 'cl_zip5',
 318+ array(
 319+ 'clz5_rep_id' => $rep_id,
 320+ 'clz5_zip' => $zip,
 321+ )
 322+ );
 323+ echo "Updated $zip to include rep id $rep_id\n";
 324+ }
 325+ }
 326+
205327 function insert_reps_by_district( $zip, $districts ){
206328 $dbr = wfGetDB( DB_SLAVE );
207329 echo "Zip: $zip\n";
Index: branches/wmf/1.18wmf1/extensions/CongressLookup/data/cl_house.sql
@@ -1,10 +1,10 @@
22 REPLACE INTO /*$wgDBprefix*/cl_house (`clh_id`, `clh_bioguideid`, `clh_gender`, `clh_name`, `clh_title`, `clh_state`, `clh_district`, `clh_phone`, `clh_fax`, `clh_contactform`, `clh_twitter`) VALUES
33 (400003, 'A000022', 'M', 'Rep. Gary Ackerman [D, NY-5]', 'Rep.', 'NY', '5', '202-225-2601', '202-225-1589', 'https://ackerman-forms.house.gov/index.cfm?sectionid=128', NULL),
44 (400004, 'A000055', 'M', 'Rep. Robert Aderholt [R, AL-4]', 'Rep.', 'AL', '4', '202-225-4876', '202-225-5587', 'http://aderholt.house.gov/index.cfm?sectionid=195&sectiontree=195', 'Robert_Aderholt'),
5 -(400005, 'A000358', 'M', 'Rep. Todd Akin [R, MO-2]', 'Rep.', 'MO', '2', '202-225-2561', '202-225-2563', 'https://forms.house.gov/akin/webforms/issue_subscribe.htm', 'ToddAkin'),
 5+(400005, 'A000358', 'M', 'Rep. Todd Akin [R, MO-2]', 'Rep.', 'MO', '2', '202-225-2561', '202-225-2563', 'https://forms.house.gov/akin/webforms/issue_subscribe.htm', 'RepToddAkin'),
66 (400006, 'A000361', 'M', 'Rep. Rodney Alexander [R, LA-5]', 'Rep.', 'LA', '5', '202-225-8490', '202-225-5639', 'https://alexanderforms.house.gov/contact-form-cc8', 'USRepAlexander'),
77 (400008, 'A000210', 'M', 'Rep. Robert Andrews [D, NJ-1]', 'Rep.', 'NJ', '1', '202-225-6501', '', 'http://www.house.gov/andrews/contact_form_za.shtml', NULL),
8 -(400009, 'B001234', 'M', 'Rep. Joe Baca [D, CA-43]', 'Rep.', 'CA', '43', '202-225-6161', '202-225-8671', 'https://bacaforms.house.gov/contact-form', 'BacaCA43'),
 8+(400009, 'B001234', 'M', 'Rep. Joe Baca [D, CA-43]', 'Rep.', 'CA', '43', '202-225-6161', '202-225-8671', 'https://bacaforms.house.gov/contact-form', 'RepJoeBaca'),
99 (400010, 'B000013', 'M', 'Rep. Spencer Bachus [R, AL-6]', 'Rep.', 'AL', '6', '202-225-4921', '202-225-2082', 'https://writerep.house.gov/writerep/welcome.shtml', 'BachusAL06'),
1010 (400013, 'B001230', 'F', 'Rep. Tammy Baldwin [D, WI-2]', 'Rep.', 'WI', '2', '202-225-2906', '202-225-6942', 'https://tammybaldwin.house.gov/contact/email-me.shtml', 'RepTammyBaldwin'),
1111 (400017, 'B000208', 'M', 'Rep. Roscoe Bartlett [R, MD-6]', 'Rep.', 'MD', '6', '202-225-2721', '202-225-2193', 'https://bartlettforms.house.gov/Email_Roscoe/default.aspx', NULL),
@@ -18,10 +18,10 @@
1919 (400030, 'B000490', 'M', 'Rep. Sanford Bishop [D, GA-2]', 'Rep.', 'GA', '2', '202-225-3631', '202-225-2203', 'https://forms.house.gov/bishop/webforms/issue_subscribe.html', 'SanfordBishop'),
2020 (400031, 'B001242', 'M', 'Rep. Timothy Bishop [D, NY-1]', 'Rep.', 'NY', '1', '202-225-3826', '202-225-3143', 'http://timbishop.house.gov/index.cfm?sectionid=96&sectiontree=796', NULL),
2121 (400032, 'B001243', 'F', 'Rep. Marsha Blackburn [R, TN-7]', 'Rep.', 'TN', '7', '202-225-2811', '202-225-3004', 'https://blackburnforms.house.gov/contactform/default.aspx', NULL),
22 -(400033, 'B000574', 'M', 'Rep. Earl Blumenauer [D, OR-3]', 'Rep.', 'OR', '3', '202-225-4811', '202-225-8941', 'https://forms.house.gov/blumenauer/webforms/issue_subscribe.html', 'repblumenauer'),
23 -(400036, 'B000589', 'M', 'Rep. John Boehner [R, OH-8]', 'Rep.', 'OH', '8', '202-225-6205', '202-225-0704', 'http://johnboehner.house.gov/Contact/', 'johnboehner'),
 22+(400033, 'B000574', 'M', 'Rep. Earl Blumenauer [D, OR-3]', 'Rep.', 'OR', '3', '202-225-4811', '202-225-8941', 'https://forms.house.gov/blumenauer/webforms/issue_subscribe.html', 'blumenauermedia'),
 23+(400036, 'B000589', 'M', 'Rep. John Boehner [R, OH-8]', 'Rep.', 'OH', '8', '202-225-6205', '202-225-0704', 'http://johnboehner.house.gov/Contact/', 'SpeakerBoehner'),
2424 (400038, 'B001244', 'M', 'Rep. Jo Bonner [R, AL-1]', 'Rep.', 'AL', '1', '202-225-4931', '202-225-0562', 'https://forms.house.gov/bonner/webforms/issue_subscribe.html', 'RepJoBonner'),
25 -(400039, 'B001228', 'F', 'Rep. Mary Bono Mack [R, CA-45]', 'Rep.', 'CA', '45', '202-225-5330', '202-225-2961', 'https://bonoforms.house.gov/Contact_Mary/ContactForm.htm', 'MaryBonoMack'),
 25+(400039, 'B001228', 'F', 'Rep. Mary Bono Mack [R, CA-45]', 'Rep.', 'CA', '45', '202-225-5330', '202-225-2961', 'https://bonoforms.house.gov/Contact_Mary/ContactForm.htm', 'Rep_BonoMack'),
2626 (400041, 'B001245', 'F', 'Del. Madeleine Bordallo [D, GU-0]', 'Del.', 'GU', '0', '202-225-1188', '', 'http://www.house.gov/bordallo/contact.shtml', NULL),
2727 (400042, 'B000652', 'M', 'Rep. Leonard Boswell [D, IA-3]', 'Rep.', 'IA', '3', '202-225-3806', '202-225-5608', 'http://boswell.house.gov/index.cfm?sectionid=81&sectiontree=481', 'LeonardBoswell'),
2828 (400046, 'B000755', 'M', 'Rep. Kevin Brady [R, TX-8]', 'Rep.', 'TX', '8', '202-225-4901', '202-225-5524', 'http://www.house.gov/brady/contact_page.html', 'RepKevinBrady'),
@@ -31,28 +31,28 @@
3232 (400055, 'B001149', 'M', 'Rep. Dan Burton [R, IN-5]', 'Rep.', 'IN', '5', '202-225-2276', '202-225-0016', 'http://burton.house.gov/contacts/new', 'RepDanBurton'),
3333 (400057, 'C000059', 'M', 'Rep. Ken Calvert [R, CA-44]', 'Rep.', 'CA', '44', '202-225-1986', '202-225-2004', 'http://calvert.house.gov/Contact/', 'KenCalvert'),
3434 (400058, 'C000071', 'M', 'Rep. David Camp [R, MI-4]', 'Rep.', 'MI', '4', '202-225-3561', '202-225-9679', 'http://camp.house.gov/Contact/', 'RepDaveCamp'),
35 -(400060, 'C001046', 'M', 'Rep. Eric Cantor [R, VA-7]', 'Rep.', 'VA', '7', '202-225-2815', '202-225-0011', 'http://cantor.house.gov/contact/', 'EricCantor'),
 35+(400060, 'C001046', 'M', 'Rep. Eric Cantor [R, VA-7]', 'Rep.', 'VA', '7', '202-225-2815', '202-225-0011', 'http://cantor.house.gov/contact/', 'GOPLeader'),
3636 (400061, 'C001047', 'F', 'Rep. Shelley Capito [R, WV-2]', 'Rep.', 'WV', '2', '202-225-2711', '202-225-7856', 'https://capitoforms.house.gov/index.cfm?sectionid=58&sectiontree=358', 'RepShelley'),
37 -(400062, 'C001036', 'F', 'Rep. Lois Capps [D, CA-23]', 'Rep.', 'CA', '23', '202-225-3601', '202-225-5632', 'https://capps.house.gov/contact-me/email-me', NULL),
 37+(400062, 'C001036', 'F', 'Rep. Lois Capps [D, CA-23]', 'Rep.', 'CA', '23', '202-225-3601', '202-225-5632', 'https://capps.house.gov/contact-me/email-me', 'RepLoisCapps'),
3838 (400063, 'C001037', 'M', 'Rep. Michael Capuano [D, MA-8]', 'Rep.', 'MA', '8', '202-225-5111', '202-225-9322', 'http://www.house.gov/capuano/contact/email.shtml', NULL),
3939 (400065, 'C001050', 'M', 'Rep. Dennis Cardoza [D, CA-18]', 'Rep.', 'CA', '18', '202-225-6131', '202-225-0819', 'https://writerep.house.gov/writerep/welcome.shtml', 'RepCardoza'),
4040 (400068, 'C001051', 'M', 'Rep. John Carter [R, TX-31]', 'Rep.', 'TX', '31', '202-225-3864', '202-225-5886', 'https://carterforms.house.gov/index.cfm?sectionid=139&sectiontree=139', 'judgecarter'),
4141 (400071, 'C000266', 'M', 'Rep. Steven Chabot [R, OH-1]', 'Rep.', 'OH', '1', '202-225-2216', '202-225-3012', 'https://chabotforms.house.gov/index.cfm?sectionid=58&sectiontree=358', 'RepSteveChabot'),
42 -(400073, 'C000380', 'F', 'Del. Donna Christensen [D, VI-0]', 'Del.', 'VI', '0', '202-225-1790', '', 'https://donnachristensen.house.gov/contact-me/email-me', NULL),
 42+(400073, 'C000380', 'F', 'Del. Donna Christensen [D, VI-0]', 'Del.', 'VI', '0', '202-225-1790', '', 'https://donnachristensen.house.gov/contact-me/email-me', 'DelegateDonna'),
4343 (400074, 'C001049', 'M', 'Rep. William Clay [D, MO-1]', 'Rep.', 'MO', '1', '202-225-2406', '202-226-3717', 'http://lacyclay.house.gov/index.cfm?sectionid=90&sectiontree=390', NULL),
44 -(400075, 'C000537', 'M', 'Rep. James Clyburn [D, SC-6]', 'Rep.', 'SC', '6', '202-225-3315', '202-225-2313', 'https://forms.house.gov/clyburn/zipauth.shtml', NULL),
 44+(400075, 'C000537', 'M', 'Rep. James Clyburn [D, SC-6]', 'Rep.', 'SC', '6', '202-225-3315', '202-225-2313', 'https://clyburn.house.gov/contact-me/email-me', 'clyburn'),
4545 (400076, 'C000556', 'M', 'Rep. Howard Coble [R, NC-6]', 'Rep.', 'NC', '6', '202-225-3065', '202-225-8611', 'http://coble.house.gov/Contact/ZipCheck.htm', NULL),
4646 (400077, 'C001053', 'M', 'Rep. Tom Cole [R, OK-4]', 'Rep.', 'OK', '4', '202-225-6165', '202-225-3512', 'https://coleforms.house.gov/Contact/', NULL),
4747 (400080, 'C000714', 'M', 'Rep. John Conyers [D, MI-14]', 'Rep.', 'MI', '14', '202-225-5126', '202-225-0072', 'http://conyers.house.gov/index.cfm?FuseAction=Contact.OnlineContactForm', 'repjohnconyers'),
4848 (400081, 'C000754', 'M', 'Rep. Jim Cooper [D, TN-5]', 'Rep.', 'TN', '5', '202-225-4311', '202-226-1035', 'https://forms.house.gov/cooper/webforms/issue_subscribe.html', 'repjimcooper'),
4949 (400082, 'C000794', 'M', 'Rep. Jerry Costello [D, IL-12]', 'Rep.', 'IL', '12', '202-225-5661', '202-225-0285', 'http://costello.house.gov/IMA/issue_subscribe.shtml', 'JerryCostello'),
5050 (400086, 'C001045', 'M', 'Rep. Ander Crenshaw [R, FL-4]', 'Rep.', 'FL', '4', '202-225-2501', '202-225-2504', 'https://writerep.house.gov/writerep/welcome.shtml', 'AnderCrenshaw'),
51 -(400087, 'C001038', 'M', 'Rep. Joseph Crowley [D, NY-7]', 'Rep.', 'NY', '7', '202-225-3965', '202-225-1909', 'https://crowley.house.gov/contact-me/email-me', NULL),
 51+(400087, 'C001038', 'M', 'Rep. Joseph Crowley [D, NY-7]', 'Rep.', 'NY', '7', '202-225-3965', '202-225-1909', 'https://crowley.house.gov/contact-me/email-me', 'repjoecrowley'),
5252 (400089, 'C001048', 'M', 'Rep. John Culberson [R, TX-7]', 'Rep.', 'TX', '7', '202-225-2571', '202-225-4381', 'http://culbersonforms.house.gov/Contact/ZipAuth.htm', 'johnculberson'),
53 -(400090, 'C000984', 'M', 'Rep. Elijah Cummings [D, MD-7]', 'Rep.', 'MD', '7', '202-225-4741', '202-225-3178', 'https://cummingsforms.house.gov/contact/message-form.shtml', NULL),
 53+(400090, 'C000984', 'M', 'Rep. Elijah Cummings [D, MD-7]', 'Rep.', 'MD', '7', '202-225-4741', '202-225-3178', 'http://cummings.house.gov/contact/', NULL),
5454 (400093, 'D000096', 'M', 'Rep. Danny Davis [D, IL-7]', 'Rep.', 'IL', '7', '202-225-5006', '202-225-5641', 'https://forms.house.gov/davis/webforms/issue_subscribe.htm', NULL),
5555 (400097, 'D000598', 'F', 'Rep. Susan Davis [D, CA-53]', 'Rep.', 'CA', '53', '202-225-2040', '202-225-2948', 'https://susandavisforms.house.gov/forms/writeyourrep/', NULL),
56 -(400100, 'D000191', 'M', 'Rep. Peter DeFazio [D, OR-4]', 'Rep.', 'OR', '4', '202-225-6416', '202-225-0032', 'https://forms.house.gov/defazio/IMA/contact.html', NULL),
 56+(400100, 'D000191', 'M', 'Rep. Peter DeFazio [D, OR-4]', 'Rep.', 'OR', '4', '202-225-6416', '202-225-0032', 'https://forms.house.gov/defazio/IMA/contact.html', 'RepPeterDeFazio'),
5757 (400101, 'D000197', 'F', 'Rep. Diana DeGette [D, CO-1]', 'Rep.', 'CO', '1', '202-225-4431', '202-225-5657', 'http://degette.house.gov/index.php?option=com_content&view=article&id=1045&Itemid=202', 'RepDianaDeGette'),
5858 (400103, 'D000216', 'F', 'Rep. Rosa DeLauro [D, CT-3]', 'Rep.', 'CT', '3', '202-225-3661', '202-225-4890', 'http://delauro.house.gov/contact_form_email.cfm', 'rosadelauro'),
5959 (400108, 'D000600', 'M', 'Rep. Mario Diaz-Balart [R, FL-21]', 'Rep.', 'FL', '21', '202-225-4211', '202-225-8576', 'https://writerep.house.gov/writerep/welcome.shtml', 'MarioDB'),
@@ -65,7 +65,7 @@
6666 (400121, 'E000172', 'F', 'Rep. Jo Ann Emerson [R, MO-8]', 'Rep.', 'MO', '8', '202-225-4404', '202-226-0326', 'https://forms.house.gov/emerson/webforms/contact.html', 'joannemerson'),
6767 (400122, 'E000179', 'M', 'Rep. Eliot Engel [D, NY-17]', 'Rep.', 'NY', '17', '202-225-2464', '202-225-5513', 'http://engel.house.gov/index.cfm?sectionid=169&sectiontree=3169', NULL),
6868 (400124, 'E000215', 'F', 'Rep. Anna Eshoo [D, CA-14]', 'Rep.', 'CA', '14', '202-225-8104', '202-225-8890', 'https://forms.house.gov/eshoo/webforms/issue_subscribe.htm', 'RepAnnaEshoo'),
69 -(400128, 'F000010', 'M', 'Del. Eni Faleomavaega [D, AS-0]', 'Del.', 'AS', '0', '202-225-8577', '', 'faleomavaega@mail.house.gov', NULL),
 69+(400128, 'F000010', 'M', 'Del. Eni Faleomavaega [D, AS-0]', 'Del.', 'AS', '0', '202-225-8577', '', 'mailto:faleomavaega@mail.house.gov', NULL),
7070 (400129, 'F000030', 'M', 'Rep. Sam Farr [D, CA-17]', 'Rep.', 'CA', '17', '202-225-2861', '202-225-6791', 'https://forms.house.gov/farr/webforms/issue_subscribe.html', NULL),
7171 (400130, 'F000043', 'M', 'Rep. Chaka Fattah [D, PA-2]', 'Rep.', 'PA', '2', '202-225-4001', '202-225-5392', 'https://fattahforms.house.gov/index.cfm?sectionid=244&sectiontree=244', 'chakafattah'),
7272 (400133, 'F000116', 'M', 'Rep. Bob Filner [D, CA-51]', 'Rep.', 'CA', '51', '202-225-8045', '202-225-9073', 'https://filner.house.gov/contact-me/email-me', 'CongBobFilner'),
@@ -108,7 +108,7 @@
109109 (400211, 'K000009', 'F', 'Rep. Marcy Kaptur [D, OH-9]', 'Rep.', 'OH', '9', '202-225-4146', '202-225-7711', 'https://forms.house.gov/kaptur/webforms/issue_subscribe.htm', NULL),
110110 (400216, 'K000172', 'M', 'Rep. Dale Kildee [D, MI-5]', 'Rep.', 'MI', '5', '202-225-3611', '202-225-6393', 'https://kildeeforms.house.gov/contact/contact-form.shtml', NULL),
111111 (400218, 'K000188', 'M', 'Rep. Ronald Kind [D, WI-3]', 'Rep.', 'WI', '3', '202-225-5506', '202-225-5739', 'https://kindforms.house.gov/index.cfm?sectionid=146&sectiontree=18146', NULL),
112 -(400219, 'K000210', 'M', 'Rep. Peter King [R, NY-3]', 'Rep.', 'NY', '3', '202-225-7896', '202-226-2279', 'Pete.King@mail.house.gov', 'RepPeteKing'),
 112+(400219, 'K000210', 'M', 'Rep. Peter King [R, NY-3]', 'Rep.', 'NY', '3', '202-225-7896', '202-226-2279', 'mailto:Pete.King@mail.house.gov', 'RepPeteKing'),
113113 (400220, 'K000362', 'M', 'Rep. Steve King [R, IA-5]', 'Rep.', 'IA', '5', '202-225-4426', '202-225-3193', 'https://forms.house.gov/king/webforms/issue_subscribe.html', 'SteveKingPress'),
114114 (400221, 'K000220', 'M', 'Rep. Jack Kingston [R, GA-1]', 'Rep.', 'GA', '1', '202-225-5831', '202-226-2269', 'https://kingstonforms.house.gov/ContactForm/default.aspx', 'JackKingston'),
115115 (400224, 'K000363', 'M', 'Rep. John Kline [R, MN-2]', 'Rep.', 'MN', '2', '202-225-2271', '202-225-2595', 'http://kline.house.gov/index.cfm?sectionid=7&sectiontree=47', NULL),
Property changes on: branches/wmf/1.18wmf1/extensions/CongressLookup
___________________________________________________________________
Added: svn:mergeinfo
116116 Merged /branches/sqlite/extensions/CongressLookup:r58211-58321
117117 Merged /trunk/phase3/extensions/CongressLookup:r92580,92634,92713,92762,92765,92791,92854,92884,92886-92887,92894,92898,92907,92932,92958,93141,93149,93151,93233-93234,93258,93266,93303,93516-93518,93520,93818-93822,93847,93858,93891,93935-93936,94058,94062,94068,94107,94155,94235,94277,94346,94372,94422,94425,94444,94448,94456,94498,94517,94601,94630,94728,94738,94825,94862,94995-94997,95023,95042,95072-95073,95155,95327,95332,95410,95422,95426,95442,95468,95601,95812,98578,98598,98656
118118 Merged /branches/new-installer/phase3/extensions/CongressLookup:r43664-66004
119119 Merged /branches/REL1_15/phase3/extensions/CongressLookup:r51646
120120 Merged /branches/REL1_18/extensions/CongressLookup:r101758,103190
121121 Merged /branches/REL1_17/phase3/extensions/CongressLookup:r81445,81448
122122 Merged /trunk/extensions/CongressLookup:r95614,99592,99653,100092,100419,100516,100686,100692,100699,103260,103315,103378,103382,103669,104337,104736,104862-104863,104865,104971,105275,105902,105908,107043,107050,107337,107783,107816,107818,108701,108789,109299-109315

Status & tagging log