30 require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
41 $this->
addOption(
'async',
'Don\'t fix anything directly, just queue the jobs' );
42 $this->
addOption(
'title',
'Fix only redirects pointing to this page',
false,
true );
43 $this->
addOption(
'dry-run',
'Perform a dry run, fix nothing' );
51 $title = Title::newFromText( $this->
getOption(
'title' ) );
52 if ( !$title || !$title->isRedirect() ) {
53 $this->
fatalError( $title->getPrefixedText() .
" is not a redirect!\n" );
63 $queryBuilder = $dbr->newSelectQueryBuilder()
65 'pa.page_namespace AS pa_namespace',
66 'pa.page_title AS pa_title',
67 'pb.page_namespace AS pb_namespace',
68 'pb.page_title AS pb_title',
71 ->join(
'page',
'pa',
'rd_from = pa.page_id' )
72 ->join(
'page',
'pb', [
'rd_namespace = pb.page_namespace',
'rd_title = pb.page_title' ] )
74 ->where( [
'rd_interwiki' => [
null,
'' ],
'pb.page_is_redirect' => 1 ] );
76 if ( $title !=
null ) {
77 $queryBuilder->andWhere( [
78 'pb.page_namespace' => $title->getNamespace(),
79 'pb.page_title' => $title->getDBkey()
82 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
84 if ( !$res->numRows() ) {
85 $this->
output(
"No double redirects found.\n" );
91 $processedTitles =
"\n";
94 foreach ( $res as $row ) {
95 $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
96 $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
97 if ( !$titleA->canExist() || !$titleB->canExist() ) {
98 $this->
error(
"Cannot fix redirect from" .
99 ( $titleA->canExist() ?
"" :
" invalid" ) .
" title " . $titleA->getPrefixedText()
101 ( $titleB->canExist() ?
"" :
" invalid" ) .
" target " . $titleB->getPrefixedText()
107 $processedTitles .=
"* [[$titleA]]\n";
112 'reason' =>
'maintenance',
113 'redirTitle' => $titleB->getPrefixedDBkey()
115 $services->getRevisionLookup(),
116 $services->getMagicWordFactory(),
117 $services->getWikiPageFactory()
123 $this->
error(
"Error fixing " . $titleA->getPrefixedText()
124 .
": " .
$job->getLastError() .
"\n" );
128 if ( count( $jobs ) > DoubleRedirectJob::MAX_DR_JOBS_COUNTER ) {
134 if ( ++$n % 100 == 0 ) {
135 $this->
output(
"$n...\n" );
139 if ( count( $jobs ) ) {
142 $this->
output(
"$n double redirects processed" . $processedTitles .
"\n" );
145 protected function queueJobs( $jobs, $dryrun =
false ) {
146 $this->
output(
"Queuing batch of " . count( $jobs ) .
" double redirects.\n" );
152 require_once RUN_MAINTENANCE_IF_MAIN;
Fix any double redirects after moving a page.
Maintenance script that fixes double redirects.
queueJobs( $jobs, $dryrun=false)
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(count( $args)< 1) $job