r109309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109308‎ | r109309 | r109310 >
Date:04:55, 18 January 2012
Author:aaron
Status:ok
Tags:
Comment:
Made checkContactLink() handle email addresses better. Also send a user-agent.
Modified paths:
  • /trunk/extensions/CongressLookup/maintenance/checkContacts.php (modified) (history)

Diff [purge]

Index: trunk/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" );

Status & tagging log