MediaWiki
REL1_35
checkBadRedirects.php
Go to the documentation of this file.
1
<?php
24
use
MediaWiki\MediaWikiServices
;
25
use
MediaWiki\Revision\SlotRecord
;
26
27
require_once __DIR__ .
'/Maintenance.php'
;
28
34
class
CheckBadRedirects
extends
Maintenance
{
35
public
function
__construct
() {
36
parent::__construct();
37
$this->
addDescription
(
'Check for bad redirects'
);
38
}
39
40
public
function
execute
() {
41
$this->
output
(
"Fetching redirects...\n"
);
42
$dbr
= $this->
getDB
(
DB_REPLICA
);
43
$result =
$dbr
->select(
44
[
'page'
],
45
[
'page_namespace'
,
'page_title'
,
'page_latest'
],
46
[
'page_is_redirect'
=> 1 ],
47
__METHOD__
48
);
49
50
$count = $result->numRows();
51
$this->
output
(
"Found $count redirects.\n"
.
52
"Checking for bad redirects:\n\n"
);
53
54
$revLookup = MediaWikiServices::getInstance()->getRevisionLookup();
55
foreach
( $result as $row ) {
56
$title
= Title::makeTitle( $row->page_namespace, $row->page_title );
57
$revRecord = $revLookup->getRevisionById( $row->page_latest );
58
if
( $revRecord ) {
59
$target = $revRecord->getContent( SlotRecord::MAIN )->getRedirectTarget();
60
if
( !$target ) {
61
$this->
output
(
$title
->getPrefixedText() .
"\n"
);
62
}
63
}
64
}
65
$this->
output
(
"\nDone.\n"
);
66
}
67
}
68
69
$maintClass
= CheckBadRedirects::class;
70
require_once
RUN_MAINTENANCE_IF_MAIN
;
getDB
getDB()
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition
Maintenance.php:38
$maintClass
$maintClass
Definition
checkBadRedirects.php:69
CheckBadRedirects
Maintenance script to check that pages marked as being redirects really are.
Definition
checkBadRedirects.php:34
CheckBadRedirects\execute
execute()
Do the actual work.
Definition
checkBadRedirects.php:40
CheckBadRedirects\__construct
__construct()
Default constructor.
Definition
checkBadRedirects.php:35
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:55
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:432
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:325
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition
MediaWikiServices.php:152
MediaWiki\Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition
SlotRecord.php:39
DB_REPLICA
const DB_REPLICA
Definition
defines.php:25
$dbr
$dbr
Definition
testCompression.php:54
$title
$title
Definition
testCompression.php:38
maintenance
checkBadRedirects.php
Generated on Sat Apr 6 2024 00:08:22 for MediaWiki by
1.9.8