MediaWiki  1.34.0
checkBadRedirects.php
Go to the documentation of this file.
1 <?php
24 require_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;
64 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:119
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$dbr
$dbr
Definition: testCompression.php:50
$maintClass
$maintClass
Definition: checkBadRedirects.php:63
$title
$title
Definition: testCompression.php:34
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
CheckBadRedirects\execute
execute()
Do the actual work.
Definition: checkBadRedirects.php:37
CheckBadRedirects
Maintenance script to check that pages marked as being redirects really are.
Definition: checkBadRedirects.php:31
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
CheckBadRedirects\__construct
__construct()
Default constructor.
Definition: checkBadRedirects.php:32