MediaWiki master
checkBadRedirects.php
Go to the documentation of this file.
1<?php
13
14// @codeCoverageIgnoreStart
15require_once __DIR__ . '/Maintenance.php';
16// @codeCoverageIgnoreEnd
17
24 public function __construct() {
25 parent::__construct();
26 $this->addDescription( 'Check for bad redirects' );
27 }
28
29 public function execute() {
30 $this->output( "Fetching redirects...\n" );
31 $dbr = $this->getReplicaDB();
32 $result = $dbr->newSelectQueryBuilder()
33 ->select( [ 'page_namespace', 'page_title', 'page_latest' ] )
34 ->from( 'page' )
35 ->where( [ 'page_is_redirect' => 1 ] )
36 ->caller( __METHOD__ )
37 ->fetchResultSet();
38
39 $count = $result->numRows();
40 $this->output( "Found $count redirects.\n" .
41 "Checking for bad redirects:\n\n" );
42
43 $revLookup = $this->getServiceContainer()->getRevisionLookup();
44 foreach ( $result as $row ) {
45 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
46 $revRecord = $revLookup->getRevisionById( $row->page_latest );
47 if ( $revRecord ) {
48 $target = $revRecord->getContent( SlotRecord::MAIN )->getRedirectTarget();
49 if ( !$target ) {
50 $this->output( $title->getPrefixedText() . "\n" );
51 }
52 }
53 }
54 $this->output( "\nDone.\n" );
55 }
56}
57
58// @codeCoverageIgnoreStart
59$maintClass = CheckBadRedirects::class;
60require_once RUN_MAINTENANCE_IF_MAIN;
61// @codeCoverageIgnoreEnd
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.
getReplicaDB(string|false $virtualDomain=false)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Value object representing a content slot associated with a page revision.
Represents a title within MediaWiki.
Definition Title.php:69