MediaWiki REL1_34
checkBadRedirects.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
32 public function __construct() {
33 parent::__construct();
34 $this->addDescription( 'Check for bad redirects' );
35 }
36
37 public function execute() {
38 $this->output( "Fetching redirects...\n" );
39 $dbr = $this->getDB( DB_REPLICA );
40 $result = $dbr->select(
41 [ 'page' ],
42 [ 'page_namespace', 'page_title', 'page_latest' ],
43 [ 'page_is_redirect' => 1 ] );
44
45 $count = $result->numRows();
46 $this->output( "Found $count redirects.\n" .
47 "Checking for bad redirects:\n\n" );
48
49 foreach ( $result as $row ) {
50 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
51 $rev = Revision::newFromId( $row->page_latest );
52 if ( $rev ) {
53 $target = $rev->getContent()->getRedirectTarget();
54 if ( !$target ) {
55 $this->output( $title->getPrefixedText() . "\n" );
56 }
57 }
58 }
59 $this->output( "\nDone.\n" );
60 }
61}
62
63$maintClass = CheckBadRedirects::class;
64require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
const RUN_MAINTENANCE_IF_MAIN
Maintenance script to check that pages marked as being redirects really are.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition Revision.php:119
const DB_REPLICA
Definition defines.php:25