00001 <?php 00024 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00025 00026 class CheckBadRedirects extends Maintenance { 00027 public function __construct() { 00028 parent::__construct(); 00029 $this->mDescription = "Look for bad redirects"; 00030 } 00031 00032 public function execute() { 00033 $this->output( "Fetching redirects...\n" ); 00034 $dbr = wfGetDB( DB_SLAVE ); 00035 $result = $dbr->select( 00036 array( 'page' ), 00037 array( 'page_namespace','page_title', 'page_latest' ), 00038 array( 'page_is_redirect' => 1 ) ); 00039 00040 $count = $result->numRows(); 00041 $this->output( "Found $count total redirects.\n" . 00042 "Looking for bad redirects:\n\n" ); 00043 00044 foreach( $result as $row ) { 00045 $title = Title::makeTitle( $row->page_namespace, $row->page_title ); 00046 $rev = Revision::newFromId( $row->page_latest ); 00047 if( $rev ) { 00048 $target = Title::newFromRedirect( $rev->getText() ); 00049 if( !$target ) { 00050 $this->output( $title->getPrefixedText() . "\n" ); 00051 } 00052 } 00053 } 00054 $this->output( "\ndone.\n" ); 00055 } 00056 } 00057 00058 $maintClass = "CheckBadRedirects"; 00059 require_once( DO_MAINTENANCE );