MediaWiki REL1_30
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";
64require_once 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...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition Revision.php:116
if(! $regexes) $dbr
Definition cleanup.php:94
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1760
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25