Index: trunk/extensions/CongressLookup/maintenance/checkContacts.php |
— | — | @@ -0,0 +1,57 @@ |
| 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 CheckCongressLinks extends Maintenance { |
| 15 | + public function __construct() { |
| 16 | + $this->mDescription = "Detect bad links in congress contact links."; |
| 17 | + } |
| 18 | + |
| 19 | + public function execute() { |
| 20 | + $db = wfGetDB( DB_SLAVE ); |
| 21 | + |
| 22 | + $this->output( "Checking House contact links...\n" ); |
| 23 | + $res = $db->select( 'cl_house', array( 'clh_name', 'clh_contactform' ) ); |
| 24 | + $countOk = $n = 0; |
| 25 | + foreach ( $res as $row ) { |
| 26 | + if ( ( ++$n % 50 ) == 0 ) { |
| 27 | + sleep( 2 ); // rate-limit |
| 28 | + } |
| 29 | + $this->checkContactLink( $row->clh_name, $row->clh_contactform, $countOk ); |
| 30 | + } |
| 31 | + $this->output( "...{$countOk} OK / {$res->numRows()} Total\n" ); |
| 32 | + |
| 33 | + $this->output( "\n" ); |
| 34 | + |
| 35 | + $this->output( "Checking Senate contact links...\n" ); |
| 36 | + $res = $db->select( 'cl_senate', array( 'cls_name', 'cls_contactform' ) ); |
| 37 | + $countOk = $n = 0; |
| 38 | + foreach ( $res as $row ) { |
| 39 | + if ( ( ++$n % 50 ) == 0 ) { |
| 40 | + sleep( 2 ); // rate-limit |
| 41 | + } |
| 42 | + $this->checkContactLink( $row->cls_name, $row->cls_contactform, $countOk ); |
| 43 | + } |
| 44 | + $this->output( "...{$countOk} OK / {$res->numRows()} Total\n" ); |
| 45 | + } |
| 46 | + |
| 47 | + protected function checkContactLink( $name, $url, &$countOk ) { |
| 48 | + $req = MWHttpRequest::factory( $url, array( 'method' => 'GET', 'timeout' => 6 ) ); |
| 49 | + if ( $req->execute()->isOK() ) { |
| 50 | + ++$countOk; |
| 51 | + } else { |
| 52 | + $this->output( "Broken: [$name] [$url]\n" ); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +$maintClass = "CheckCongressLinks"; |
| 58 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/extensions/CongressLookup/maintenance/checkContacts.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |