Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / checkBadRedirects.php
1 <?php
2 /**
3 * CheckBadRedirects - See if pages marked as being redirects
4 * really are.
5 */
6
7 require_once( "Maintenance.php" );
8
9 class CheckBadRedirects extends Maintenance {
10 public function __construct() {
11 parent::__construct();
12 $this->mDescription = "Look for bad redirects";
13 }
14
15 public function execute() {
16 $this->output( "Fetching redirects...\n" );
17 $dbr = wfGetDB( DB_SLAVE );
18 $result = $dbr->select(
19 array( 'page' ),
20 array( 'page_namespace','page_title', 'page_latest' ),
21 array( 'page_is_redirect' => 1 ) );
22
23 $count = $result->numRows();
24 $this->output( "Found $count total redirects.\n" .
25 "Looking for bad redirects:\n\n" );
26
27 foreach( $result as $row ) {
28 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
29 $rev = Revision::newFromId( $row->page_latest );
30 if( $rev ) {
31 $target = Title::newFromRedirect( $rev->getText() );
32 if( !$target ) {
33 $this->output( $title->getPrefixedText() . "\n" );
34 }
35 }
36 }
37 $this->output( "\ndone.\n" );
38 }
39 }
40
41 $maintClass = "CheckBadRedirects";
42 require_once( DO_MAINTENANCE );