MediaWiki 1.40.4
checkBadRedirects.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Check for bad redirects' );
39 }
40
41 public function execute() {
42 $this->output( "Fetching redirects...\n" );
43 $dbr = $this->getDB( DB_REPLICA );
44 $result = $dbr->newSelectQueryBuilder()
45 ->select( [ 'page_namespace', 'page_title', 'page_latest' ] )
46 ->from( 'page' )
47 ->where( [ 'page_is_redirect' => 1 ] )
48 ->caller( __METHOD__ )
49 ->fetchResultSet();
50
51 $count = $result->numRows();
52 $this->output( "Found $count redirects.\n" .
53 "Checking for bad redirects:\n\n" );
54
55 $revLookup = MediaWikiServices::getInstance()->getRevisionLookup();
56 foreach ( $result as $row ) {
57 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
58 $revRecord = $revLookup->getRevisionById( $row->page_latest );
59 if ( $revRecord ) {
60 $target = $revRecord->getContent( SlotRecord::MAIN )->getRedirectTarget();
61 if ( !$target ) {
62 $this->output( $title->getPrefixedText() . "\n" );
63 }
64 }
65 }
66 $this->output( "\nDone.\n" );
67 }
68}
69
70$maintClass = CheckBadRedirects::class;
71require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
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.
Service locator for MediaWiki core services.
Value object representing a content slot associated with a page revision.
Represents a title within MediaWiki.
Definition Title.php:82
const DB_REPLICA
Definition defines.php:26